UNPKG

@accounter/client

Version:
1 lines 2.37 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{A as r,Ct as i,jt as a,rn as o,yt as s}from"./common-CXB0UgWw.js";import{t as c}from"./editable-business-trip-BNY2ELXe.js";import{c as l}from"./separator-CQBUMn7G.js";import{t as u}from"./loader-circle-CZACSY-b.js";import{i as d,n as f,r as p,t as m}from"./accordion-Bfa7-As4.js";import{el as h}from"./table-Dje35oxp.js";import{Ht as g,Ut as _,Vt as v,us as y}from"./graphql-BIob9ctl.js";import{t as b}from"./page-layout-YKSXEkhJ.js";var x=e(n(),1),S=t(),C=({data:e,isOpened:t,shouldValidate:n})=>{let r=h(v,e),[{data:i,fetching:a}]=y({pause:!n,query:g,variables:{id:r.id}}),s=(0,x.useMemo)(()=>n?i?.businessTrip&&(i.businessTrip.uncategorizedTransactions?.length||i?.businessTrip.summary?.errors?.length):!1,[i]),l=s||r?.accountantApproval!==`APPROVED`;return(0,S.jsxs)(p,{value:r.id,children:[(0,S.jsx)(d,{children:(0,S.jsx)(o,{inline:!0,size:12,processing:a,disabled:!l,color:s?`red`:`yellow`,zIndex:`auto`,children:r.name})}),(0,S.jsx)(f,{children:t&&(0,S.jsx)(c,{tripId:r.id,isExtended:!0},r.id)})]})},w=()=>{let{setFiltersContext:e}=(0,x.useContext)(l),[t,n]=(0,x.useState)([]),[o,c]=(0,x.useState)(!1),[{data:d,fetching:f}]=y({query:_});(0,x.useEffect)(()=>{if(!d?.allBusinessTrips?.length){n([]);return}let e=d.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);n(e)},[d?.allBusinessTrips]);let[p,h]=(0,x.useState)([]);return(0,x.useEffect)(()=>{e((0,S.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,S.jsx)(r,{}),(0,S.jsx)(i,{content:`Toggle business trips validation`,children:(0,S.jsxs)(`div`,{className:`flex flex-row items-center gap-x-2`,children:[(0,S.jsx)(s,{checked:o??!1,onCheckedChange:e=>c(e)}),(0,S.jsx)(`span`,{className:`text-sm text-gray-500`,children:`Validate`})]})}),(0,S.jsx)(a,{filename:`business_trips`})]}))},[d,f,e,o]),(0,S.jsx)(b,{title:`Business Trips`,description:`Manage business trips`,children:t.length===0&&f?(0,S.jsx)(u,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,S.jsx)(m,{className:`w-full`,type:`multiple`,value:p,onValueChange:h,children:t?.map(e=>(0,S.jsx)(C,{data:t.find(t=>t.id===e.id),shouldValidate:o,isOpened:p.includes(e.id)},e.id))})})};export{w as BusinessTrips};