umwd-components 0.1.639 → 0.1.640

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,8 +28,23 @@ import Divider from "@mui/material/Divider";
28
28
  import Card from "@mui/material/Card";
29
29
  import CardContent from "@mui/material/CardContent";
30
30
  import { confirmationService } from "../../../data/services/common/confirmation-service";
31
+ import { cancellationService } from "../../../data/services/common/cancellation-service";
32
+ // TODO this should be futher removed from client side code, reimplement via action ??
31
33
  import { PreReport } from "../../../types/logistics/Report";
32
- import { FormControlLabel, Checkbox } from "@mui/material";
34
+ import {
35
+ FormControlLabel,
36
+ Checkbox,
37
+ List,
38
+ ListItem,
39
+ TextField,
40
+ } from "@mui/material";
41
+ import NumbersIcon from "@mui/icons-material/Numbers";
42
+ import AssignmentReturnIcon from "@mui/icons-material/AssignmentReturn";
43
+ import CalendarTodayIcon from "@mui/icons-material/CalendarToday";
44
+ import BusinessIcon from "@mui/icons-material/Business";
45
+ import DescriptionIcon from "@mui/icons-material/Description";
46
+ import UpdateIcon from "@mui/icons-material/Update";
47
+ import { OpoStatusIndicator } from "./OpoStatusIndicator";
33
48
 
