UNPKG

@accounter/client

Version:
1 lines 2.15 kB
import{t as e}from"./editable-business-trip-BbpBdsqT.js";import{i as t,n,r,t as i}from"./accordion-D7tsZGVD.js";import{Al as a,Cu as o,Id as s,In as c,So as l,Xn as u,Zu as d,bo as f,dn as p,en as m,er as h,fr as g,jd as _,lt as v,xo as y}from"./index-DUZECcXr.js";import{t as b}from"./page-layout-BfWJC_SV.js";var x=s(_(),1),S=o(),C=({data:i,isOpened:o,shouldValidate:s})=>{let c=u(f,i),[{data:l,fetching:d}]=a({pause:!s,query:y,variables:{id:c.id}}),p=(0,x.useMemo)(()=>s?l?.businessTrip&&(l.businessTrip.uncategorizedTransactions?.length||l?.businessTrip.summary?.errors?.length):!1,[l]),m=p||c?.accountantApproval!==`APPROVED`;return(0,S.jsxs)(r,{value:c.id,children:[(0,S.jsx)(t,{children:(0,S.jsx)(g,{inline:!0,size:12,processing:d,disabled:!m,color:p?`red`:`yellow`,zIndex:`auto`,children:c.name})}),(0,S.jsx)(n,{children:o&&(0,S.jsx)(e,{tripId:c.id,isExtended:!0},c.id)})]})},w=()=>{let{setFiltersContext:e}=(0,x.useContext)(h),[t,n]=(0,x.useState)([]),[r,o]=(0,x.useState)(!1),[{data:s,fetching:u}]=a({query:l});(0,x.useEffect)(()=>{if(!s?.allBusinessTrips?.length){n([]);return}n(s.allBusinessTrips.sort((e,t)=>e.dates?.start&&t.dates?.start?e.dates.start<t.dates.start?1:-1:e.dates?.start?-1:t.dates?.start?1:e.name.toLocaleLowerCase()<t.name.toLocaleLowerCase()?-1:1))},[s?.allBusinessTrips]);let[f,g]=(0,x.useState)([]);return(0,x.useEffect)(()=>{e((0,S.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,S.jsx)(v,{}),(0,S.jsx)(m,{content:`Toggle business trips validation`,children:(0,S.jsxs)(`div`,{className:`flex flex-row items-center gap-x-2`,children:[(0,S.jsx)(p,{checked:r??!1,onCheckedChange:e=>o(e)}),(0,S.jsx)(`span`,{className:`text-sm text-gray-500`,children:`Validate`})]})}),(0,S.jsx)(c,{filename:`business_trips`})]}))},[s,u,e,r]),(0,S.jsx)(b,{title:`Business Trips`,description:`Manage business trips`,children:t.length===0&&u?(0,S.jsx)(d,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,S.jsx)(i,{className:`w-full`,type:`multiple`,value:f,onValueChange:g,children:t?.map(e=>(0,S.jsx)(C,{data:t.find(t=>t.id===e.id),shouldValidate:r,isOpened:f.includes(e.id)},e.id))})})};export{w as BusinessTrips};