umwd-components 0.1.660 → 0.1.661

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.
Files changed (40) hide show
  1. package/.ai/action-patterns.md +170 -0
  2. package/.ai/form-patterns.md +21 -0
  3. package/.ai/instructions/form-patterns.instructions.md +10 -0
  4. package/.ai/prompts/form-patterns.prompt.md +15 -0
  5. package/dist/src/components/e-commerce/enduser/EnduserProfileDisplay.js +7 -0
  6. package/dist/src/components/e-commerce/enduser/EnduserProfileEditForm.js +7 -0
  7. package/dist/src/components/e-commerce/opo/TextualManageOpoForm.js +1 -1
  8. package/dist/src/components/logistics/dispatcher/DispatcherProfileEditForm.js +1 -1
  9. package/dist/src/components/logistics/ipo/AddIPOForm.js +1 -1
  10. package/dist/src/components/logistics/ipo/ManageIPOForm.js +1 -1
  11. package/dist/src/components/logistics/ipo/TextualManageIPOForm.js +1 -1
  12. package/dist/src/data/actions/e-commerce/enduser/profile-actions.js +7 -0
  13. package/dist/src/data/actions/logistics/dispatcher/profile-actions.js +1 -1
  14. package/dist/src/data/actions/logistics/ipo/createIPOAction.js +1 -1
  15. package/dist/src/data/actions/logistics/ipo/updateIpoAction.js +1 -1
  16. package/dist/src/index.js +1 -1
  17. package/dist/tsconfig.build.tsbuildinfo +1 -1
  18. package/dist/types/components/e-commerce/enduser/EnduserProfileDisplay.d.ts +13 -0
  19. package/dist/types/components/e-commerce/enduser/EnduserProfileEditForm.d.ts +9 -0
  20. package/dist/types/components/logistics/ipo/AddIPOForm.d.ts +3 -1
  21. package/dist/types/components/logistics/ipo/TextualManageIPOForm.d.ts +1 -1
  22. package/dist/types/data/actions/e-commerce/enduser/profile-actions.d.ts +1 -0
  23. package/dist/types/data/actions/logistics/dispatcher/profile-actions.d.ts +1 -1
  24. package/dist/types/data/actions/logistics/ipo/updateIpoAction.d.ts +1 -1
  25. package/dist/types/index.d.ts +2 -0
  26. package/dist/types/types/e-commerce/enduser/types.d.ts +14 -0
  27. package/package.json +1 -1
  28. package/src/components/e-commerce/enduser/EnduserProfileDisplay.tsx +100 -0
  29. package/src/components/e-commerce/enduser/EnduserProfileEditForm.tsx +145 -0
  30. package/src/components/e-commerce/opo/TextualManageOpoForm.tsx +0 -1
  31. package/src/components/logistics/dispatcher/DispatcherProfileEditForm.tsx +2 -5
  32. package/src/components/logistics/ipo/AddIPOForm.tsx +58 -21
  33. package/src/components/logistics/ipo/ManageIPOForm.tsx +95 -133
  34. package/src/components/logistics/ipo/TextualManageIPOForm.tsx +165 -118
  35. package/src/data/actions/e-commerce/enduser/profile-actions.ts +47 -0
  36. package/src/data/actions/logistics/dispatcher/profile-actions.ts +6 -8
  37. package/src/data/actions/logistics/ipo/createIPOAction.ts +8 -9
  38. package/src/data/actions/logistics/ipo/updateIpoAction.ts +12 -7
  39. package/src/index.ts +3 -0
  40. package/src/types/e-commerce/enduser/types.ts +15 -0
@@ -0,0 +1,170 @@
1
+ # Action Patterns
2
+
3
+ ## Server Action Parameter Pattern
4
+
5
+ ### Setup
6
+
7
+ 1. Action Definition:
8
+
9
+ ```typescript
10
+ export async function updateEntityAction(
11
+ id: EntityId, // Entity identifier first
12
+ prevState: any, // Form state second
13
+ formData: FormData // Form data last
14
+ ) {
15
+ // action implementation
16
+ }
17
+ ```
18
+
19
+ 2. Form Implementation:
20
+
21
+ ```typescript
22
+ const boundAction = updateEntityAction.bind(null, entityId);
23
+ const [formState, formAction] = useFormState(boundAction, INITIAL_STATE);
24
+ ```
25
+
26
+ ### Implementation Pattern
27
+
28
+ 1. Action Structure:
29
+
30
+ ```typescript
31
+ export async function updateEntityAction(
32
+ id: number,
33
+ prevState: any,
34
+ formData: FormData
35
+ ) {
36
+ // 1. Parse form data if needed
37
+ const parsedData = parseFormData(formData);
38
+
39
+ // 2. Call API or service
40
+ const responseData = await mutateData(
41
+ "PUT",
42
+ `/api/entities/${id}`,
43
+ parsedData
44
+ );
45
+
46
+ // 3. Handle error cases
47
+ if (!responseData) {
48
+ return {
49
+ ...prevState,
50
+ severity: "error",
51
+ strapiErrors: null,
52
+ message: "Operation failed. Please try again.",
53
+ };
54
+ }
55
+
56
+ // 4. Return success result
57
+ return {
58
+ ...prevState,
59
+ severity: "success",
60
+ message: "Operation completed successfully",
61
+ data: responseData,
62
+ strapiErrors: null,
63
+ };
64
+ }
65
+ ```
66
+
67
+ ### Key Features
68
+
69
+ 1. **Parameter Order by Action Type**:
70
+
71
+ For Update Actions:
72
+
73
+ - Entity identifiers come first (id, uuid, etc.)
74
+ - prevState is always second
75
+ - formData is always last
76
+
77
+ For Create Actions:
78
+
79
+ - prevState is always first
80
+ - formData is always second
81
+ - No entity identifiers needed
82
+
83
+ 2. **Action Binding**:
84
+
85
+ - Only used for update operations on specific entities
86
+ - Use Function.bind() to pre-fill entity parameters
87
+ - Bind with null as first argument
88
+ - Not needed for creation actions
89
+
90
+ 3. **Response Structure**:
91
+
92
+ ```typescript
93
+ {
94
+ ...prevState, // Always preserve previous state
95
+ severity: string, // "success" | "error"
96
+ message: string, // User-friendly message
97
+ data?: any, // Optional updated entity data
98
+ strapiErrors?: any // Optional Strapi error details
99
+ }
100
+ ```
101
+
102
+ ### Best Practices
103
+
104
+ 1. **Error Handling**:
105
+
106
+ - Always return prevState spread first
107
+ - Include user-friendly error messages
108
+ - Provide appropriate severity levels
109
+ - Handle API errors consistently
110
+
111
+ 2. **Success Handling**:
112
+
113
+ - Return updated data when available
114
+ - Clear error states on success
115
+ - Set appropriate success message
116
+ - Use "success" severity
117
+
118
+ 3. **Code Organization**:
119
+
120
+ - Group related actions in feature folders
121
+ - Use consistent file naming (e.g., updateEntityAction.ts)
122
+ - Export actions as named exports
123
+ - Include proper TypeScript types
124
+
125
+ ## Server Action Types
126
+
127
+ ### 1. Entity Update Actions
128
+
129
+ These actions modify an existing entity and therefore require the entity ID as
130
+ the first parameter.
131
+
132
+ 1. Action Definition:
133
+
134
+ ```typescript
135
+ export async function updateEntityAction(
136
+ id: EntityId, // Entity identifier first
137
+ prevState: any, // Form state second
138
+ formData: FormData // Form data last
139
+ ) {
140
+ // action implementation
141
+ }
142
+ ```
143
+
144
+ 2. Form Implementation:
145
+
146
+ ```typescript
147
+ const boundAction = updateEntityAction.bind(null, entityId);
148
+ const [formState, formAction] = useFormState(boundAction, INITIAL_STATE);
149
+ ```
150
+
151
+ ### 2. Entity Creation Actions
152
+
153
+ These actions create new entities and don't require pre-bound parameters.
154
+
155
+ 1. Action Definition:
156
+
157
+ ```typescript
158
+ export async function createEntityAction(
159
+ prevState: any, // Form state first
160
+ formData: FormData // Form data second
161
+ ) {
162
+ // action implementation
163
+ }
164
+ ```
165
+
166
+ 2. Form Implementation:
167
+
168
+ ```typescript
169
+ const [formState, formAction] = useFormState(createEntityAction, INITIAL_STATE);
170
+ ```
@@ -132,6 +132,27 @@ styling:
132
132
  - Remove StrapiErrors component as errors are shown in Snackbar
133
133
  - Success messages automatically close the form and revalidate data
134
134
 
135
+ ### Form Action Setup
136
+
137
+ 1. Action Binding Pattern:
138
+
139
+ ```typescript
140
+ // For actions that require an ID or other parameters
141
+ const boundAction = actionFunction.bind(null, entityId);
142
+ const [formState, formAction] = useFormState(boundAction, INITIAL_STATE);
143
+
144
+ // Example with type:
145
+ const updateEntityWithIdAction = updateEntityAction.bind(null, entity.id);
146
+ const [formState, formAction] = useFormState(updateEntityWithIdAction, INITIAL_STATE);
147
+ ```
148
+
149
+ This pattern ensures:
150
+
151
+ - Clean separation of entity ID from form data
152
+ - Consistent action parameter order
153
+ - Type safety for bound parameters
154
+ - Clear distinction between entity parameters and form data
155
+
135
156
  ### Example Usage
136
157
 
137
158
  ```typescript
@@ -36,6 +36,16 @@ const INITIAL_STATE = {
36
36
  };
37
37
  ```
38
38
 
39
+ 4. Setup form action binding:
40
+
41
+ ```typescript
42
+ // For forms that operate on an entity
43
+ const boundAction = actionFunction.bind(null, entity.id);
44
+ const [formState, formAction] = useFormState(boundAction, INITIAL_STATE);
45
+ ```
46
+
47
+ Note: Always bind entity IDs and other fixed parameters to the action, rather than including them in the form data.
48
+
39
49
  ## Required Form Structure
40
50
 
41
51
  1. **Base Structure**:
@@ -31,6 +31,7 @@ are followed:
31
31
  - Verify INITIAL_STATE includes all required fields
32
32
  - Check useFormState implementation
33
33
  - Validate form action setup
34
+ - Ensure entity IDs are bound to action using bind pattern
34
35
 
35
36
  2. **Message Handling**
36
37
 