34
49
  const INITIAL_STATE = {
35
50
  zodErrors: null,
@@ -38,76 +53,6 @@ const INITIAL_STATE = {
38
53
  message: null,
39
54
  };
40
55
 
41
- /*
42
- I took away the updateOpoAction and am using the service for confirming directly
43
- There must be a solid explanation for this, but I don't have it right now
44
- something with the confirm-route and the update-route not being the same
45
-
46
- const CONFIRMATION_STATE = {
47
- zodErrors: null,
48
- strapiErrors: null,
49
- data: null,
50
- message: null,
51
- };
52
-
53
- function ConfirmFormDialog({
54
- open,
55
- handleClose,
56
- orderID,
57
- currentStatus,
58
- revalidateCallback,
59
- }: {
60
- open: boolean;
61
- handleClose: () => void;
62
- orderID: number;
63
- currentStatus: "placed" | "external_shipping_process";
64
- revalidateCallback?: () => void;
65
- }) {
66
- const [formState, formAction] = useFormState(
67
- updateOpoAction,
68
- CONFIRMATION_STATE
69
- );
70
-
71
- useEffect(() => {
72
- if (formState?.message === "Opo Updated") {
73
- revalidateCallback && revalidateCallback();
74
- handleClose();
75
- }
76
- }, [formState?.message]);
77
-
78
- return (
79
- <Dialog open={open}>
80
- <form action={formAction}>
81
- <input name="id" type="hidden" value={orderID} />
82
- <input
83
- name="status"
84
- type="hidden"
85
- value={currentStatus === "placed" ? "ordered" : "done"}
86
- />
87
- <DialogTitle>Confirm Order</DialogTitle>
88
- <DialogContent>
89
- <Stack spacing={2}>
90
- <Typography>
91
- Are you sure you want to confirm this order?
92
- </Typography>
93
- <Typography>Current status: {currentStatus}</Typography>
94
- </Stack>
95
- </DialogContent>
96
- <DialogActions>
97
- <SubmitButton text="Confirm" loadingText="Loading..." />
98
- <StrapiErrors error={formState?.strapiErrors} />
99
- {formState?.message && (
100
- <Alert severity="error">{formState?.message}</Alert>
101
- )}
102
- <Button variant="contained" color="secondary" onClick={handleClose}>
103
- Cancel
104
- </Button>
105
- </DialogActions>
106
- </form>
107
- </Dialog>
108
- );
109
- } */
110
-
111
56
  function ConfirmFormDialog({
112
57
  open,
113
58
  handleClose,
@@ -136,18 +81,90 @@ function ConfirmFormDialog({
136
81
  onClick={(e) => {
137
82
  confirmationService("opos", [orderID]);
138
83
  revalidateCallback && revalidateCallback();
84
+ handleClose();
139
85
  }}
140
86
  >
141
- Confirm
87
+ Yes
142
88
  </Button>
143
89
  <Button variant="contained" onClick={handleClose}>
144
- Cancel
90
+ No
145
91
  </Button>
146
92
  </DialogActions>
147
93
  </Dialog>
148
94
  );
149
95
  }
150
96
 
97
+ // TODO
98
+ function CancelOpoDialog({
99
+ open,
100
+ handleClose,
101
+ orderID,
102
+ revalidateCallback,
103
+ }: {
104
+ open: boolean;
105
+ handleClose: () => void;
106
+ orderID: number;
107
+ revalidateCallback?: () => void;
108
+ }) {
109
+ const [reason, setRoason] = useState<string>("");
110
+ const [reasonError, setReasonError] = useState<string>("");
111
+ return (
112
+ <form>
113
+ <Dialog open={open}>
114
+ <DialogTitle>Cancel Return</DialogTitle>
115
+ <DialogContent>
116
+ <Stack spacing={2}>
117
+ <Typography>Are you sure you want to cancel this order?</Typography>
118
+ <List>
119
+ <ListItem>
120
+ By cancelling this order you will update it's status from
121
+ ordered to cancelled
122
+ </ListItem>
123
+ <ListItem>Please provide a reason for the cancellation</ListItem>
124
+ <ListItem>
125
+ The customer will be notified about the cancellation and of the
126
+ reason for the cancellation
127
+ </ListItem>
128
+ </List>
129
+ <TextField
130
+ label="Cancellation reason"
131
+ name="reason"
132
+ multiline
133
+ rows={4}
134
+ fullWidth
135
+ variant="outlined"
136
+ value={reason}
137
+ onChange={(e) => setRoason(e.target.value)}
138
+ placeholder="Please provide a reason for the cancellation"
139
+ error={!!reasonError}
140
+ helperText={reasonError}
141
+ />
142
+ </Stack>
143
+ </DialogContent>
144
+ <DialogActions>
145
+ <Button
146
+ variant="contained"
147
+ onClick={(e) => {
148
+ if (reason.length < 5) {
149
+ setReasonError("Please provide a reason for the cancellation");
150
+ return;
151
+ }
152
+ cancellationService("opos", orderID, reason);
153
+ revalidateCallback && revalidateCallback();
154
+ handleClose();
155
+ }}
156
+ >
157
+ Yes
158
+ </Button>
159
+ <Button variant="contained" onClick={handleClose}>
160
+ No
161
+ </Button>
162
+ </DialogActions>
163
+ </Dialog>
164
+ </form>
165
+ );
166
+ }
167
+
151
168
  export default function TextualManageOPOForm({
152
169
  opo,
153
170
  sx,
@@ -164,6 +181,7 @@ export default function TextualManageOPOForm({
164
181
  );
165
182
 
166
183
  const [confirmDialogOpen, setConfirmDialogOpen] = useState(false);
184
+ const [cancelDialogOpen, setCancelDialogOpen] = useState(false);
167
185
 
168
186
  const [showing, setShowing] = useState<
169
187
  ("picked" | "packed" | "shipped" | "reports")[]
@@ -282,54 +300,91 @@ export default function TextualManageOPOForm({
282
300
  <Divider />
283
301
  </Stack>
284
302
  </Grid>
303
+ <Grid item xs={12}>
304
+ <Typography variant="h5" sx={{ py: 1 }}>
305
+ Details
306
+ </Typography>
307
+ </Grid>
285
308
  <Grid item xs={6}>
286
- <Stack spacing={1}>
287
- <Typography variant="h5">Details</Typography>
288
-
289
- <Stack direction="row" spacing={2}>
290
- <Typography variant="body1" width={"250px"}>
291
- Purchase Order Number
292
- </Typography>
293
- <Typography variant="body2">{opo.opo_number}</Typography>
294
- </Stack>
295
-
296
- <Stack direction="row" spacing={2}>
297
- <Typography variant="body1" width={"250px"}>
298
- Custom reference
299
- </Typography>
300
- <Typography variant="body2">{opo.customer_reference}</Typography>
301
- </Stack>
309
+ <Paper elevation={2} sx={{ p: 2, height: "100%" }}>
310
+ <Stack spacing={2}>
311
+ <Stack direction="row" spacing={2} alignItems="center">
312
+ <NumbersIcon color="primary" />
313
+ <Typography
314
+ variant="subtitle1"
315
+ color="text.secondary"
316
+ width="200px"
317
+ >
318
+ Purchase Order Number
319
+ </Typography>
320
+ <Typography variant="body1" fontWeight="medium">
321
+ {opo.opo_number}
322
+ </Typography>
323
+ </Stack>
302
324
 
303
- <Stack direction="row" spacing={2}>
304
- <Typography variant="body1" width={"250px"}>
305
- Order Date
306
- </Typography>
325
+ <Stack direction="row" spacing={2} alignItems="center">
326
+ <DescriptionIcon color="primary" />
327
+ <Typography
328
+ variant="subtitle1"
329
+ color="text.secondary"
330
+ width="200px"
331
+ >
332
+ Custom reference
333
+ </Typography>
334
+ <Typography variant="body1" fontWeight="medium">
335
+ {opo.customer_reference}
336
+ </Typography>
337
+ </Stack>
307
338
 
308
- <Typography variant="body2">{opo.order_date}</Typography>
309
- </Stack>
339
+ <Stack direction="row" spacing={2} alignItems="center">
340
+ <CalendarTodayIcon color="primary" />
341
+ <Typography
342
+ variant="subtitle1"
343
+ color="text.secondary"
344
+ width="200px"
345
+ >
346
+ Order Date
347
+ </Typography>
348
+ <Typography variant="body1" fontWeight="medium">
349
+ {opo.order_date}
350
+ </Typography>
351
+ </Stack>
310
352
 
311
- <Stack direction="row" spacing={2}>
312
- <Typography variant="body1" width={"250px"}>
313
- Customer
314
- </Typography>
315
- <Typography variant="body2">
316
- {opo.customer?.business_credentials?.company_name}
317
- </Typography>
318
- </Stack>
353
+ <Stack direction="row" spacing={2} alignItems="center">
354
+ <BusinessIcon color="primary" />
355
+ <Typography
356
+ variant="subtitle1"
357
+ color="text.secondary"
358
+ width="200px"
359
+ >
360
+ Customer
361
+ </Typography>
362
+ <Typography variant="body1" fontWeight="medium">
363
+ {opo.customer?.business_credentials?.company_name}
364
+ </Typography>
365
+ </Stack>
319
366
 
320
- <Stack direction="row" spacing={2}>
321
- <Typography variant="body1" width={"250px"}>
322
- Order Status
323
- </Typography>
324
- <Typography variant="body2" width={"250px"}>
325
- {opo.status}
326
- </Typography>
367
+ <Stack direction="row" spacing={2} alignItems="center">
368
+ <UpdateIcon color="primary" />
369
+ <Typography
370
+ variant="subtitle1"
371
+ color="text.secondary"
372
+ width="200px"
373
+ >
374
+ Order Status
375
+ </Typography>
376
+ <OpoStatusIndicator status={opo.status} />
377
+ </Stack>
327
378
  </Stack>
379
+ </Paper>
380
+ </Grid>
328
381
 
329
- {(opo.status === "placed" ||
330
- opo.status === "external_shipping_process") &&
331
- role === "enduser" && (
332
- <>
382
+ {(opo.status === "placed" ||
383
+ opo.status === "external_shipping_process") &&
384
+ role === "enduser" && (
385
+ <Grid item xs={6}>
386
+ <Paper elevation={2} sx={{ p: 2, height: "100%" }}>
387
+ <Stack spacing={2}>
333
388
  <Button
334
389
  variant="contained"
335
390
  color="primary"
@@ -341,6 +396,13 @@ export default function TextualManageOPOForm({
341
396
  Please confirm the order as soon as possible, only upon
342
397
  confirmation this order will be available to the dispatcher
343
398
  </Alert>
399
+ <Button
400
+ variant="contained"
401
+ color="error"
402
+ onClick={() => setCancelDialogOpen(true)}
403
+ >
404
+ Cancel order
405
+ </Button>
344
406
  <ConfirmFormDialog
345
407
  open={confirmDialogOpen}
346
408
  handleClose={() => setConfirmDialogOpen(false)}
@@ -348,10 +410,16 @@ export default function TextualManageOPOForm({
348
410
  currentStatus={opo.status}
349
411
  revalidateCallback={revalidateCallback}
350
412
  />
351
- </>
352
- )}
353
- </Stack>
354
- </Grid>
413
+ <CancelOpoDialog
414
+ open={cancelDialogOpen}
415
+ handleClose={() => setCancelDialogOpen(false)}
416
+ orderID={opo.id}
417
+ revalidateCallback={revalidateCallback}
418
+ />
419
+ </Stack>
420
+ </Paper>
421
+ </Grid>
422
+ )}
355
423
 
356
424
  <Grid item xs={12}>
357
425
  <Stack spacing={2}>
@@ -468,7 +536,10 @@ export default function TextualManageOPOForm({
468
536
  items.map((item: OpoItem, index: number) => {
469
537
  return (
470
538
  <Paper sx={{ p: 2, mb: 2 }} key={index}>
471
- {opo.status === "placed" ? (
539
+ {opo.status === "placed" ||
540
+ opo.status === "external_shipping_process" ||
541
+ opo.status === "done" ||
542
+ opo.status === "cancelled" ? (
472
543
  <OpoItemDisplay
473
544
  item={item}
474
545
  index={index}