UNPKG

@accounter/client

Version:

2 lines (1 loc) 2.89 kB
import{v as w,g as C,hF as U,r as d,t as p,i as I,hG as j,hH as c,a5 as m,e as b,j as o,bZ as y,b_ as $,B as k,c0 as B,dU as v}from"./index-DRqooPz9.js";const D=[["path",{d:"M12 6v6l4 2",key:"mmk7yg"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],x=w("clock",D),N="updateBusinessTripAccountantApproval",E=()=>{const[{fetching:t},i]=C(U),u=d.useCallback(async e=>{const n=`Error toggling accountant approval for trip [${e.businessTripId}]`,a=`${N}-${e.businessTripId}`;p.loading("Updating accountant approval status",{id:a});try{const s=await i(e),r=I(s,n,a);if(r)return p.success("Success",{id:a,description:"Accountant approval status updated"}),r.updateBusinessTripAccountantApproval}catch(s){console.error(`${n}: ${s}`),p.error("Error",{id:a,description:n,duration:1e5,closeButton:!0})}},[i]);return{fetching:t,updateBusinessTripAccountantApproval:u}},S="updateChargeAccountantApproval",M=()=>{const[{fetching:t},i]=C(j),u=d.useCallback(async e=>{const n=`Error toggling accountant approval to ledger record ID [${e.chargeId}]`,a=`${S}-${e.chargeId}`;p.loading("Updating approval status",{id:a});try{const s=await i(e),r=I(s,n,a,"updateChargeAccountantApproval");if(r)return p.success("Success",{id:a,description:"Accountant approval was updated"}),r.updateChargeAccountantApproval}catch(s){console.error(`${n}: ${s}`),p.error("Error",{id:a,description:n,duration:1e5,closeButton:!0})}},[i]);return{fetching:t,updateChargeAccountantApproval:u}},O={[c.Approved]:{icon:b,color:"text-green-600",bgColor:"hover:bg-green-50",label:"Approved",value:c.Approved},[c.Pending]:{icon:x,color:"text-yellow-600",bgColor:"hover:bg-yellow-50",label:"Pending",value:c.Pending},[c.Unapproved]:{icon:m,color:"text-red-600",bgColor:"hover:bg-red-50",label:"Unapproved",value:c.Unapproved}},P=t=>O[t];function F(t){const{onChange:i,value:u}=t,[e,n]=d.useState(u??c.Unapproved),{updateChargeAccountantApproval:a}=M(),{updateBusinessTripAccountantApproval:s}=E(),r=P(e),T=r.icon,l=d.useCallback(async g=>{const f=e;n(g);let h=null;t.chargeId?h=await a({chargeId:t.chargeId,status:g}):t.businessTripId&&(h=await s({businessTripId:t.businessTripId,status:g})),h||n(f),i?.()},[t.chargeId,a,t.businessTripId,s,e,i]);d.useEffect(()=>{u&&n(u)},[u]);const A=!t.chargeId&&!t.businessTripId;return o.jsxs(y,{children:[o.jsx($,{asChild:!0,disabled:A,children:o.jsx(k,{variant:"ghost",size:"sm",className:`h-7 w-7 p-0 ${r.bgColor}`,title:r.label,disabled:A,children:o.jsx(T,{className:`h-3.5 w-3.5 ${r.color}`})})}),o.jsxs(B,{align:"center",children:[o.jsxs(v,{onClick:()=>l(c.Approved),children:[o.jsx(b,{className:"h-4 w-4 mr-2 text-green-600"}),"Approved"]}),o.jsxs(v,{onClick:()=>l(c.Pending),children:[o.jsx(x,{className:"h-4 w-4 mr-2 text-yellow-600"}),"Pending"]}),o.jsxs(v,{onClick:()=>l(c.Unapproved),children:[o.jsx(m,{className:"h-4 w-4 mr-2 text-red-600"}),"Unapproved"]})]})]})}export{F as U,O as a};