UNPKG

@accounter/client

Version:
1 lines 2.37 kB
import{s as e}from"./dist-BmACi7k_.js";import{i as t,o as n}from"./utils-BxkqV8PM.js";import{Ht as r,Ut as i,Vo as a,Vt as o}from"./error-handling-BcsQohmh.js";import{ut as s}from"./select-B9uPAoLq.js";import{Et as c,Zt as l,gt as u,k as d,ot as f}from"./common-CTTXK2Za.js";import{t as p}from"./editable-business-trip-DSlWSILK.js";import{c as m}from"./separator-Dgd_YdPn.js";import{i as h,n as g,r as _,t as v}from"./accordion-DhPrIhAq.js";import{el as y}from"./table-QvPx-2PG.js";import{t as b}from"./page-layout-DpKAaJTp.js";var x=e(n(),1),S=t(),C=({data:e,isOpened:t,shouldValidate:n})=>{let i=y(o,e),[{data:s,fetching:c}]=a({pause:!n,query:r,variables:{id:i.id}}),u=(0,x.useMemo)(()=>n?s?.businessTrip&&(s.businessTrip.uncategorizedTransactions?.length||s?.businessTrip.summary?.errors?.length):!1,[s]),d=u||i?.accountantApproval!==`APPROVED`;return(0,S.jsxs)(_,{value:i.id,children:[(0,S.jsx)(h,{children:(0,S.jsx)(l,{inline:!0,size:12,processing:c,disabled:!d,color:u?`red`:`yellow`,zIndex:`auto`,children:i.name})}),(0,S.jsx)(g,{children:t&&(0,S.jsx)(p,{tripId:i.id,isExtended:!0},i.id)})]})},w=()=>{let{setFiltersContext:e}=(0,x.useContext)(m),[t,n]=(0,x.useState)([]),[r,o]=(0,x.useState)(!1),[{data:l,fetching:p}]=a({query:i});(0,x.useEffect)(()=>{if(!l?.allBusinessTrips?.length){n([]);return}let e=l.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)},[l?.allBusinessTrips]);let[h,g]=(0,x.useState)([]);return(0,x.useEffect)(()=>{e((0,S.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,S.jsx)(d,{}),(0,S.jsx)(f,{content:`Toggle business trips validation`,children:(0,S.jsxs)(`div`,{className:`flex flex-row items-center gap-x-2`,children:[(0,S.jsx)(u,{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`})]}))},[l,p,e,r]),(0,S.jsx)(b,{title:`Business Trips`,description:`Manage business trips`,children:t.length===0&&p?(0,S.jsx)(s,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,S.jsx)(v,{className:`w-full`,type:`multiple`,value:h,onValueChange:g,children:t?.map(e=>(0,S.jsx)(C,{data:t.find(t=>t.id===e.id),shouldValidate:r,isOpened:h.includes(e.id)},e.id))})})};export{w as BusinessTrips};