umwd-components 0.1.661 → 0.1.663

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.
@@ -0,0 +1,20 @@
1
+ ---
2
+ mode: "agent"
3
+ tools: []
4
+ ---
5
+
6
+ # Apply form patterns and actions to update forms in the codebase.
7
+
8
+ Take the documentation from [form-patterns.md](../form-patterns.md) and read it
9
+ carefully. make sure the Form component matches the patterns described there.
10
+
11
+ Then within this Form component find the actions it uses and make sure these are
12
+ updated according to the documentation in
13
+ [action-patterns.md](../action-patterns.md)
14
+
15
+ - Respect comments by previous devs (me) and do not remove them unless they are
16
+ no longer relevant.
17
+
18
+ - Do not change the currently used texts, often they are by the client, you
19
+ might however leave suggestions for improvement in comments, these are
20
+ appriciated.
@@ -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 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};
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 n,useEffect as i}from"react";import m from"@mui/material/Box";import l from"@mui/material/Stack";import s from"@mui/material/TextField";import c from"@mui/material/Typography";import d from"@mui/material/Divider";import u from"@mui/material/Button";import{SubmitButton as p}from"../../SubmitButton.js";import{useFormState as f}from"react-dom";import{createIPOAction as v}from"../../../data/actions/logistics/ipo/createIPOAction.js";import E from"@mui/material/Grid";import g from"../vendor/VendorSelector.js";import{getSingleVendor as x}from"../../../data/loaders/logistics/getSingleVendor.js";import{IPOItemFields as y}from"./IPOItemFields.js";import{AdapterDayjs as h}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as b}from"@mui/x-date-pickers/LocalizationProvider";import{DatePicker as C}from"@mui/x-date-pickers/DatePicker";import{useSnackbar as j}from"../../../context/common/SnackbarContext.js";var A={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function k(k){var I=this,P=k.vendorNamesArr,D=k.sx,O=k.revalidateCallback,S=k.handleClose,w=e(f(v,A),2),T=w[0],V=w[1],_=e(n([]),2),B=_[0],N=_[1],z=e(n(null),2),F=z[0],G=z[1],L=j().handleAddMessage;i((function(){(null==T?void 0:T.message)&&(L({message:T.message,severity:T.severity||"error"}),"success"===T.severity&&(O&&O(),S&&S()))}),[null==T?void 0:T.message]),i((function(){(null==T?void 0:T.strapiErrors)&&L({message:T.strapiErrors.message||"Error performing action",severity:"error"})}),[null==T?void 0:T.strapiErrors]);return o.createElement(m,{sx:r([],e(Array.isArray(D)?D:[D]),!1)},o.createElement("form",{action:V},o.createElement(E,{container:!0,spacing:2},o.createElement(E,{item:!0,xs:12},o.createElement(l,{spacing:2},o.createElement(c,{variant:"h3",component:"h1"},"Add IPO"),o.createElement(c,{variant:"body1"},"Create a new incoming purchase order"))),o.createElement(E,{item:!0,xs:12,md:6,sx:{mt:1}},P?o.createElement(g,{vendorNames:P,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 G(e),e?[4,x(e)]:(N([]),[2]);case 1:return r=a.sent(),N(null===(t=null==r?void 0:r.products)||void 0===t?void 0:t.data),[2]}}))}))}}):o.createElement(c,null,"No vendors on file, you need to create a vendor first before you are able to create incoming purchase orders")),o.createElement(E,{item:!0,xs:12},o.createElement(l,{spacing:2},o.createElement(c,{variant:"h5"},"Order Details"),o.createElement(c,{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(b,{dateAdapter:h},o.createElement(C,{name:"order_date",label:"Order Date"})),o.createElement(c,{variant:"body1"},"Please enter a custom reference for this order"),o.createElement(s,{id:"customer_reference",name:"customer_reference",type:"text",label:"Custom Reference"}),o.createElement(d,null))),o.createElement(E,{item:!0,xs:12},o.createElement(y,{productsArr:B,vendorID:F})),o.createElement(E,{item:!0,xs:12},o.createElement(l,{direction:"row",justifyContent:"space-between",alignItems:"center",sx:{mt:2}},S&&o.createElement(u,{onClick:S,variant:"outlined"},"Cancel"),o.createElement(p,{text:"Create IPO",loadingText:"Creating...",variant:"contained"}))))))}export{k 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,__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};
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(x,{direction:"row",spacing:2,justifyContent:"space-between"},q&&i.createElement(O,{onClick:q,variant:"outlined"},"Cancel"),i.createElement(L,{variant:"contained",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};
@@ -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,{useState as m,useEffect as n}from"react";import a from"@mui/material/Paper";import o from"@mui/material/Box";import i from"@mui/material/Stack";import c from"@mui/material/Alert";import l from"@mui/material/TextField";import s from"@mui/material/Typography";import{SubmitButton as d}from"../../SubmitButton.js";import{useFormState as p}from"react-dom";import{StrapiErrors as u}from"../../StrapiErrors.js";import{createVendorAction as E}from"../../../data/actions/logistics/vendor/createVendorAction.js";import f from"@mui/material/Grid";import{BusinessCredentialsFields as x}from"../../e-commerce/customer/BusinessCredentials.js";import{AddressFields as g}from"../../common/Address.js";import b from"../../e-commerce/products/ProductSelector.js";import{ContactsFields as v}from"../../common/Contacts.js";import h from"@mui/material/Button";import y from"@mui/icons-material/Add";import{ContactType as j}from"../../../types/common/Contact.js";import{ExplanatoryFoldOut as _}from"../../ExplanatoryFoldOut.js";var A={zodErrors:null,strapiErrors:null,data:null,message:null};function C(C){var N=C.productNamesArr,k=C.revalidateCallback,V=e(p(E,A),2),w=V[0],B=V[1],P=e(m([]),2),R=P[0],S=P[1];return n((function(){(null==w?void 0:w.data)&&k&&k()}),[w.data]),r.createElement(o,{component:a,sx:{p:2}},r.createElement("form",{action:B},r.createElement(f,{container:!0,spacing:2},r.createElement(f,{item:!0,xs:12},r.createElement(s,{variant:"h5"},"Add Vendor")),r.createElement(f,{item:!0,xs:12},r.createElement(_,{title:"Vendor",description:"Vendors are businesses that you purchase products from."})),r.createElement(f,{item:!0,xs:12,md:6},r.createElement(x,{componentName:"business_credentials",componentReference:"common.business-credentials"})),r.createElement(f,{item:!0,xs:12,md:6},r.createElement(i,{spacing:1,sx:{pt:1}},r.createElement(l,{id:"website_url",name:"website_url",label:"Website Url"}),r.createElement(l,{id:"phone_number",name:"phone_number",label:"Phone Number"}),r.createElement(l,{id:"email",name:"email",label:"Email"}))),r.createElement(f,{item:!0,xs:12,md:6},r.createElement(s,{variant:"h6"},"Address"),r.createElement(g,{componentName:"address",componentReference:"common.address"})),r.createElement(f,{item:!0,xs:12,sx:{mt:1}},r.createElement(s,{variant:"h6"},"Products"),r.createElement(b,{productNames:N,currentValue:[]})),r.createElement(f,{item:!0,xs:12,sx:{mt:1}},r.createElement(s,{variant:"h6"},"Contacts"),r.createElement(f,{container:!0,spacing:2},R.map((function(e,t){return r.createElement(f,{item:!0,xs:12,sm:6,md:4,lg:3,key:t},r.createElement(v,{key:t,data:e.data,componentName:e.componentName,componentReference:"logistics-elements.contact",deleteCallback:function(){!function(e){console.log("delete",e);var t=R.filter((function(t,r){return r!==e}));S(t)}(t)}}))})),r.createElement(f,{item:!0,xs:12,sm:6,md:4,lg:3,sx:{justifyContent:"center",display:"flex",alignItems:"center"}},r.createElement(h,{variant:"contained",startIcon:r.createElement(y,null),onClick:function(){S(t(t([],e(R),!1),[{componentName:"contacts[".concat(R.length,"]"),componentReference:"logistics-elements.contact",data:{first_name:"",last_name:"",email:"",phone_number:"",type:j.Other}}],!1))},size:"large"},"Add contact")))),r.createElement(f,{item:!0,xs:12},r.createElement(i,{direction:"row-reverse",spacing:2,alignItems:"center",sx:{py:1}},r.createElement(d,{text:"create new vendor",loadingText:"loading"}),(null==w?void 0:w.strapiErrors)&&r.createElement(u,{error:null==w?void 0:w.strapiErrors}),(null==w?void 0:w.message)&&r.createElement(c,{severity:"error"},null==w?void 0:w.message))))))}export{C as AddVendorForm};
7
+ import{__read as e,__spreadArray as t}from"../../../../node_modules/tslib/tslib.es6.js";import r,{useState as n,useEffect as m}from"react";import a from"@mui/material/Box";import o from"@mui/material/Stack";import i from"@mui/material/Button";import s from"@mui/material/TextField";import c from"@mui/material/Typography";import{SubmitButton as l}from"../../SubmitButton.js";import{useFormState as d}from"react-dom";import{useSnackbar as u}from"../../../context/common/SnackbarContext.js";import{createVendorAction as p}from"../../../data/actions/logistics/vendor/createVendorAction.js";import E from"@mui/material/Grid";import{BusinessCredentialsFields as f}from"../../e-commerce/customer/BusinessCredentials.js";import{AddressFields as x}from"../../common/Address.js";import g from"../../e-commerce/products/ProductSelector.js";import{ContactsFields as v}from"../../common/Contacts.js";import b from"@mui/icons-material/Add";import{ContactType as y}from"../../../types/common/Contact.js";import{ExplanatoryFoldOut as h}from"../../ExplanatoryFoldOut.js";var C={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function j(j){var A=j.productNamesArr,_=j.revalidateCallback,k=j.handleClose,N=j.sx,V=e(d(p,C),2),w=V[0],B=V[1],R=u().handleAddMessage,S=e(n([]),2),P=S[0],T=S[1];return m((function(){(null==w?void 0:w.message)&&(R({message:w.message,severity:w.severity||"error"}),"success"===w.severity&&(_&&_(),k&&k()))}),[null==w?void 0:w.message]),m((function(){(null==w?void 0:w.strapiErrors)&&R({message:w.strapiErrors.message||"Error creating vendor",severity:"error"})}),[null==w?void 0:w.strapiErrors]),r.createElement(a,{sx:t([],e(Array.isArray(N)?N:[N]),!1)},r.createElement("form",{action:B},r.createElement(E,{container:!0,spacing:2},r.createElement(E,{item:!0,xs:12},r.createElement(o,{spacing:2},r.createElement(c,{variant:"h3",component:"h1"},"Add Vendor"),r.createElement(c,{variant:"body1"},"Create a new vendor for your business"))),r.createElement(E,{item:!0,xs:12},r.createElement(h,{title:"Vendor",description:"Vendors are businesses that you purchase products from."})),r.createElement(E,{item:!0,xs:12,md:6},r.createElement(f,{componentName:"business_credentials",componentReference:"common.business-credentials"})),r.createElement(E,{item:!0,xs:12,md:6},r.createElement(o,{spacing:1,sx:{pt:1}},r.createElement(s,{id:"website_url",name:"website_url",label:"Website Url"}),r.createElement(s,{id:"phone_number",name:"phone_number",label:"Phone Number"}),r.createElement(s,{id:"email",name:"email",label:"Email"}))),r.createElement(E,{item:!0,xs:12,md:6},r.createElement(c,{variant:"h6"},"Address"),r.createElement(x,{componentName:"address",componentReference:"common.address"})),r.createElement(E,{item:!0,xs:12,sx:{mt:1}},r.createElement(c,{variant:"h6"},"Products"),r.createElement(g,{productNames:A,currentValue:[]})),r.createElement(E,{item:!0,xs:12,sx:{mt:1}},r.createElement(c,{variant:"h6"},"Contacts"),r.createElement(E,{container:!0,spacing:2},P.map((function(e,t){return r.createElement(E,{item:!0,xs:12,sm:6,md:4,lg:3,key:t},r.createElement(v,{key:t,data:e.data,componentName:e.componentName,componentReference:"logistics-elements.contact",deleteCallback:function(){!function(e){var t=P.filter((function(t,r){return r!==e}));T(t)}(t)}}))})),r.createElement(E,{item:!0,xs:12,sm:6,md:4,lg:3,sx:{justifyContent:"center",display:"flex",alignItems:"center"}},r.createElement(i,{variant:"contained",startIcon:r.createElement(b,null),onClick:function(){T(t(t([],e(P),!1),[{componentName:"contacts[".concat(P.length,"]"),componentReference:"logistics-elements.contact",data:{first_name:"",last_name:"",email:"",phone_number:"",type:y.Other}}],!1))},size:"large"},"Add contact"))))," ",r.createElement(E,{item:!0,xs:12},r.createElement(o,{direction:"row",spacing:2,justifyContent:"flex-end",sx:{mt:2}},k&&r.createElement(i,{onClick:k,variant:"outlined"},"Cancel"),r.createElement(l,{text:"Create Vendor",loadingText:"Creating...",variant:"contained"}))))))}export{j as AddVendorForm};
@@ -4,4 +4,4 @@
4
4
  * @copyright Jelle Paulus
5
5
  * @license MIT
6
6
  */
7
- import{__read as e,__spreadArray as t,__assign as n}from"../../../../node_modules/tslib/tslib.es6.js";import a,{useState as r}from"react";import o from"@mui/material/Paper";import m from"@mui/material/Box";import i from"@mui/material/Stack";import c from"@mui/material/Alert";import l from"@mui/material/TextField";import s from"@mui/material/Typography";import{SubmitButton as d}from"../../SubmitButton.js";import{useFormState as u}from"react-dom";import{StrapiErrors as p}from"../../StrapiErrors.js";import{updateVendorAction as f}from"../../../data/actions/logistics/vendor/updateVendorAction.js";import E from"@mui/material/Grid";import{BusinessCredentialsFields as v}from"../../e-commerce/customer/BusinessCredentials.js";import{AddressFields as g}from"../../common/Address.js";import b from"../../e-commerce/products/ProductSelector.js";import x,{ContactsFields as h}from"../../common/Contacts.js";import y from"@mui/material/IconButton";import _ from"@mui/icons-material/Add";import{ContactType as N}from"../../../types/common/Contact.js";import{ExplanatoryFoldOut as j}from"../../ExplanatoryFoldOut.js";import C from"../note/NoteTakingComponent.js";import k from"../note/NotesDisplay.js";var A={zodErrors:null,strapiErrors:null,data:null,message:null};function V(V){var w=V.data,R=V.productNamesArr,B=V.revalidateCallback,P=V.sx,S=w.id,T=w.website_url,I=w.phone_number,F=w.email,O=w.business_credentials,z=w.address,D=w.products,G=w.contacts,M=w.notes;console.log("data",w);var U=e(u(f,A),2),W=U[0],q=U[1],H=(null==D?void 0:D.data)||[],J=e(r([]),2),K=J[0],L=J[1],Q=function(n,a){K.includes(a)?L(K.filter((function(e){return e!==a}))):L(t(t([],e(K),!1),[a],!1))},X=e(r(G.reduce((function(e,t,n){return e.push({componentName:"contacts[".concat(n,"]"),componentReference:"logistics-elements.contact",data:t}),e}),[])),2),Y=X[0],Z=X[1],$=e(r([]),2),ee=$[0],te=$[1];return a.createElement(m,{sx:t([{p:2}],e(Array.isArray(P)?P:[P]),!1),component:o},a.createElement("form",{action:q},S&&a.createElement("input",{id:"id",type:"hidden",name:"id",value:S}),a.createElement(E,{container:!0,spacing:2},a.createElement(E,{item:!0,xs:12},a.createElement(i,{direction:"row",justifyContent:"space-between"},a.createElement(s,{variant:"h5"},"Edit Vendor"),a.createElement(C,{content:"",related:[{id:w.id,__type:"api::logistics.vendor-profile"}],revalidateCallback:B}))),a.createElement(E,{item:!0,xs:12},a.createElement(j,{title:"Vendor",description:"Vendors are businesses that you purchase products from."})),a.createElement(E,{item:!0,xs:12,md:6},a.createElement(v,{data:O,componentName:"business_credentials",componentReference:"common.business-credentials"})),a.createElement(E,{item:!0,xs:12,md:6},a.createElement(i,{spacing:2},a.createElement(l,{id:"website_url",name:"website_url",label:"Website Url",defaultValue:T}),a.createElement(l,{id:"phone_number",name:"phone_number",label:"Phone Number",defaultValue:I}),a.createElement(l,{id:"email",name:"email",label:"Email",defaultValue:F}))),a.createElement(E,{item:!0,xs:12,md:6},a.createElement(s,{variant:"h6"},"Address"),a.createElement(g,{data:z,componentName:"address",componentReference:"common.address"})),a.createElement(E,{item:!0,xs:12,sx:{mt:1}},a.createElement(s,{variant:"h6"},"Products"),a.createElement(b,{productNames:R,currentValue:H.map((function(e){return e.id}))})),a.createElement(E,{item:!0,xs:12,sx:{mt:1}},a.createElement(s,{variant:"h6"},"Contacts")),null==Y?void 0:Y.map((function(e,t){var r,o;return(null===(r=e.data)||void 0===r?void 0:r.id)?K.includes(null===(o=e.data)||void 0===o?void 0:o.id)?a.createElement(E,{item:!0,xs:12,md:6,lg:4,key:e.data.id},a.createElement(h,{data:e.data,componentName:"contacts[".concat(t,"]"),componentReference:"logistics-elements.contact",deleteCallback:function(){Z(Y.filter((function(e,n){return n!==t})))}})):a.createElement(E,{item:!0,xs:12,md:6,lg:4,key:e.data.id},a.createElement("input",{type:"hidden",name:"contacts[".concat(t,"].id"),value:e.data.id}),a.createElement("input",{type:"hidden",name:"contacts[".concat(t,"].__component"),value:"logistics-elements.contact"}),a.createElement(x,{data:n(n({},e.data),{onClick:Q})})):null})),ee.map((function(e,t){var r;return a.createElement(E,{item:!0,xs:12,md:6,lg:4,key:null===(r=e.data)||void 0===r?void 0:r.uuid},a.createElement(h,{data:e.data,componentName:e.componentName,componentReference:"logistics-elements.contact",deleteCallback:function(){te(ee.filter((function(e,n){return n!==t})).map((function(e,t){return n(n({},e),{componentName:"contacts[".concat(t+Y.length,"]")})})))}}))})),a.createElement(E,{item:!0,xs:12,md:6,lg:4,justifyContent:"center",alignItems:"center"},a.createElement(y,{onClick:function(){te(t(t([],e(ee),!1),[{componentName:"contacts[".concat(Y.length+ee.length,"]"),componentReference:"logistics-elements.contact",data:{uuid:Math.random(),first_name:"",last_name:"",email:"",phone_number:"",type:N.Other}}],!1))}},a.createElement(_,null))),a.createElement(E,{item:!0,xs:12},a.createElement(s,{variant:"h6"},"Notes"),void 0!==(null==M?void 0:M.data)?a.createElement(k,{notes:M.data}):a.createElement(s,null,"No notes to display")),a.createElement(E,{item:!0,xs:12},a.createElement(i,{direction:"row-reverse",spacing:2,alignItems:"center",sx:{py:1}},a.createElement(d,{text:"update vendor",loadingText:"loading"}),(null==W?void 0:W.strapiErrors)&&a.createElement(p,{error:null==W?void 0:W.strapiErrors}),(null==W?void 0:W.message)&&a.createElement(c,{severity:"error"},null==W?void 0:W.message))))))}export{V as EditVendorForm};
7
+ import{__read as e,__spreadArray as t,__assign as n}from"../../../../node_modules/tslib/tslib.es6.js";import a,{useEffect as r,useState as o}from"react";import m from"@mui/material/Box";import i from"@mui/material/Stack";import c from"@mui/material/Button";import l from"@mui/material/TextField";import s from"@mui/material/Typography";import{SubmitButton as d}from"../../SubmitButton.js";import{useFormState as u}from"react-dom";import{useSnackbar as p}from"../../../context/common/SnackbarContext.js";import{updateVendorAction as f}from"../../../data/actions/logistics/vendor/updateVendorAction.js";import E from"@mui/material/Grid";import{BusinessCredentialsFields as v}from"../../e-commerce/customer/BusinessCredentials.js";import{AddressFields as g}from"../../common/Address.js";import x from"../../e-commerce/products/ProductSelector.js";import b,{ContactsFields as y}from"../../common/Contacts.js";import h from"@mui/material/IconButton";import C from"@mui/icons-material/Add";import{ContactType as _}from"../../../types/common/Contact.js";import{ExplanatoryFoldOut as j}from"../../ExplanatoryFoldOut.js";import N from"../note/NoteTakingComponent.js";import k from"../note/NotesDisplay.js";var V={zodErrors:null,strapiErrors:null,data:null,message:null,severity:null};function A(A){var w=A.data,R=A.productNamesArr,B=A.revalidateCallback,S=A.handleClose,T=A.sx,P=w.id,U=w.website_url,F=w.phone_number,I=w.email,M=w.business_credentials,O=w.address,z=w.products,D=w.contacts,G=w.notes;console.log("data",w);var W=e(u(f,V),2),q=W[0],H=W[1],J=p().handleAddMessage;r((function(){(null==q?void 0:q.message)&&(J({message:q.message,severity:q.severity||"error"}),"success"===q.severity&&(B&&B(),S&&S()))}),[null==q?void 0:q.message]),r((function(){(null==q?void 0:q.strapiErrors)&&J({message:q.strapiErrors.message||"Error updating vendor",severity:"error"})}),[null==q?void 0:q.strapiErrors]);var K=(null==z?void 0:z.data)||[],L=e(o([]),2),Q=L[0],X=L[1],Y=function(n,a){Q.includes(a)?X(Q.filter((function(e){return e!==a}))):X(t(t([],e(Q),!1),[a],!1))},Z=e(o(D.reduce((function(e,t,n){return e.push({componentName:"contacts[".concat(n,"]"),componentReference:"logistics-elements.contact",data:t}),e}),[])),2),$=Z[0],ee=Z[1],te=e(o([]),2),ne=te[0],ae=te[1];return a.createElement(m,{sx:t([],e(Array.isArray(T)?T:[T]),!1)},a.createElement("form",{action:H},P&&a.createElement("input",{id:"id",type:"hidden",name:"id",value:P}),a.createElement(E,{container:!0,spacing:2},a.createElement(E,{item:!0,xs:12},a.createElement(i,{direction:"row",justifyContent:"space-between"},a.createElement(s,{variant:"h5"},"Edit Vendor"),a.createElement(N,{content:"",related:[{id:w.id,__type:"api::logistics.vendor-profile"}],revalidateCallback:B}))),a.createElement(E,{item:!0,xs:12},a.createElement(j,{title:"Vendor",description:"Vendors are businesses that you purchase products from."})),a.createElement(E,{item:!0,xs:12,md:6},a.createElement(v,{data:M,componentName:"business_credentials",componentReference:"common.business-credentials"})),a.createElement(E,{item:!0,xs:12,md:6},a.createElement(i,{spacing:2},a.createElement(l,{id:"website_url",name:"website_url",label:"Website Url",defaultValue:U}),a.createElement(l,{id:"phone_number",name:"phone_number",label:"Phone Number",defaultValue:F}),a.createElement(l,{id:"email",name:"email",label:"Email",defaultValue:I}))),a.createElement(E,{item:!0,xs:12,md:6},a.createElement(s,{variant:"h6"},"Address"),a.createElement(g,{data:O,componentName:"address",componentReference:"common.address"})),a.createElement(E,{item:!0,xs:12,sx:{mt:1}},a.createElement(s,{variant:"h6"},"Products"),a.createElement(x,{productNames:R,currentValue:K.map((function(e){return e.id}))})),a.createElement(E,{item:!0,xs:12,sx:{mt:1}},a.createElement(s,{variant:"h6"},"Contacts")),null==$?void 0:$.map((function(e,t){var r,o;return(null===(r=e.data)||void 0===r?void 0:r.id)?Q.includes(null===(o=e.data)||void 0===o?void 0:o.id)?a.createElement(E,{item:!0,xs:12,md:6,lg:4,key:e.data.id},a.createElement(y,{data:e.data,componentName:"contacts[".concat(t,"]"),componentReference:"logistics-elements.contact",deleteCallback:function(){ee($.filter((function(e,n){return n!==t})))}})):a.createElement(E,{item:!0,xs:12,md:6,lg:4,key:e.data.id},a.createElement("input",{type:"hidden",name:"contacts[".concat(t,"].id"),value:e.data.id}),a.createElement("input",{type:"hidden",name:"contacts[".concat(t,"].__component"),value:"logistics-elements.contact"}),a.createElement(b,{data:n(n({},e.data),{onClick:Y})})):null})),ne.map((function(e,t){var r;return a.createElement(E,{item:!0,xs:12,md:6,lg:4,key:null===(r=e.data)||void 0===r?void 0:r.uuid},a.createElement(y,{data:e.data,componentName:e.componentName,componentReference:"logistics-elements.contact",deleteCallback:function(){ae(ne.filter((function(e,n){return n!==t})).map((function(e,t){return n(n({},e),{componentName:"contacts[".concat(t+$.length,"]")})})))}}))})),a.createElement(E,{item:!0,xs:12,md:6,lg:4,justifyContent:"center",alignItems:"center"},a.createElement(h,{onClick:function(){ae(t(t([],e(ne),!1),[{componentName:"contacts[".concat($.length+ne.length,"]"),componentReference:"logistics-elements.contact",data:{uuid:Math.random(),first_name:"",last_name:"",email:"",phone_number:"",type:_.Other}}],!1))}},a.createElement(C,null))),a.createElement(E,{item:!0,xs:12},a.createElement(s,{variant:"h6"},"Notes"),void 0!==(null==G?void 0:G.data)?a.createElement(k,{notes:G.data}):a.createElement(s,null,"No notes to display"))," ",a.createElement(E,{item:!0,xs:12},a.createElement(i,{direction:"row",spacing:2,justifyContent:"flex-end",sx:{mt:2}},S&&a.createElement(c,{onClick:S,variant:"outlined"},"Cancel"),a.createElement(d,{text:"Update Vendor",loadingText:"Updating..."}))))))}export{A as EditVendorForm};
@@ -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 o}from"../../../../lib/utils.js";import{parseFormData as a}from"../../../../lib/parseFormData.js";function i(i,n){return r(this,void 0,void 0,(function(){var r,d,l;return e(this,(function(e){switch(e.label){case 0:return Object.fromEntries(n),(r=a(n)).data.products&&(r.data.products=JSON.parse(r.data.products)),[4,s("POST","/api/vendor-profiles",r)];case 1:return d=e.sent(),console.dir(d,{depth:null}),d?d.error?[2,t(t({},i),{strapiErrors:d.error,message:"Failed to Create Vendor."})]:(l=o(d),[2,t(t({},i),{message:"New Vendor Created",data:l,strapiErrors:null})]):[2,t(t({},i),{strapiErrors:null,message:"Ops! Something went wrong. Please try again."})]}}))}))}export{i as createVendorAction};
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 o}from"../../../../lib/utils.js";import{parseFormData as a}from"../../../../lib/parseFormData.js";function n(n,i){return r(this,void 0,void 0,(function(){var r,l,u,d;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),(r=a(i)).data.products&&(r.data.products=JSON.parse(r.data.products)),[4,t("POST","/api/vendor-profiles",r)];case 1:return(l=e.sent())?l.error?[2,s(s({},n),{strapiErrors:l.error,zodErrors:null,message:"Failed to create vendor. Please check the form and try again.",severity:"error"})]:(u=o(l),[2,s(s({},n),{data:u,strapiErrors:null,zodErrors:null,message:"Vendor created successfully!",severity:"success"})]):[2,s(s({},n),{strapiErrors:null,zodErrors:null,message:"Something went wrong while creating the vendor. Please try again.",severity:"error"})];case 2:return d=e.sent(),console.error("Error creating vendor:",d),[2,s(s({},n),{data:null,strapiErrors:null,zodErrors:null,message:"An unexpected error occurred. Please try again later.",severity:"error"})];case 3:return[2]}}))}))}export{n as createVendorAction};
@@ -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 e}from"../../../../../node_modules/tslib/tslib.es6.js";import{mutateData as s}from"../../../services/mutate-data.js";import{flattenAttributes as o}from"../../../../lib/utils.js";import{parseFormData as a}from"../../../../lib/parseFormData.js";function i(i,n){return r(this,void 0,void 0,(function(){var r,d,p,m;return t(this,(function(t){switch(t.label){case 0:return r=Object.fromEntries(n),(d=a(n)).data.products&&(d.data.products=JSON.parse(d.data.products)),[4,s("PUT","/api/vendor-profiles/".concat(r.id),d)];case 1:return(p=t.sent())?p.error?[2,e(e({},i),{strapiErrors:p.error,message:"Failed to Update Vendor."})]:(m=o(p),[2,e(e({},i),{message:"Vendor Updated",data:m,strapiErrors:null})]):[2,e(e({},i),{strapiErrors:null,message:"Ops! Something went wrong. Please try again."})]}}))}))}export{i as updateVendorAction};
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 o}from"../../../../lib/utils.js";import{parseFormData as a}from"../../../../lib/parseFormData.js";function n(n,i){return r(this,void 0,void 0,(function(){var r,l,u,d,c;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),r=Object.fromEntries(i),(l=a(i)).data.products&&(l.data.products=JSON.parse(l.data.products)),[4,t("PUT","/api/vendor-profiles/".concat(r.id),l)];case 1:return(u=e.sent())?u.error?[2,s(s({},n),{data:null,strapiErrors:u.error,zodErrors:null,message:"Failed to update vendor. Please check the form and try again.",severity:"error"})]:(d=o(u),[2,s(s({},n),{data:d,strapiErrors:null,zodErrors:null,message:"Vendor updated successfully!",severity:"success"})]):[2,s(s({},n),{data:null,strapiErrors:null,zodErrors:null,message:"Something went wrong while updating the vendor. Please try again.",severity:"error"})];case 2:return c=e.sent(),console.error("Error updating vendor:",c),[2,s(s({},n),{data:null,strapiErrors:null,zodErrors:null,message:"An unexpected error occurred. Please try again later.",severity:"error"})];case 3:return[2]}}))}))}export{n as updateVendorAction};