@accounter/client
Version:
Accounter client application
1 lines • 5.54 kB
JavaScript
import{t as e}from"./building-2-BBv615u9.js";import{$ as t,Al as n,B as r,Cu as i,Fc as a,G as o,H as s,Id as c,K as l,Li as u,Ml as d,Ni as f,Pi as p,Ps as m,Ri as h,Rl as g,U as _,V as v,W as y,Wl as b,Y as x,_i as S,cd as C,gl as w,j as T,jd as E,kl as D,nr as O,q as k,tt as A,vi as j,yd as M}from"./index-CSYTUOOk.js";var N=M(`badge-question-mark`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`line`,{x1:`12`,x2:`12.01`,y1:`17`,y2:`17`,key:`io3f8k`}]]),P=M(`bitcoin`,[[`path`,{d:`M11.767 19.089c4.924.868 6.14-6.025 1.216-6.894m-1.216 6.894L5.86 18.047m5.908 1.042-.347 1.97m1.563-8.864c4.924.869 6.14-6.025 1.215-6.893m-1.215 6.893-3.94-.694m5.155-6.2L8.29 4.26m5.908 1.042.348-1.97M7.48 20.364l3.126-17.727`,key:`yr8idg`}]]),F=c(E(),1),I=i(),L=t=>{switch(t){case m.BankAccount:return(0,I.jsx)(e,{className:`h-5 w-5`});case m.CreditCard:return(0,I.jsx)(C,{className:`h-5 w-5`});case m.CryptoWallet:return(0,I.jsx)(P,{className:`h-5 w-5`});case m.BankDepositAccount:return(0,I.jsx)(e,{className:`h-5 w-5`});case m.ForeignSecurities:return(0,I.jsx)(e,{className:`h-5 w-5`});default:return(0,I.jsx)(N,{className:`h-5 w-5`})}},R=e=>{switch(e){case m.BankAccount:return`Bank Account`;case m.CreditCard:return`Credit Card`;case m.CryptoWallet:return`Crypto Wallet`;case m.BankDepositAccount:return`Bank Deposit Account`;case m.ForeignSecurities:return`Foreign Securities`;default:return`Unknown Account Type`}},z=`updateTransactions`,B=()=>{let[{fetching:e},t]=D(w);return{fetching:e,updateTransactions:(0,F.useCallback)(async e=>{let n=Array.isArray(e.transactionIds)?e.transactionIds.join(`, `):e.transactionIds,r=`Error updating transactions ID [${n}]`,i=`${z}-${n}`;j.loading(`Updating Transactions`,{id:i});try{let n=S(await t(e),r,i,`updateTransactions`);if(n)return j.success(`Success`,{id:i,description:`Transactions updated`}),n.updateTransactions.transactions.map(e=>e.id)}catch(e){console.error(`${r}: ${e}`),j.error(`Error`,{id:i,description:r,duration:1e5,closeButton:!0})}},[t])}},V=[{id:`select`,header:({table:e})=>(0,I.jsx)(A,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,I.jsx)(A,{checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(!!t),"aria-label":`Select row`}),enableSorting:!1,enableHiding:!1},{accessorKey:`accountType`,header:`Type`,cell:({row:e})=>(0,I.jsx)(`div`,{children:e.getValue(`accountType`)})},{accessorKey:`accountName`,header:`Account`,cell:({row:e})=>(0,I.jsx)(`div`,{children:e.getValue(`accountName`)})},{accessorKey:`amountRaw`,header:`Amount`,cell:({row:e})=>(0,I.jsx)(`div`,{children:e.original.amountFormatted})},{accessorKey:`sourceDescription`,header:`Description`,cell:({row:e})=>(0,I.jsx)(`div`,{children:e.getValue(`sourceDescription`)})},{accessorKey:`eventDate`,header:`Event Date`,cell:({row:e})=>(0,I.jsx)(`div`,{children:d(e.getValue(`eventDate`),`yyyy-MM-dd`)})},{accessorKey:`valueDate`,header:`Value Date`,cell:({row:e})=>(0,I.jsx)(`div`,{children:e.getValue(`valueDate`)?d(e.getValue(`valueDate`),`yyyy-MM-dd`):``})}];function H({transactionId:e,counterpartyId:t,open:r,onOpenChange:i,onClose:o}){let[{data:s,fetching:c},l]=n({pause:!0,query:a,variables:{transactionId:e,withMissingInfo:!0}});(0,F.useEffect)(()=>{r&&t&&l()},[r,t,l,e]);let u=(0,F.useCallback)(e=>{i(e),r&&!e&&o?.()},[i,o,r]),d=(0,F.useMemo)(()=>{let e=s?.similarTransactions.map(e=>({id:e.id,amountRaw:e.amount.raw,amountFormatted:e.amount.formatted,sourceDescription:e.sourceDescription,eventDate:new Date(e.eventDate),valueDate:e.effectiveDate?new Date(e.effectiveDate):void 0,accountType:R(e.account.type),accountName:e.account.name}))??[];return s&&e.length===0&&u(!1),e},[s,u]);return(0,I.jsx)(f,{open:r&&!!t&&d.length>0,onOpenChange:u,children:(0,I.jsx)(p,{className:`overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]`,children:(0,I.jsx)(T,{fallback:(0,I.jsx)(`div`,{children:`Error fetching similar transactions`}),children:c?(0,I.jsx)(O,{}):t?(0,I.jsx)(U,{data:d,counterpartyId:t,onOpenChange:u}):null})})})}function U({data:e,counterpartyId:n,onOpenChange:i}){let[a,c]=F.useState([]),[d,f]=F.useState({}),p=k({data:e,columns:V,onSortingChange:c,getCoreRowModel:x(),getSortedRowModel:t(),onRowSelectionChange:f,state:{sorting:a,rowSelection:d}}),{updateTransactions:m}=B(),S=(0,F.useCallback)(async()=>{await m({transactionIds:p.getSelectedRowModel().rows.map(e=>e.original.id),fields:{counterpartyId:n}}),i(!1)},[m,i,p,n]);return(0,F.useEffect)(()=>{e.length===0&&i(!1)},[e.length,i]),e.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(u,{className:`flex flex-row items-center justify-between`,children:[(0,I.jsx)(h,{children:`Transactions`}),(0,I.jsx)(b,{onClick:S,children:`Approve selected`})]}),(0,I.jsx)(g,{children:(0,I.jsxs)(r,{children:[(0,I.jsx)(y,{children:p.getHeaderGroups().map(e=>(0,I.jsx)(o,{children:e.headers.map(e=>(0,I.jsx)(_,{children:e.isPlaceholder?null:l(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,I.jsx)(v,{children:p.getRowModel().rows.map(e=>(0,I.jsx)(o,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,I.jsx)(s,{children:l(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})]}):null}export{L as n,R as r,H as t};