@@ -99,6 +100,20 @@ handleAddMessage({
99
100
  </Stack>
100
101
  ```
101
102
 
103
+ 4. **Action Binding Fixes**
104
+
105
+ ```typescript
106
+ // Convert from
107
+ const [formState, formAction] = useFormState(
108
+ (prevState, formData) => updateAction(id, prevState, formData),
109
+ INITIAL_STATE
110
+ );
111
+
112
+ // To
113
+ const boundAction = updateAction.bind(null, id);
114
+ const [formState, formAction] = useFormState(boundAction, INITIAL_STATE);
115
+ ```
116
+
102
117
  ### Response Guidelines
103
118
 
104
119
  When helping users with forms:
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ /*
3
+ * UMWD-Components
4
+ * @copyright Jelle Paulus
5
+ * @license MIT
6
+ */
7
+ import e from"react";import t from"@mui/material/Paper";import r from"@mui/material/Stack";import a from"@mui/material/Typography";import i from"@mui/material/Button";import m from"@mui/material/Divider";import n from"@mui/material/Grid";import o from"@mui/material/Alert";import l from"../../common/Address.js";import s from"../customer/BusinessCredentials.js";import{StyledLink as c}from"../../StyledLink.js";import{usePathname as d}from"next/navigation";function u(u){var p=u.data,f=p.private_address,E=p.company_address,v=p.business_credentials,y=p.editProfileUrl,g=void 0===y?"/dashboard/enduser/user/profile/edit":y,h=p.completeEnough,x=void 0!==h&&h,b=d().includes("/user/");return e.createElement(t,{sx:{p:2}},e.createElement(r,{spacing:2},b&&e.createElement(e.Fragment,null,Boolean(x)?e.createElement(r,{direction:"row",justifyContent:"flex-end"},e.createElement(c,{href:g,target:"_self"},e.createElement(i,{variant:"contained"},"edit profile"))):e.createElement(o,{severity:"warning",action:e.createElement(c,{href:g,target:"_self"},e.createElement(i,{variant:"contained"},"complete profile"))},"After completion of your profile you can enjoy all the benefits of your services.")),v?e.createElement(s,{data:v}):e.createElement(a,null,"Business credentials not available"),e.createElement(m,null)," ",e.createElement(n,{container:!0,spacing:2,sx:{width:"100%"}},e.createElement(n,{item:!0,xs:12,md:6},e.createElement(a,{variant:"h6",gutterBottom:!0},"Company Address"),E?e.createElement(l,{data:E}):e.createElement(a,null,"Company address not available")),e.createElement(n,{item:!0,xs:12,md:6},e.createElement(a,{variant:"h6",gutterBottom:!0},"Private Address"),f?e.createElement(l,{data:f}):e.createElement(a,null,"Private address not available")))))}export{u as default};
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ /*
3
+ * UMWD-Components
4
+ * @copyright Jelle Paulus
5
+ * @license MIT
6
+ */
7
+ import{__read as e,__spreadArray as t}from"../../../../node_modules/tslib/tslib.es6.js";import r from"@mui/material/Divider";import a from"@mui/material/Paper";import m from"@mui/material/Box";import n from"@mui/material/Stack";import s from"@mui/material/Grid";import o from"@mui/material/Button";import i from"@mui/material/Typography";import{AddressFields as l}from"../../common/Address.js";import{BusinessCredentialsFields as c}from"../customer/BusinessCredentials.js";import{SubmitButton as d}from"../../SubmitButton.js";import{useFormState as p}from"react-dom";import{updateEnduserProfileAction as u}from"../../../data/actions/e-commerce/enduser/profile-actions.js";import{useSession as E}from"../../../context/auth/SessionContext.js";import{useSnackbar as f}from"../../../context/common/SnackbarContext.js";import v,{useEffect as x}from"react";var g={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function b(b){var y=b.data,h=b.sx,C=b.revalidateCallback,B=b.handleClose,j=y.id,S=y.private_address,_=y.company_address,A=y.business_credentials,k=u.bind(null,parseInt(j)),N=e(p(k,g),2),P=N[0],R=N[1],w=f().handleAddMessage,I=E().refreshSession;return x((function(){(null==P?void 0:P.message)&&(w({message:P.message,severity:P.severity||"error"}),"success"===P.severity&&(I(),C&&C(),B&&B()))}),[null==P?void 0:P.message]),x((function(){(null==P?void 0:P.strapiErrors)&&w({message:P.strapiErrors.message||"Error performing action",severity:"error"})}),[null==P?void 0:P.strapiErrors]),v.createElement(m,{sx:t([],e(Array.isArray(h)?h:[h]),!1)},v.createElement("form",{action:R},v.createElement(s,{container:!0,spacing:2},v.createElement(s,{item:!0,xs:12},v.createElement(n,{spacing:2},v.createElement(i,{variant:"h3",component:"h1",gutterBottom:!0},"Edit Profile"))),v.createElement(s,{item:!0,xs:12},v.createElement(a,{sx:{p:2}},v.createElement(i,{variant:"h6",gutterBottom:!0},"Business Credentials"),v.createElement(r,{sx:{mb:2}}),v.createElement(c,{componentName:"business_credentials",componentReference:"business.credentials",data:A})))," ",v.createElement(s,{item:!0,xs:12},v.createElement(a,{sx:{p:2}},v.createElement(i,{variant:"h6",gutterBottom:!0},"Company Address"),v.createElement(r,{sx:{mb:2}}),v.createElement(l,{componentName:"company_address",componentReference:"common.address",data:_}))),v.createElement(s,{item:!0,xs:12},v.createElement(a,{sx:{p:2}},v.createElement(i,{variant:"h6",gutterBottom:!0},"Private Address"),v.createElement(r,{sx:{mb:2}}),v.createElement(l,{componentName:"private_address",componentReference:"common.address",data:S}))),v.createElement(s,{item:!0,xs:12},v.createElement(n,{direction:"row",justifyContent:"space-between",spacing:2,alignItems:"center",sx:{mt:2}},B&&v.createElement(o,{onClick:B,variant:"outlined"},"Cancel"),v.createElement(d,{text:"Save Changes",loadingText:"Saving...",variant:"contained"}))))))}export{b as default};
@@ -3,4 +3,4 @@
3
3
  * @copyright Jelle Paulus
4
4
  * @license MIT
5
5
  */
6
- import{__read as e,__spreadArray as t,__assign as n}from"../../../../node_modules/tslib/tslib.es6.js";import r,{useState as a,useEffect as i}from"react";import{useFormState as o}from"react-dom";import{updateOpoAction as l}from"../../../data/actions/e-commerce/opo/updateOpoAction.js";import{UploadBase64MediaForm as c}from"../../common/media/UploadBase64MediaForm.js";import m from"../../../data/loaders/common/media/downloadBase64File.js";import s from"./TextualOpoItemUpdater.js";import d from"./OpoItemDisplay.js";import u from"../../logistics/note/NotesDisplay.js";import p from"../../logistics/note/NoteTakingComponent.js";import v from"@mui/material/Alert";import E from"@mui/material/Dialog";import f from"@mui/material/DialogActions";import g from"@mui/material/DialogContent";import h from"@mui/material/DialogTitle";import y from"@mui/material/Typography";import x from"@mui/material/Button";import b from"@mui/material/Grid";import C from"@mui/material/Box";import k from"@mui/material/Paper";import _ from"@mui/material/Stack";import w from"@mui/material/Divider";import{confirmationService as I}from"../../../data/services/common/confirmation-service.js";import{cancellationService as D}from"../../../data/services/common/cancellation-service.js";import{FormControlLabel as j,Checkbox as O,List as A,ListItem as N,TextField as q}from"@mui/material";import S from"@mui/icons-material/Numbers";import B from"@mui/icons-material/CalendarToday";import P from"@mui/icons-material/Business";import T from"@mui/icons-material/Description";import F from"@mui/icons-material/Update";import{OpoStatusIndicator as U}from"./OpoStatusIndicator.js";import{useSnackbar as R}from"../../../context/common/SnackbarContext.js";import{SubmitButton as W}from"../../SubmitButton.js";var M={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null},Y=["picked","packed","shipped","reports"];function z(e){var t=e.open,n=e.handleClose,a=e.orderID,i=e.currentStatus,o=e.revalidateCallback;return r.createElement(E,{open:t},r.createElement(h,null,"Confirm Order"),r.createElement(g,null,r.createElement(_,{spacing:2},r.createElement(y,null,"Are you sure you want to confirm this order?"),r.createElement(y,null,"Current status: ",i))),r.createElement(f,null,r.createElement(x,{variant:"contained",onClick:function(e){I("opos",[a]),o&&o(),n()}},"Yes"),r.createElement(x,{variant:"contained",onClick:n},"No")))}function G(t){var n=t.open,i=t.handleClose,o=t.orderID,l=t.revalidateCallback,c=e(a(""),2),m=c[0],s=c[1],d=e(a(""),2),u=d[0],p=d[1];return r.createElement("form",null,r.createElement(E,{open:n},r.createElement(h,null,"Cancel Return"),r.createElement(g,null,r.createElement(_,{spacing:2},r.createElement(y,null,"Are you sure you want to cancel this order?"),r.createElement(A,null,r.createElement(N,null,"By cancelling this order you will update it's status from ordered to cancelled"),r.createElement(N,null,"Please provide a reason for the cancellation"),r.createElement(N,null,"The customer will be notified about the cancellation and of the reason for the cancellation")),r.createElement(q,{label:"Cancellation reason",name:"reason",multiline:!0,rows:4,fullWidth:!0,variant:"outlined",value:m,onChange:function(e){return s(e.target.value)},placeholder:"Please provide a reason for the cancellation",error:!!u,helperText:u}))),r.createElement(f,null,r.createElement(x,{variant:"contained",onClick:function(e){m.length<5?p("Please provide a reason for the cancellation"):(D("opos",o,m),l&&l(),i())}},"Yes"),r.createElement(x,{variant:"contained",onClick:i},"No"))))}function H(E){var f,g,h,I,D,A=E.opo,N=E.sx,q=E.revalidateCallback,H=E.handleClose,J=E.role,Q=l.bind(null,A.id),K=e(o(Q,M),2),L=K[0],V=K[1],X=R().handleAddMessage,Z=e(a(A.opo_items.data?A.opo_items.data:[]),2),$=Z[0],ee=Z[1],te=e(a(!1),2),ne=te[0],re=te[1],ae=e(a(!1),2),ie=ae[0],oe=ae[1],le=e(a(["picked","packed","shipped","reports"]),2),ce=le[0],me=le[1];i((function(){(null==L?void 0:L.message)&&(X({message:L.message,severity:L.severity||"info"}),"success"===L.severity&&(null==q||q(),null==H||H()))}),[null==L?void 0:L.message]),i((function(){(null==L?void 0:L.strapiErrors)&&X({message:L.strapiErrors.message||"Error updating OPO",severity:"error"})}),[null==L?void 0:L.strapiErrors]),i((function(){var e;(null===(e=A.opo_items)||void 0===e?void 0:e.data)&&ee(A.opo_items.data?A.opo_items.data:[])}),[A]);var se=function(n,r,a){var i=t([],e($),!1),o=i.findIndex((function(e){return e.id===r}));i[o][a]=n,ee(i)},de=function(r,a){var i,o,l,c=t([],e($),!1),m=c.findIndex((function(e){return e.id===a})),s=(null===(o=null===(i=c[m])||void 0===i?void 0:i.reports)||void 0===o?void 0:o.data)||[],d=t(t([],e(s),!1),[r],!1);null==(null===(l=c[m])||void 0===l?void 0:l.reports)&&(c[m]=n(n({},c[m]),{reports:{data:[]}})),c[m].reports.data=d,ee(c)},ue=function(n,r){var a,i,o=t([],e($),!1),l=o.findIndex((function(e){return e.id===n})),c=(null===(i=null===(a=o[l])||void 0===a?void 0:a.reports)||void 0===i?void 0:i.data)||[],m=c.filter((function(e){return"id"in e})),s=c.filter((function(e){return!("id"in e)}));s.splice(r,1);var d=t(t([],e(m),!1),e(s),!1);o[l].reports.data=d,ee(o)};return r.createElement(C,{sx:t([],e(Array.isArray(N)?N:[N]),!1)},r.createElement(b,{container:!0,spacing:2},r.createElement(b,{item:!0,xs:12},r.createElement(_,{spacing:2},r.createElement(_,{direction:"row",spacing:2,justifyContent:"space-between"},r.createElement(_,{spacing:2},r.createElement(y,{variant:"h3",component:"h1"},"Management Outbound Purchase Order"),r.createElement(y,{variant:"body1"},"Manage picking, packing and shipping of purchase order")),r.createElement(p,{content:"",related:[{id:A.id,__type:"api::e-commerce.opo"}],revalidateCallback:q})),r.createElement(w,null))),r.createElement(b,{item:!0,xs:12},r.createElement(y,{variant:"h5",sx:{py:1}},"Details")),r.createElement(b,{item:!0,xs:6},r.createElement(k,{elevation:2,sx:{p:2,height:"100%"}},r.createElement(_,{spacing:2},r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(S,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Purchase Order Number"),r.createElement(y,{variant:"body1",fontWeight:"medium"},A.opo_number)),r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(T,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Custom reference"),r.createElement(y,{variant:"body1",fontWeight:"medium"},A.customer_reference)),r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(B,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Order Date"),r.createElement(y,{variant:"body1",fontWeight:"medium"},A.order_date)),r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(P,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Customer"),r.createElement(y,{variant:"body1",fontWeight:"medium"},null===(g=null===(f=A.customer)||void 0===f?void 0:f.business_credentials)||void 0===g?void 0:g.company_name)),r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(F,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Order Status"),r.createElement(U,{status:A.status}))))),"enduser"===J&&r.createElement(b,{item:!0,xs:6},r.createElement(k,{elevation:2,sx:{p:2,height:"100%"}},r.createElement(_,{spacing:2},("placed"===A.status||"external_shipping_process"===A.status)&&r.createElement(r.Fragment,null,r.createElement(x,{variant:"contained",color:"primary",onClick:function(){return re(!0)}},"Confirm order"),r.createElement(v,{severity:"warning"},"Please confirm the order as soon as possible, only upon confirmation this order will be available to the dispatcher"),r.createElement(z,{open:ne,handleClose:function(){return re(!1)},orderID:A.id,currentStatus:A.status,revalidateCallback:q})),("placed"===A.status||"ordered"===A.status)&&r.createElement(r.Fragment,null,r.createElement(x,{variant:"contained",color:"error",onClick:function(){return oe(!0)}},"Cancel order"),r.createElement(G,{open:ie,handleClose:function(){return oe(!1)},orderID:A.id,revalidateCallback:q}))))),r.createElement(b,{item:!0,xs:12},r.createElement(_,{spacing:2},r.createElement(y,{variant:"h5"},"Documents"),r.createElement(k,{sx:{p:2}},r.createElement(_,{spacing:1},A.delivery_note?r.createElement(r.Fragment,null,r.createElement(y,{variant:"h6"},"Delivery Note"),r.createElement(y,null,null===(h=A.delivery_note)||void 0===h?void 0:h.name),r.createElement(x,{variant:"contained",onClick:function(){m("api/ipos/".concat(A.id),"delivery_note")}},"Download")):r.createElement(r.Fragment,null,r.createElement(y,{variant:"h5"},"Delivery Note"),r.createElement(y,{variant:"body1"},"Here you can upload the the delivery note for this order"),r.createElement(w,null),r.createElement(c,{reference:"api::e-commerce.opo",refID:A.id,field:"delivery_note",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"delivery_note",componentReference:"common.base64-encoded-media",revalidateCallback:q})))))),(null===(D=null===(I=null==A?void 0:A.notes)||void 0===I?void 0:I.data)||void 0===D?void 0:D.length)>0&&r.createElement(b,{item:!0,xs:12},r.createElement(_,{spacing:2},r.createElement(y,{variant:"h5"},"Notes"),r.createElement(u,{notes:A.notes.data}),r.createElement(w,null))),r.createElement(b,{item:!0,xs:12},r.createElement(_,{spacing:1},r.createElement(y,{variant:"h5"},"Items"),r.createElement(_,{direction:"row",alignItems:"center",justifyContent:"flex-end",spacing:2,component:k,p:1},r.createElement(y,{variant:"body1"},"Show:"),Y.map((function(n){return r.createElement(j,{key:n,control:r.createElement(O,{checked:ce.includes(n),onChange:function(r){r.target.checked?me(t(t([],e(ce),!1),[n],!1)):me(ce.filter((function(e){return e!==n})))}}),label:n.charAt(0).toUpperCase()+n.slice(1)})}))),"placed"===A.status&&r.createElement(v,{severity:"warning"},"Before confirmation you cannot update the items"),r.createElement(w,null),r.createElement("form",{action:V},r.createElement("input",{name:"id",type:"hidden",value:A.id}),r.createElement("input",{type:"hidden",name:"items",value:JSON.stringify(function(e){return e.map((function(e){var t,n;return{id:e.id,ordered_quantity:e.ordered_quantity,picked_quantity:e.picked_quantity,packed_quantity:e.packed_quantity,shipped_quantity:e.shipped_quantity,reports:(null===(n=null===(t=e.reports)||void 0===t?void 0:t.data)||void 0===n?void 0:n.map((function(e){return{id:"id"in e?e.id:void 0,quantity:e.quantity,content:e.content,type:e.type}})))||[]}}))}($))}),$&&$.map((function(e,t){var n,a;return r.createElement(k,{sx:{p:2,mb:2},key:t},"placed"===A.status||"external_shipping_process"===A.status||"done"===A.status||"cancelled"===A.status?r.createElement(d,{item:e,index:t,image:null===(n=null==e?void 0:e.product)||void 0===n?void 0:n.image}):r.createElement(s,{item:e,index:t,handleUpdateQuantity:se,handleAddReport:de,image:null===(a=null==e?void 0:e.product)||void 0===a?void 0:a.image,handleRemoveReportAtIndex:ue,revalidateCallback:q,showing:ce}))}))," ",r.createElement(_,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{pt:2}},H&&r.createElement(x,{onClick:H,variant:"outlined"},"Cancel"),r.createElement(W,{text:"Update items",loadingText:"Saving...",variant:"contained"})))))))}export{H as default};
6
+ import{__read as e,__spreadArray as t,__assign as n}from"../../../../node_modules/tslib/tslib.es6.js";import r,{useState as a,useEffect as i}from"react";import{useFormState as o}from"react-dom";import{updateOpoAction as l}from"../../../data/actions/e-commerce/opo/updateOpoAction.js";import{UploadBase64MediaForm as c}from"../../common/media/UploadBase64MediaForm.js";import m from"../../../data/loaders/common/media/downloadBase64File.js";import s from"./TextualOpoItemUpdater.js";import d from"./OpoItemDisplay.js";import u from"../../logistics/note/NotesDisplay.js";import p from"../../logistics/note/NoteTakingComponent.js";import v from"@mui/material/Alert";import E from"@mui/material/Dialog";import f from"@mui/material/DialogActions";import g from"@mui/material/DialogContent";import h from"@mui/material/DialogTitle";import y from"@mui/material/Typography";import x from"@mui/material/Button";import b from"@mui/material/Grid";import C from"@mui/material/Box";import k from"@mui/material/Paper";import _ from"@mui/material/Stack";import w from"@mui/material/Divider";import{confirmationService as I}from"../../../data/services/common/confirmation-service.js";import{cancellationService as D}from"../../../data/services/common/cancellation-service.js";import{FormControlLabel as j,Checkbox as O,List as A,ListItem as N,TextField as q}from"@mui/material";import S from"@mui/icons-material/Numbers";import B from"@mui/icons-material/CalendarToday";import P from"@mui/icons-material/Business";import T from"@mui/icons-material/Description";import F from"@mui/icons-material/Update";import{OpoStatusIndicator as U}from"./OpoStatusIndicator.js";import{useSnackbar as R}from"../../../context/common/SnackbarContext.js";import{SubmitButton as W}from"../../SubmitButton.js";var M={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null},Y=["picked","packed","shipped","reports"];function z(e){var t=e.open,n=e.handleClose,a=e.orderID,i=e.currentStatus,o=e.revalidateCallback;return r.createElement(E,{open:t},r.createElement(h,null,"Confirm Order"),r.createElement(g,null,r.createElement(_,{spacing:2},r.createElement(y,null,"Are you sure you want to confirm this order?"),r.createElement(y,null,"Current status: ",i))),r.createElement(f,null,r.createElement(x,{variant:"contained",onClick:function(e){I("opos",[a]),o&&o(),n()}},"Yes"),r.createElement(x,{variant:"contained",onClick:n},"No")))}function G(t){var n=t.open,i=t.handleClose,o=t.orderID,l=t.revalidateCallback,c=e(a(""),2),m=c[0],s=c[1],d=e(a(""),2),u=d[0],p=d[1];return r.createElement("form",null,r.createElement(E,{open:n},r.createElement(h,null,"Cancel Return"),r.createElement(g,null,r.createElement(_,{spacing:2},r.createElement(y,null,"Are you sure you want to cancel this order?"),r.createElement(A,null,r.createElement(N,null,"By cancelling this order you will update it's status from ordered to cancelled"),r.createElement(N,null,"Please provide a reason for the cancellation"),r.createElement(N,null,"The customer will be notified about the cancellation and of the reason for the cancellation")),r.createElement(q,{label:"Cancellation reason",name:"reason",multiline:!0,rows:4,fullWidth:!0,variant:"outlined",value:m,onChange:function(e){return s(e.target.value)},placeholder:"Please provide a reason for the cancellation",error:!!u,helperText:u}))),r.createElement(f,null,r.createElement(x,{variant:"contained",onClick:function(e){m.length<5?p("Please provide a reason for the cancellation"):(D("opos",o,m),l&&l(),i())}},"Yes"),r.createElement(x,{variant:"contained",onClick:i},"No"))))}function H(E){var f,g,h,I,D,A=E.opo,N=E.sx,q=E.revalidateCallback,H=E.handleClose,J=E.role,Q=l.bind(null,A.id),K=e(o(Q,M),2),L=K[0],V=K[1],X=R().handleAddMessage,Z=e(a(A.opo_items.data?A.opo_items.data:[]),2),$=Z[0],ee=Z[1],te=e(a(!1),2),ne=te[0],re=te[1],ae=e(a(!1),2),ie=ae[0],oe=ae[1],le=e(a(["picked","packed","shipped","reports"]),2),ce=le[0],me=le[1];i((function(){(null==L?void 0:L.message)&&(X({message:L.message,severity:L.severity||"info"}),"success"===L.severity&&(null==q||q(),null==H||H()))}),[null==L?void 0:L.message]),i((function(){(null==L?void 0:L.strapiErrors)&&X({message:L.strapiErrors.message||"Error updating OPO",severity:"error"})}),[null==L?void 0:L.strapiErrors]),i((function(){var e;(null===(e=A.opo_items)||void 0===e?void 0:e.data)&&ee(A.opo_items.data?A.opo_items.data:[])}),[A]);var se=function(n,r,a){var i=t([],e($),!1),o=i.findIndex((function(e){return e.id===r}));i[o][a]=n,ee(i)},de=function(r,a){var i,o,l,c=t([],e($),!1),m=c.findIndex((function(e){return e.id===a})),s=(null===(o=null===(i=c[m])||void 0===i?void 0:i.reports)||void 0===o?void 0:o.data)||[],d=t(t([],e(s),!1),[r],!1);null==(null===(l=c[m])||void 0===l?void 0:l.reports)&&(c[m]=n(n({},c[m]),{reports:{data:[]}})),c[m].reports.data=d,ee(c)},ue=function(n,r){var a,i,o=t([],e($),!1),l=o.findIndex((function(e){return e.id===n})),c=(null===(i=null===(a=o[l])||void 0===a?void 0:a.reports)||void 0===i?void 0:i.data)||[],m=c.filter((function(e){return"id"in e})),s=c.filter((function(e){return!("id"in e)}));s.splice(r,1);var d=t(t([],e(m),!1),e(s),!1);o[l].reports.data=d,ee(o)};return r.createElement(C,{sx:t([],e(Array.isArray(N)?N:[N]),!1)},r.createElement(b,{container:!0,spacing:2},r.createElement(b,{item:!0,xs:12},r.createElement(_,{spacing:2},r.createElement(_,{direction:"row",spacing:2,justifyContent:"space-between"},r.createElement(_,{spacing:2},r.createElement(y,{variant:"h3",component:"h1"},"Management Outbound Purchase Order"),r.createElement(y,{variant:"body1"},"Manage picking, packing and shipping of purchase order")),r.createElement(p,{content:"",related:[{id:A.id,__type:"api::e-commerce.opo"}],revalidateCallback:q})),r.createElement(w,null))),r.createElement(b,{item:!0,xs:12},r.createElement(y,{variant:"h5",sx:{py:1}},"Details")),r.createElement(b,{item:!0,xs:6},r.createElement(k,{elevation:2,sx:{p:2,height:"100%"}},r.createElement(_,{spacing:2},r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(S,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Purchase Order Number"),r.createElement(y,{variant:"body1",fontWeight:"medium"},A.opo_number)),r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(T,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Custom reference"),r.createElement(y,{variant:"body1",fontWeight:"medium"},A.customer_reference)),r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(B,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Order Date"),r.createElement(y,{variant:"body1",fontWeight:"medium"},A.order_date)),r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(P,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Customer"),r.createElement(y,{variant:"body1",fontWeight:"medium"},null===(g=null===(f=A.customer)||void 0===f?void 0:f.business_credentials)||void 0===g?void 0:g.company_name)),r.createElement(_,{direction:"row",spacing:2,alignItems:"center"},r.createElement(F,{color:"primary"}),r.createElement(y,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Order Status"),r.createElement(U,{status:A.status}))))),"enduser"===J&&r.createElement(b,{item:!0,xs:6},r.createElement(k,{elevation:2,sx:{p:2,height:"100%"}},r.createElement(_,{spacing:2},("placed"===A.status||"external_shipping_process"===A.status)&&r.createElement(r.Fragment,null,r.createElement(x,{variant:"contained",color:"primary",onClick:function(){return re(!0)}},"Confirm order"),r.createElement(v,{severity:"warning"},"Please confirm the order as soon as possible, only upon confirmation this order will be available to the dispatcher"),r.createElement(z,{open:ne,handleClose:function(){return re(!1)},orderID:A.id,currentStatus:A.status,revalidateCallback:q})),("placed"===A.status||"ordered"===A.status)&&r.createElement(r.Fragment,null,r.createElement(x,{variant:"contained",color:"error",onClick:function(){return oe(!0)}},"Cancel order"),r.createElement(G,{open:ie,handleClose:function(){return oe(!1)},orderID:A.id,revalidateCallback:q}))))),r.createElement(b,{item:!0,xs:12},r.createElement(_,{spacing:2},r.createElement(y,{variant:"h5"},"Documents"),r.createElement(k,{sx:{p:2}},r.createElement(_,{spacing:1},A.delivery_note?r.createElement(r.Fragment,null,r.createElement(y,{variant:"h6"},"Delivery Note"),r.createElement(y,null,null===(h=A.delivery_note)||void 0===h?void 0:h.name),r.createElement(x,{variant:"contained",onClick:function(){m("api/ipos/".concat(A.id),"delivery_note")}},"Download")):r.createElement(r.Fragment,null,r.createElement(y,{variant:"h5"},"Delivery Note"),r.createElement(y,{variant:"body1"},"Here you can upload the the delivery note for this order"),r.createElement(w,null),r.createElement(c,{reference:"api::e-commerce.opo",refID:A.id,field:"delivery_note",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"delivery_note",componentReference:"common.base64-encoded-media",revalidateCallback:q})))))),(null===(D=null===(I=null==A?void 0:A.notes)||void 0===I?void 0:I.data)||void 0===D?void 0:D.length)>0&&r.createElement(b,{item:!0,xs:12},r.createElement(_,{spacing:2},r.createElement(y,{variant:"h5"},"Notes"),r.createElement(u,{notes:A.notes.data}),r.createElement(w,null))),r.createElement(b,{item:!0,xs:12},r.createElement(_,{spacing:1},r.createElement(y,{variant:"h5"},"Items"),r.createElement(_,{direction:"row",alignItems:"center",justifyContent:"flex-end",spacing:2,component:k,p:1},r.createElement(y,{variant:"body1"},"Show:"),Y.map((function(n){return r.createElement(j,{key:n,control:r.createElement(O,{checked:ce.includes(n),onChange:function(r){r.target.checked?me(t(t([],e(ce),!1),[n],!1)):me(ce.filter((function(e){return e!==n})))}}),label:n.charAt(0).toUpperCase()+n.slice(1)})}))),"placed"===A.status&&r.createElement(v,{severity:"warning"},"Before confirmation you cannot update the items"),r.createElement(w,null),r.createElement("form",{action:V},r.createElement("input",{type:"hidden",name:"items",value:JSON.stringify(function(e){return e.map((function(e){var t,n;return{id:e.id,ordered_quantity:e.ordered_quantity,picked_quantity:e.picked_quantity,packed_quantity:e.packed_quantity,shipped_quantity:e.shipped_quantity,reports:(null===(n=null===(t=e.reports)||void 0===t?void 0:t.data)||void 0===n?void 0:n.map((function(e){return{id:"id"in e?e.id:void 0,quantity:e.quantity,content:e.content,type:e.type}})))||[]}}))}($))}),$&&$.map((function(e,t){var n,a;return r.createElement(k,{sx:{p:2,mb:2},key:t},"placed"===A.status||"external_shipping_process"===A.status||"done"===A.status||"cancelled"===A.status?r.createElement(d,{item:e,index:t,image:null===(n=null==e?void 0:e.product)||void 0===n?void 0:n.image}):r.createElement(s,{item:e,index:t,handleUpdateQuantity:se,handleAddReport:de,image:null===(a=null==e?void 0:e.product)||void 0===a?void 0:a.image,handleRemoveReportAtIndex:ue,revalidateCallback:q,showing:ce}))}))," ",r.createElement(_,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{pt:2}},H&&r.createElement(x,{onClick:H,variant:"outlined"},"Cancel"),r.createElement(W,{text:"Update items",loadingText:"Saving...",variant:"contained"})))))))}export{H as default};
@@ -4,4 +4,4 @@
4
4
  * @copyright Jelle Paulus
5
5
  * @license MIT
6
6
  */
7
- import{__read as e,__spreadArray as t}from"../../../../node_modules/tslib/tslib.es6.js";import r from"@mui/material/Divider";import a from"@mui/material/Paper";import m from"@mui/material/Box";import n from"@mui/material/Stack";import s from"@mui/material/Grid";import i from"@mui/material/Typography";import o from"@mui/material/Button";import{AddressFields as l}from"../../common/Address.js";import{SubmitButton as c}from"../../SubmitButton.js";import{useFormState as d}from"react-dom";import{updateDispatcherProfileAction as u}from"../../../data/actions/logistics/dispatcher/profile-actions.js";import{BusinessCredentialsFields as p}from"../../e-commerce/customer/BusinessCredentials.js";import{useSession as f}from"../../../context/auth/SessionContext.js";import{useSnackbar as E}from"../../../context/common/SnackbarContext.js";import v,{useEffect as g}from"react";var x={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function h(h){var b=h.data,y=h.sx,C=h.revalidateCallback,j=h.handleClose,B=b.id;b.uuid,b.dispatcher_number;var S=b.address,A=b.business_credentials,k=e(d(u,x),2),_=k[0],w=k[1],N=E().handleAddMessage,P=f().refreshSession;return g((function(){(null==_?void 0:_.message)&&(N({message:_.message,severity:_.severity||"error"}),"success"===_.severity&&(P(),C&&C(),j&&j()))}),[null==_?void 0:_.message]),g((function(){(null==_?void 0:_.strapiErrors)&&N({message:_.strapiErrors.message||"Error performing action",severity:"error"})}),[null==_?void 0:_.strapiErrors]),v.createElement(m,{sx:t([],e(Array.isArray(y)?y:[y]),!1)},v.createElement("form",{action:w},v.createElement(s,{container:!0,spacing:2},v.createElement(s,{item:!0,xs:12},v.createElement(n,{spacing:2},v.createElement(i,{variant:"h3",component:"h1",gutterBottom:!0},"Edit Profile"))),v.createElement(s,{item:!0,xs:12},v.createElement("input",{type:"hidden",name:"id",value:B}),v.createElement(a,{sx:{p:2}},v.createElement(i,{variant:"h6",gutterBottom:!0},"Business Credentials"),v.createElement(r,{sx:{mb:2}}),v.createElement(p,{componentName:"business_credentials",componentReference:"business.credentials",data:A}))),v.createElement(s,{item:!0,xs:12},v.createElement(a,{sx:{p:2}},v.createElement(i,{variant:"h6",gutterBottom:!0},"Company Address"),v.createElement(r,{sx:{mb:2}}),v.createElement(l,{componentName:"address",componentReference:"common.address",data:S}))),v.createElement(s,{item:!0,xs:12},v.createElement(n,{direction:"row",justifyContent:"space-between",spacing:2,alignItems:"center",sx:{mt:2}},j&&v.createElement(o,{onClick:j,variant:"outlined"},"Cancel"),v.createElement(c,{text:"Save Changes",loadingText:"Saving...",variant:"contained"}))))))}export{h as default};
7
+ import{__read as e,__spreadArray as t}from"../../../../node_modules/tslib/tslib.es6.js";import r from"@mui/material/Divider";import a from"@mui/material/Paper";import s from"@mui/material/Box";import m from"@mui/material/Stack";import n from"@mui/material/Grid";import o from"@mui/material/Typography";import i from"@mui/material/Button";import{AddressFields as l}from"../../common/Address.js";import{SubmitButton as c}from"../../SubmitButton.js";import{useFormState as d}from"react-dom";import{updateDispatcherProfileAction as u}from"../../../data/actions/logistics/dispatcher/profile-actions.js";import{BusinessCredentialsFields as p}from"../../e-commerce/customer/BusinessCredentials.js";import{useSession as f}from"../../../context/auth/SessionContext.js";import{useSnackbar as E}from"../../../context/common/SnackbarContext.js";import g,{useEffect as v}from"react";var x={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function b(b){var h=b.data,y=b.sx,C=b.revalidateCallback,j=b.handleClose,B=h.id;h.uuid,h.dispatcher_number;var S=h.address,A=h.business_credentials,k=u.bind(null,parseInt(B)),_=e(d(k,x),2),w=_[0],I=_[1],N=E().handleAddMessage,P=f().refreshSession;return v((function(){(null==w?void 0:w.message)&&(N({message:w.message,severity:w.severity||"error"}),"success"===w.severity&&(P(),C&&C(),j&&j()))}),[null==w?void 0:w.message]),v((function(){(null==w?void 0:w.strapiErrors)&&N({message:w.strapiErrors.message||"Error performing action",severity:"error"})}),[null==w?void 0:w.strapiErrors]),g.createElement(s,{sx:t([],e(Array.isArray(y)?y:[y]),!1)},g.createElement("form",{action:I},g.createElement(n,{container:!0,spacing:2},g.createElement(n,{item:!0,xs:12},g.createElement(m,{spacing:2},g.createElement(o,{variant:"h3",component:"h1",gutterBottom:!0},"Edit Profile"))),g.createElement(n,{item:!0,xs:12},g.createElement(a,{sx:{p:2}},g.createElement(o,{variant:"h6",gutterBottom:!0},"Business Credentials"),g.createElement(r,{sx:{mb:2}}),g.createElement(p,{componentName:"business_credentials",componentReference:"business.credentials",data:A}))),g.createElement(n,{item:!0,xs:12},g.createElement(a,{sx:{p:2}},g.createElement(o,{variant:"h6",gutterBottom:!0},"Company Address"),g.createElement(r,{sx:{mb:2}}),g.createElement(l,{componentName:"address",componentReference:"common.address",data:S}))),g.createElement(n,{item:!0,xs:12},g.createElement(m,{direction:"row",justifyContent:"space-between",spacing:2,alignItems:"center",sx:{mt:2}},j&&g.createElement(i,{onClick:j,variant:"outlined"},"Cancel"),g.createElement(c,{text:"Save Changes",loadingText:"Saving...",variant:"contained"}))))))}export{b as default};
@@ -4,4 +4,4 @@
4
4
  * @copyright Jelle Paulus
5
5
  * @license MIT
6
6
  */
7
- import{__read as e,__spreadArray as r,__awaiter as t,__generator as o}from"../../../../node_modules/tslib/tslib.es6.js";import a,{useState as i}from"react";import m from"@mui/material/Paper";import n from"@mui/material/Box";import l from"@mui/material/Stack";import s from"@mui/material/Alert";import c from"@mui/material/TextField";import d from"@mui/material/Typography";import u from"@mui/material/Divider";import{SubmitButton as p}from"../../SubmitButton.js";import{useFormState as f}from"react-dom";import{StrapiErrors as E}from"../../StrapiErrors.js";import{createIPOAction as v}from"../../../data/actions/logistics/ipo/createIPOAction.js";import x from"@mui/material/Grid";import g from"../vendor/VendorSelector.js";import{getSingleVendor as y}from"../../../data/loaders/logistics/getSingleVendor.js";import{IPOItemFields as h}from"./IPOItemFields.js";import{AdapterDayjs as b}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as A}from"@mui/x-date-pickers/LocalizationProvider";import{DatePicker as j}from"@mui/x-date-pickers/DatePicker";var P={zodErrors:null,strapiErrors:null,data:null,message:null};function D(D){var I=this,S=D.vendorNamesArr,k=D.sx,O=e(f(v,P),2),w=O[0],T=O[1],V=e(i([]),2),_=V[0],N=V[1],z=e(i(null),2),B=z[0],F=z[1];return a.createElement(n,{sx:r([{p:2}],e(Array.isArray(k)?k:[k]),!1),component:m},a.createElement("form",{action:T},a.createElement(x,{container:!0,spacing:2},a.createElement(x,{item:!0,xs:12},a.createElement(d,{variant:"h5"},"Add IPO")),a.createElement(x,{item:!0,xs:12,md:6,sx:{mt:1}},S?a.createElement(g,{vendorNames:S,currentValue:null,onSelectVendor:function(e){return t(I,void 0,void 0,(function(){var r,t;return o(this,(function(o){switch(o.label){case 0:return F(e),e?[4,y(e)]:(N([]),[2]);case 1:return r=o.sent(),N(null===(t=null==r?void 0:r.products)||void 0===t?void 0:t.data),[2]}}))}))}}):a.createElement(d,null,"No vendors on file, you need to create a vendor first before you are able to create incoming purchase orders")),a.createElement(x,{item:!0,xs:12},a.createElement(l,{spacing:2},a.createElement(d,{variant:"h5"},"Order Details"),a.createElement(d,{variant:"body1"},"The orderdate should be the official date of the order, don't worry, you can also set days in the past or future"),a.createElement(A,{dateAdapter:b},a.createElement(j,{name:"order_date",label:"Order Date"})),a.createElement(d,{variant:"body1"},"Please enter a custom reference for this order"),a.createElement(c,{id:"customer_reference",name:"customer_reference",type:"text",label:"Custom Reference"}),a.createElement(u,null))),a.createElement(x,{item:!0,xs:12},a.createElement(h,{productsArr:_,vendorID:B}))),a.createElement(x,{item:!0,xs:12},a.createElement(l,{direction:"row-reverse",spacing:2,alignItems:"center",sx:{py:1}},a.createElement(p,{text:"create new ipo",loadingText:"loading"}),(null==w?void 0:w.strapiErrors)&&a.createElement(E,{error:null==w?void 0:w.strapiErrors}),(null==w?void 0:w.message)&&a.createElement(s,{severity:"error"},null==w?void 0:w.message)))))}export{D as AddIPOForm};
7
+ import{__read as e,__spreadArray as r,__awaiter as t,__generator as a}from"../../../../node_modules/tslib/tslib.es6.js";import o,{useState as i,useEffect as n}from"react";import m from"@mui/material/Paper";import l from"@mui/material/Box";import s from"@mui/material/Stack";import c from"@mui/material/TextField";import d from"@mui/material/Typography";import u from"@mui/material/Divider";import p from"@mui/material/Button";import{SubmitButton as f}from"../../SubmitButton.js";import{useFormState as v}from"react-dom";import{createIPOAction as E}from"../../../data/actions/logistics/ipo/createIPOAction.js";import g from"@mui/material/Grid";import x from"../vendor/VendorSelector.js";import{getSingleVendor as y}from"../../../data/loaders/logistics/getSingleVendor.js";import{IPOItemFields as h}from"./IPOItemFields.js";import{AdapterDayjs as b}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as C}from"@mui/x-date-pickers/LocalizationProvider";import{DatePicker as j}from"@mui/x-date-pickers/DatePicker";import{useSnackbar as A}from"../../../context/common/SnackbarContext.js";var k={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function P(P){var I=this,D=P.vendorNamesArr,O=P.sx,S=P.revalidateCallback,w=P.handleClose,T=e(v(E,k),2),V=T[0],_=T[1],B=e(i([]),2),N=B[0],z=B[1],F=e(i(null),2),G=F[0],L=F[1],M=A().handleAddMessage;n((function(){(null==V?void 0:V.message)&&(M({message:V.message,severity:V.severity||"error"}),"success"===V.severity&&(S&&S(),w&&w()))}),[null==V?void 0:V.message]),n((function(){(null==V?void 0:V.strapiErrors)&&M({message:V.strapiErrors.message||"Error performing action",severity:"error"})}),[null==V?void 0:V.strapiErrors]);return o.createElement(l,{sx:r([{p:2}],e(Array.isArray(O)?O:[O]),!1),component:m},o.createElement("form",{action:_},o.createElement(g,{container:!0,spacing:2},o.createElement(g,{item:!0,xs:12},o.createElement(s,{spacing:2},o.createElement(d,{variant:"h3",component:"h1"},"Add IPO"),o.createElement(d,{variant:"body1"},"Create a new incoming purchase order"))),o.createElement(g,{item:!0,xs:12,md:6,sx:{mt:1}},D?o.createElement(x,{vendorNames:D,currentValue:null,onSelectVendor:function(e){return t(I,void 0,void 0,(function(){var r,t;return a(this,(function(a){switch(a.label){case 0:return L(e),e?[4,y(e)]:(z([]),[2]);case 1:return r=a.sent(),z(null===(t=null==r?void 0:r.products)||void 0===t?void 0:t.data),[2]}}))}))}}):o.createElement(d,null,"No vendors on file, you need to create a vendor first before you are able to create incoming purchase orders")),o.createElement(g,{item:!0,xs:12},o.createElement(s,{spacing:2},o.createElement(d,{variant:"h5"},"Order Details"),o.createElement(d,{variant:"body1"},"The orderdate should be the official date of the order, don't worry, you can also set days in the past or future"),o.createElement(C,{dateAdapter:b},o.createElement(j,{name:"order_date",label:"Order Date"})),o.createElement(d,{variant:"body1"},"Please enter a custom reference for this order"),o.createElement(c,{id:"customer_reference",name:"customer_reference",type:"text",label:"Custom Reference"}),o.createElement(u,null))),o.createElement(g,{item:!0,xs:12},o.createElement(h,{productsArr:N,vendorID:G})),o.createElement(g,{item:!0,xs:12},o.createElement(s,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{mt:2}},w&&o.createElement(p,{onClick:w,variant:"outlined"},"Cancel"),o.createElement(f,{text:"Create IPO",loadingText:"Creating...",variant:"contained"}))))))}export{P as AddIPOForm};
@@ -3,4 +3,4 @@
3
3
  * @copyright Jelle Paulus
4
4
  * @license MIT
5
5
  */
6
- import{__read as e,__spreadArray as t}from"../../../../node_modules/tslib/tslib.es6.js";import a,{useState as r}from"react";import{useFormState as n}from"react-dom";import{updateIpoAction as i}from"../../../data/actions/logistics/ipo/updateIpoAction.js";import{UploadBase64MediaForm as o}from"../../common/media/UploadBase64MediaForm.js";import l from"../../../data/loaders/common/media/downloadBase64File.js";import m from"./IPOItemUpdater.js";import c from"./ItemDisplay.js";import d from"../note/NotesDisplay.js";import s from"../note/NoteTakingComponent.js";import{StrapiErrors as p}from"../../StrapiErrors.js";import{SubmitButton as u}from"../../SubmitButton.js";import E from"@mui/material/Alert";import v from"@mui/material/Dialog";import f from"@mui/material/DialogActions";import g from"@mui/material/DialogContent";import y from"@mui/material/DialogTitle";import h from"@mui/material/Typography";import b from"@mui/material/Button";import x from"@mui/material/Grid";import C from"@mui/material/Box";import _ from"@mui/material/Paper";import w from"@mui/material/Stack";import D from"@mui/material/Divider";import{confirmationService as k}from"../../../data/services/common/confirmation-service.js";var j={zodErrors:null,strapiErrors:null,data:null,message:null};function I(e){var t=e.open,r=e.handleClose,n=e.orderID,i=e.currentStatus,o=e.revalidateCallback;return a.createElement(v,{open:t},a.createElement(y,null,"Confirm Order"),a.createElement(g,null,a.createElement(w,{spacing:2},a.createElement(h,null,"Are you sure you want to confirm this order?"),a.createElement(h,null,"Current status: ",i))),a.createElement(f,null,a.createElement(b,{variant:"contained",onClick:function(e){k("ipos",[n]),o&&o()}},"Confirm"),a.createElement(b,{variant:"contained",onClick:r},"Cancel")))}function F(v){var f,g,y,k,F,N,O,S=v.data,q=v.sx,A=v.revalidateCallback;v.handleClose;var B=v.role,P=e(n(i,j),2),U=P[0],T=P[1],M=e(r(S.items.data?S.items.data:[]),2),H=M[0],R=M[1],z=e(r(!1),2),G=z[0],J=z[1],L=function(a,r,n){var i=t([],e(H),!1),o=i.findIndex((function(e){return e.id===r}));i[o][n]=a,R(i)};return a.createElement(C,{sx:t([],e(Array.isArray(q)?q:[q]),!1)},a.createElement(x,{container:!0,spacing:2},a.createElement(x,{item:!0,xs:12},a.createElement(w,{spacing:2},a.createElement(w,{direction:"row",spacing:2,justifyContent:"space-between"},a.createElement(w,{spacing:2},a.createElement(h,{variant:"h3",component:"h1"},"Management Inbound Purchase Order"),a.createElement(h,{variant:"body1"},"Manage arrival, registration and recieval of purchase order")),a.createElement(s,{content:"",related:[{id:S.id,__type:"api::logistics.ipo"}],revalidateCallback:A})),a.createElement(D,null))),a.createElement(x,{item:!0,xs:6},a.createElement(w,{spacing:1},a.createElement(h,{variant:"h5"},"Details"),a.createElement(w,{direction:"row",spacing:2},a.createElement(h,{variant:"body1",width:"250px"},"Purchase Order Number"),a.createElement(h,{variant:"body2"},S.ipo_number)),a.createElement(w,{direction:"row",spacing:2},a.createElement(h,{variant:"body1",width:"250px"},"Custom reference"),a.createElement(h,{variant:"body2"},S.customer_reference)),a.createElement(w,{direction:"row",spacing:2},a.createElement(h,{variant:"body1",width:"250px"},"Order Date"),a.createElement(h,{variant:"body2"},S.order_date)),a.createElement(w,{direction:"row",spacing:2},a.createElement(h,{variant:"body1",width:"250px"},"Supplier"),a.createElement(h,{variant:"body2"},null===(g=null===(f=S.vendor_profile)||void 0===f?void 0:f.business_credentials)||void 0===g?void 0:g.company_name)),a.createElement(w,{direction:"row",spacing:2},a.createElement(h,{variant:"body1",width:"250px"},"Order Status"),a.createElement(h,{variant:"body2",width:"250px"},S.status)),("placed"===S.status||"released_on_stock"===S.status)&&"enduser"===B&&a.createElement(a.Fragment,null,a.createElement(b,{variant:"contained",color:"primary",onClick:function(){return J(!0)}},"Confirm order"),a.createElement(E,{severity:"warning"},"Please confirm the order as soon as possible, only upon confirmation this order will be available to the dispatcher"),a.createElement(I,{open:G,handleClose:function(){return J(!1)},orderID:S.id,currentStatus:S.status,revalidateCallback:A})))),a.createElement(x,{item:!0,xs:12},a.createElement(w,{spacing:2},a.createElement(h,{variant:"h5"},"Documents"),a.createElement(_,{sx:{p:2}},a.createElement(w,{spacing:1},"enduser"===B&&a.createElement(a.Fragment,null,S.order_confirmation?a.createElement(a.Fragment,null,a.createElement(h,{variant:"h6"},"Order Confirmation"),a.createElement(h,null,null===(y=S.order_confirmation)||void 0===y?void 0:y.name),a.createElement(b,{variant:"contained",onClick:function(){l("api/ipos/".concat(S.id),"order_confirmation")}},"Download")):a.createElement(a.Fragment,null,a.createElement(h,{variant:"h5"},"Order Confirmation"),a.createElement(h,{variant:"body1"},"Here you can upload the the order confirmation for this order"),a.createElement(h,{variant:"body1"},"FileUpload"),a.createElement(D,null),a.createElement(o,{reference:"api::logistics.ipo",refID:S.id,field:"order_confirmation",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"order_confirmation",componentReference:"common.base64-encoded-media",revalidateCallback:A}))),S.delivery_note?a.createElement(a.Fragment,null,a.createElement(h,{variant:"h6"},"Delivery Note"),a.createElement(h,null,null===(k=S.delivery_note)||void 0===k?void 0:k.name),a.createElement(b,{variant:"contained",onClick:function(){l("api/ipos/".concat(S.id),"delivery_note")}},"Download")):a.createElement(a.Fragment,null,a.createElement(h,{variant:"h5"},"Delivery Note"),a.createElement(h,{variant:"body1"},"Here you can upload the the delivery note for this order"),a.createElement(D,null),a.createElement(o,{reference:"api::logistics.ipo",refID:S.id,field:"delivery_note",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"delivery_note",componentReference:"common.base64-encoded-media",revalidateCallback:A})))))),(null===(N=null===(F=null==S?void 0:S.notes)||void 0===F?void 0:F.data)||void 0===N?void 0:N.length)>0&&a.createElement(x,{item:!0,xs:12},a.createElement(w,{spacing:2},a.createElement(h,{variant:"h5"},"Notes"),a.createElement(d,{notes:S.notes.data}),a.createElement(D,null))),a.createElement(x,{item:!0,xs:12},a.createElement(w,{spacing:1},a.createElement(h,{variant:"h5"},"Items"),"placed"===S.status&&a.createElement(E,{severity:"warning"},"Before confirmation you cannot update the items"),a.createElement(D,null),a.createElement("form",{action:T},a.createElement("input",{name:"id",type:"hidden",value:S.id}),(null===(O=null==S?void 0:S.items)||void 0===O?void 0:O.data)&&S.items.data.map((function(e,t){var r,n;return console.log("item",e),a.createElement(_,{sx:{p:2,mb:2},key:t},"placed"===S.status?a.createElement(c,{item:e,index:t,image:null===(r=null==e?void 0:e.product)||void 0===r?void 0:r.image}):a.createElement(m,{item:e,index:t,handleUpdateQuantity:L,image:null===(n=null==e?void 0:e.product)||void 0===n?void 0:n.image,revalidateCallback:A}))})),a.createElement(_,{sx:{p:2}},a.createElement(w,{direction:"row",spacing:2,justifyContent:"end"},a.createElement(u,{text:"Update items",loadingText:"Loading..."}),a.createElement(p,{error:null==U?void 0:U.strapiErrors}),(null==U?void 0:U.message)&&a.createElement(E,{severity:"error"},null==U?void 0:U.message))),a.createElement("input",{type:"hidden",name:"items",value:JSON.stringify(function(e){return e.map((function(e){return{id:e.id,received_quantity:e.received_quantity,registered_quantity:e.registered_quantity,released_quantity:e.released_quantity}}))}(H))}))))))}export{F as default};
6
+ import{__read as e,__spreadArray as t}from"../../../../node_modules/tslib/tslib.es6.js";import a,{useState as r,useEffect as n}from"react";import{useFormState as i}from"react-dom";import{useSnackbar as o}from"../../../context/common/SnackbarContext.js";import{updateIpoAction as l}from"../../../data/actions/logistics/ipo/updateIpoAction.js";import{UploadBase64MediaForm as m}from"../../common/media/UploadBase64MediaForm.js";import c from"../../../data/loaders/common/media/downloadBase64File.js";import d from"./IPOItemUpdater.js";import s from"./ItemDisplay.js";import p from"../note/NotesDisplay.js";import u from"../note/NoteTakingComponent.js";import{SubmitButton as v}from"../../SubmitButton.js";import{confirmationService as E}from"../../../data/services/common/confirmation-service.js";import f from"@mui/material/Alert";import g from"@mui/material/Dialog";import y from"@mui/material/DialogActions";import h from"@mui/material/DialogContent";import b from"@mui/material/DialogTitle";import x from"@mui/material/Typography";import C from"@mui/material/Button";import _ from"@mui/material/Grid";import w from"@mui/material/Box";import k from"@mui/material/Paper";import D from"@mui/material/Stack";import j from"@mui/material/Divider";var I={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function O(e){var t=e.open,r=e.handleClose,n=e.orderID,i=e.currentStatus,o=e.revalidateCallback;return a.createElement(g,{open:t},a.createElement(b,null,"Confirm Order"),a.createElement(h,null,a.createElement(D,{spacing:2},a.createElement(x,null,"Are you sure you want to confirm this order?"),a.createElement(x,null,"Current status: ",i))),a.createElement(y,null,a.createElement(C,{variant:"contained",onClick:function(e){E("ipos",[n]),o&&o(),r()}},"Confirm"),a.createElement(C,{variant:"outlined",onClick:r},"Cancel")))}function N(E){var g,y,h,b,N,S,U,A=E.data,q=E.sx,B=E.revalidateCallback,P=E.handleClose,F=E.role,T=e(i((function(e,t){return l(A.id,e,t)}),I),2),M=T[0],R=T[1],z=o().handleAddMessage,G=e(r(A.items.data?A.items.data:[]),2),J=G[0],Q=G[1],H=e(r(!1),2),K=H[0],L=H[1];n((function(){(null==M?void 0:M.message)&&(z({message:M.message,severity:M.severity||"error"}),"success"===M.severity&&(B&&B(),P&&P()))}),[null==M?void 0:M.message]),n((function(){(null==M?void 0:M.strapiErrors)&&z({message:M.strapiErrors.message||"Error performing action",severity:"error"})}),[null==M?void 0:M.strapiErrors]);var V=function(a,r,n){var i=t([],e(J),!1),o=i.findIndex((function(e){return e.id===r}));i[o][n]=a,Q(i)};return a.createElement(w,{sx:t([],e(Array.isArray(q)?q:[q]),!1)},a.createElement(_,{container:!0,spacing:2},a.createElement(_,{item:!0,xs:12},a.createElement(D,{spacing:2},a.createElement(D,{direction:"row",spacing:2,justifyContent:"space-between"},a.createElement(D,{spacing:2},a.createElement(x,{variant:"h3",component:"h1"},"Manage Inbound Purchase Order"),a.createElement(x,{variant:"body1"},"Update the incoming purchase order details")),a.createElement(u,{content:"",related:[{id:A.id,__type:"api::logistics.ipo"}],revalidateCallback:B})),a.createElement(j,null))),a.createElement(_,{item:!0,xs:6},a.createElement(D,{spacing:1},a.createElement(x,{variant:"h5"},"Details"),a.createElement(D,{direction:"row",spacing:2},a.createElement(x,{variant:"body1",width:"250px"},"Purchase Order Number"),a.createElement(x,{variant:"body2"},A.ipo_number)),a.createElement(D,{direction:"row",spacing:2},a.createElement(x,{variant:"body1",width:"250px"},"Custom reference"),a.createElement(x,{variant:"body2"},A.customer_reference)),a.createElement(D,{direction:"row",spacing:2},a.createElement(x,{variant:"body1",width:"250px"},"Order Date"),a.createElement(x,{variant:"body2"},A.order_date)),a.createElement(D,{direction:"row",spacing:2},a.createElement(x,{variant:"body1",width:"250px"},"Supplier"),a.createElement(x,{variant:"body2"},null===(y=null===(g=A.vendor_profile)||void 0===g?void 0:g.business_credentials)||void 0===y?void 0:y.company_name)),a.createElement(D,{direction:"row",spacing:2},a.createElement(x,{variant:"body1",width:"250px"},"Order Status"),a.createElement(x,{variant:"body2",width:"250px"},A.status)),("placed"===A.status||"released_on_stock"===A.status)&&"enduser"===F&&a.createElement(a.Fragment,null,a.createElement(C,{variant:"contained",color:"primary",onClick:function(){return L(!0)}},"Confirm order"),a.createElement(f,{severity:"warning"},"Please confirm the order as soon as possible. Only upon confirmation will this order be available to the dispatcher."),a.createElement(O,{open:K,handleClose:function(){return L(!1)},orderID:A.id,currentStatus:A.status,revalidateCallback:B})))),a.createElement(_,{item:!0,xs:12},a.createElement(D,{spacing:2},a.createElement(x,{variant:"h5"},"Documents"),a.createElement(k,{sx:{p:2}},a.createElement(D,{spacing:1},"enduser"===F&&a.createElement(a.Fragment,null,A.order_confirmation?a.createElement(D,{spacing:1},a.createElement(x,{variant:"h6"},"Order Confirmation"),a.createElement(x,null,null===(h=A.order_confirmation)||void 0===h?void 0:h.name),a.createElement(C,{variant:"contained",onClick:function(){c("api/ipos/".concat(A.id),"order_confirmation")}},"Download")):a.createElement(D,{spacing:1},a.createElement(x,{variant:"h6"},"Order Confirmation"),a.createElement(x,{variant:"body1"},"Upload the order confirmation for this order"),a.createElement(m,{reference:"api::logistics.ipo",refID:A.id,field:"order_confirmation",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"order_confirmation",componentReference:"common.base64-encoded-media",revalidateCallback:B}))),A.delivery_note?a.createElement(D,{spacing:1},a.createElement(x,{variant:"h6"},"Delivery Note"),a.createElement(x,null,null===(b=A.delivery_note)||void 0===b?void 0:b.name),a.createElement(C,{variant:"contained",onClick:function(){c("api/ipos/".concat(A.id),"delivery_note")}},"Download")):a.createElement(D,{spacing:1},a.createElement(x,{variant:"h6"},"Delivery Note"),a.createElement(x,{variant:"body1"},"Upload the delivery note for this order"),a.createElement(m,{reference:"api::logistics.ipo",refID:A.id,field:"delivery_note",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"delivery_note",componentReference:"common.base64-encoded-media",revalidateCallback:B})))))),(null===(S=null===(N=null==A?void 0:A.notes)||void 0===N?void 0:N.data)||void 0===S?void 0:S.length)>0&&a.createElement(_,{item:!0,xs:12},a.createElement(D,{spacing:2},a.createElement(x,{variant:"h5"},"Notes"),a.createElement(p,{notes:A.notes.data}),a.createElement(j,null))),a.createElement(_,{item:!0,xs:12},a.createElement(D,{spacing:2},a.createElement(x,{variant:"h5"},"Items"),"placed"===A.status&&a.createElement(f,{severity:"warning"},"Items cannot be updated before order confirmation"),a.createElement("form",{action:R},a.createElement("input",{name:"id",type:"hidden",value:A.id}),a.createElement("input",{type:"hidden",name:"items",value:JSON.stringify(function(e){return e.map((function(e){return{id:e.id,received_quantity:e.received_quantity,registered_quantity:e.registered_quantity,released_quantity:e.released_quantity}}))}(J))}),a.createElement(D,{spacing:2},(null===(U=null==A?void 0:A.items)||void 0===U?void 0:U.data)&&A.items.data.map((function(e,t){var r,n;return a.createElement(k,{sx:{p:2},key:t},"placed"===A.status?a.createElement(s,{item:e,index:t,image:null===(r=null==e?void 0:e.product)||void 0===r?void 0:r.image}):a.createElement(d,{item:e,index:t,handleUpdateQuantity:V,image:null===(n=null==e?void 0:e.product)||void 0===n?void 0:n.image,revalidateCallback:B}))})),"placed"!==A.status&&a.createElement(k,{sx:{p:2}},a.createElement(D,{direction:"row",justifyContent:"flex-end",spacing:2},P&&a.createElement(C,{onClick:P,variant:"outlined"},"Cancel"),a.createElement(v,{text:"Update Items",loadingText:"Updating...",variant:"contained"})))))))))}export{N as default};
@@ -3,4 +3,4 @@
3
3
  * @copyright Jelle Paulus
4
4
  * @license MIT
5
5
  */
6
- import{__read as e,__spreadArray as t,__assign as r}from"../../../../node_modules/tslib/tslib.es6.js";import n,{useState as a,useEffect as o}from"react";import{useFormState as i}from"react-dom";import{updateIpoAction as l}from"../../../data/actions/logistics/ipo/updateIpoAction.js";import{UploadBase64MediaForm as c}from"../../common/media/UploadBase64MediaForm.js";import m from"../../../data/loaders/common/media/downloadBase64File.js";import d from"./TextualIPOItemUpdater.js";import s from"./ItemDisplay.js";import u from"../note/NotesDisplay.js";import p from"../note/NoteTakingComponent.js";import{SubmitButton as v}from"../../SubmitButton.js";import f from"@mui/material/Alert";import E from"@mui/material/Dialog";import g from"@mui/material/DialogActions";import y from"@mui/material/DialogContent";import h from"@mui/material/DialogTitle";import x from"@mui/material/Typography";import b from"@mui/material/Button";import C from"@mui/material/Grid";import w from"@mui/material/Box";import _ from"@mui/material/Paper";import I from"@mui/material/Stack";import k from"@mui/material/Divider";import{confirmationService as D}from"../../../data/services/common/confirmation-service.js";import{cancellationService as j}from"../../../data/services/common/cancellation-service.js";import{FormControlLabel as q,Checkbox as A,List as N,ListItem as S,TextField as F}from"@mui/material";import O from"@mui/icons-material/Numbers";import P from"@mui/icons-material/CalendarToday";import U from"@mui/icons-material/Business";import B from"@mui/icons-material/Description";import T from"@mui/icons-material/Update";import{IpoStatusIndicator as R}from"./IpoStatusIndicator.js";import{useSnackbar as W}from"../../../context/common/SnackbarContext.js";var M={zodErrors:null,strapiErrors:null,data:null,message:null};function z(e){var t=e.open,r=e.handleClose,a=e.orderID,o=e.currentStatus,i=e.revalidateCallback;return n.createElement(E,{open:t},n.createElement(h,null,"Confirm Order"),n.createElement(y,null,n.createElement(I,{spacing:2},n.createElement(x,null,"Are you sure you want to confirm this order?"),n.createElement(x,null,"Current status: ",o))),n.createElement(g,null,n.createElement(b,{variant:"contained",onClick:function(e){D("ipos",[a]),i&&i(),r()}},"Confirm"),n.createElement(b,{variant:"contained",onClick:r},"Cancel")))}function H(t){var r=t.open,o=t.handleClose,i=t.orderID,l=t.revalidateCallback,c=e(a(""),2),m=c[0],d=c[1],s=e(a(""),2),u=s[0],p=s[1];return n.createElement("form",null,n.createElement(E,{open:r},n.createElement(h,null,"Cancel Return"),n.createElement(y,null,n.createElement(I,{spacing:2},n.createElement(x,null,"Are you sure you want to cancel this return?"),n.createElement(N,null,n.createElement(S,null,"By cancelling this return order you will update it's status from requested to cancelled"),n.createElement(S,null,"Please provide a reason for the cancellation"),n.createElement(S,null,"The customer will be notified about the cancellation and of the reason for the cancellation")),n.createElement(F,{label:"Cancellation reason",name:"reason",multiline:!0,rows:4,fullWidth:!0,variant:"outlined",value:m,onChange:function(e){return d(e.target.value)},placeholder:"Please provide a reason for the cancellation",error:!!u,helperText:u}))),n.createElement(g,null,n.createElement(b,{variant:"contained",onClick:function(e){m.length<5?p("Please provide a reason for the cancellation"):(j("ipos",i,m),l&&l(),o())}},"Yes"),n.createElement(b,{variant:"contained",onClick:o},"No"))))}function G(E){var g,y,h,D,j,N,S=E.data,F=E.sx,G=E.revalidateCallback,J=E.handleClose,L=E.role,Q=e(i(l,M),2),Y=Q[0],K=Q[1],V=e(a(S.items.data?S.items.data:[]),2),X=V[0],Z=V[1],$=e(a(!1),2),ee=$[0],te=$[1],re=e(a(!1),2),ne=re[0],ae=re[1],oe=e(a(["received","registered","released","reports"]),2),ie=oe[0],le=oe[1],ce=function(r,n,a){var o=t([],e(X),!1),i=o.findIndex((function(e){return e.id===n}));o[i][a]=r,Z(o)},me=function(n,a){var o,i,l,c=t([],e(X),!1),m=c.findIndex((function(e){return e.id===a})),d=(null===(i=null===(o=c[m])||void 0===o?void 0:o.reports)||void 0===i?void 0:i.data)||[],s=t(t([],e(d),!1),[n],!1);null==(null===(l=c[m])||void 0===l?void 0:l.reports)&&(c[m]=r(r({},c[m]),{reports:{data:[]}})),c[m].reports.data=s,Z(c)},de=function(r,n){var a,o,i=t([],e(X),!1),l=i.findIndex((function(e){return e.id===r})),c=(null===(o=null===(a=i[l])||void 0===a?void 0:a.reports)||void 0===o?void 0:o.data)||[],m=c.filter((function(e){return"id"in e})),d=c.filter((function(e){return!("id"in e)}));d.splice(n,1);var s=t(t([],e(m),!1),e(d),!1);i[l].reports.data=s,Z(i)},se=W().handleAddMessage;return o((function(){"Ipo Updated"===(null==Y?void 0:Y.message)&&(se({message:"Ipo Updated",severity:"success"}),J&&J(),G&&G())}),[Y]),o((function(){(null==Y?void 0:Y.strapiErrors)&&se({message:Y.strapiErrors.message||"Error updating IPO",severity:"error"})}),[null==Y?void 0:Y.strapiErrors]),o((function(){var e;console.log("data",S),(null===(e=S.items)||void 0===e?void 0:e.data)&&Z(S.items.data?S.items.data:[])}),[S]),n.createElement(w,{sx:t([],e(Array.isArray(F)?F:[F]),!1)},n.createElement(C,{container:!0,spacing:2},n.createElement(C,{item:!0,xs:12},n.createElement(I,{spacing:2},n.createElement(I,{direction:"row",spacing:2,justifyContent:"space-between"},n.createElement(I,{spacing:2},n.createElement(x,{variant:"h3",component:"h1"},"Management Inbound Purchase Order"),n.createElement(x,{variant:"body1"},"Manage arrival, registration and recieval of purchase order")),n.createElement(p,{content:"",related:[{id:S.id,__type:"api::logistics.ipo"}],revalidateCallback:G})),n.createElement(k,null))),n.createElement(C,{item:!0,xs:12},n.createElement(x,{variant:"h5",sx:{py:1}},"Details")),n.createElement(C,{item:!0,xs:6},n.createElement(_,{elevation:2,sx:{p:2,height:"100%"}},n.createElement(I,{spacing:2},n.createElement(I,{direction:"row",spacing:2,alignItems:"center"},n.createElement(O,{color:"primary"}),n.createElement(x,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Purchase Order Number"),n.createElement(x,{variant:"body1",fontWeight:"medium"},S.ipo_number)),n.createElement(I,{direction:"row",spacing:2,alignItems:"center"},n.createElement(B,{color:"primary"}),n.createElement(x,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Custom Reference"),n.createElement(x,{variant:"body1",fontWeight:"medium"},S.customer_reference)),n.createElement(I,{direction:"row",spacing:2,alignItems:"center"},n.createElement(P,{color:"primary"}),n.createElement(x,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Order Date"),n.createElement(x,{variant:"body1",fontWeight:"medium"},S.order_date)),n.createElement(I,{direction:"row",spacing:2,alignItems:"center"},n.createElement(U,{color:"primary"}),n.createElement(x,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Supplier"),n.createElement(x,{variant:"body1",fontWeight:"medium"},null===(y=null===(g=S.vendor_profile)||void 0===g?void 0:g.business_credentials)||void 0===y?void 0:y.company_name)),n.createElement(I,{direction:"row",spacing:2,alignItems:"center"},n.createElement(T,{color:"primary"}),n.createElement(x,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Order Status"),n.createElement(R,{status:S.status}))))),"enduser"===L&&n.createElement(C,{item:!0,xs:6},n.createElement(_,{elevation:2,sx:{p:2,height:"100%"}},n.createElement(I,{spacing:2},("placed"===S.status||"released_on_stock"===S.status)&&n.createElement(n.Fragment,null,n.createElement(b,{variant:"contained",color:"primary",onClick:function(){return te(!0)}},"Confirm order"),n.createElement(f,{severity:"warning"},"Please confirm the order as soon as possible, only upon confirmation this order will be available to the dispatcher"),n.createElement(z,{open:ee,handleClose:function(){return te(!1)},orderID:S.id,currentStatus:S.status,revalidateCallback:G})),("placed"===S.status||"ordered"===S.status)&&n.createElement(n.Fragment,null,n.createElement(b,{variant:"contained",color:"error",onClick:function(){return ae(!0)}},"Cancel order"),n.createElement(H,{open:ne,handleClose:function(){return ae(!1)},orderID:S.id,revalidateCallback:G}))))),n.createElement(C,{item:!0,xs:12},n.createElement(I,{spacing:2},n.createElement(x,{variant:"h5"},"Documents"),n.createElement(_,{sx:{p:2}},n.createElement(I,{spacing:1},"enduser"===L&&n.createElement(n.Fragment,null,S.order_confirmation?n.createElement(n.Fragment,null,n.createElement(x,{variant:"h6"},"Order Confirmation"),n.createElement(x,null,null===(h=S.order_confirmation)||void 0===h?void 0:h.name),n.createElement(b,{variant:"contained",onClick:function(){m("api/ipos/".concat(S.id),"order_confirmation")}},"Download")):n.createElement(n.Fragment,null,n.createElement(x,{variant:"h5"},"Order Confirmation"),n.createElement(x,{variant:"body1"},"Here you can upload the the order confirmation for this order"),n.createElement(x,{variant:"body1"},"FileUpload"),n.createElement(k,null),n.createElement(c,{reference:"api::logistics.ipo",refID:S.id,field:"order_confirmation",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"order_confirmation",componentReference:"common.base64-encoded-media",revalidateCallback:G}))),S.delivery_note?n.createElement(n.Fragment,null,n.createElement(x,{variant:"h6"},"Delivery Note"),n.createElement(x,null,null===(D=S.delivery_note)||void 0===D?void 0:D.name),n.createElement(b,{variant:"contained",onClick:function(){m("api/ipos/".concat(S.id),"delivery_note")}},"Download")):n.createElement(n.Fragment,null,n.createElement(x,{variant:"h5"},"Delivery Note"),n.createElement(x,{variant:"body1"},"Here you can upload the the delivery note for this order"),n.createElement(k,null),n.createElement(c,{reference:"api::logistics.ipo",refID:S.id,field:"delivery_note",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"delivery_note",componentReference:"common.base64-encoded-media",revalidateCallback:G})))))),(null===(N=null===(j=null==S?void 0:S.notes)||void 0===j?void 0:j.data)||void 0===N?void 0:N.length)>0&&n.createElement(C,{item:!0,xs:12},n.createElement(I,{spacing:2},n.createElement(x,{variant:"h5"},"Notes"),n.createElement(u,{notes:S.notes.data}),n.createElement(k,null))),n.createElement(C,{item:!0,xs:12},n.createElement(I,{spacing:1},n.createElement(x,{variant:"h5"},"Items"),n.createElement(I,{direction:"row",alignItems:"center",justifyContent:"flex-end",spacing:2,component:_,p:1,sx:{bgcolor:"background.default",border:"1px solid",borderColor:"divider",boxShadow:"none"}},n.createElement(x,{variant:"body2",color:"text.secondary"},"Show:"),["received","registered","released","reports"].map((function(r){return n.createElement(q,{key:r,control:n.createElement(A,{size:"small",checked:ie.includes(r),onChange:function(n){n.target.checked?le(t(t([],e(ie),!1),[r],!1)):le(ie.filter((function(e){return e!==r})))}}),label:n.createElement(x,{variant:"body2",color:"text.secondary"},r.charAt(0).toUpperCase()+r.slice(1)),sx:{mr:0}})}))),"placed"===S.status&&n.createElement(f,{severity:"warning"},"Before confirmation you cannot update the items"),n.createElement(k,null),n.createElement("form",{action:K},n.createElement("input",{name:"id",type:"hidden",value:S.id}),X&&X.map((function(e,t){var r,a;return n.createElement(_,{sx:{p:2,mb:2},key:t},"placed"===S.status||"cancelled"===S.status||"done"===S.status?n.createElement(s,{item:e,index:t,image:null===(r=null==e?void 0:e.product)||void 0===r?void 0:r.image}):n.createElement(d,{item:e,index:t,handleUpdateQuantity:ce,handleAddReport:me,image:null===(a=null==e?void 0:e.product)||void 0===a?void 0:a.image,handleRemoveReportAtIndex:de,revalidateCallback:G,showing:ie}))})),n.createElement(_,{sx:{p:2}},n.createElement(I,{direction:"row",spacing:2,justifyContent:"end"},n.createElement(v,{text:"Update items",loadingText:"Loading..."}))),n.createElement("input",{type:"hidden",name:"items",value:JSON.stringify(function(e){return e.map((function(e){var t,r;return{id:e.id,ordered_quantity:e.ordered_quantity,received_quantity:e.received_quantity,registered_quantity:e.registered_quantity,released_quantity:e.released_quantity,reports:(null===(r=null===(t=e.reports)||void 0===t?void 0:t.data)||void 0===r?void 0:r.map((function(e){return{id:"id"in e?e.id:void 0,quantity:e.quantity,content:e.content,type:e.type}})))||[]}}))}(X))}))))))}export{G as default};
6
+ import{__read as e,__spreadArray as t,__assign as r,__awaiter as n,__generator as a}from"../../../../node_modules/tslib/tslib.es6.js";import i,{useState as o,useEffect as l}from"react";import{useFormState as c}from"react-dom";import{useSnackbar as m}from"../../../context/common/SnackbarContext.js";import{updateIpoAction as s}from"../../../data/actions/logistics/ipo/updateIpoAction.js";import{confirmationService as d}from"../../../data/services/common/confirmation-service.js";import{cancellationService as u}from"../../../data/services/common/cancellation-service.js";import p from"../../../data/loaders/common/media/downloadBase64File.js";import{UploadBase64MediaForm as v}from"../../common/media/UploadBase64MediaForm.js";import f from"../note/NoteTakingComponent.js";import E from"../note/NotesDisplay.js";import g from"./ItemDisplay.js";import y from"./TextualIPOItemUpdater.js";import{IpoStatusIndicator as h}from"./IpoStatusIndicator.js";import b from"@mui/material/Box";import x from"@mui/material/Stack";import C from"@mui/material/Paper";import w from"@mui/material/Dialog";import I from"@mui/material/DialogActions";import _ from"@mui/material/DialogContent";import k from"@mui/material/DialogTitle";import D from"@mui/material/Typography";import O from"@mui/material/Button";import j from"@mui/material/Grid";import F from"@mui/material/Divider";import P from"@mui/material/TextField";import A from"@mui/material/List";import q from"@mui/material/ListItem";import S from"@mui/material/Alert";import N from"@mui/material/Checkbox";import T from"@mui/material/FormControlLabel";import U from"@mui/icons-material/Numbers";import B from"@mui/icons-material/Description";import R from"@mui/icons-material/CalendarToday";import M from"@mui/icons-material/Business";import W from"@mui/icons-material/Update";import{SubmitButton as L}from"../../SubmitButton.js";var z={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function H(e){var t=this,r=e.open,o=e.handleClose,l=e.orderID,c=e.currentStatus,s=e.revalidateCallback,u=m().handleAddMessage;return i.createElement(w,{open:r},i.createElement(k,null,"Confirm Order"),i.createElement(_,null,i.createElement(x,{spacing:2},i.createElement(D,null,"Are you sure you want to confirm this order?"),i.createElement(D,null,"Current status: ",c),i.createElement(S,{severity:"info"},"Once confirmed, the order will be available for processing."))),i.createElement(I,null,i.createElement(O,{variant:"outlined",onClick:o},"Cancel"),i.createElement(O,{variant:"contained",color:"primary",onClick:function(){return n(t,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,d("ipos",[l])];case 1:return e.sent(),u({message:"IPO confirmed successfully",severity:"success"}),s&&s(),o(),[3,3];case 2:return e.sent(),u({message:"Failed to confirm IPO",severity:"error"}),[3,3];case 3:return[2]}}))}))}},"Confirm Order")))}function G(t){var r=this,l=t.open,c=t.handleClose,s=t.orderID,d=t.revalidateCallback,p=e(o(""),2),v=p[0],f=p[1],E=e(o(""),2),g=E[0],y=E[1],h=m().handleAddMessage;return i.createElement(w,{open:l},i.createElement(k,null,"Cancel Return"),i.createElement(_,null,i.createElement(x,{spacing:2},i.createElement(D,null,"Are you sure you want to cancel this return?"),i.createElement(A,null,i.createElement(q,null,"By cancelling this return order you will update it's status from requested to cancelled"),i.createElement(q,null,"Please provide a reason for the cancellation"),i.createElement(q,null,"The customer will be notified about the cancellation and of the reason for the cancellation")),i.createElement(P,{label:"Cancellation reason",name:"reason",multiline:!0,rows:4,fullWidth:!0,variant:"outlined",value:v,onChange:function(e){return f(e.target.value)},placeholder:"Please provide a reason for the cancellation",error:!!g,helperText:g}))),i.createElement(I,null,i.createElement(O,{variant:"outlined",onClick:c},"Cancel"),i.createElement(O,{variant:"contained",color:"error",onClick:function(){return n(r,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:if(v.length<5)return y("Please provide a reason for the cancellation (min 5 characters)"),[2];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,u("ipos",s,v)];case 2:return e.sent(),h({message:"IPO cancelled successfully",severity:"success"}),d&&d(),c(),[3,4];case 3:return e.sent(),h({message:"Failed to cancel IPO",severity:"error"}),[3,4];case 4:return[2]}}))}))}},"Confirm Cancellation")))}function J(n){var a,d,u,w,I,_,k=n.data,P=n.sx,A=n.revalidateCallback,q=n.handleClose,J=n.role,Q=e(c((function(e,t){return s(k.id,e,t)}),z),2),K=Q[0],V=Q[1],X=m().handleAddMessage,Y=e(o(k.items.data?k.items.data:[]),2),Z=Y[0],$=Y[1],ee=e(o(!1),2),te=ee[0],re=ee[1],ne=e(o(!1),2),ae=ne[0],ie=ne[1],oe=e(o(["received","registered","released","reports"]),2),le=oe[0],ce=oe[1];l((function(){(null==K?void 0:K.message)&&(X({message:K.message,severity:K.severity||"error"}),"success"===K.severity&&(A&&A(),q&&q()))}),[null==K?void 0:K.message]),l((function(){(null==K?void 0:K.strapiErrors)&&X({message:K.strapiErrors.message||"Error updating IPO",severity:"error"})}),[null==K?void 0:K.strapiErrors]);var me=function(r,n,a){var i=t([],e(Z),!1),o=i.findIndex((function(e){return e.id===n}));i[o][a]=r,$(i)},se=function(n,a){var i,o,l,c=t([],e(Z),!1),m=c.findIndex((function(e){return e.id===a})),s=(null===(o=null===(i=c[m])||void 0===i?void 0:i.reports)||void 0===o?void 0:o.data)||[],d=t(t([],e(s),!1),[n],!1);null==(null===(l=c[m])||void 0===l?void 0:l.reports)&&(c[m]=r(r({},c[m]),{reports:{data:[]}})),c[m].reports.data=d,$(c)},de=function(r,n){var a,i,o=t([],e(Z),!1),l=o.findIndex((function(e){return e.id===r})),c=(null===(i=null===(a=o[l])||void 0===a?void 0:a.reports)||void 0===i?void 0:i.data)||[],m=c.filter((function(e){return"id"in e})),s=c.filter((function(e){return!("id"in e)}));s.splice(n,1);var d=t(t([],e(m),!1),e(s),!1);o[l].reports.data=d,$(o)};return l((function(){"Ipo Updated"===(null==K?void 0:K.message)&&(X({message:"Ipo Updated",severity:"success"}),q&&q(),A&&A())}),[K]),l((function(){(null==K?void 0:K.strapiErrors)&&X({message:K.strapiErrors.message||"Error updating IPO",severity:"error"})}),[null==K?void 0:K.strapiErrors]),l((function(){var e;console.log("data",k),(null===(e=k.items)||void 0===e?void 0:e.data)&&$(k.items.data?k.items.data:[])}),[k]),i.createElement(b,{sx:t([],e(Array.isArray(P)?P:[P]),!1)},i.createElement(j,{container:!0,spacing:2},i.createElement(j,{item:!0,xs:12},i.createElement(x,{spacing:2},i.createElement(x,{direction:"row",spacing:2,justifyContent:"space-between"},i.createElement(x,{spacing:2},i.createElement(D,{variant:"h3",component:"h1"},"Management Inbound Purchase Order"),i.createElement(D,{variant:"body1"},"Manage arrival, registration and recieval of purchase order")),i.createElement(f,{content:"",related:[{id:k.id,__type:"api::logistics.ipo"}],revalidateCallback:A})),i.createElement(F,null))),i.createElement(j,{item:!0,xs:12},i.createElement(D,{variant:"h5",sx:{py:1}},"Details")),i.createElement(j,{item:!0,xs:6},i.createElement(C,{elevation:2,sx:{p:2,height:"100%"}},i.createElement(x,{spacing:2},i.createElement(x,{direction:"row",spacing:2,alignItems:"center"},i.createElement(U,{color:"primary"}),i.createElement(D,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Purchase Order Number"),i.createElement(D,{variant:"body1",fontWeight:"medium"},k.ipo_number)),i.createElement(x,{direction:"row",spacing:2,alignItems:"center"},i.createElement(B,{color:"primary"}),i.createElement(D,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Custom Reference"),i.createElement(D,{variant:"body1",fontWeight:"medium"},k.customer_reference)),i.createElement(x,{direction:"row",spacing:2,alignItems:"center"},i.createElement(R,{color:"primary"}),i.createElement(D,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Order Date"),i.createElement(D,{variant:"body1",fontWeight:"medium"},k.order_date)),i.createElement(x,{direction:"row",spacing:2,alignItems:"center"},i.createElement(M,{color:"primary"}),i.createElement(D,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Supplier"),i.createElement(D,{variant:"body1",fontWeight:"medium"},null===(d=null===(a=k.vendor_profile)||void 0===a?void 0:a.business_credentials)||void 0===d?void 0:d.company_name)),i.createElement(x,{direction:"row",spacing:2,alignItems:"center"},i.createElement(W,{color:"primary"}),i.createElement(D,{variant:"subtitle1",color:"text.secondary",width:"200px"},"Order Status"),i.createElement(h,{status:k.status}))))),"enduser"===J&&i.createElement(j,{item:!0,xs:6},i.createElement(C,{elevation:2,sx:{p:2,height:"100%"}},i.createElement(x,{spacing:2},("placed"===k.status||"released_on_stock"===k.status)&&i.createElement(i.Fragment,null,i.createElement(O,{variant:"contained",color:"primary",onClick:function(){return re(!0)}},"Confirm order"),i.createElement(S,{severity:"warning"},"Please confirm the order as soon as possible, only upon confirmation this order will be available to the dispatcher"),i.createElement(H,{open:te,handleClose:function(){return re(!1)},orderID:k.id,currentStatus:k.status,revalidateCallback:A})),("placed"===k.status||"ordered"===k.status)&&i.createElement(i.Fragment,null,i.createElement(O,{variant:"contained",color:"error",onClick:function(){return ie(!0)}},"Cancel order"),i.createElement(G,{open:ae,handleClose:function(){return ie(!1)},orderID:k.id,revalidateCallback:A}))))),i.createElement(j,{item:!0,xs:12},i.createElement(x,{spacing:2},i.createElement(D,{variant:"h5"},"Documents"),i.createElement(C,{sx:{p:2}},i.createElement(x,{spacing:1},"enduser"===J&&i.createElement(i.Fragment,null,k.order_confirmation?i.createElement(i.Fragment,null,i.createElement(D,{variant:"h6"},"Order Confirmation"),i.createElement(D,null,null===(u=k.order_confirmation)||void 0===u?void 0:u.name),i.createElement(O,{variant:"contained",onClick:function(){p("api/ipos/".concat(k.id),"order_confirmation")}},"Download")):i.createElement(i.Fragment,null,i.createElement(D,{variant:"h5"},"Order Confirmation"),i.createElement(D,{variant:"body1"},"Here you can upload the the order confirmation for this order"),i.createElement(D,{variant:"body1"},"FileUpload"),i.createElement(F,null),i.createElement(v,{reference:"api::logistics.ipo",refID:k.id,field:"order_confirmation",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"order_confirmation",componentReference:"common.base64-encoded-media",revalidateCallback:A}))),k.delivery_note?i.createElement(i.Fragment,null,i.createElement(D,{variant:"h6"},"Delivery Note"),i.createElement(D,null,null===(w=k.delivery_note)||void 0===w?void 0:w.name),i.createElement(O,{variant:"contained",onClick:function(){p("api/ipos/".concat(k.id),"delivery_note")}},"Download")):i.createElement(i.Fragment,null,i.createElement(D,{variant:"h5"},"Delivery Note"),i.createElement(D,{variant:"body1"},"Here you can upload the the delivery note for this order"),i.createElement(F,null),i.createElement(v,{reference:"api::logistics.ipo",refID:k.id,field:"delivery_note",multiple:!1,accept:"text/*,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",path:"api/ipos",componentName:"delivery_note",componentReference:"common.base64-encoded-media",revalidateCallback:A})))))),(null===(_=null===(I=null==k?void 0:k.notes)||void 0===I?void 0:I.data)||void 0===_?void 0:_.length)>0&&i.createElement(j,{item:!0,xs:12},i.createElement(x,{spacing:2},i.createElement(D,{variant:"h5"},"Notes"),i.createElement(E,{notes:k.notes.data}),i.createElement(F,null))),i.createElement(j,{item:!0,xs:12},i.createElement(x,{spacing:1},i.createElement(D,{variant:"h5"},"Items"),i.createElement(x,{direction:"row",alignItems:"center",justifyContent:"flex-end",spacing:2,component:C,p:1,sx:{bgcolor:"background.default",border:"1px solid",borderColor:"divider",boxShadow:"none"}},i.createElement(D,{variant:"body2",color:"text.secondary"},"Show:"),["received","registered","released","reports"].map((function(r){return i.createElement(T,{key:r,control:i.createElement(N,{size:"small",checked:le.includes(r),onChange:function(n){n.target.checked?ce(t(t([],e(le),!1),[r],!1)):ce(le.filter((function(e){return e!==r})))}}),label:i.createElement(D,{variant:"body2",color:"text.secondary"},r.charAt(0).toUpperCase()+r.slice(1)),sx:{mr:0}})}))),"placed"===k.status&&i.createElement(S,{severity:"warning"},"Before confirmation you cannot update the items"),i.createElement(F,null),i.createElement("form",{action:V},i.createElement("input",{name:"id",type:"hidden",value:k.id}),Z&&Z.map((function(e,t){var r,n;return i.createElement(C,{sx:{p:2,mb:2},key:t},"placed"===k.status||"cancelled"===k.status||"done"===k.status?i.createElement(g,{item:e,index:t,image:null===(r=null==e?void 0:e.product)||void 0===r?void 0:r.image}):i.createElement(y,{item:e,index:t,handleUpdateQuantity:me,handleAddReport:se,image:null===(n=null==e?void 0:e.product)||void 0===n?void 0:n.image,handleRemoveReportAtIndex:de,revalidateCallback:A,showing:le}))})),i.createElement(C,{sx:{p:2}},i.createElement(x,{direction:"row",spacing:2,justifyContent:"end"},i.createElement(L,{text:"Update items",loadingText:"Loading..."}))),i.createElement("input",{type:"hidden",name:"items",value:JSON.stringify(function(e){return e.map((function(e){var t,r;return{id:e.id,ordered_quantity:e.ordered_quantity,received_quantity:e.received_quantity,registered_quantity:e.registered_quantity,released_quantity:e.released_quantity,reports:(null===(r=null===(t=e.reports)||void 0===t?void 0:t.data)||void 0===r?void 0:r.map((function(e){return{id:"id"in e?e.id:void 0,quantity:e.quantity,content:e.content,type:e.type}})))||[]}}))}(Z))}))))))}export{J as default};
@@ -0,0 +1,7 @@
1
+ "use server";
2
+ /*
3
+ * UMWD-Components
4
+ * @copyright Jelle Paulus
5
+ * @license MIT
6
+ */
7
+ import{__awaiter as r,__generator as e,__assign as s}from"../../../../../node_modules/tslib/tslib.es6.js";import{mutateData as t}from"../../../services/mutate-data.js";import{flattenAttributes as i}from"../../../../lib/utils.js";import{parseFormData as o}from"../../../../lib/parseFormData.js";function a(a,n,l){return r(this,void 0,void 0,(function(){var r,u,m;return e(this,(function(e){switch(e.label){case 0:return r=o(l),[4,t("PUT","/api/enduser-profiles/".concat(a),r)];case 1:return(u=e.sent())?u.error?[2,s(s({},n),{severity:"error",strapiErrors:u.error,message:"Failed to update profile."})]:(m=i(u),[2,s(s({},n),{severity:"success",message:"Profile Updated Successfully",data:m,strapiErrors:null})]):[2,s(s({},n),{severity:"error",strapiErrors:null,message:"Ops! Something went wrong. Please try again."})]}}))}))}export{a as updateEnduserProfileAction};
@@ -4,4 +4,4 @@
4
4
  * @copyright Jelle Paulus
5
5
  * @license MIT
6
6
  */
7
- import{__awaiter as r,__generator as e,__assign as t}from"../../../../../node_modules/tslib/tslib.es6.js";import{mutateData as s}from"../../../services/mutate-data.js";import{flattenAttributes as i}from"../../../../lib/utils.js";import{parseFormData as o}from"../../../../lib/parseFormData.js";function a(a,n){return r(this,void 0,void 0,(function(){var r,l,m,p,u;return e(this,(function(e){switch(e.label){case 0:return r=Object.fromEntries(n),l=o(n),m=r.id,[4,s("PUT","/api/dispatcher-profiles/".concat(m),l)];case 1:return(p=e.sent())?p.error?[2,t(t({},a),{strapiErrors:p.error,message:"Failed to Register."})]:(u=i(p),[2,t(t({},a),{message:"Profile Updated",data:u,strapiErrors:null})]):[2,t(t({},a),{strapiErrors:null,message:"Ops! Something went wrong. Please try again."})]}}))}))}export{a as updateDispatcherProfileAction};
7
+ import{__awaiter as r,__generator as e,__assign as s}from"../../../../../node_modules/tslib/tslib.es6.js";import{mutateData as t}from"../../../services/mutate-data.js";import{flattenAttributes as i}from"../../../../lib/utils.js";import{parseFormData as o}from"../../../../lib/parseFormData.js";function a(a,l,n){return r(this,void 0,void 0,(function(){var r,p,u;return e(this,(function(e){switch(e.label){case 0:return r=o(n),[4,t("PUT","/api/dispatcher-profiles/".concat(a),r)];case 1:return(p=e.sent())?p.error?[2,s(s({},l),{severity:"error",strapiErrors:p.error,message:"Failed to update profile."})]:(u=i(p),[2,s(s({},l),{severity:"success",message:"Profile Updated Successfully",data:u,strapiErrors:null})]):[2,s(s({},l),{severity:"error",strapiErrors:null,message:"Ops! Something went wrong. Please try again."})]}}))}))}export{a as updateDispatcherProfileAction};
@@ -4,4 +4,4 @@
4
4
  * @copyright Jelle Paulus
5
5
  * @license MIT
6
6
  */
7
- import{__awaiter as e,__generator as r,__assign as t}from"../../../../../node_modules/tslib/tslib.es6.js";import{mutateData as s}from"../../../services/mutate-data.js";import{flattenAttributes as a}from"../../../../lib/utils.js";import{parseFormData as o}from"../../../../lib/parseFormData.js";import i from"../../../../../node_modules/dayjs/dayjs.min.js";function n(n,d){return e(this,void 0,void 0,(function(){var e,m,l,p;return r(this,(function(r){switch(r.label){case 0:return Object.fromEntries(d),(e=o(d)).data.order_date?(m={data:{vendor_profile:e.data.vendors,customer_reference:e.data.customer_reference,order_date:i(e.data.order_date).format("YYYY-MM-DD"),items:e.data.ipo_items}},0===JSON.parse(e.data.ipo_items).length?(console.log("No items in IPO"),[2,t(t({},n),{strapiErrors:null,message:"Please add items to the IPO."})]):(console.log("ipoData",m),[4,s("POST","/api/ipos",m)])):[2,t(t({},n),{strapiErrors:null,message:"Please select an Order Date."})];case 1:return(l=r.sent())?l.error?[2,t(t({},n),{strapiErrors:l.error,message:"Failed to Create IPO."})]:(p=a(l),[2,t(t({},n),{message:"New IPO Created",data:p,strapiErrors:null})]):[2,t(t({},n),{strapiErrors:null,message:"Ops! Something went wrong. Please try again."})]}}))}))}export{n as createIPOAction};
7
+ import{__awaiter as e,__generator as r,__assign as s}from"../../../../../node_modules/tslib/tslib.es6.js";import{mutateData as t}from"../../../services/mutate-data.js";import{flattenAttributes as a}from"../../../../lib/utils.js";import{parseFormData as o}from"../../../../lib/parseFormData.js";import i from"../../../../../node_modules/dayjs/dayjs.min.js";function d(d,l){return e(this,void 0,void 0,(function(){var e,m,n,u;return r(this,(function(r){switch(r.label){case 0:return(e=o(l)).data.order_date?(m={data:{vendor_profile:e.data.vendors,customer_reference:e.data.customer_reference,order_date:i(e.data.order_date).format("YYYY-MM-DD"),items:e.data.ipo_items}},0===JSON.parse(e.data.ipo_items).length?[2,s(s({},d),{severity:"error",strapiErrors:null,message:"Please add items to the IPO."})]:[4,t("POST","/api/ipos",m)]):[2,s(s({},d),{severity:"error",strapiErrors:null,message:"Please select an Order Date."})];case 1:return(n=r.sent())?n.error?[2,s(s({},d),{severity:"error",strapiErrors:n.error,message:"Failed to create IPO."})]:(u=a(n),[2,s(s({},d),{severity:"success",message:"IPO Created Successfully",data:u,strapiErrors:null})]):[2,s(s({},d),{severity:"error",strapiErrors:null,message:"Failed to create IPO. Please try again."})]}}))}))}export{d as createIPOAction};
@@ -4,4 +4,4 @@
4
4
  * @copyright Jelle Paulus
5
5
  * @license MIT
6
6
  */
7
- import{__awaiter as r,__generator as t,__assign as s}from"../../../../../node_modules/tslib/tslib.es6.js";import{mutateData as e}from"../../../services/mutate-data.js";import{flattenAttributes as o}from"../../../../lib/utils.js";import{parseFormData as i}from"../../../../lib/parseFormData.js";function a(a,n){return r(this,void 0,void 0,(function(){var r,m,p,l;return t(this,(function(t){switch(t.label){case 0:return r=Object.fromEntries(n),m=i(n),[4,e("PUT","/api/ipos/".concat(r.id),m)];case 1:return(p=t.sent())?p.error?[2,s(s({},a),{strapiErrors:p.error,message:"Failed to Update Ipo."})]:(l=o(p),[2,s(s({},a),{message:"Ipo Updated",data:l,strapiErrors:null})]):[2,s(s({},a),{strapiErrors:null,message:"Ops! Something went wrong. Please try again."})]}}))}))}export{a as updateIpoAction};
7
+ import{__awaiter as r,__generator as e,__assign as s}from"../../../../../node_modules/tslib/tslib.es6.js";import{mutateData as t}from"../../../services/mutate-data.js";import{flattenAttributes as i}from"../../../../lib/utils.js";import{parseFormData as a}from"../../../../lib/parseFormData.js";function o(o,l,u){return r(this,void 0,void 0,(function(){var r,n,m;return e(this,(function(e){switch(e.label){case 0:return r=a(u),[4,t("PUT","/api/ipos/".concat(o),r)];case 1:return(n=e.sent())?n.error?[2,s(s({},l),{severity:"error",strapiErrors:n.error,message:"Failed to update IPO."})]:(m=i(n),[2,s(s({},l),{severity:"success",message:"IPO Updated Successfully",data:m,strapiErrors:null})]):[2,s(s({},l),{severity:"error",strapiErrors:null,message:"Failed to update IPO. Please try again."})]}}))}))}export{o as updateIpoAction};