UNPKG

@accounter/client

Version:
1 lines • 11.1 kB
import{s as e}from"./dist-BmACi7k_.js";import{i as t,o as n}from"./utils-BxkqV8PM.js";import{ar as r,zo as i}from"./error-handling-sQ-z99nE.js";import{i as a,n as o}from"./routes-C4NpBRv7.js";import{dt as s}from"./select-KYQbDWZT.js";import{Gt as c,Ht as l,St as u,en as d,ht as f,it as p,p as m,r as h,rr as g,vt as _}from"./common-DtK-TFhT.js";import{t as v}from"./arrow-up-down-DoaoFKgd.js";import{c as y,d as b,h as x,l as S,u as C}from"./separator-CNv9f_S5.js";import{t as w}from"./funnel-Djj7k08w.js";import{t as T}from"./button-BZ6z_NAl.js";import{$c as E,Gc as D,Jc as O,Kl as k,Pl as A,Wc as j,Xc as M,Yc as N,a as P,al as F,c as ee,i as te,m as I,n as L,nl as R,o as z,p as B,qc as V,r as H,s as U,t as W,u as G}from"./table-D4eAFW7G.js";import{t as K}from"./sub-v_k-SWYe.js";import{t as q}from"./MultiSelect-DsfA2qgR.js";import{t as J}from"./use-url-query-DXFemxIX.js";import{t as Y}from"./page-layout-jrXvjrbd.js";var X=e(n(),1),Z=e(A(),1),Q=t();function ne({filter:e,setFilter:t,closeModal:n}){let{userContext:r}=(0,X.useContext)(R),i=E({defaultValues:{ownerIDs:r?.context.adminBusinessId?[r.context.adminBusinessId]:void 0,toDate:k(new Date,`yyyy-MM-dd`),fromDate:k(K(new Date,{years:1}),`yyyy-MM-dd`),...e}}),{control:a,handleSubmit:o}=i,{selectableFinancialEntities:s,fetching:l}=f(),u=e=>{t(e),n()};function d(){t({}),n()}return(0,Q.jsxs)(Q.Fragment,{children:[l?(0,Q.jsx)(`div`,{children:`Loading...`}):(0,Q.jsx)(`div`,{}),(0,Q.jsx)(j,{...i,children:(0,Q.jsxs)(`form`,{onSubmit:o(u),children:[(0,Q.jsxs)(c,{cols:2,children:[(0,Q.jsx)(V,{name:`ownerIDs`,control:a,defaultValue:e.ownerIDs,render:({field:e,fieldState:t})=>(0,Q.jsxs)(O,{children:[(0,Q.jsx)(N,{children:`Owners`}),(0,Q.jsx)(D,{children:(0,Q.jsx)(q,{...e,data:s,value:e.value??[],disabled:l,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}),(0,Q.jsx)(M,{})]})}),(0,Q.jsx)(V,{name:`businessIDs`,control:a,defaultValue:e.businessIDs,render:({field:e,fieldState:t})=>(0,Q.jsxs)(O,{children:[(0,Q.jsx)(N,{children:`Financial Entities`}),(0,Q.jsx)(D,{children:(0,Q.jsx)(q,{...e,data:s,value:e.value??[],disabled:l,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message,withinPortal:!0})}),(0,Q.jsx)(M,{})]})}),(0,Q.jsx)(V,{name:`fromDate`,control:a,defaultValue:e.fromDate,rules:{pattern:{value:g,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,Q.jsxs)(O,{children:[(0,Q.jsx)(N,{htmlFor:`documents-from-date`,children:`From Date`}),(0,Q.jsx)(D,{children:(0,Q.jsx)(p,{id:`documents-from-date`,onChange:t=>{t!==e.value&&e.onChange(t)},value:e.value??void 0,"aria-invalid":!!t.error})}),(0,Q.jsx)(M,{})]})}),(0,Q.jsx)(V,{name:`toDate`,control:a,defaultValue:e.toDate,rules:{pattern:{value:g,message:`Date must be in format yyyy-mm-dd`}},render:({field:e,fieldState:t})=>(0,Q.jsxs)(O,{children:[(0,Q.jsx)(N,{htmlFor:`documents-to-date`,children:`To Date`}),(0,Q.jsx)(D,{children:(0,Q.jsx)(p,{id:`documents-to-date`,onChange:t=>{t!==e.value&&e.onChange(t)},value:e.value??void 0,"aria-invalid":!!t.error})}),(0,Q.jsx)(M,{})]})}),(0,Q.jsx)(V,{name:`unmatched`,control:a,render:({field:t})=>(0,Q.jsxs)(O,{className:`flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm`,children:[(0,Q.jsx)(`div`,{className:`space-y-0.5`,children:(0,Q.jsx)(N,{children:`Unmatched only`})}),(0,Q.jsx)(D,{children:(0,Q.jsx)(_,{defaultChecked:e.unmatched??!1,onCheckedChange:t.onChange})})]})})]}),(0,Q.jsxs)(`div`,{className:`flex justify-center mt-5 gap-3`,children:[(0,Q.jsx)(`button`,{type:`submit`,disabled:l,className:`text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg`,children:`Filter`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg`,onClick:d,children:`Clear`}),(0,Q.jsx)(`button`,{type:`button`,className:`text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg`,onClick:n,children:`Cancel`})]})]})})]})}function re({filter:e={},setFilter:t,initiallyOpened:n=!1}){let[r,i]=(0,X.useState)(n),[s,c]=(0,X.useState)(!a(e)),{get:l,set:u}=J();return(0,X.useEffect)(()=>{let t=o(e);t!==l(`documentsFilters`)&&u(`documentsFilters`,t)},[e,l,u]),(0,Q.jsxs)(`div`,{className:`flex flex-row gap-5 items-center`,children:[(0,Q.jsx)(m,{opened:r,onClose:()=>i(!1),content:(0,Q.jsx)(ne,{filter:e,setFilter:(0,X.useCallback)(n=>{(0,Z.default)(n,e)||(t(n),c(!a(n)))},[e,t]),closeModal:()=>i(!1)}),modalSize:`xl`}),(0,Q.jsx)(d,{inline:!0,size:16,disabled:!s,children:(0,Q.jsx)(T,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>i(!0),children:(0,Q.jsx)(w,{className:`size-5`})})})]})}var $=[{accessorKey:`__typename`,header:({column:e})=>(0,Q.jsxs)(T,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[(0,Q.jsx)(`div`,{className:`text-left`,children:`Type`}),(0,Q.jsx)(v,{className:`ml-2 h-4 w-4`})]}),cell:({row:e})=>{let{__typename:t}=e.original;return(0,Q.jsx)(`div`,{className:`text-left font-medium`,children:t})}},{accessorKey:`image`,header:()=>(0,Q.jsx)(`div`,{className:`text-left`,children:`Image`}),cell:({row:e})=>{let{image:t}=e.original;return(0,Q.jsx)(`div`,{className:`text-left font-medium`,children:t?(0,Q.jsx)(`img`,{alt:`missing img`,src:t?.toString(),height:80,width:80}):`No image`})}},{accessorKey:`file`,header:()=>(0,Q.jsx)(`div`,{className:`text-left`,children:`File`}),cell:({row:e})=>{let{file:t}=e.original;return(0,Q.jsx)(`div`,{className:`text-left font-medium`,children:t&&(0,Q.jsx)(T,{variant:`outline`,size:`sm`,asChild:!0,children:(0,Q.jsx)(`a`,{target:`_blank`,rel:`noreferrer`,href:t?.toString(),children:`Open`})})})}},{accessorKey:`date`,header:({column:e})=>(0,Q.jsxs)(T,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[(0,Q.jsx)(`div`,{className:`text-left`,children:`Date`}),(0,Q.jsx)(v,{className:`ml-2 h-4 w-4`})]}),cell:({row:e})=>`date`in e.original&&e.original.date?(0,Q.jsx)(`div`,{className:`text-left font-medium`,children:k(new Date(e.original.date),`dd/MM/yy`)}):null},{accessorKey:`serialNumber`,header:({column:e})=>(0,Q.jsxs)(T,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[(0,Q.jsx)(`div`,{className:`text-left`,children:`Serial Number`}),(0,Q.jsx)(v,{className:`ml-2 h-4 w-4`})]}),cell:({row:e})=>`serialNumber`in e.original&&e.original.serialNumber?(0,Q.jsx)(`div`,{className:`text-left font-medium`,children:e.original.serialNumber}):null},{accessorKey:`vat.raw`,header:({column:e})=>(0,Q.jsxs)(T,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[(0,Q.jsx)(`div`,{className:`text-left`,children:`VAT`}),(0,Q.jsx)(v,{className:`ml-2 h-4 w-4`})]}),cell:({row:e})=>`vat`in e.original&&e.original.vat?.formatted?(0,Q.jsx)(`div`,{className:`text-left font-medium whitespace-nowrap`,children:e.original.vat.formatted}):null},{accessorKey:`amount.raw`,header:({column:e})=>(0,Q.jsxs)(T,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[(0,Q.jsx)(`div`,{className:`text-left`,children:`Amount`}),(0,Q.jsx)(v,{className:`ml-2 h-4 w-4`})]}),cell:({row:e})=>`amount`in e.original&&e.original.amount?.formatted?(0,Q.jsx)(`div`,{className:`text-left font-medium whitespace-nowrap`,children:e.original.amount.formatted}):null},{accessorKey:`creditor.name`,header:({column:e})=>(0,Q.jsxs)(T,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[(0,Q.jsx)(`div`,{className:`text-left`,children:`Creditor`}),(0,Q.jsx)(v,{className:`ml-2 h-4 w-4`})]}),cell:({row:e})=>`creditor`in e.original&&e.original.creditor?.name?(0,Q.jsx)(`div`,{className:`text-left font-medium whitespace-nowrap`,children:e.original.creditor.name}):null},{accessorKey:`debtor.name`,header:({column:e})=>(0,Q.jsxs)(T,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[(0,Q.jsx)(`div`,{className:`text-left`,children:`Debtor`}),(0,Q.jsx)(v,{className:`ml-2 h-4 w-4`})]}),cell:({row:e})=>`debtor`in e.original&&e.original.debtor?.name?(0,Q.jsx)(`div`,{className:`text-left font-medium whitespace-nowrap`,children:e.original.debtor.name}):null},{accessorKey:`charge.transactions[0].id`,header:()=>(0,Q.jsx)(`div`,{className:`text-left`,children:`Related Transaction`}),cell:({row:e})=>e.original.charge?.transactions?.[0]?.id?(0,Q.jsx)(l,{items:e.original.charge?.transactions??[],columns:[{title:`Transaction Amount`,value:e=>e?.amount.formatted},{title:`Transaction Created At`,value:e=>e?.eventDate?k(new Date(e.eventDate),`dd/MM/yy`):null},{title:`Transaction Effective Date`,value:e=>e?.effectiveDate?k(new Date(e.effectiveDate),`dd/MM/yy`):null},{title:`Transaction Description`,value:e=>e?.sourceDescription}]}):`No Related Transaction`}],ie=()=>{let[e,t]=(0,X.useState)(null),[n,a]=(0,X.useState)(!1),{get:o}=J(),c=o(`documentsFilters`),l=(0,X.useMemo)(()=>{if(c)try{return JSON.parse(decodeURIComponent(c))}catch{return}},[c]),[d,f]=(0,X.useState)(l),[p,g]=(0,X.useState)([]),[_,v]=(0,X.useState)({}),{setFiltersContext:w}=(0,X.useContext)(y),[{data:E,fetching:D},O]=i({query:r,variables:{filters:d??{}},pause:!0});(0,X.useEffect)(()=>{d&&O()},[d,O]);let k=ee({data:E?.documentsByFilters??[],columns:$,getCoreRowModel:G(),getPaginationRowModel:B(),onSortingChange:g,getSortedRowModel:I(),onColumnVisibilityChange:v,state:{sorting:p,columnVisibility:_}}),A=k.getState().pagination.pageIndex;return(0,X.useEffect)(()=>{w((0,Q.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,Q.jsx)(u,{table:k}),(0,Q.jsx)(re,{filter:d,setFilter:f,initiallyOpened:!d})]}))},[k,D,d,w,f,l,A]),(0,Q.jsx)(Y,{title:`Documents`,description:`All documents`,headerActions:(0,Q.jsxs)(`div`,{className:`flex items-center py-4 gap-4`,children:[(0,Q.jsxs)(S,{children:[(0,Q.jsx)(x,{asChild:!0,children:(0,Q.jsx)(T,{className:`ml-auto`,children:`Columns`})}),(0,Q.jsx)(b,{align:`end`,children:k.getAllColumns().filter(e=>e.getCanHide()).map(e=>(0,Q.jsx)(C,{className:`capitalize`,checked:e.getIsVisible(),onCheckedChange:t=>e.toggleVisibility(!!t),children:e.id},e.id))})]}),(0,Q.jsx)(T,{onClick:()=>a(!0),children:`Upload Documents`})]}),children:D?(0,Q.jsx)(s,{className:`h-10 w-10 animate-spin mr-2 self-center`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{open:n,onOpenChange:a,onChange:O}),e&&(0,Q.jsx)(m,{modalSize:`45%`,content:(0,Q.jsx)(F,{src:e}),opened:!!e,onClose:()=>t(null)}),(0,Q.jsxs)(W,{children:[(0,Q.jsx)(P,{children:k.getHeaderGroups().map(e=>(0,Q.jsx)(z,{children:e.headers.map(e=>(0,Q.jsx)(te,{children:e.isPlaceholder?null:U(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,Q.jsx)(L,{children:k.getRowModel().rows?.length?k.getRowModel().rows.map(e=>(0,Q.jsx)(z,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,Q.jsx)(H,{children:U(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,Q.jsx)(z,{children:(0,Q.jsx)(H,{colSpan:$.length,className:`h-24 text-center`,children:`No results.`})})})]})]})})};export{ie as DocumentsReport};