UNPKG

@accounter/client

Version:
1 lines 5.73 kB
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n}from"./utils-DdVdMk8X.js";import{Io as r,Lo as i,ao as a,r as o,sa as s,t as c,xr as l}from"./error-handling-Dpfd9svJ.js";import{_t as u,c as d,f,l as p,p as m}from"./select-CrsvQyhZ.js";import{t as h}from"./building-2-BpbnxFOU.js";import{t as g}from"./button-Dzp2INW0.js";import{J as _,Lt as v,a as y,c as b,i as x,m as S,n as C,o as w,r as T,s as E,t as D,u as O}from"./table--bF0wbxq.js";import{H as k,M as A,Pr as j,_i as M}from"./index-CL8-JoMZ.js";var N=u(`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=u(`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=e(n(),1),I=t(),L=e=>{switch(e){case l.BankAccount:return(0,I.jsx)(h,{className:`h-5 w-5`});case l.CreditCard:return(0,I.jsx)(M,{className:`h-5 w-5`});case l.CryptoWallet:return(0,I.jsx)(P,{className:`h-5 w-5`});case l.BankDepositAccount:return(0,I.jsx)(h,{className:`h-5 w-5`});case l.ForeignSecurities:return(0,I.jsx)(h,{className:`h-5 w-5`});default:return(0,I.jsx)(N,{className:`h-5 w-5`})}},R=e=>{switch(e){case l.BankAccount:return`Bank Account`;case l.CreditCard:return`Credit Card`;case l.CryptoWallet:return`Crypto Wallet`;case l.BankDepositAccount:return`Bank Deposit Account`;case l.ForeignSecurities:return`Foreign Securities`;default:return`Unknown Account Type`}},z=`updateTransactions`,B=()=>{let[{fetching:e},t]=r(a);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}`;o.loading(`Updating Transactions`,{id:i});try{let n=c(await t(e),r,i,`updateTransactions`);if(n)return o.success(`Success`,{id:i,description:`Transactions updated`}),n.updateTransactions.transactions.map(e=>e.id)}catch(e){console.error(`${r}: ${e}`),o.error(`Error`,{id:i,description:r,duration:1e5,closeButton:!0})}},[t])}},V=[{id:`select`,header:({table:e})=>(0,I.jsx)(k,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,I.jsx)(k,{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:v(e.getValue(`eventDate`),`yyyy-MM-dd`)})},{accessorKey:`valueDate`,header:`Value Date`,cell:({row:e})=>(0,I.jsx)(`div`,{children:e.getValue(`valueDate`)?v(e.getValue(`valueDate`),`yyyy-MM-dd`):``})}];function H({transactionId:e,counterpartyId:t,open:n,onOpenChange:r,onClose:a}){let[{data:o,fetching:c},l]=i({pause:!0,query:s,variables:{transactionId:e,withMissingInfo:!0}});(0,F.useEffect)(()=>{n&&t&&l()},[n,t,l,e]);let u=(0,F.useCallback)(e=>{r(e),n&&!e&&a?.()},[r,a,n]),f=(0,F.useMemo)(()=>{let e=o?.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 o&&e.length===0&&u(!1),e},[o,u]);return(0,I.jsx)(d,{open:n&&!!t&&f.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)(A,{fallback:(0,I.jsx)(`div`,{children:`Error fetching similar transactions`}),children:c?(0,I.jsx)(_,{}):t?(0,I.jsx)(U,{data:f,counterpartyId:t,onOpenChange:u}):null})})})}function U({data:e,counterpartyId:t,onOpenChange:n}){let[r,i]=F.useState([]),[a,o]=F.useState({}),s=b({data:e,columns:V,onSortingChange:i,getCoreRowModel:O(),getSortedRowModel:S(),onRowSelectionChange:o,state:{sorting:r,rowSelection:a}}),{updateTransactions:c}=B(),l=(0,F.useCallback)(async()=>{await c({transactionIds:s.getSelectedRowModel().rows.map(e=>e.original.id),fields:{counterpartyId:t}}),n(!1)},[c,n,s,t]);return(0,F.useEffect)(()=>{e.length===0&&n(!1)},[e.length,n]),e.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(f,{className:`flex flex-row items-center justify-between`,children:[(0,I.jsx)(m,{children:`Transactions`}),(0,I.jsx)(g,{onClick:l,children:`Approve selected`})]}),(0,I.jsx)(j,{children:(0,I.jsxs)(D,{children:[(0,I.jsx)(y,{children:s.getHeaderGroups().map(e=>(0,I.jsx)(w,{children:e.headers.map(e=>(0,I.jsx)(x,{children:e.isPlaceholder?null:E(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,I.jsx)(C,{children:s.getRowModel().rows.map(e=>(0,I.jsx)(w,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,I.jsx)(T,{children:E(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})]}):null}export{L as n,R as r,H as t};