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,Vt as a,zo as o}from"./error-handling-sQ-z99nE.js";import{lt as s}from"./select-BbuF1w16.js";import{Ot as c,ct as l,en as u,k as d,vt as f}from"./common-BW2g48Zf.js";import{t as p}from"./editable-business-trip-BjqGxZ_U.js";import{c as m}from"./separator-BimKXMpI.js";import{i as h,n as g,r as _,t as v}from"./accordion-Bo8DXOWg.js";import{el as y}from"./table-CJNgrg7p.js";import{t as b}from"./page-layout-CaKaH8li.js";var x=e(n(),1),S=t(),C=({data:e,isOpened:t,shouldValidate:n})=>{let i=y(a,e),[{data:s,fetching:c}]=o({pause:!n,query:r,variables:{id:i.id}}),l=(0,x.useMemo)(()=>n?s?.businessTrip&&(s.businessTrip.uncategorizedTransactions?.length||s?.businessTrip.summary?.errors?.length):!1,[s]),d=l||i?.accountantApproval!==`APPROVED`;return(0,S.jsxs)(_,{value:i.id,children:[(0,S.jsx)(h,{children:(0,S.jsx)(u,{inline:!0,size:12,processing:c,disabled:!d,color:l?`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,a]=(0,x.useState)(!1),[{data:u,fetching:p}]=o({query:i});(0,x.useEffect)(()=>{if(!u?.allBusinessTrips?.length){n([]);return}let e=u.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)},[u?.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)(l,{content:`Toggle business trips validation`,children:(0,S.jsxs)(`div`,{className:`flex flex-row items-center gap-x-2`,children:[(0,S.jsx)(f,{checked:r??!1,onCheckedChange:e=>a(e)}),(0,S.jsx)(`span`,{className:`text-sm text-gray-500`,children:`Validate`})]})}),(0,S.jsx)(c,{filename:`business_trips`})]}))},[u,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};