UNPKG

@accounter/client

Version:
1 lines 2.33 kB
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n}from"./utils-DdVdMk8X.js";import{Bt as r,Ht as i,Lo as a,Vt as o}from"./error-handling-Dpfd9svJ.js";import{ft as s}from"./select-CrsvQyhZ.js";import{t as c}from"./editable-business-trip-B9uxbfRo.js";import{i as l,n as u,r as d,t as f}from"./accordion-D0VCW409.js";import{W as p}from"./table--bF0wbxq.js";import{It as m,Kt as h,Tt as g,X as _,cn as v,vn as y}from"./index-CL8-JoMZ.js";import{t as b}from"./page-layout-DoLDsSrs.js";var x=e(n(),1),S=t(),C=({data:e,isOpened:t,shouldValidate:n})=>{let i=p(r,e),[{data:s,fetching:f}]=a({pause:!n,query:o,variables:{id:i.id}}),m=(0,x.useMemo)(()=>n?s?.businessTrip&&(s.businessTrip.uncategorizedTransactions?.length||s?.businessTrip.summary?.errors?.length):!1,[s]),h=m||i?.accountantApproval!==`APPROVED`;return(0,S.jsxs)(d,{value:i.id,children:[(0,S.jsx)(l,{children:(0,S.jsx)(y,{inline:!0,size:12,processing:f,disabled:!h,color:m?`red`:`yellow`,zIndex:`auto`,children:i.name})}),(0,S.jsx)(u,{children:t&&(0,S.jsx)(c,{tripId:i.id,isExtended:!0},i.id)})]})},w=()=>{let{setFiltersContext:e}=(0,x.useContext)(v),[t,n]=(0,x.useState)([]),[r,o]=(0,x.useState)(!1),[{data:c,fetching:l}]=a({query:i});(0,x.useEffect)(()=>{if(!c?.allBusinessTrips?.length){n([]);return}n(c.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))},[c?.allBusinessTrips]);let[u,d]=(0,x.useState)([]);return(0,x.useEffect)(()=>{e((0,S.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,S.jsx)(_,{}),(0,S.jsx)(g,{content:`Toggle business trips validation`,children:(0,S.jsxs)(`div`,{className:`flex flex-row items-center gap-x-2`,children:[(0,S.jsx)(m,{checked:r??!1,onCheckedChange:e=>o(e)}),(0,S.jsx)(`span`,{className:`text-sm text-gray-500`,children:`Validate`})]})}),(0,S.jsx)(h,{filename:`business_trips`})]}))},[c,l,e,r]),(0,S.jsx)(b,{title:`Business Trips`,description:`Manage business trips`,children:t.length===0&&l?(0,S.jsx)(s,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,S.jsx)(f,{className:`w-full`,type:`multiple`,value:u,onValueChange:d,children:t?.map(e=>(0,S.jsx)(C,{data:t.find(t=>t.id===e.id),shouldValidate:r,isOpened:u.includes(e.id)},e.id))})})};export{w as BusinessTrips};