@dropins/storefront-purchase-order 1.2.3 → 1.3.0-alpha-20261109151740
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.
- package/CHANGELOG.md +9 -0
- package/api.js +1 -1
- package/chunks/components.js +1 -1
- package/chunks/components.js.map +1 -1
- package/containers/ApprovalRuleDetails.js +1 -1
- package/containers/ApprovalRuleDetails.js.map +1 -1
- package/containers/ApprovalRuleForm.js +1 -1
- package/containers/ApprovalRuleForm.js.map +1 -1
- package/containers/ApprovalRulesList.js +1 -1
- package/containers/ApprovalRulesList.js.map +1 -1
- package/containers/CompanyPurchaseOrders.js +1 -1
- package/containers/CompanyPurchaseOrders.js.map +1 -1
- package/containers/CustomerPurchaseOrders.js +1 -1
- package/containers/CustomerPurchaseOrders.js.map +1 -1
- package/containers/PurchaseOrderApprovalFlow.js +1 -1
- package/containers/PurchaseOrderApprovalFlow.js.map +1 -1
- package/containers/PurchaseOrderCommentForm.js +1 -1
- package/containers/PurchaseOrderCommentForm.js.map +1 -1
- package/containers/PurchaseOrderCommentsList.js +1 -1
- package/containers/PurchaseOrderCommentsList.js.map +1 -1
- package/containers/PurchaseOrderConfirmation.js +1 -1
- package/containers/PurchaseOrderConfirmation.js.map +1 -1
- package/containers/PurchaseOrderHistoryLog.js +1 -1
- package/containers/PurchaseOrderHistoryLog.js.map +1 -1
- package/containers/PurchaseOrderStatus.js +1 -1
- package/containers/PurchaseOrderStatus.js.map +1 -1
- package/containers/RequireApprovalPurchaseOrders.js +1 -1
- package/containers/RequireApprovalPurchaseOrders.js.map +1 -1
- package/containers.d.ts +1 -0
- package/containers.js +5 -0
- package/containers.js.map +1 -0
- package/package.json +1 -1
- package/render.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @dropins/storefront-purchase-order
|
|
2
2
|
|
|
3
|
+
## 1.3.0-alpha-20261109151740
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d2fe70a: Load containers through the consolidated `containers.js` bundle
|
|
8
|
+
instead of each container's individual entry point. This replaces one request
|
|
9
|
+
per container with a single request, which reduces request pressure on EDS.
|
|
10
|
+
The per-container entry points remain available for backwards compatibility.
|
|
11
|
+
|
|
3
12
|
## 1.2.3
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/api.js
CHANGED
|
@@ -835,5 +835,5 @@ import{events as $}from"@dropins/tools/event-bus.js";import{Initializer as Pe,ge
|
|
|
835
835
|
}
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
|
-
`,V={currentPage:1,pageSize:20,totalPages:1},Qr=async(e=V.currentPage,a=V.pageSize)=>v(tr,{variables:{currentPage:e,pageSize:a}}).then(u=>{var p,E,c,y,o,h;(p=u.errors)!=null&&p.length&&T(u.errors);const t=(c=(E=u==null?void 0:u.data)==null?void 0:E.customer)==null?void 0:c.purchase_order_approval_rules,i=(t==null?void 0:t.total_count)??0,s={currentPage:((y=t==null?void 0:t.page_info)==null?void 0:y.current_page)??V.currentPage,pageSize:((o=t==null?void 0:t.page_info)==null?void 0:o.page_size)??V.pageSize,totalPages:((h=t==null?void 0:t.page_info)==null?void 0:h.total_pages)??V.totalPages};return{totalCount:i,pageInfo:s,items:((t==null?void 0:t.items)||[]).map(z)}}).catch(S),zr={PO_ALL:"Magento_PurchaseOrder::all",VIEW_CUSTOMER:"Magento_PurchaseOrder::view_purchase_orders",VIEW_SUBORDINATES:"Magento_PurchaseOrder::view_purchase_orders_for_subordinates",VIEW_COMPANY:"Magento_PurchaseOrder::view_purchase_orders_for_company",AUTO_APPROVE:"Magento_PurchaseOrder::autoapprove_purchase_order",SUPER_APPROVE:"Magento_PurchaseOrderRule::super_approve_purchase_order",VIEW_RULES:"Magento_PurchaseOrderRule::view_approval_rules",MANAGE_RULES:"Magento_PurchaseOrderRule::manage_approval_rules"};export{Dr as
|
|
838
|
+
`,V={currentPage:1,pageSize:20,totalPages:1},Qr=async(e=V.currentPage,a=V.pageSize)=>v(tr,{variables:{currentPage:e,pageSize:a}}).then(u=>{var p,E,c,y,o,h;(p=u.errors)!=null&&p.length&&T(u.errors);const t=(c=(E=u==null?void 0:u.data)==null?void 0:E.customer)==null?void 0:c.purchase_order_approval_rules,i=(t==null?void 0:t.total_count)??0,s={currentPage:((y=t==null?void 0:t.page_info)==null?void 0:y.current_page)??V.currentPage,pageSize:((o=t==null?void 0:t.page_info)==null?void 0:o.page_size)??V.pageSize,totalPages:((h=t==null?void 0:t.page_info)==null?void 0:h.total_pages)??V.totalPages};return{totalCount:i,pageInfo:s,items:((t==null?void 0:t.items)||[]).map(z)}}).catch(S),zr={PO_ALL:"Magento_PurchaseOrder::all",VIEW_CUSTOMER:"Magento_PurchaseOrder::view_purchase_orders",VIEW_SUBORDINATES:"Magento_PurchaseOrder::view_purchase_orders_for_subordinates",VIEW_COMPANY:"Magento_PurchaseOrder::view_purchase_orders_for_company",AUTO_APPROVE:"Magento_PurchaseOrder::autoapprove_purchase_order",SUPER_APPROVE:"Magento_PurchaseOrderRule::super_approve_purchase_order",VIEW_RULES:"Magento_PurchaseOrderRule::view_approval_rules",MANAGE_RULES:"Magento_PurchaseOrderRule::manage_approval_rules"};export{Dr as INITIAL_FORM_STATE,zr as PO_PERMISSIONS,Cr as REQUIRED_FIELDS_ON_SUBMIT,Lr as VALIDATION_ERROR_KEYS,Ar as addPurchaseOrderComment,Rr as addPurchaseOrderItemsToCart,Er as approvePurchaseOrders,gr as cancelPurchaseOrders,Nr as cleanAndDeep,pr as config,Ir as createAppliesToOptions,mr as createConditionOperators,hr as createPurchaseOrderApprovalRule,wr as createRuleTypeOptions,kr as currencyInfo,br as deletePurchaseOrderApprovalRule,v as fetchGraphQl,Sr as formatDate,or as getConfig,de as getPurchaseOrder,Br as getPurchaseOrderApprovalRule,$r as getPurchaseOrderApprovalRuleMetadata,Qr as getPurchaseOrderApprovalRules,Hr as getPurchaseOrders,Tr as getRange,Fr as getStatusVariant,Y as initialize,vr as isValidUrl,Mr as navigate,Vr as placeOrderForPurchaseOrder,Gr as placePurchaseOrder,yr as rejectPurchaseOrders,cr as removeFetchGraphQlHeader,lr as setEndpoint,_r as setFetchGraphQlHeader,sr as setFetchGraphQlHeaders,xr as transformToFormValues,Or as updateFormFieldValue,Pr as updatePurchaseOrderApprovalRule,dr as updateValidationErrors,Ur as validateFormFields,fr as validatePurchaseOrders};
|
|
839
839
|
//# sourceMappingURL=api.js.map
|
package/chunks/components.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2026 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{classes as V,Slot as He}from"@dropins/tools/lib.js";import{useText as ae,Text as P}from"@dropins/tools/i18n.js";import{jsxs as u,Fragment as Oe,jsx as e}from"@dropins/tools/preact-bundle.js";import{InLineAlert as Le,Table as $e,Pagination as je,Picker as me,Card as Me,Header as ze,Button as H,Tag as ke,Price as Ge,ActionButton as ne,PriceRange as qe,Checkbox as We,Input as Se,TextArea as Fe,RadioButton as Qe,MultiSelect as we,Skeleton as Ze,SkeletonRow as re}from"@dropins/tools/components.js";import{events as G}from"@dropins/tools/event-bus.js";import{g as Ke,getPurchaseOrders as Je,i as xe,rejectPurchaseOrders as Ie,approvePurchaseOrders as Ve,a as De,f as ve,n as ce,PO_PERMISSIONS as Z,I as Ye,c as Xe,b as er,d as rr,currencyInfo as ar,getPurchaseOrderApprovalRuleMetadata as sr,getPurchaseOrderApprovalRule as Ue,t as tr,V as fe,R as lr,v as be,e as or,updatePurchaseOrderApprovalRule as nr,createPurchaseOrderApprovalRule as cr,u as ge,h as ir,getPurchaseOrderApprovalRules as dr,deletePurchaseOrderApprovalRule as ur,cancelPurchaseOrders as pr,placeOrderForPurchaseOrder as hr,addPurchaseOrderComment as mr}from"../api.js";import{useState as A,useEffect as q,useCallback as M,useMemo as B,useReducer as br}from"@dropins/tools/preact-bundle.js";import{Fragment as Pe}from"@dropins/tools/preact.js";import*as K from"@dropins/tools/preact-bundle.js";const Dr=({pageSizeConfig:r,totalCount:a=0,columns:s=[],rows:i=[],paginationConfig:t,alertMessageConfig:n={heading:"",description:"",type:"success"},loading:c=!1,className:l="",variant:o="secondary",skeletonRowCount:f=10,emptyTitle:y,header:R,footer:g,withWrapper:_,expandedRows:T})=>{var v;const O=ae({title:"PurchaseOrders.purchaseOrdersTable.noPurchaseOrders.default"}),{heading:d,description:k,type:L}=n,{currentPage:p,totalPages:E,handlePageChange:I}=t,{pageSizeOptionsList:S,onChange:F}=r,D=S==null?void 0:S.find(x=>x.selected),$=D&&D.value!==void 0?Number(D.value):10,{from:W,to:Q,total:ie}=Ke(p,$,a),j=!c&&i.length===0,se=u(Oe,{children:[d||k?e(Le,{heading:d,description:k,type:L}):null,R?e("div",{className:"purchase-orders-table__header",children:R}):null,e($e,{className:"purchase-orders-table__table-wrapper",mobileLayout:"stacked",columns:s,rowData:i,expandedRows:T,loading:c,skeletonRowCount:+f}),j&&e("div",{className:"purchase-orders-table__empty-state",role:"status","aria-live":"polite",children:e("p",{children:y||O.title})}),a>0?u("div",{className:"purchase-orders-table__pagination-wrapper",children:[e("div",{className:"purchase-orders-table__pagination-counter",children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.pagination.status",fields:{from:W,to:Q,total:ie}})}),E>1&&e(je,{className:V(["purchase-orders-table__pagination",["purchase-orders-table__pagination--loading",c]]),currentPage:p,totalPages:E,onChange:I}),a>0&&S.length?u("div",{className:"purchase-orders-table__pagination-page-size",children:[e(P,{id:"PurchaseOrders.purchaseOrdersTable.pagination.pageSizeLabel.start"}),e(me,{disabled:c,handleSelect:F,options:S,value:((v=S==null?void 0:S.find(x=>x.selected))==null?void 0:v.value)||""})]}):null]}):null,g?e("div",{className:"purchase-orders-table__footer",children:g}):null]});return _?e(Me,{variant:o,"data-testid":"purchaseOrdersTable",className:V(["b2b-purchase-order-purchase-orders-table",["b2b-purchase-order-purchase-orders-table--empty-state",j],l]),children:se}):e("div",{"data-testid":"purchaseOrdersTable",className:V(["b2b-purchase-order-purchase-orders-table",["b2b-purchase-order-purchase-orders-table--empty-state",j],l]),children:se})},vr=({headerText:r,divider:a=!1})=>e(ze,{title:r,divider:a,className:V(["purchase-orders-header",["purchase-orders-header--with-divider",a]]),"data-testid":"purchase-orders-header"}),Ur=({loading:r,selectedCount:a,className:s,handleRejectSelected:i,handleApproveSelected:t})=>u("div",{className:V(["b2b-purchase-order-purchase-orders-table-actions",s]),children:[u("div",{children:["Selected ",a]}),u("div",{className:"b2b-purchase-order-purchase-orders-table-actions__buttons",children:[e(H,{variant:"secondary",onClick:i,disabled:r||a===0,children:"Reject selected"}),e(H,{variant:"primary",onClick:t,disabled:r||a===0,children:"Approve selected"})]})]});var _e=(r=>(r.CUSTOMER_PURCHASE_ORDERS="customerPurchaseOrders",r.COMPANY_PURCHASE_ORDERS="companyPurchaseOrders",r.CUSTOMER_APPROVAL_PURCHASE_ORDERS="customerApprovalPurchaseOrders",r))(_e||{});const Br=[{text:"10",value:"10",selected:!1},{text:"20",value:"20",selected:!0},{text:"30",value:"30",selected:!1},{text:"50",value:"50",selected:!1}],Be=[{key:"poNumber",label:"PO #"},{key:"status",label:"Status"},{key:"createdBy",label:"Created By"},{key:"action",label:"Actions"}],Ne=[{key:"ruleName",label:"Rule Name"},{key:"status",label:"Status"},{key:"createdBy",label:"Created By"},{key:"action",label:"Actions"}],fr=[{key:"checkboxView",label:""},...Be],gr=20,Hr=({view:r,initialPageSize:a,routePurchaseOrderDetails:s,setColumns:i,setRowsData:t,t:n,permissions:c,loadingPermissions:l})=>{const o=r===_e.COMPANY_PURCHASE_ORDERS,f=r===_e.CUSTOMER_APPROVAL_PURCHASE_ORDERS,[y,R]=A(!0),[g,_]=A([]),[T,O]=A([]),[d,k]=A(a),[L,p]=A(!0),[E,I]=A({currentPage:1,totalPages:1,totalCount:0}),[S,F]=A({heading:"",description:"",type:"success"}),[D,$]=A(new Set);q(()=>{const b=G.on("purchase-order/refresh",()=>{R(!0)},{eager:!0});return()=>{b==null||b.off()}},[]),q(()=>{if(S.heading||S.description){const b=setTimeout(()=>{F({heading:"",description:"",type:"success"})},7e3);return()=>clearTimeout(b)}},[S.heading,S.description]);const{currentPage:W,totalPages:Q,totalCount:ie}=E,j=M(b=>{I(w=>({...w,currentPage:b})),$(new Set),R(!0)},[]),se=M(b=>{const w=b.target.value;k(m=>m.map(C=>({...C,selected:C.value===w}))),j(1),$(new Set),R(!0)},[j]),v=(c==null?void 0:c.isAdmin)??!1,x=B(()=>{let b={};return o&&(b={companyPurchaseOrders:!0}),f&&(b={myApprovals:!0}),b},[o,f]);q(()=>{var m;if(!y||l)return;p(!0);const b=(m=d==null?void 0:d.find(C=>C.selected))==null?void 0:m.value,w=parseInt(b??gr.toString(),10);Je(x,w,W).then(C=>{var ue,pe;const z=(C==null?void 0:C.purchaseOrderItems)??[],X=(ue=C==null?void 0:C.pageInfo)==null?void 0:ue.currentPage,U=(pe=C==null?void 0:C.pageInfo)==null?void 0:pe.totalPages,ee=C==null?void 0:C.totalCount;I({currentPage:X>U?U||1:X,totalPages:U,totalCount:ee}),O(z)}).catch(C=>{console.error("Failed to fetch purchase orders:",C),O([])}).finally(()=>{p(!1),R(!1)})},[y,W,d,x,l]);const h=M(b=>{const w=s==null?void 0:s(b);return xe(w??"")?w:"#"},[s]),N=M(b=>{$(w=>{const m=new Set(w);return m.has(b)?m.delete(b):m.add(b),m})},[]),te=M(b=>{const w=b.target.value,m=b.target.checked;_(C=>m?[...C,w]:C.filter(z=>z!==w))},[]),J=M(b=>{const w=b.target.checked;_(()=>w?T.filter(m=>["PENDING","APPROVAL_REQUIRED"].includes(m.status)).map(m=>m.uid??""):[])},[T]),Y=M(()=>{p(!0),Ie(g).then(()=>{F({heading:n.alertHeaderReject,description:n.alertDescriptionReject,type:"success"}),_([]),G.emit("purchase-order/refresh",!0)}).catch(b=>{F({heading:n.alertHeaderError,description:n.alertDescriptionError,type:"error"}),console.error(b)}).finally(()=>{p(!1)})},[g,n]),de=M(()=>{p(!0),Ve(g).then(()=>{F({heading:n.alertHeaderApprove,description:n.alertDescriptionApprove,type:"success"}),_([]),G.emit("purchase-order/refresh",!0)}).catch(b=>{F({heading:n.alertHeaderError,description:n.alertDescriptionError,type:"error"}),console.error(b)}).finally(()=>{p(!1)})},[g,n]),le=B(()=>{const b=o||f?fr:Be;return(i==null?void 0:i(b))??b.map(w=>w.key==="checkboxView"&&(v||f)?{key:w.key,label:e("input",{type:"checkbox",name:"selectAll",disabled:T.every(m=>!["PENDING","APPROVAL_REQUIRED"].includes(m.status)),onChange:J}),ariaLabel:n.selectAllAriaLabel}:{...w,label:n[w.key]||w.label})},[n,v,o,f,i,T,J]),oe=B(()=>{const b=T.map((m,C)=>{var ye,Ee,Re,Te,Ce,Ae;const z=m.number??"",X=D.has(C),U=`${((ye=m.createdBy)==null?void 0:ye.firstname)??""} ${((Ee=m.createdBy)==null?void 0:Ee.lastname)??""}`.trim(),ee=e(ne,{type:"button",onClick:()=>N(C),children:e(P,{id:`PurchaseOrders.purchaseOrdersTable.buttons.${X?"expandedHidden":"expandedShow"}`})}),ue=e(ke,{className:`b2b-purchase-order-purchase-orders-table__status b2b-purchase-order-purchase-orders-table__status--${De(m.status)}`,children:e(P,{id:`PurchaseOrders.purchaseOrdersTable.statusOrder.${m.status.toLowerCase()}`})}),pe=u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details",children:[u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-content",children:[u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.orderNumber"})})," ",m.order.orderNumber]}),u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.createdDate"})})," ",ve(m.createdAt)]}),u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.updatedDate"})})," ",ve(m.updatedAt)]}),u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.total"})})," ",e(Ge,{amount:(Te=(Re=m==null?void 0:m.quote)==null?void 0:Re.grandTotal)==null?void 0:Te.value,currency:(Ae=(Ce=m==null?void 0:m.quote)==null?void 0:Ce.grandTotal)==null?void 0:Ae.currency,weight:"normal"})]})]}),e("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-action",children:e(ne,{onClick:()=>{ce(h(m.uid??""))},"aria-label":`View purchase order ${z}`,children:n.actionView})})]});return{...v||f?{checkboxView:e("input",{type:"checkbox",name:z,value:m.uid,checked:g.includes(m.uid),onChange:te,disabled:!["PENDING","APPROVAL_REQUIRED"].includes(m.status)})}:{},poNumber:z,status:ue,createdBy:U,action:ee,_rowDetails:pe}});let w=b;if(t){const m=t(b);m!==void 0&&Array.isArray(m)&&(w=m)}return w},[T,t,v,f,g,te,h,n.actionView,D,N]);return{tableConfig:{columns:le,rows:oe,expandedRows:D},paginationConfig:{currentPage:W,totalPages:Q,handlePageChange:j},pageSizeConfig:{pageSizeOptionsList:d,onChange:se},totalCount:ie,loading:L,selectedOrderIds:g,handleRejectSelected:Y,handleApproveSelected:de,isAdmin:v,isRequireApprovalPOsView:f,alertMessageConfig:S}},_r=r=>{if(!r)return{isAdmin:!1,purchaseOrderEnabled:!1,role:{id:"",name:""},permissions:{purchaseOrderAll:!1,viewPurchaseOrders:!1,viewPurchaseOrdersForSubordinates:!1,viewPurchaseOrdersForCompany:!1,autoApprovePurchaseOrder:!1,superApprovePurchaseOrder:!1,viewApprovalRules:!1,manageApprovalRules:!1}};const a=r.admin===!0,s=c=>{const l=r[c];return l===!1?!1:l===!0?!0:a},i={purchaseOrderAll:s(Z.PO_ALL),viewPurchaseOrders:s(Z.VIEW_CUSTOMER),viewPurchaseOrdersForSubordinates:s(Z.VIEW_SUBORDINATES),viewPurchaseOrdersForCompany:s(Z.VIEW_COMPANY),autoApprovePurchaseOrder:s(Z.AUTO_APPROVE),superApprovePurchaseOrder:s(Z.SUPER_APPROVE),viewApprovalRules:s(Z.VIEW_RULES),manageApprovalRules:s(Z.MANAGE_RULES)},n=Object.values(r).some(c=>c===!1)?!1:Object.values(i).some(c=>c===!0);return{isAdmin:a,purchaseOrderEnabled:n,role:{id:"",name:a?"Company Administrator":""},permissions:i}},Or=()=>{const r=G.lastPayload("auth/permissions"),[a,s]=A(r);q(()=>{const n=G.on("auth/permissions",c=>{s(c)},{eager:!0});return()=>{n==null||n.off()}},[]);const i=!a;return{permissions:B(()=>_r(a),[a]),loadingPermissions:i}};function Pr(r,a){switch(a.type){case"SET_LOADING":return{...r,isLoading:a.payload};case"SET_SUBMIT_ERROR":return{...r,submitError:a.payload};case"SET_FORM_VALUES":return{...r,formValues:a.payload};case"SET_AVAILABLE_APPLIES_TO":return{...r,availableAppliesTo:a.payload};case"SET_AVAILABLE_APPROVERS":return{...r,availableRequiresApprovalFrom:a.payload};case"SET_ERRORS":return{...r,errors:a.payload};case"SET_TOUCHED":return{...r,touched:a.payload};case"SET_CURRENCIES":return{...r,currencyCodesList:a.payload};case"UPDATE_FIELD":{const{key:s,value:i}=a.payload,t=ir(r.formValues,s,i),n={...r.touched,[s]:!0};s==="roleType"&&i==="specific_roles"&&(n.appliesTo=!0);const c=be(t),l=ge(c,r.errors,n);return{...r,formValues:t,touched:n,errors:l}}case"TOUCH_FIELD":{const s=a.payload,i={...r.touched,[s]:!0},t=be(r.formValues),n=ge(t,r.errors,i);return{...r,touched:i,errors:n}}case"MARK_FIELDS_TOUCHED":{const s={...r.touched,...a.payload},i=be(r.formValues),t=ge(i,r.errors,s);return{...r,touched:s,errors:t}}default:return r}}const yr=({t:r,approvalRuleID:a,routeApprovalRulesList:s,onSubmit:i,onChange:t,permissions:n,loadingPermissions:c})=>{const[l,o]=br(Pr,Ye),f=B(()=>Xe(r),[r]),y=B(()=>er(r),[r]),R=B(()=>rr(r),[r]);q(()=>{o({type:"SET_LOADING",payload:!0}),ar().then(d=>{o({type:"SET_CURRENCIES",payload:d.availableCurrencyCodes})}).catch(d=>{console.error("Failed to fetch currencies:",d)}),sr().then(d=>{const{availableAppliesTo:k,availableRequiresApprovalFrom:L}=d;return o({type:"SET_AVAILABLE_APPLIES_TO",payload:k}),o({type:"SET_AVAILABLE_APPROVERS",payload:L}),a?Ue(a):null}).then(d=>{d&&o({type:"SET_FORM_VALUES",payload:tr(d)}),o({type:"SET_SUBMIT_ERROR",payload:null})}).catch(d=>{console.error("Failed to fetch data:",d),o({type:"SET_SUBMIT_ERROR",payload:(d==null?void 0:d.message)||fe.FAILED_TO_LOAD})}).finally(()=>{o({type:"SET_LOADING",payload:!1})})},[a]);const g=M((d,k)=>{o({type:"UPDATE_FIELD",payload:{key:d,value:k}}),t&&t({...l.formValues,[d]:k})},[t,l.formValues]),_=M(d=>{o({type:"TOUCH_FIELD",payload:d}),t&&t(l.formValues)},[t,l.formValues]),T=M(async()=>{o({type:"SET_LOADING",payload:!0}),o({type:"SET_SUBMIT_ERROR",payload:null}),o({type:"MARK_FIELDS_TOUCHED",payload:lr});const d=be(l.formValues);if(Object.keys(d).length>0){o({type:"SET_ERRORS",payload:d}),o({type:"SET_LOADING",payload:!1});return}const k=or(l.formValues);try{let L;if(a?L=await nr({uid:a,...k}):L=await cr(k),!L.uid){o({type:"SET_SUBMIT_ERROR",payload:fe.FAILED_TO_CREATE}),o({type:"SET_LOADING",payload:!1});return}i&&i(l.formValues),s?ce(s()):o({type:"SET_LOADING",payload:!1})}catch(L){console.error("Failed to save approval rule:",L),o({type:"SET_SUBMIT_ERROR",payload:(L==null?void 0:L.message)||fe.FAILED_TO_CREATE}),o({type:"SET_LOADING",payload:!1})}},[l.formValues,s,a,i]),O=B(()=>!!(l.isLoading||c||!(n!=null&&n.permissions.viewApprovalRules)&&!(n!=null&&n.permissions.manageApprovalRules)),[l.isLoading,c,n]);return{availableAppliesTo:l.availableAppliesTo,availableRequiresApprovalFrom:l.availableRequiresApprovalFrom,formValues:l.formValues,ruleTypeOptions:f,conditionOperators:y,currencies:l.currencyCodesList,appliesToOptions:R,handleSetFormValues:g,handleSubmit:T,handleFieldTouch:_,errors:l.errors,touched:l.touched,isLoading:l.isLoading,formLoading:O,submitError:l.submitError}},$r=({approvalRuleID:r,routeApprovalRulesList:a})=>{const[s,i]=A(!0),[t,n]=A(null);q(()=>{r&&(i(!0),Ue(r).then(o=>{o.uid&&n(o)}).catch(()=>{n(null)}).finally(()=>{i(!1)}))},[r]);const c=B(()=>{if(!t||s)return[];const{name:o,status:f,description:y,appliesToRoles:R,approverRoles:g,condition:_}=t;return[{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.ruleName"}),value:o},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.status"}),value:e(P,{id:`PurchaseOrders.approvalRuleDetails.fields.statusView.${f.toLocaleLowerCase()}`})},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.description"}),value:y},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.appliesTo"}),value:e("ul",{children:R.map(T=>e("li",{children:T.name},T.id))})},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.ruleType"}),value:e(P,{id:`PurchaseOrders.approvalRuleDetails.fields.condition.attribute.${_.attribute.toLocaleLowerCase()}`})},{label:u(Oe,{children:[e(P,{id:`PurchaseOrders.approvalRuleDetails.fields.condition.attribute.${_.attribute.toLocaleLowerCase()}`}),":"]}),value:u("div",{children:[e(P,{id:`PurchaseOrders.approvalRuleDetails.fields.condition.operator.${_.operator.toLocaleLowerCase()}`}),e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.amount.label"}),e(qe,{amount:_.amount.value,currency:_.amount.currency})]})},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.requiresApprovalFrom"}),value:e("ul",{children:g.map(T=>e("li",{children:T.name},T.id))})}]},[t,s]);return{handleRedirectToList:()=>{ce((a==null?void 0:a())??"")},loading:s,formValues:c}},Er=20,jr=({routeApprovalRuleDetails:r,routeCreateApprovalRule:a,routeEditApprovalRule:s,setColumns:i,setRowsData:t,initialPageSize:n,permissions:c,loadingPermissions:l,t:o})=>{const[f,y]=A([]),[R,g]=A(!0),[_,T]=A(!0),[O,d]=A(n),[k,L]=A({currentPage:1,totalPages:1,totalCount:0}),[p,E]=A(new Set);q(()=>{const v=G.on("purchase-order/refresh",()=>{g(!0)},{eager:!0});return()=>{v==null||v.off()}},[]);const{currentPage:I,totalPages:S,totalCount:F}=k,D=M(v=>{L(x=>({...x,currentPage:v})),E(new Set),g(!0)},[]),$=M(v=>{const x=v.target.value;d(h=>h.map(N=>({...N,selected:N.value===x}))),D(1),E(new Set),g(!0)},[D]),W=M(v=>{E(x=>{const h=new Set(x);return h.has(v)?h.delete(v):h.add(v),h})},[]);q(()=>{var h;if(!R||l)return;T(!0);const v=(h=O==null?void 0:O.find(N=>N.selected))==null?void 0:h.value,x=parseInt(v??Er.toString(),10);dr(I,x).then(N=>{var le,oe;const te=(N==null?void 0:N.items)??[],J=(le=N==null?void 0:N.pageInfo)==null?void 0:le.currentPage,Y=(oe=N==null?void 0:N.pageInfo)==null?void 0:oe.totalPages,de=N==null?void 0:N.totalCount;L({currentPage:J>Y?Y||1:J,totalPages:Y,totalCount:de}),y(te)}).catch(N=>{console.error("Error fetching approval rules:",N),y([])}).finally(()=>{T(!1),g(!1)})},[R,I,O,S,l]);const Q=M((v,x)=>{let h="";switch(x){case"new":{h=a==null?void 0:a(v);break}case"edit":{h=s==null?void 0:s(v);break}case"view":{h=r==null?void 0:r(v);break}}return xe(h??"")?h:"#"},[a,s,r]),ie=B(()=>(i==null?void 0:i(Ne))??Ne.map(v=>({...v,label:o[v.key]||v.label})),[i,o]),j=M((v,x)=>{v.preventDefault(),T(!0),ur(x).then(()=>{G.emit("purchase-order/refresh",!0)}).finally(()=>{E(new Set)})},[]),se=B(()=>{const v=f==null?void 0:f.map((h,N)=>{var b,w,m,C,z,X;const{isAdmin:te,permissions:{manageApprovalRules:J}}=c,Y=p.has(N),de=te||J,le=e(ne,{onClick:()=>W(N),children:e(P,{id:`PurchaseOrders.purchaseOrdersTable.buttons.${Y?"expandedHidden":"expandedShow"}`})}),oe=u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details",children:[u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-content",children:[u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.ruleType"})})," ",e(P,{id:`PurchaseOrders.purchaseOrdersTable.ruleTypes.${(w=(b=h.condition)==null?void 0:b.attribute)==null?void 0:w.toLocaleLowerCase()}`})]}),e("p",{children:e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.appliesTo"})})}),e("ul",{children:((m=h==null?void 0:h.appliesToRoles)==null?void 0:m.length)<=0?e("li",{children:o.appliesToAll}):(C=h==null?void 0:h.appliesToRoles)==null?void 0:C.map((U,ee)=>e("li",{children:U.name},ee))}),e("p",{children:e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.approver"})})}),e("ul",{children:(z=h==null?void 0:h.approverRoles)==null?void 0:z.map((U,ee)=>e("li",{children:U==null?void 0:U.name},ee))})]}),de?e("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-action",children:u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-action-inner-wrapper",children:[e(ne,{onClick:()=>{ce(Q(h.uid,"edit"))},"aria-label":o.ariaLabelEditRule.replace("{{ruleName}}",h.name),"data-testid":`edit-approval-rule-${h.uid}`,children:o.actionEdit}),e(ne,{onClick:U=>j(U,h.uid),"aria-label":o.ariaLabelDeleteRule.replace("{{ruleName}}",h.name),"data-testid":`delete-approval-rule-${h.uid}`,children:o.actionDelete})]})}):e("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-action",children:e(ne,{onClick:()=>{ce(Q(h.uid,"view"))},"aria-label":o.ariaLabelViewRule.replace("{{ruleName}}",h.name),"data-testid":`view-approval-rule-${h.uid}`,children:o.actionView})})]});return{ruleName:h.name,status:e(ke,{className:`b2b-purchase-order-purchase-orders-table__status b2b-purchase-order-purchase-orders-table__status--${De(h.status)}`,children:e(P,{id:`PurchaseOrders.purchaseOrdersTable.rulesStatus.${(X=h.status)==null?void 0:X.toLocaleLowerCase()}`})}),createdBy:h.createdBy,action:le,_rowDetails:oe}});let x=v;if(t){const h=t(v);h!==void 0&&Array.isArray(h)&&(x=h)}return x},[f,p,c,t,o,Q,j,W]);return{tableConfig:{columns:ie,rows:se,expandedRows:p},paginationConfig:{currentPage:I,totalPages:S,handlePageChange:D},pageSizeConfig:{pageSizeOptionsList:O,onChange:$},totalCount:F,loading:_,handleCreateUrl:Q}},Rr=()=>{const[r,a]=A(!0),[s,i]=A(null);return q(()=>{const t=G.on("purchase-order/data",n=>{n!=null&&n.uid&&i(n),a(!1)},{eager:!0});return()=>{t==null||t.off()}},[]),{poDataLoading:r,purchaseOrderData:s}},zr=()=>{const{poDataLoading:r,purchaseOrderData:a}=Rr(),s=ae({approvalSuccessMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.success.approval",rejectSuccessMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.success.reject",cancelSuccessMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.success.cancel",placeOrderSuccessMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.success.placeOrder",approvalErrorMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.errors.approval",rejectErrorMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.errors.reject",cancelErrorMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.errors.cancel",placeOrderErrorMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.errors.placeOrder"}),i=(a==null?void 0:a.uid)??null,t=(a==null?void 0:a.status)??"PENDING",n=(a==null?void 0:a.availableActions)??[],[c,l]=A("success"),[o,f]=A(""),[y,R]=A(!1),[g,_]=A(!0),T=()=>{_(!0)},O=M((I,S)=>{let F="";if(I){switch(S){case"APPROVE":F=s.approvalSuccessMessage;break;case"REJECT":F=s.rejectSuccessMessage;break;case"CANCEL":F=s.cancelSuccessMessage;break;case"PLACE_ORDER":F=s.placeOrderSuccessMessage;break}l("success")}else{switch(S){case"APPROVE":F=s.approvalErrorMessage;break;case"REJECT":F=s.rejectErrorMessage;break;case"CANCEL":F=s.cancelErrorMessage;break;case"PLACE_ORDER":F=s.placeOrderErrorMessage;break}l("error")}f(F),_(!1)},[s]),d=M(async(I,S)=>{if(i){R(!0);try{await I(i),O(!0,S)}catch{O(!1,S)}finally{R(!1),G.emit("purchase-order/refresh",!0)}}},[i,O]),k=M(()=>d(Ve,"APPROVE"),[d]),L=M(()=>d(Ie,"REJECT"),[d]),p=M(()=>d(pr,"CANCEL"),[d]),E=M(()=>d(hr,"PLACE_ORDER"),[d]);return{poId:i,status:t,availableActions:n,alertType:c,loading:y,poDataLoading:r,isDismissed:g,alertMessage:o,handleOnDismiss:T,handleApprove:k,handleReject:L,handleCancel:p,handlePlaceOrder:E}},he=({touched:r=!1,error:a,className:s="error-message"})=>!r||!a?null:e("span",{className:s,children:e(P,{id:a})}),Tr=({availableRequiresApprovalFrom:r,conditionOperators:a,availableAppliesTo:s,appliesToOptions:i,ruleTypeOptions:t,currencies:n,formValues:c,errors:l,touched:o,isLoading:f,permissions:y,handleSubmit:R,handleFieldTouch:g,handleSetFormValues:_,routeApprovalRulesList:T,t:O})=>{var k,L;const d=f||!((k=y==null?void 0:y.permissions)!=null&&k.viewApprovalRules);return u("form",{"data-testid":"approval-rule-form",children:[e(We,{"data-testid":"status-toggle",className:"b2b-purchase-order-approval-rule-form__toggle",disabled:d,name:"status",label:O.formEnabled,checked:c.status==="ENABLED",onChange:p=>{const E=p.target.checked;_("status",E)}}),u("div",{"data-testid":"name-input-container",children:[e(Se,{"data-testid":"name-input",className:"b2b-purchase-order-approval-rule-form__name-input",disabled:d,name:"name",floatingLabel:O.inputRuleNameFloatingLabel,placeholder:O.inputRuleNamePlaceholder,value:c.name,error:!!(o.name&&l.name),onChange:p=>{const E=p.target.value;_("name",E)},onBlur:()=>g("name")}),e(he,{touched:o.name,error:l.name})]}),e(Fe,{"data-testid":"description-textarea",className:"b2b-purchase-order-approval-rule-form__description",disabled:d,name:"description",label:O.textAreaDescriptionLabel,value:c.description,onChange:p=>{const E=p.target.value;_("description",E)}}),u("div",{"data-testid":"applies-to-section",className:"b2b-purchase-order-approval-rule-form__applies-to",children:[e("span",{className:"b2b-purchase-order-approval-rule-form__applies-to-title",children:O.titleAppliesTo}),i.map((p,E)=>e(Qe,{"data-testid":`applies-to-radio-${E}`,disabled:d,name:"radio-group",value:p.value,label:p.text,checked:c.roleType===p.value,onChange:I=>{const S=I.target.value;_("roleType",S)}},p.value)),c.roleType==="specific_roles"?u("div",{"data-testid":"applies-to-multiselect-container",className:"b2b-purchase-order-approval-rule-form__applies-to-multiselect",children:[e(we,{"data-testid":"applies-to-multiselect",disabled:d,name:"appliesTo",value:[...c.appliesTo],options:s.map(p=>({value:p.id,label:p.name})),error:!!(o.appliesTo&&l.appliesTo),onChange:p=>{_("appliesTo",p),o.appliesTo||g("appliesTo")}}),e(he,{touched:o.appliesTo,error:l.appliesTo})]}):null]}),u("div",{"data-testid":"rule-type-section",className:"b2b-purchase-order-approval-rule-form__rule-type",children:[e("span",{className:"b2b-purchase-order-approval-rule-form__rule-type-title",children:O.titleRuleType}),e(me,{"data-testid":"rule-type-picker",className:"b2b-purchase-order-approval-rule-form__rule-type-picker",disabled:d,name:"ruleType",value:c.condition.attribute,options:t,handleSelect:p=>{const E=p.target.value;_("ruleType",E)}})]}),u("div",{"data-testid":"rule-condition-section",className:"b2b-purchase-order-approval-rule-form__rule-condition",children:[e("span",{className:"b2b-purchase-order-approval-rule-form__rule-condition-title",children:(L=t.find(p=>p.value===c.condition.attribute))==null?void 0:L.text}),u("div",{className:V(["b2b-purchase-order-approval-rule-form__rule-condition-container",["b2b-purchase-order-approval-rule-form__rule-condition-container--error",!!l.ruleValue&&!!o.ruleValue]]),children:[e(me,{"data-testid":"rule-condition-picker",className:"b2b-purchase-order-approval-rule-form__rule-condition-picker",disabled:d,name:"ruleCondition",value:c.condition.operator,options:a,handleSelect:p=>{const E=p.target.value;_("ruleCondition",E)}}),u("div",{"data-testid":"rule-value-container",children:[e(Se,{"data-testid":"rule-value-input",className:"b2b-purchase-order-approval-rule-form__rule-value-input",disabled:d,name:"ruleValue",floatingLabel:c.condition.attribute==="NUMBER_OF_SKUS"?O.inputQuantityFloatingLabel:O.inputAmountFloatingLabel,placeholder:c.condition.attribute==="NUMBER_OF_SKUS"?O.inputQuantityPlaceholder:O.inputAmountPlaceholder,value:c.condition.attribute==="NUMBER_OF_SKUS"?c.condition.quantity:c.condition.amount.value,error:!!(o.ruleValue&&l.ruleValue),onChange:p=>{const E=p.target.value;_("ruleValue",E)},onBlur:()=>g("ruleValue")}),e(he,{touched:o.ruleValue,error:l.ruleValue})]}),c.condition.attribute!=="NUMBER_OF_SKUS"?e(me,{"data-testid":"rule-condition-currency-picker",className:"b2b-purchase-order-approval-rule-form__rule-condition-currency-picker",disabled:d,name:"ruleConditionCurrency",value:c.condition.amount.currency,options:n,handleSelect:p=>{const E=p.target.value;_("ruleConditionCurrency",E)}}):null]})]}),u("div",{"data-testid":"approval-role-section",className:"b2b-purchase-order-approval-rule-form__approval-role",children:[e("span",{className:"b2b-purchase-order-approval-rule-form__approval-role-title",children:O.titleRequiresApprovalRole}),u("div",{className:"b2b-purchase-order-approval-rule-form__approval-role-multiselect",children:[e(we,{"data-testid":"approvers-multiselect",disabled:d,name:"approvers",value:[...c.approvers],options:r.map(p=>({value:p.id,label:p.name})),error:!!(o.approvers&&l.approvers),onChange:p=>{_("approvers",p),o.approvers||g("approvers")}}),e(he,{touched:o.approvers,error:l.approvers})]})]}),u("div",{"data-testid":"form-buttons",className:"b2b-purchase-order-approval-rule-form__buttons",children:[e(H,{"data-testid":"save-button",type:"button",disabled:d,onClick:R,children:O.buttonSave}),e(H,{"data-testid":"cancel-button",disabled:f,variant:"secondary",type:"button",onClick:()=>{ce((T==null?void 0:T())??"")},children:O.buttonCancel})]})]})},Gr=({className:r,approvalRuleID:a,withHeader:s,withWrapper:i,routeApprovalRulesList:t,onSubmit:n,onChange:c})=>{const l=ae({headerText:"PurchaseOrders.approvalRuleForm.headerText",titleAppliesTo:"PurchaseOrders.approvalRuleForm.titleAppliesTo",titleRuleType:"PurchaseOrders.approvalRuleForm.titleRuleType",titleRequiresApprovalRole:"PurchaseOrders.approvalRuleForm.titleRequiresApprovalRole",formEnabled:"PurchaseOrders.approvalRuleForm.fields.enabled",formDisabled:"PurchaseOrders.approvalRuleForm.fields.disabled",inputRuleNameFloatingLabel:"PurchaseOrders.approvalRuleForm.fields.inputRuleName.floatingLabel",inputRuleNamePlaceholder:"PurchaseOrders.approvalRuleForm.fields.inputRuleName.placeholder",textAreaDescriptionLabel:"PurchaseOrders.approvalRuleForm.fields.textAreaDescription.label",appliesToAllUsers:"PurchaseOrders.approvalRuleForm.fields.appliesTo.allUsers",appliesToSpecificRoles:"PurchaseOrders.approvalRuleForm.fields.appliesTo.specificRoles",ruleTypeGrandTotal:"PurchaseOrders.approvalRuleForm.fields.ruleTypeOptions.grandTotal",ruleTypeShippingInclTax:"PurchaseOrders.approvalRuleForm.fields.ruleTypeOptions.shippingInclTax",ruleTypeNumberOfSkus:"PurchaseOrders.approvalRuleForm.fields.ruleTypeOptions.numberOfSkus",conditionOperatorMoreThan:"PurchaseOrders.approvalRuleForm.fields.conditionOperators.moreThan",conditionOperatorLessThan:"PurchaseOrders.approvalRuleForm.fields.conditionOperators.lessThan",conditionOperatorMoreThanOrEqualTo:"PurchaseOrders.approvalRuleForm.fields.conditionOperators.moreThanOrEqualTo",conditionOperatorLessThanOrEqualTo:"PurchaseOrders.approvalRuleForm.fields.conditionOperators.lessThanOrEqualTo",inputQuantityFloatingLabel:"PurchaseOrders.approvalRuleForm.fields.inputQuantity.floatingLabel",inputQuantityPlaceholder:"PurchaseOrders.approvalRuleForm.fields.inputQuantity.placeholder",inputAmountFloatingLabel:"PurchaseOrders.approvalRuleForm.fields.inputAmount.floatingLabel",inputAmountPlaceholder:"PurchaseOrders.approvalRuleForm.fields.inputAmount.placeholder",buttonCancel:"PurchaseOrders.approvalRuleForm.fields.buttons.cancel",buttonSave:"PurchaseOrders.approvalRuleForm.fields.buttons.save"}),{permissions:o,loadingPermissions:f}=Or(),{availableRequiresApprovalFrom:y,conditionOperators:R,availableAppliesTo:g,appliesToOptions:_,ruleTypeOptions:T,currencies:O,formValues:d,errors:k,touched:L,isLoading:p,submitError:E,formLoading:I,handleSubmit:S,handleFieldTouch:F,handleSetFormValues:D}=yr({t:l,approvalRuleID:a,loadingPermissions:f,permissions:o,routeApprovalRulesList:t,onSubmit:n,onChange:c});if(I)return e(Cr,{testId:"b2b-purchase-order-approval-rule-form",className:V(["b2b-purchase-order-approval-rule-form",r])});const $=u(Oe,{children:[!!E&&e(Le,{heading:"",description:E}),e(Tr,{availableRequiresApprovalFrom:y,conditionOperators:R,availableAppliesTo:g,appliesToOptions:_,ruleTypeOptions:T,currencies:O,formValues:d,errors:k,touched:L,isLoading:p,handleSubmit:S,handleFieldTouch:F,handleSetFormValues:D,permissions:o,routeApprovalRulesList:t,t:l})]});return u("div",{"data-testid":"b2b-purchase-order-approval-rule-form",className:V(["b2b-purchase-order-approval-rule-form",r]),children:[s?e(vr,{headerText:l.headerText}):null,i?e(Me,{variant:"secondary",children:$}):$]})},qr=({className:r,purchaseOrderNumber:a,routePurchaseOrderDetails:s,...i})=>{const t=ae({title:"PurchaseOrders.purchaseOrderConfirmation.title",messagePrefix:"PurchaseOrders.purchaseOrderConfirmation.messagePrefix",messageSuffix:"PurchaseOrders.purchaseOrderConfirmation.messageSuffix"});return u("div",{...i,className:V(["purchase-orders-confirmation-content",r]),children:[e("h2",{className:"purchase-orders-confirmation-content__title",children:t.title}),u("p",{className:"purchase-orders-confirmation-content__message",children:[t.messagePrefix," ",u("a",{className:"purchase-orders-confirmation-content__link",href:s()??"",children:["#",a]}),". ",t.messageSuffix]})]})},Wr=({slots:r,t:a,loading:s,children:i,availableActions:t=[],handleApprove:n,handleReject:c,handleCancel:l,handlePlaceOrder:o})=>{const f=t.map(y=>{switch(y){case"APPROVE":return e(H,{variant:"secondary",disabled:s,type:"button",onClick:n,children:a.approveButtonText},y);case"PLACE_ORDER":return e(H,{variant:"secondary",disabled:s,type:"button",onClick:o,children:a.placeOrderButtonText},y);case"REJECT":return e(H,{variant:"secondary",disabled:s,type:"button",onClick:c,children:a.rejectButtonText},y);case"CANCEL":return e(H,{variant:"secondary",disabled:s,type:"button",onClick:l,children:a.cancelButtonText},y);default:return null}});return u("div",{className:V(["b2b-purchase-order-status-content"]),children:[e("div",{className:"b2b-purchase-order-status-content__message",children:a.statusMessageText}),i,e("div",{className:"b2b-purchase-order-status-content__actions",children:e(He,{"data-testid":"PurchaseOrderActions",name:"PurchaseOrderActions",slot:r==null?void 0:r.PurchaseOrderActions,context:{loading:s,availableActions:t,handleApprove:n,handleReject:c,handleCancel:l,handlePlaceOrder:o},children:f})})]})},Qr=({formValues:r})=>e("div",{className:V(["b2b-purchase-order-approval-rule-details-content"]),children:r.map((a,s)=>u("div",{className:V(["b2b-purchase-order-approval-rule-details-content__item"]),children:[e("span",{className:"b2b-purchase-order-approval-rule-details-content__label",children:a.label}),e("div",{className:"b2b-purchase-order-approval-rule-details-content__value",children:a.value})]},s))}),Cr=({testId:r="",className:a=""})=>e("div",{"data-testid":r,className:V(["b2b-purchase-order-form-loader",a]),children:u(Ze,{rowGap:"medium","data-testid":"form-loader-root",children:[e(re,{size:"small",variant:"row",fullWidth:!0,lines:1,style:{maxWidth:300},"data-testid":"form-loader-status-toggle"}),e(re,{size:"medium",variant:"row",fullWidth:!0,lines:1,"data-testid":"form-loader-name"}),e(re,{size:"medium",variant:"row",fullWidth:!0,lines:4,"data-testid":"form-loader-description"}),u("div",{className:"approval-rule-form-loader__section","data-testid":"form-loader-approval-role-section",children:[e(re,{size:"small",variant:"row",fullWidth:!0,lines:1,"data-testid":"form-loader-approval-role-label"}),e(re,{size:"small",variant:"row",fullWidth:!0,lines:1,"data-testid":"form-loader-approval-role-input"})]}),u("div",{className:"approval-rule-form-loader__buttons","data-testid":"form-loader-buttons",children:[e(re,{size:"medium",variant:"row",fullWidth:!0,lines:1,style:{width:120},"data-testid":"form-loader-button-save"}),e(re,{size:"medium",variant:"row",fullWidth:!0,lines:1,style:{width:120},"data-testid":"form-loader-button-cancel"})]})]})}),Zr=({commentsList:r=[],visibleRecordsLimit:a=5})=>{const[s,i]=A(a),t=r.length>s,n=r.length<=a,c=ae({showMoreLabel:"PurchaseOrders.comments.view.ariaLabel.showMore",showLessLabel:"PurchaseOrders.comments.view.ariaLabel.showLess"});return r.length?u("div",{className:"b2b-purchase-order-comment-list-content",children:[e("ul",{className:"b2b-purchase-order-comment-list-content__list",children:r.slice(0,s).map((l,o)=>{var y,R;const f=Math.min(s,r.length);return u(Pe,{children:[u("li",{className:"b2b-purchase-order-comment-list-content__item",children:[u("div",{className:"b2b-purchase-order-comment-list-content__title",children:[ve(l.createdAt),(y=l.author)!=null&&y.firstname&&((R=l.author)!=null&&R.lastname)?` (${l.author.firstname} ${l.author.lastname})`:""]}),e("div",{className:"b2b-purchase-order-comment-list-content__description",children:l.text})]}),o<f-1&&e("hr",{className:"b2b-purchase-order-comment-list-content__divider"})]},l.uid)})}),!n&&e("div",{className:"b2b-purchase-order-comment-list-content__actions",children:e(H,{variant:"secondary","aria-expanded":!t,"aria-label":t?c.showMoreLabel:c.showLessLabel,onClick:()=>{i(t?r.length:a)},children:e(P,{id:`PurchaseOrders.comments.view.buttons.${t?"viewMore":"viewLess"}`})})})]}):e("div",{className:"b2b-purchase-order-comment-list-content",children:e(P,{id:"PurchaseOrders.comments.view.emptyText"})})},Kr=({t:r,purchaseOrderData:a})=>{const[s,i]=A(!1),[t,n]=A(""),[c,l]=A(""),o=B(()=>!t.trim().length||!(a!=null&&a.uid)||s,[t,a,s]),f=M(R=>{const g=R.target.value;n(g),c&&l("")},[c]),y=M(()=>{const R=(a==null?void 0:a.uid)??"";!R||!t.trim().length||(i(!0),mr(R,t).then(g=>{g&&(a!=null&&a.uid)&&(G.emit("purchase-order/refresh",!0),n(""))}).catch(()=>{l(r.errorMessage||"Failed to add comment. Please try again.")}).finally(()=>{i(!1)}))},[a,t,r]);return u("div",{className:V(["b2b-purchase-order-comment-form-content"]),children:[e(Fe,{errorMessage:c,disabled:s,value:t,label:r.textAreaPlaceholder,onChange:f}),e(H,{variant:"primary",disabled:o,onClick:y,children:r.buttonText})]})},Ar=r=>K.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},K.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),K.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.75 12.762L10.2385 15.75L17.25 9",stroke:"currentColor"})),Sr=r=>K.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},K.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M0 12C0 5.37931 5.37931 0 12 0C18.6207 0 24 5.37931 24 12C24 18.6207 18.6207 24 12 24C5.37931 24 0 18.6207 0 12ZM11.8885 5.06101C11.1405 5.06101 10.5357 5.66579 10.5357 6.4138V6.57295C10.5835 7.27321 11.1882 7.81433 11.8885 7.76658H12.0795C12.7797 7.70292 13.289 7.09815 13.2413 6.4138C13.2413 5.66579 12.6365 5.06101 11.8885 5.06101ZM13.1935 16.8223H14.1007C14.2599 16.8223 14.4031 16.9655 14.4031 17.1247V17.7294C14.4031 17.9045 14.2599 18.0318 14.1007 18.0318H9.8832C9.70813 18.0318 9.58081 17.8886 9.58081 17.7294V17.1247C9.58081 16.9496 9.72405 16.8223 9.8832 16.8223H10.7904V10.7905H9.8832C9.70813 10.7905 9.58081 10.6472 9.58081 10.4881V9.88329C9.58081 9.70823 9.72405 9.58091 9.8832 9.58091H12.5888C12.923 9.58091 13.1935 9.85146 13.1935 10.1857V16.8223Z",fill:"currentColor"})),wr=r=>K.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},K.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),K.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),Jr=({approvalFlow:r=[]})=>{const a=ae({pending:"PurchaseOrders.approvalFlow.ariaLabels.icons.pending",approved:"PurchaseOrders.approvalFlow.ariaLabels.icons.approved",rejected:"PurchaseOrders.approvalFlow.ariaLabels.icons.rejected"});if(!(r!=null&&r.length))return e("div",{className:"b2b-purchase-order-approval-flow-content",children:e(P,{id:"PurchaseOrders.approvalFlow.emptyText"})});const s=i=>{switch(i){case"PENDING":return e(Sr,{className:"b2b-purchase-order-approval-flow-content__icon--pending","aria-label":a.pending,role:"img"});case"APPROVED":return e(Ar,{className:"b2b-purchase-order-approval-flow-content__icon--approved","aria-label":a.approved,role:"img"});case"REJECTED":return e(wr,{className:"b2b-purchase-order-approval-flow-content__icon--rejected","aria-label":a.rejected,role:"img"});default:return null}};return e("div",{className:V(["b2b-purchase-order-approval-flow-content"]),children:e("ul",{className:"b2b-purchase-order-approval-flow-content__list",children:r.map((i,t)=>u(Pe,{children:[u("li",{className:"b2b-purchase-order-approval-flow-content__item",children:[e("div",{className:"b2b-purchase-order-approval-flow-content__title",children:i.ruleName}),i.events.map((n,c)=>u("div",{className:"b2b-purchase-order-approval-flow-content__description",children:[s(n.status),n.message]},c))]}),t<r.length-1&&e("hr",{className:"b2b-purchase-order-approval-flow-content__divider"})]},t))})})},Yr=({historyLogRecords:r=[],visibleRecordsLimit:a})=>{const[s,i]=A(a),t=r.length>s,n=r.length<=a,c=ae({showMoreLabel:"PurchaseOrders.historyLog.ariaLabel.showMore",showLessLabel:"PurchaseOrders.historyLog.ariaLabel.showLess"});return r.length?u("div",{className:"b2b-purchase-order-history-log-content",children:[e("ul",{className:"b2b-purchase-order-history-log-content__list",role:"list",children:r.slice(0,s).map((l,o)=>{const f=Math.min(s,r.length);return u(Pe,{children:[u("li",{className:"b2b-purchase-order-history-log-content__item",children:[e("div",{className:"b2b-purchase-order-history-log-content__title",children:e(P,{id:`PurchaseOrders.historyLog.status.${l.activity}`,fields:{date:ve(l.createdAt)}})}),e("div",{className:"b2b-purchase-order-history-log-content__description",children:l.message})]}),o<f-1&&e("hr",{className:"b2b-purchase-order-history-log-content__divider"})]},l.uid)})}),!n&&e("div",{className:"b2b-purchase-order-history-log-content__actions",children:e(H,{variant:"secondary","aria-expanded":!t,"aria-label":t?c.showMoreLabel:c.showLessLabel,onClick:()=>{i(t?r.length:a)},children:e(P,{id:`PurchaseOrders.historyLog.buttons.${t?"viewMore":"viewLess"}`})})})]}):e("div",{className:"b2b-purchase-order-history-log-content",children:e(P,{id:"PurchaseOrders.historyLog.emptyText"})})};export{Gr as A,_e as E,Cr as F,vr as P,Hr as a,Dr as b,Ur as c,Br as d,zr as e,Wr as f,Rr as g,Yr as h,qr as i,Zr as j,Kr as k,Jr as l,jr as m,$r as n,Qr as o,Or as u};
|
|
3
|
+
import{classes as V,Slot as He}from"@dropins/tools/lib.js";import{useText as ae,Text as P}from"@dropins/tools/i18n.js";import{jsxs as u,Fragment as Oe,jsx as e}from"@dropins/tools/preact-bundle.js";import{InLineAlert as Le,Table as $e,Pagination as je,Picker as me,Card as Me,Header as ze,Button as H,Tag as ke,Price as Ge,ActionButton as ne,PriceRange as qe,Checkbox as We,Input as Se,TextArea as xe,RadioButton as Qe,MultiSelect as we,Skeleton as Ze,SkeletonRow as re}from"@dropins/tools/components.js";import{events as G}from"@dropins/tools/event-bus.js";import{getRange as Ke,getPurchaseOrders as Je,isValidUrl as Fe,rejectPurchaseOrders as Ie,approvePurchaseOrders as Ve,getStatusVariant as De,formatDate as ve,navigate as ce,PO_PERMISSIONS as Z,INITIAL_FORM_STATE as Ye,createRuleTypeOptions as Xe,createConditionOperators as er,createAppliesToOptions as rr,currencyInfo as ar,getPurchaseOrderApprovalRuleMetadata as sr,getPurchaseOrderApprovalRule as Ue,transformToFormValues as tr,VALIDATION_ERROR_KEYS as fe,REQUIRED_FIELDS_ON_SUBMIT as lr,validateFormFields as be,cleanAndDeep as or,updatePurchaseOrderApprovalRule as nr,createPurchaseOrderApprovalRule as cr,updateValidationErrors as ge,updateFormFieldValue as ir,getPurchaseOrderApprovalRules as dr,deletePurchaseOrderApprovalRule as ur,cancelPurchaseOrders as pr,placeOrderForPurchaseOrder as hr,addPurchaseOrderComment as mr}from"../api.js";import{useState as A,useEffect as q,useCallback as M,useMemo as B,useReducer as br}from"@dropins/tools/preact-bundle.js";import{Fragment as Pe}from"@dropins/tools/preact.js";import*as K from"@dropins/tools/preact-bundle.js";const Dr=({pageSizeConfig:r,totalCount:a=0,columns:s=[],rows:i=[],paginationConfig:t,alertMessageConfig:n={heading:"",description:"",type:"success"},loading:c=!1,className:l="",variant:o="secondary",skeletonRowCount:f=10,emptyTitle:y,header:R,footer:g,withWrapper:_,expandedRows:T})=>{var v;const O=ae({title:"PurchaseOrders.purchaseOrdersTable.noPurchaseOrders.default"}),{heading:d,description:k,type:L}=n,{currentPage:p,totalPages:E,handlePageChange:I}=t,{pageSizeOptionsList:S,onChange:x}=r,D=S==null?void 0:S.find(F=>F.selected),$=D&&D.value!==void 0?Number(D.value):10,{from:W,to:Q,total:ie}=Ke(p,$,a),j=!c&&i.length===0,se=u(Oe,{children:[d||k?e(Le,{heading:d,description:k,type:L}):null,R?e("div",{className:"purchase-orders-table__header",children:R}):null,e($e,{className:"purchase-orders-table__table-wrapper",mobileLayout:"stacked",columns:s,rowData:i,expandedRows:T,loading:c,skeletonRowCount:+f}),j&&e("div",{className:"purchase-orders-table__empty-state",role:"status","aria-live":"polite",children:e("p",{children:y||O.title})}),a>0?u("div",{className:"purchase-orders-table__pagination-wrapper",children:[e("div",{className:"purchase-orders-table__pagination-counter",children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.pagination.status",fields:{from:W,to:Q,total:ie}})}),E>1&&e(je,{className:V(["purchase-orders-table__pagination",["purchase-orders-table__pagination--loading",c]]),currentPage:p,totalPages:E,onChange:I}),a>0&&S.length?u("div",{className:"purchase-orders-table__pagination-page-size",children:[e(P,{id:"PurchaseOrders.purchaseOrdersTable.pagination.pageSizeLabel.start"}),e(me,{disabled:c,handleSelect:x,options:S,value:((v=S==null?void 0:S.find(F=>F.selected))==null?void 0:v.value)||""})]}):null]}):null,g?e("div",{className:"purchase-orders-table__footer",children:g}):null]});return _?e(Me,{variant:o,"data-testid":"purchaseOrdersTable",className:V(["b2b-purchase-order-purchase-orders-table",["b2b-purchase-order-purchase-orders-table--empty-state",j],l]),children:se}):e("div",{"data-testid":"purchaseOrdersTable",className:V(["b2b-purchase-order-purchase-orders-table",["b2b-purchase-order-purchase-orders-table--empty-state",j],l]),children:se})},vr=({headerText:r,divider:a=!1})=>e(ze,{title:r,divider:a,className:V(["purchase-orders-header",["purchase-orders-header--with-divider",a]]),"data-testid":"purchase-orders-header"}),Ur=({loading:r,selectedCount:a,className:s,handleRejectSelected:i,handleApproveSelected:t})=>u("div",{className:V(["b2b-purchase-order-purchase-orders-table-actions",s]),children:[u("div",{children:["Selected ",a]}),u("div",{className:"b2b-purchase-order-purchase-orders-table-actions__buttons",children:[e(H,{variant:"secondary",onClick:i,disabled:r||a===0,children:"Reject selected"}),e(H,{variant:"primary",onClick:t,disabled:r||a===0,children:"Approve selected"})]})]});var _e=(r=>(r.CUSTOMER_PURCHASE_ORDERS="customerPurchaseOrders",r.COMPANY_PURCHASE_ORDERS="companyPurchaseOrders",r.CUSTOMER_APPROVAL_PURCHASE_ORDERS="customerApprovalPurchaseOrders",r))(_e||{});const Br=[{text:"10",value:"10",selected:!1},{text:"20",value:"20",selected:!0},{text:"30",value:"30",selected:!1},{text:"50",value:"50",selected:!1}],Be=[{key:"poNumber",label:"PO #"},{key:"status",label:"Status"},{key:"createdBy",label:"Created By"},{key:"action",label:"Actions"}],Ne=[{key:"ruleName",label:"Rule Name"},{key:"status",label:"Status"},{key:"createdBy",label:"Created By"},{key:"action",label:"Actions"}],fr=[{key:"checkboxView",label:""},...Be],gr=20,Hr=({view:r,initialPageSize:a,routePurchaseOrderDetails:s,setColumns:i,setRowsData:t,t:n,permissions:c,loadingPermissions:l})=>{const o=r===_e.COMPANY_PURCHASE_ORDERS,f=r===_e.CUSTOMER_APPROVAL_PURCHASE_ORDERS,[y,R]=A(!0),[g,_]=A([]),[T,O]=A([]),[d,k]=A(a),[L,p]=A(!0),[E,I]=A({currentPage:1,totalPages:1,totalCount:0}),[S,x]=A({heading:"",description:"",type:"success"}),[D,$]=A(new Set);q(()=>{const b=G.on("purchase-order/refresh",()=>{R(!0)},{eager:!0});return()=>{b==null||b.off()}},[]),q(()=>{if(S.heading||S.description){const b=setTimeout(()=>{x({heading:"",description:"",type:"success"})},7e3);return()=>clearTimeout(b)}},[S.heading,S.description]);const{currentPage:W,totalPages:Q,totalCount:ie}=E,j=M(b=>{I(w=>({...w,currentPage:b})),$(new Set),R(!0)},[]),se=M(b=>{const w=b.target.value;k(m=>m.map(C=>({...C,selected:C.value===w}))),j(1),$(new Set),R(!0)},[j]),v=(c==null?void 0:c.isAdmin)??!1,F=B(()=>{let b={};return o&&(b={companyPurchaseOrders:!0}),f&&(b={myApprovals:!0}),b},[o,f]);q(()=>{var m;if(!y||l)return;p(!0);const b=(m=d==null?void 0:d.find(C=>C.selected))==null?void 0:m.value,w=parseInt(b??gr.toString(),10);Je(F,w,W).then(C=>{var ue,pe;const z=(C==null?void 0:C.purchaseOrderItems)??[],X=(ue=C==null?void 0:C.pageInfo)==null?void 0:ue.currentPage,U=(pe=C==null?void 0:C.pageInfo)==null?void 0:pe.totalPages,ee=C==null?void 0:C.totalCount;I({currentPage:X>U?U||1:X,totalPages:U,totalCount:ee}),O(z)}).catch(C=>{console.error("Failed to fetch purchase orders:",C),O([])}).finally(()=>{p(!1),R(!1)})},[y,W,d,F,l]);const h=M(b=>{const w=s==null?void 0:s(b);return Fe(w??"")?w:"#"},[s]),N=M(b=>{$(w=>{const m=new Set(w);return m.has(b)?m.delete(b):m.add(b),m})},[]),te=M(b=>{const w=b.target.value,m=b.target.checked;_(C=>m?[...C,w]:C.filter(z=>z!==w))},[]),J=M(b=>{const w=b.target.checked;_(()=>w?T.filter(m=>["PENDING","APPROVAL_REQUIRED"].includes(m.status)).map(m=>m.uid??""):[])},[T]),Y=M(()=>{p(!0),Ie(g).then(()=>{x({heading:n.alertHeaderReject,description:n.alertDescriptionReject,type:"success"}),_([]),G.emit("purchase-order/refresh",!0)}).catch(b=>{x({heading:n.alertHeaderError,description:n.alertDescriptionError,type:"error"}),console.error(b)}).finally(()=>{p(!1)})},[g,n]),de=M(()=>{p(!0),Ve(g).then(()=>{x({heading:n.alertHeaderApprove,description:n.alertDescriptionApprove,type:"success"}),_([]),G.emit("purchase-order/refresh",!0)}).catch(b=>{x({heading:n.alertHeaderError,description:n.alertDescriptionError,type:"error"}),console.error(b)}).finally(()=>{p(!1)})},[g,n]),le=B(()=>{const b=o||f?fr:Be;return(i==null?void 0:i(b))??b.map(w=>w.key==="checkboxView"&&(v||f)?{key:w.key,label:e("input",{type:"checkbox",name:"selectAll",disabled:T.every(m=>!["PENDING","APPROVAL_REQUIRED"].includes(m.status)),onChange:J}),ariaLabel:n.selectAllAriaLabel}:{...w,label:n[w.key]||w.label})},[n,v,o,f,i,T,J]),oe=B(()=>{const b=T.map((m,C)=>{var ye,Ee,Re,Te,Ce,Ae;const z=m.number??"",X=D.has(C),U=`${((ye=m.createdBy)==null?void 0:ye.firstname)??""} ${((Ee=m.createdBy)==null?void 0:Ee.lastname)??""}`.trim(),ee=e(ne,{type:"button",onClick:()=>N(C),children:e(P,{id:`PurchaseOrders.purchaseOrdersTable.buttons.${X?"expandedHidden":"expandedShow"}`})}),ue=e(ke,{className:`b2b-purchase-order-purchase-orders-table__status b2b-purchase-order-purchase-orders-table__status--${De(m.status)}`,children:e(P,{id:`PurchaseOrders.purchaseOrdersTable.statusOrder.${m.status.toLowerCase()}`})}),pe=u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details",children:[u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-content",children:[u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.orderNumber"})})," ",m.order.orderNumber]}),u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.createdDate"})})," ",ve(m.createdAt)]}),u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.updatedDate"})})," ",ve(m.updatedAt)]}),u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.total"})})," ",e(Ge,{amount:(Te=(Re=m==null?void 0:m.quote)==null?void 0:Re.grandTotal)==null?void 0:Te.value,currency:(Ae=(Ce=m==null?void 0:m.quote)==null?void 0:Ce.grandTotal)==null?void 0:Ae.currency,weight:"normal"})]})]}),e("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-action",children:e(ne,{onClick:()=>{ce(h(m.uid??""))},"aria-label":`View purchase order ${z}`,children:n.actionView})})]});return{...v||f?{checkboxView:e("input",{type:"checkbox",name:z,value:m.uid,checked:g.includes(m.uid),onChange:te,disabled:!["PENDING","APPROVAL_REQUIRED"].includes(m.status)})}:{},poNumber:z,status:ue,createdBy:U,action:ee,_rowDetails:pe}});let w=b;if(t){const m=t(b);m!==void 0&&Array.isArray(m)&&(w=m)}return w},[T,t,v,f,g,te,h,n.actionView,D,N]);return{tableConfig:{columns:le,rows:oe,expandedRows:D},paginationConfig:{currentPage:W,totalPages:Q,handlePageChange:j},pageSizeConfig:{pageSizeOptionsList:d,onChange:se},totalCount:ie,loading:L,selectedOrderIds:g,handleRejectSelected:Y,handleApproveSelected:de,isAdmin:v,isRequireApprovalPOsView:f,alertMessageConfig:S}},_r=r=>{if(!r)return{isAdmin:!1,purchaseOrderEnabled:!1,role:{id:"",name:""},permissions:{purchaseOrderAll:!1,viewPurchaseOrders:!1,viewPurchaseOrdersForSubordinates:!1,viewPurchaseOrdersForCompany:!1,autoApprovePurchaseOrder:!1,superApprovePurchaseOrder:!1,viewApprovalRules:!1,manageApprovalRules:!1}};const a=r.admin===!0,s=c=>{const l=r[c];return l===!1?!1:l===!0?!0:a},i={purchaseOrderAll:s(Z.PO_ALL),viewPurchaseOrders:s(Z.VIEW_CUSTOMER),viewPurchaseOrdersForSubordinates:s(Z.VIEW_SUBORDINATES),viewPurchaseOrdersForCompany:s(Z.VIEW_COMPANY),autoApprovePurchaseOrder:s(Z.AUTO_APPROVE),superApprovePurchaseOrder:s(Z.SUPER_APPROVE),viewApprovalRules:s(Z.VIEW_RULES),manageApprovalRules:s(Z.MANAGE_RULES)},n=Object.values(r).some(c=>c===!1)?!1:Object.values(i).some(c=>c===!0);return{isAdmin:a,purchaseOrderEnabled:n,role:{id:"",name:a?"Company Administrator":""},permissions:i}},Or=()=>{const r=G.lastPayload("auth/permissions"),[a,s]=A(r);q(()=>{const n=G.on("auth/permissions",c=>{s(c)},{eager:!0});return()=>{n==null||n.off()}},[]);const i=!a;return{permissions:B(()=>_r(a),[a]),loadingPermissions:i}};function Pr(r,a){switch(a.type){case"SET_LOADING":return{...r,isLoading:a.payload};case"SET_SUBMIT_ERROR":return{...r,submitError:a.payload};case"SET_FORM_VALUES":return{...r,formValues:a.payload};case"SET_AVAILABLE_APPLIES_TO":return{...r,availableAppliesTo:a.payload};case"SET_AVAILABLE_APPROVERS":return{...r,availableRequiresApprovalFrom:a.payload};case"SET_ERRORS":return{...r,errors:a.payload};case"SET_TOUCHED":return{...r,touched:a.payload};case"SET_CURRENCIES":return{...r,currencyCodesList:a.payload};case"UPDATE_FIELD":{const{key:s,value:i}=a.payload,t=ir(r.formValues,s,i),n={...r.touched,[s]:!0};s==="roleType"&&i==="specific_roles"&&(n.appliesTo=!0);const c=be(t),l=ge(c,r.errors,n);return{...r,formValues:t,touched:n,errors:l}}case"TOUCH_FIELD":{const s=a.payload,i={...r.touched,[s]:!0},t=be(r.formValues),n=ge(t,r.errors,i);return{...r,touched:i,errors:n}}case"MARK_FIELDS_TOUCHED":{const s={...r.touched,...a.payload},i=be(r.formValues),t=ge(i,r.errors,s);return{...r,touched:s,errors:t}}default:return r}}const yr=({t:r,approvalRuleID:a,routeApprovalRulesList:s,onSubmit:i,onChange:t,permissions:n,loadingPermissions:c})=>{const[l,o]=br(Pr,Ye),f=B(()=>Xe(r),[r]),y=B(()=>er(r),[r]),R=B(()=>rr(r),[r]);q(()=>{o({type:"SET_LOADING",payload:!0}),ar().then(d=>{o({type:"SET_CURRENCIES",payload:d.availableCurrencyCodes})}).catch(d=>{console.error("Failed to fetch currencies:",d)}),sr().then(d=>{const{availableAppliesTo:k,availableRequiresApprovalFrom:L}=d;return o({type:"SET_AVAILABLE_APPLIES_TO",payload:k}),o({type:"SET_AVAILABLE_APPROVERS",payload:L}),a?Ue(a):null}).then(d=>{d&&o({type:"SET_FORM_VALUES",payload:tr(d)}),o({type:"SET_SUBMIT_ERROR",payload:null})}).catch(d=>{console.error("Failed to fetch data:",d),o({type:"SET_SUBMIT_ERROR",payload:(d==null?void 0:d.message)||fe.FAILED_TO_LOAD})}).finally(()=>{o({type:"SET_LOADING",payload:!1})})},[a]);const g=M((d,k)=>{o({type:"UPDATE_FIELD",payload:{key:d,value:k}}),t&&t({...l.formValues,[d]:k})},[t,l.formValues]),_=M(d=>{o({type:"TOUCH_FIELD",payload:d}),t&&t(l.formValues)},[t,l.formValues]),T=M(async()=>{o({type:"SET_LOADING",payload:!0}),o({type:"SET_SUBMIT_ERROR",payload:null}),o({type:"MARK_FIELDS_TOUCHED",payload:lr});const d=be(l.formValues);if(Object.keys(d).length>0){o({type:"SET_ERRORS",payload:d}),o({type:"SET_LOADING",payload:!1});return}const k=or(l.formValues);try{let L;if(a?L=await nr({uid:a,...k}):L=await cr(k),!L.uid){o({type:"SET_SUBMIT_ERROR",payload:fe.FAILED_TO_CREATE}),o({type:"SET_LOADING",payload:!1});return}i&&i(l.formValues),s?ce(s()):o({type:"SET_LOADING",payload:!1})}catch(L){console.error("Failed to save approval rule:",L),o({type:"SET_SUBMIT_ERROR",payload:(L==null?void 0:L.message)||fe.FAILED_TO_CREATE}),o({type:"SET_LOADING",payload:!1})}},[l.formValues,s,a,i]),O=B(()=>!!(l.isLoading||c||!(n!=null&&n.permissions.viewApprovalRules)&&!(n!=null&&n.permissions.manageApprovalRules)),[l.isLoading,c,n]);return{availableAppliesTo:l.availableAppliesTo,availableRequiresApprovalFrom:l.availableRequiresApprovalFrom,formValues:l.formValues,ruleTypeOptions:f,conditionOperators:y,currencies:l.currencyCodesList,appliesToOptions:R,handleSetFormValues:g,handleSubmit:T,handleFieldTouch:_,errors:l.errors,touched:l.touched,isLoading:l.isLoading,formLoading:O,submitError:l.submitError}},$r=({approvalRuleID:r,routeApprovalRulesList:a})=>{const[s,i]=A(!0),[t,n]=A(null);q(()=>{r&&(i(!0),Ue(r).then(o=>{o.uid&&n(o)}).catch(()=>{n(null)}).finally(()=>{i(!1)}))},[r]);const c=B(()=>{if(!t||s)return[];const{name:o,status:f,description:y,appliesToRoles:R,approverRoles:g,condition:_}=t;return[{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.ruleName"}),value:o},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.status"}),value:e(P,{id:`PurchaseOrders.approvalRuleDetails.fields.statusView.${f.toLocaleLowerCase()}`})},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.description"}),value:y},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.appliesTo"}),value:e("ul",{children:R.map(T=>e("li",{children:T.name},T.id))})},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.ruleType"}),value:e(P,{id:`PurchaseOrders.approvalRuleDetails.fields.condition.attribute.${_.attribute.toLocaleLowerCase()}`})},{label:u(Oe,{children:[e(P,{id:`PurchaseOrders.approvalRuleDetails.fields.condition.attribute.${_.attribute.toLocaleLowerCase()}`}),":"]}),value:u("div",{children:[e(P,{id:`PurchaseOrders.approvalRuleDetails.fields.condition.operator.${_.operator.toLocaleLowerCase()}`}),e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.amount.label"}),e(qe,{amount:_.amount.value,currency:_.amount.currency})]})},{label:e(P,{id:"PurchaseOrders.approvalRuleDetails.fields.requiresApprovalFrom"}),value:e("ul",{children:g.map(T=>e("li",{children:T.name},T.id))})}]},[t,s]);return{handleRedirectToList:()=>{ce((a==null?void 0:a())??"")},loading:s,formValues:c}},Er=20,jr=({routeApprovalRuleDetails:r,routeCreateApprovalRule:a,routeEditApprovalRule:s,setColumns:i,setRowsData:t,initialPageSize:n,permissions:c,loadingPermissions:l,t:o})=>{const[f,y]=A([]),[R,g]=A(!0),[_,T]=A(!0),[O,d]=A(n),[k,L]=A({currentPage:1,totalPages:1,totalCount:0}),[p,E]=A(new Set);q(()=>{const v=G.on("purchase-order/refresh",()=>{g(!0)},{eager:!0});return()=>{v==null||v.off()}},[]);const{currentPage:I,totalPages:S,totalCount:x}=k,D=M(v=>{L(F=>({...F,currentPage:v})),E(new Set),g(!0)},[]),$=M(v=>{const F=v.target.value;d(h=>h.map(N=>({...N,selected:N.value===F}))),D(1),E(new Set),g(!0)},[D]),W=M(v=>{E(F=>{const h=new Set(F);return h.has(v)?h.delete(v):h.add(v),h})},[]);q(()=>{var h;if(!R||l)return;T(!0);const v=(h=O==null?void 0:O.find(N=>N.selected))==null?void 0:h.value,F=parseInt(v??Er.toString(),10);dr(I,F).then(N=>{var le,oe;const te=(N==null?void 0:N.items)??[],J=(le=N==null?void 0:N.pageInfo)==null?void 0:le.currentPage,Y=(oe=N==null?void 0:N.pageInfo)==null?void 0:oe.totalPages,de=N==null?void 0:N.totalCount;L({currentPage:J>Y?Y||1:J,totalPages:Y,totalCount:de}),y(te)}).catch(N=>{console.error("Error fetching approval rules:",N),y([])}).finally(()=>{T(!1),g(!1)})},[R,I,O,S,l]);const Q=M((v,F)=>{let h="";switch(F){case"new":{h=a==null?void 0:a(v);break}case"edit":{h=s==null?void 0:s(v);break}case"view":{h=r==null?void 0:r(v);break}}return Fe(h??"")?h:"#"},[a,s,r]),ie=B(()=>(i==null?void 0:i(Ne))??Ne.map(v=>({...v,label:o[v.key]||v.label})),[i,o]),j=M((v,F)=>{v.preventDefault(),T(!0),ur(F).then(()=>{G.emit("purchase-order/refresh",!0)}).finally(()=>{E(new Set)})},[]),se=B(()=>{const v=f==null?void 0:f.map((h,N)=>{var b,w,m,C,z,X;const{isAdmin:te,permissions:{manageApprovalRules:J}}=c,Y=p.has(N),de=te||J,le=e(ne,{onClick:()=>W(N),children:e(P,{id:`PurchaseOrders.purchaseOrdersTable.buttons.${Y?"expandedHidden":"expandedShow"}`})}),oe=u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details",children:[u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-content",children:[u("p",{children:[e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.ruleType"})})," ",e(P,{id:`PurchaseOrders.purchaseOrdersTable.ruleTypes.${(w=(b=h.condition)==null?void 0:b.attribute)==null?void 0:w.toLocaleLowerCase()}`})]}),e("p",{children:e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.appliesTo"})})}),e("ul",{children:((m=h==null?void 0:h.appliesToRoles)==null?void 0:m.length)<=0?e("li",{children:o.appliesToAll}):(C=h==null?void 0:h.appliesToRoles)==null?void 0:C.map((U,ee)=>e("li",{children:U.name},ee))}),e("p",{children:e("span",{children:e(P,{id:"PurchaseOrders.purchaseOrdersTable.expandedRowLabels.approver"})})}),e("ul",{children:(z=h==null?void 0:h.approverRoles)==null?void 0:z.map((U,ee)=>e("li",{children:U==null?void 0:U.name},ee))})]}),de?e("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-action",children:u("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-action-inner-wrapper",children:[e(ne,{onClick:()=>{ce(Q(h.uid,"edit"))},"aria-label":o.ariaLabelEditRule.replace("{{ruleName}}",h.name),"data-testid":`edit-approval-rule-${h.uid}`,children:o.actionEdit}),e(ne,{onClick:U=>j(U,h.uid),"aria-label":o.ariaLabelDeleteRule.replace("{{ruleName}}",h.name),"data-testid":`delete-approval-rule-${h.uid}`,children:o.actionDelete})]})}):e("div",{className:"b2b-purchase-order-purchase-orders-table__row-details-action",children:e(ne,{onClick:()=>{ce(Q(h.uid,"view"))},"aria-label":o.ariaLabelViewRule.replace("{{ruleName}}",h.name),"data-testid":`view-approval-rule-${h.uid}`,children:o.actionView})})]});return{ruleName:h.name,status:e(ke,{className:`b2b-purchase-order-purchase-orders-table__status b2b-purchase-order-purchase-orders-table__status--${De(h.status)}`,children:e(P,{id:`PurchaseOrders.purchaseOrdersTable.rulesStatus.${(X=h.status)==null?void 0:X.toLocaleLowerCase()}`})}),createdBy:h.createdBy,action:le,_rowDetails:oe}});let F=v;if(t){const h=t(v);h!==void 0&&Array.isArray(h)&&(F=h)}return F},[f,p,c,t,o,Q,j,W]);return{tableConfig:{columns:ie,rows:se,expandedRows:p},paginationConfig:{currentPage:I,totalPages:S,handlePageChange:D},pageSizeConfig:{pageSizeOptionsList:O,onChange:$},totalCount:x,loading:_,handleCreateUrl:Q}},Rr=()=>{const[r,a]=A(!0),[s,i]=A(null);return q(()=>{const t=G.on("purchase-order/data",n=>{n!=null&&n.uid&&i(n),a(!1)},{eager:!0});return()=>{t==null||t.off()}},[]),{poDataLoading:r,purchaseOrderData:s}},zr=()=>{const{poDataLoading:r,purchaseOrderData:a}=Rr(),s=ae({approvalSuccessMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.success.approval",rejectSuccessMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.success.reject",cancelSuccessMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.success.cancel",placeOrderSuccessMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.success.placeOrder",approvalErrorMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.errors.approval",rejectErrorMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.errors.reject",cancelErrorMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.errors.cancel",placeOrderErrorMessage:"PurchaseOrders.purchaseOrderStatus.alertMessages.errors.placeOrder"}),i=(a==null?void 0:a.uid)??null,t=(a==null?void 0:a.status)??"PENDING",n=(a==null?void 0:a.availableActions)??[],[c,l]=A("success"),[o,f]=A(""),[y,R]=A(!1),[g,_]=A(!0),T=()=>{_(!0)},O=M((I,S)=>{let x="";if(I){switch(S){case"APPROVE":x=s.approvalSuccessMessage;break;case"REJECT":x=s.rejectSuccessMessage;break;case"CANCEL":x=s.cancelSuccessMessage;break;case"PLACE_ORDER":x=s.placeOrderSuccessMessage;break}l("success")}else{switch(S){case"APPROVE":x=s.approvalErrorMessage;break;case"REJECT":x=s.rejectErrorMessage;break;case"CANCEL":x=s.cancelErrorMessage;break;case"PLACE_ORDER":x=s.placeOrderErrorMessage;break}l("error")}f(x),_(!1)},[s]),d=M(async(I,S)=>{if(i){R(!0);try{await I(i),O(!0,S)}catch{O(!1,S)}finally{R(!1),G.emit("purchase-order/refresh",!0)}}},[i,O]),k=M(()=>d(Ve,"APPROVE"),[d]),L=M(()=>d(Ie,"REJECT"),[d]),p=M(()=>d(pr,"CANCEL"),[d]),E=M(()=>d(hr,"PLACE_ORDER"),[d]);return{poId:i,status:t,availableActions:n,alertType:c,loading:y,poDataLoading:r,isDismissed:g,alertMessage:o,handleOnDismiss:T,handleApprove:k,handleReject:L,handleCancel:p,handlePlaceOrder:E}},he=({touched:r=!1,error:a,className:s="error-message"})=>!r||!a?null:e("span",{className:s,children:e(P,{id:a})}),Tr=({availableRequiresApprovalFrom:r,conditionOperators:a,availableAppliesTo:s,appliesToOptions:i,ruleTypeOptions:t,currencies:n,formValues:c,errors:l,touched:o,isLoading:f,permissions:y,handleSubmit:R,handleFieldTouch:g,handleSetFormValues:_,routeApprovalRulesList:T,t:O})=>{var k,L;const d=f||!((k=y==null?void 0:y.permissions)!=null&&k.viewApprovalRules);return u("form",{"data-testid":"approval-rule-form",children:[e(We,{"data-testid":"status-toggle",className:"b2b-purchase-order-approval-rule-form__toggle",disabled:d,name:"status",label:O.formEnabled,checked:c.status==="ENABLED",onChange:p=>{const E=p.target.checked;_("status",E)}}),u("div",{"data-testid":"name-input-container",children:[e(Se,{"data-testid":"name-input",className:"b2b-purchase-order-approval-rule-form__name-input",disabled:d,name:"name",floatingLabel:O.inputRuleNameFloatingLabel,placeholder:O.inputRuleNamePlaceholder,value:c.name,error:!!(o.name&&l.name),onChange:p=>{const E=p.target.value;_("name",E)},onBlur:()=>g("name")}),e(he,{touched:o.name,error:l.name})]}),e(xe,{"data-testid":"description-textarea",className:"b2b-purchase-order-approval-rule-form__description",disabled:d,name:"description",label:O.textAreaDescriptionLabel,value:c.description,onChange:p=>{const E=p.target.value;_("description",E)}}),u("div",{"data-testid":"applies-to-section",className:"b2b-purchase-order-approval-rule-form__applies-to",children:[e("span",{className:"b2b-purchase-order-approval-rule-form__applies-to-title",children:O.titleAppliesTo}),i.map((p,E)=>e(Qe,{"data-testid":`applies-to-radio-${E}`,disabled:d,name:"radio-group",value:p.value,label:p.text,checked:c.roleType===p.value,onChange:I=>{const S=I.target.value;_("roleType",S)}},p.value)),c.roleType==="specific_roles"?u("div",{"data-testid":"applies-to-multiselect-container",className:"b2b-purchase-order-approval-rule-form__applies-to-multiselect",children:[e(we,{"data-testid":"applies-to-multiselect",disabled:d,name:"appliesTo",value:[...c.appliesTo],options:s.map(p=>({value:p.id,label:p.name})),error:!!(o.appliesTo&&l.appliesTo),onChange:p=>{_("appliesTo",p),o.appliesTo||g("appliesTo")}}),e(he,{touched:o.appliesTo,error:l.appliesTo})]}):null]}),u("div",{"data-testid":"rule-type-section",className:"b2b-purchase-order-approval-rule-form__rule-type",children:[e("span",{className:"b2b-purchase-order-approval-rule-form__rule-type-title",children:O.titleRuleType}),e(me,{"data-testid":"rule-type-picker",className:"b2b-purchase-order-approval-rule-form__rule-type-picker",disabled:d,name:"ruleType",value:c.condition.attribute,options:t,handleSelect:p=>{const E=p.target.value;_("ruleType",E)}})]}),u("div",{"data-testid":"rule-condition-section",className:"b2b-purchase-order-approval-rule-form__rule-condition",children:[e("span",{className:"b2b-purchase-order-approval-rule-form__rule-condition-title",children:(L=t.find(p=>p.value===c.condition.attribute))==null?void 0:L.text}),u("div",{className:V(["b2b-purchase-order-approval-rule-form__rule-condition-container",["b2b-purchase-order-approval-rule-form__rule-condition-container--error",!!l.ruleValue&&!!o.ruleValue]]),children:[e(me,{"data-testid":"rule-condition-picker",className:"b2b-purchase-order-approval-rule-form__rule-condition-picker",disabled:d,name:"ruleCondition",value:c.condition.operator,options:a,handleSelect:p=>{const E=p.target.value;_("ruleCondition",E)}}),u("div",{"data-testid":"rule-value-container",children:[e(Se,{"data-testid":"rule-value-input",className:"b2b-purchase-order-approval-rule-form__rule-value-input",disabled:d,name:"ruleValue",floatingLabel:c.condition.attribute==="NUMBER_OF_SKUS"?O.inputQuantityFloatingLabel:O.inputAmountFloatingLabel,placeholder:c.condition.attribute==="NUMBER_OF_SKUS"?O.inputQuantityPlaceholder:O.inputAmountPlaceholder,value:c.condition.attribute==="NUMBER_OF_SKUS"?c.condition.quantity:c.condition.amount.value,error:!!(o.ruleValue&&l.ruleValue),onChange:p=>{const E=p.target.value;_("ruleValue",E)},onBlur:()=>g("ruleValue")}),e(he,{touched:o.ruleValue,error:l.ruleValue})]}),c.condition.attribute!=="NUMBER_OF_SKUS"?e(me,{"data-testid":"rule-condition-currency-picker",className:"b2b-purchase-order-approval-rule-form__rule-condition-currency-picker",disabled:d,name:"ruleConditionCurrency",value:c.condition.amount.currency,options:n,handleSelect:p=>{const E=p.target.value;_("ruleConditionCurrency",E)}}):null]})]}),u("div",{"data-testid":"approval-role-section",className:"b2b-purchase-order-approval-rule-form__approval-role",children:[e("span",{className:"b2b-purchase-order-approval-rule-form__approval-role-title",children:O.titleRequiresApprovalRole}),u("div",{className:"b2b-purchase-order-approval-rule-form__approval-role-multiselect",children:[e(we,{"data-testid":"approvers-multiselect",disabled:d,name:"approvers",value:[...c.approvers],options:r.map(p=>({value:p.id,label:p.name})),error:!!(o.approvers&&l.approvers),onChange:p=>{_("approvers",p),o.approvers||g("approvers")}}),e(he,{touched:o.approvers,error:l.approvers})]})]}),u("div",{"data-testid":"form-buttons",className:"b2b-purchase-order-approval-rule-form__buttons",children:[e(H,{"data-testid":"save-button",type:"button",disabled:d,onClick:R,children:O.buttonSave}),e(H,{"data-testid":"cancel-button",disabled:f,variant:"secondary",type:"button",onClick:()=>{ce((T==null?void 0:T())??"")},children:O.buttonCancel})]})]})},Gr=({className:r,approvalRuleID:a,withHeader:s,withWrapper:i,routeApprovalRulesList:t,onSubmit:n,onChange:c})=>{const l=ae({headerText:"PurchaseOrders.approvalRuleForm.headerText",titleAppliesTo:"PurchaseOrders.approvalRuleForm.titleAppliesTo",titleRuleType:"PurchaseOrders.approvalRuleForm.titleRuleType",titleRequiresApprovalRole:"PurchaseOrders.approvalRuleForm.titleRequiresApprovalRole",formEnabled:"PurchaseOrders.approvalRuleForm.fields.enabled",formDisabled:"PurchaseOrders.approvalRuleForm.fields.disabled",inputRuleNameFloatingLabel:"PurchaseOrders.approvalRuleForm.fields.inputRuleName.floatingLabel",inputRuleNamePlaceholder:"PurchaseOrders.approvalRuleForm.fields.inputRuleName.placeholder",textAreaDescriptionLabel:"PurchaseOrders.approvalRuleForm.fields.textAreaDescription.label",appliesToAllUsers:"PurchaseOrders.approvalRuleForm.fields.appliesTo.allUsers",appliesToSpecificRoles:"PurchaseOrders.approvalRuleForm.fields.appliesTo.specificRoles",ruleTypeGrandTotal:"PurchaseOrders.approvalRuleForm.fields.ruleTypeOptions.grandTotal",ruleTypeShippingInclTax:"PurchaseOrders.approvalRuleForm.fields.ruleTypeOptions.shippingInclTax",ruleTypeNumberOfSkus:"PurchaseOrders.approvalRuleForm.fields.ruleTypeOptions.numberOfSkus",conditionOperatorMoreThan:"PurchaseOrders.approvalRuleForm.fields.conditionOperators.moreThan",conditionOperatorLessThan:"PurchaseOrders.approvalRuleForm.fields.conditionOperators.lessThan",conditionOperatorMoreThanOrEqualTo:"PurchaseOrders.approvalRuleForm.fields.conditionOperators.moreThanOrEqualTo",conditionOperatorLessThanOrEqualTo:"PurchaseOrders.approvalRuleForm.fields.conditionOperators.lessThanOrEqualTo",inputQuantityFloatingLabel:"PurchaseOrders.approvalRuleForm.fields.inputQuantity.floatingLabel",inputQuantityPlaceholder:"PurchaseOrders.approvalRuleForm.fields.inputQuantity.placeholder",inputAmountFloatingLabel:"PurchaseOrders.approvalRuleForm.fields.inputAmount.floatingLabel",inputAmountPlaceholder:"PurchaseOrders.approvalRuleForm.fields.inputAmount.placeholder",buttonCancel:"PurchaseOrders.approvalRuleForm.fields.buttons.cancel",buttonSave:"PurchaseOrders.approvalRuleForm.fields.buttons.save"}),{permissions:o,loadingPermissions:f}=Or(),{availableRequiresApprovalFrom:y,conditionOperators:R,availableAppliesTo:g,appliesToOptions:_,ruleTypeOptions:T,currencies:O,formValues:d,errors:k,touched:L,isLoading:p,submitError:E,formLoading:I,handleSubmit:S,handleFieldTouch:x,handleSetFormValues:D}=yr({t:l,approvalRuleID:a,loadingPermissions:f,permissions:o,routeApprovalRulesList:t,onSubmit:n,onChange:c});if(I)return e(Cr,{testId:"b2b-purchase-order-approval-rule-form",className:V(["b2b-purchase-order-approval-rule-form",r])});const $=u(Oe,{children:[!!E&&e(Le,{heading:"",description:E}),e(Tr,{availableRequiresApprovalFrom:y,conditionOperators:R,availableAppliesTo:g,appliesToOptions:_,ruleTypeOptions:T,currencies:O,formValues:d,errors:k,touched:L,isLoading:p,handleSubmit:S,handleFieldTouch:x,handleSetFormValues:D,permissions:o,routeApprovalRulesList:t,t:l})]});return u("div",{"data-testid":"b2b-purchase-order-approval-rule-form",className:V(["b2b-purchase-order-approval-rule-form",r]),children:[s?e(vr,{headerText:l.headerText}):null,i?e(Me,{variant:"secondary",children:$}):$]})},qr=({className:r,purchaseOrderNumber:a,routePurchaseOrderDetails:s,...i})=>{const t=ae({title:"PurchaseOrders.purchaseOrderConfirmation.title",messagePrefix:"PurchaseOrders.purchaseOrderConfirmation.messagePrefix",messageSuffix:"PurchaseOrders.purchaseOrderConfirmation.messageSuffix"});return u("div",{...i,className:V(["purchase-orders-confirmation-content",r]),children:[e("h2",{className:"purchase-orders-confirmation-content__title",children:t.title}),u("p",{className:"purchase-orders-confirmation-content__message",children:[t.messagePrefix," ",u("a",{className:"purchase-orders-confirmation-content__link",href:s()??"",children:["#",a]}),". ",t.messageSuffix]})]})},Wr=({slots:r,t:a,loading:s,children:i,availableActions:t=[],handleApprove:n,handleReject:c,handleCancel:l,handlePlaceOrder:o})=>{const f=t.map(y=>{switch(y){case"APPROVE":return e(H,{variant:"secondary",disabled:s,type:"button",onClick:n,children:a.approveButtonText},y);case"PLACE_ORDER":return e(H,{variant:"secondary",disabled:s,type:"button",onClick:o,children:a.placeOrderButtonText},y);case"REJECT":return e(H,{variant:"secondary",disabled:s,type:"button",onClick:c,children:a.rejectButtonText},y);case"CANCEL":return e(H,{variant:"secondary",disabled:s,type:"button",onClick:l,children:a.cancelButtonText},y);default:return null}});return u("div",{className:V(["b2b-purchase-order-status-content"]),children:[e("div",{className:"b2b-purchase-order-status-content__message",children:a.statusMessageText}),i,e("div",{className:"b2b-purchase-order-status-content__actions",children:e(He,{"data-testid":"PurchaseOrderActions",name:"PurchaseOrderActions",slot:r==null?void 0:r.PurchaseOrderActions,context:{loading:s,availableActions:t,handleApprove:n,handleReject:c,handleCancel:l,handlePlaceOrder:o},children:f})})]})},Qr=({formValues:r})=>e("div",{className:V(["b2b-purchase-order-approval-rule-details-content"]),children:r.map((a,s)=>u("div",{className:V(["b2b-purchase-order-approval-rule-details-content__item"]),children:[e("span",{className:"b2b-purchase-order-approval-rule-details-content__label",children:a.label}),e("div",{className:"b2b-purchase-order-approval-rule-details-content__value",children:a.value})]},s))}),Cr=({testId:r="",className:a=""})=>e("div",{"data-testid":r,className:V(["b2b-purchase-order-form-loader",a]),children:u(Ze,{rowGap:"medium","data-testid":"form-loader-root",children:[e(re,{size:"small",variant:"row",fullWidth:!0,lines:1,style:{maxWidth:300},"data-testid":"form-loader-status-toggle"}),e(re,{size:"medium",variant:"row",fullWidth:!0,lines:1,"data-testid":"form-loader-name"}),e(re,{size:"medium",variant:"row",fullWidth:!0,lines:4,"data-testid":"form-loader-description"}),u("div",{className:"approval-rule-form-loader__section","data-testid":"form-loader-approval-role-section",children:[e(re,{size:"small",variant:"row",fullWidth:!0,lines:1,"data-testid":"form-loader-approval-role-label"}),e(re,{size:"small",variant:"row",fullWidth:!0,lines:1,"data-testid":"form-loader-approval-role-input"})]}),u("div",{className:"approval-rule-form-loader__buttons","data-testid":"form-loader-buttons",children:[e(re,{size:"medium",variant:"row",fullWidth:!0,lines:1,style:{width:120},"data-testid":"form-loader-button-save"}),e(re,{size:"medium",variant:"row",fullWidth:!0,lines:1,style:{width:120},"data-testid":"form-loader-button-cancel"})]})]})}),Zr=({commentsList:r=[],visibleRecordsLimit:a=5})=>{const[s,i]=A(a),t=r.length>s,n=r.length<=a,c=ae({showMoreLabel:"PurchaseOrders.comments.view.ariaLabel.showMore",showLessLabel:"PurchaseOrders.comments.view.ariaLabel.showLess"});return r.length?u("div",{className:"b2b-purchase-order-comment-list-content",children:[e("ul",{className:"b2b-purchase-order-comment-list-content__list",children:r.slice(0,s).map((l,o)=>{var y,R;const f=Math.min(s,r.length);return u(Pe,{children:[u("li",{className:"b2b-purchase-order-comment-list-content__item",children:[u("div",{className:"b2b-purchase-order-comment-list-content__title",children:[ve(l.createdAt),(y=l.author)!=null&&y.firstname&&((R=l.author)!=null&&R.lastname)?` (${l.author.firstname} ${l.author.lastname})`:""]}),e("div",{className:"b2b-purchase-order-comment-list-content__description",children:l.text})]}),o<f-1&&e("hr",{className:"b2b-purchase-order-comment-list-content__divider"})]},l.uid)})}),!n&&e("div",{className:"b2b-purchase-order-comment-list-content__actions",children:e(H,{variant:"secondary","aria-expanded":!t,"aria-label":t?c.showMoreLabel:c.showLessLabel,onClick:()=>{i(t?r.length:a)},children:e(P,{id:`PurchaseOrders.comments.view.buttons.${t?"viewMore":"viewLess"}`})})})]}):e("div",{className:"b2b-purchase-order-comment-list-content",children:e(P,{id:"PurchaseOrders.comments.view.emptyText"})})},Kr=({t:r,purchaseOrderData:a})=>{const[s,i]=A(!1),[t,n]=A(""),[c,l]=A(""),o=B(()=>!t.trim().length||!(a!=null&&a.uid)||s,[t,a,s]),f=M(R=>{const g=R.target.value;n(g),c&&l("")},[c]),y=M(()=>{const R=(a==null?void 0:a.uid)??"";!R||!t.trim().length||(i(!0),mr(R,t).then(g=>{g&&(a!=null&&a.uid)&&(G.emit("purchase-order/refresh",!0),n(""))}).catch(()=>{l(r.errorMessage||"Failed to add comment. Please try again.")}).finally(()=>{i(!1)}))},[a,t,r]);return u("div",{className:V(["b2b-purchase-order-comment-form-content"]),children:[e(xe,{errorMessage:c,disabled:s,value:t,label:r.textAreaPlaceholder,onChange:f}),e(H,{variant:"primary",disabled:o,onClick:y,children:r.buttonText})]})},Ar=r=>K.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},K.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),K.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M6.75 12.762L10.2385 15.75L17.25 9",stroke:"currentColor"})),Sr=r=>K.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},K.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M0 12C0 5.37931 5.37931 0 12 0C18.6207 0 24 5.37931 24 12C24 18.6207 18.6207 24 12 24C5.37931 24 0 18.6207 0 12ZM11.8885 5.06101C11.1405 5.06101 10.5357 5.66579 10.5357 6.4138V6.57295C10.5835 7.27321 11.1882 7.81433 11.8885 7.76658H12.0795C12.7797 7.70292 13.289 7.09815 13.2413 6.4138C13.2413 5.66579 12.6365 5.06101 11.8885 5.06101ZM13.1935 16.8223H14.1007C14.2599 16.8223 14.4031 16.9655 14.4031 17.1247V17.7294C14.4031 17.9045 14.2599 18.0318 14.1007 18.0318H9.8832C9.70813 18.0318 9.58081 17.8886 9.58081 17.7294V17.1247C9.58081 16.9496 9.72405 16.8223 9.8832 16.8223H10.7904V10.7905H9.8832C9.70813 10.7905 9.58081 10.6472 9.58081 10.4881V9.88329C9.58081 9.70823 9.72405 9.58091 9.8832 9.58091H12.5888C12.923 9.58091 13.1935 9.85146 13.1935 10.1857V16.8223Z",fill:"currentColor"})),wr=r=>K.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},K.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),K.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),Jr=({approvalFlow:r=[]})=>{const a=ae({pending:"PurchaseOrders.approvalFlow.ariaLabels.icons.pending",approved:"PurchaseOrders.approvalFlow.ariaLabels.icons.approved",rejected:"PurchaseOrders.approvalFlow.ariaLabels.icons.rejected"});if(!(r!=null&&r.length))return e("div",{className:"b2b-purchase-order-approval-flow-content",children:e(P,{id:"PurchaseOrders.approvalFlow.emptyText"})});const s=i=>{switch(i){case"PENDING":return e(Sr,{className:"b2b-purchase-order-approval-flow-content__icon--pending","aria-label":a.pending,role:"img"});case"APPROVED":return e(Ar,{className:"b2b-purchase-order-approval-flow-content__icon--approved","aria-label":a.approved,role:"img"});case"REJECTED":return e(wr,{className:"b2b-purchase-order-approval-flow-content__icon--rejected","aria-label":a.rejected,role:"img"});default:return null}};return e("div",{className:V(["b2b-purchase-order-approval-flow-content"]),children:e("ul",{className:"b2b-purchase-order-approval-flow-content__list",children:r.map((i,t)=>u(Pe,{children:[u("li",{className:"b2b-purchase-order-approval-flow-content__item",children:[e("div",{className:"b2b-purchase-order-approval-flow-content__title",children:i.ruleName}),i.events.map((n,c)=>u("div",{className:"b2b-purchase-order-approval-flow-content__description",children:[s(n.status),n.message]},c))]}),t<r.length-1&&e("hr",{className:"b2b-purchase-order-approval-flow-content__divider"})]},t))})})},Yr=({historyLogRecords:r=[],visibleRecordsLimit:a})=>{const[s,i]=A(a),t=r.length>s,n=r.length<=a,c=ae({showMoreLabel:"PurchaseOrders.historyLog.ariaLabel.showMore",showLessLabel:"PurchaseOrders.historyLog.ariaLabel.showLess"});return r.length?u("div",{className:"b2b-purchase-order-history-log-content",children:[e("ul",{className:"b2b-purchase-order-history-log-content__list",role:"list",children:r.slice(0,s).map((l,o)=>{const f=Math.min(s,r.length);return u(Pe,{children:[u("li",{className:"b2b-purchase-order-history-log-content__item",children:[e("div",{className:"b2b-purchase-order-history-log-content__title",children:e(P,{id:`PurchaseOrders.historyLog.status.${l.activity}`,fields:{date:ve(l.createdAt)}})}),e("div",{className:"b2b-purchase-order-history-log-content__description",children:l.message})]}),o<f-1&&e("hr",{className:"b2b-purchase-order-history-log-content__divider"})]},l.uid)})}),!n&&e("div",{className:"b2b-purchase-order-history-log-content__actions",children:e(H,{variant:"secondary","aria-expanded":!t,"aria-label":t?c.showMoreLabel:c.showLessLabel,onClick:()=>{i(t?r.length:a)},children:e(P,{id:`PurchaseOrders.historyLog.buttons.${t?"viewMore":"viewLess"}`})})})]}):e("div",{className:"b2b-purchase-order-history-log-content",children:e(P,{id:"PurchaseOrders.historyLog.emptyText"})})};export{Qr as ApprovalRuleDetailsContent,Gr as ApprovalRuleForm,_e as EnumPurchaseOrdersView,Cr as FormLoader,Jr as PurchaseOrderApprovalFlowContent,Kr as PurchaseOrderCommentFormContent,Zr as PurchaseOrderCommentsListContent,qr as PurchaseOrderConfirmationContent,Yr as PurchaseOrderHistoryLogContent,Wr as PurchaseOrderStatusContent,vr as PurchaseOrdersHeader,Dr as PurchaseOrdersTable,Ur as PurchaseOrdersTableActions,Br as defaultPageSizeConfig,$r as useApprovalRuleDetails,jr as useApprovalRulesList,Or as useCustomerRolePermissions,Rr as usePurchaseOrderData,zr as usePurchaseOrderStatus,Hr as usePurchaseOrders};
|
|
4
4
|
//# sourceMappingURL=components.js.map
|