UNPKG

@accounter/client

Version:
1 lines 5.78 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{Cr as r,Sa as i,bo as a,es as o,r as s,t as c,ts as l}from"./error-handling-Bgq5bXpB.js";import{n as u}from"./loader-circle-CfW9jOIr.js";import{Ir as d,u as f,x as p}from"./common-DXImSOXZ.js";import{t as m}from"./building-2-Bwt8dSgl.js";import{c as h,f as g,l as _,p as v}from"./select-CGkwaf8-.js";import{t as y}from"./button-DUNsVBiu.js";import{Ul as b,a as x,c as S,d as C,i as w,n as T,o as E,r as D,s as O,t as k,tl as A}from"./table-BMPR7vqs.js";import{t as j}from"./card-DR4aRSHr.js";var M=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`}]]),N=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`}]]),P=e(n(),1),F=t(),I=e=>{switch(e){case r.BankAccount:return(0,F.jsx)(m,{className:`h-5 w-5`});case r.CreditCard:return(0,F.jsx)(d,{className:`h-5 w-5`});case r.CryptoWallet:return(0,F.jsx)(N,{className:`h-5 w-5`});case r.BankDepositAccount:return(0,F.jsx)(m,{className:`h-5 w-5`});case r.ForeignSecurities:return(0,F.jsx)(m,{className:`h-5 w-5`});default:return(0,F.jsx)(M,{className:`h-5 w-5`})}},L=e=>{switch(e){case r.BankAccount:return`Bank Account`;case r.CreditCard:return`Credit Card`;case r.CryptoWallet:return`Crypto Wallet`;case r.BankDepositAccount:return`Bank Deposit Account`;case r.ForeignSecurities:return`Foreign Securities`;default:return`Unknown Account Type`}},R=`updateTransactions`,z=()=>{let[{fetching:e},t]=o(a);return{fetching:e,updateTransactions:(0,P.useCallback)(async e=>{let n=Array.isArray(e.transactionIds)?e.transactionIds.join(`, `):e.transactionIds,r=`Error updating transactions ID [${n}]`,i=`${R}-${n}`;s.loading(`Updating Transactions`,{id:i});try{let n=await t(e),a=c(n,r,i,`updateTransactions`);if(a)return s.success(`Success`,{id:i,description:`Transactions updated`}),a.updateTransactions.transactions.map(e=>e.id)}catch(e){console.error(`${r}: ${e}`),s.error(`Error`,{id:i,description:r,duration:1e5,closeButton:!0})}},[t])}},B=[{id:`select`,header:({table:e})=>(0,F.jsx)(p,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,F.jsx)(p,{checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(!!t),"aria-label":`Select row`}),enableSorting:!1,enableHiding:!1},{accessorKey:`accountType`,header:`Type`,cell:({row:e})=>(0,F.jsx)(`div`,{children:e.getValue(`accountType`)})},{accessorKey:`accountName`,header:`Account`,cell:({row:e})=>(0,F.jsx)(`div`,{children:e.getValue(`accountName`)})},{accessorKey:`amountRaw`,header:`Amount`,cell:({row:e})=>(0,F.jsx)(`div`,{children:e.original.amountFormatted})},{accessorKey:`sourceDescription`,header:`Description`,cell:({row:e})=>(0,F.jsx)(`div`,{children:e.getValue(`sourceDescription`)})},{accessorKey:`eventDate`,header:`Event Date`,cell:({row:e})=>(0,F.jsx)(`div`,{children:b(e.getValue(`eventDate`),`yyyy-MM-dd`)})},{accessorKey:`valueDate`,header:`Value Date`,cell:({row:e})=>(0,F.jsx)(`div`,{children:e.getValue(`valueDate`)?b(e.getValue(`valueDate`),`yyyy-MM-dd`):``})}];function V({transactionId:e,counterpartyId:t,open:n,onOpenChange:r,onClose:a}){let[{data:o,fetching:s},c]=l({pause:!0,query:i,variables:{transactionId:e,withMissingInfo:!0}});(0,P.useEffect)(()=>{n&&t&&c()},[n,t,c,e]);let u=(0,P.useCallback)(e=>{r(e),n&&!e&&a?.()},[r,a,n]),d=(0,P.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:L(e.account.type),accountName:e.account.name}))??[];return o&&e.length===0&&u(!1),e},[o,u]);return(0,F.jsx)(h,{open:n&&!!t&&d.length>0,onOpenChange:u,children:(0,F.jsx)(_,{className:`overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]`,children:(0,F.jsx)(f,{fallback:(0,F.jsx)(`div`,{children:`Error fetching similar transactions`}),children:s?(0,F.jsx)(A,{}):t?(0,F.jsx)(H,{data:d,counterpartyId:t,onOpenChange:u}):null})})})}function H({data:e,counterpartyId:t,onOpenChange:n}){let[r,i]=P.useState([]),[a,o]=P.useState({}),s=S({features:O,data:e,columns:B,onSortingChange:i,onRowSelectionChange:o,state:{sorting:r,rowSelection:a}}),{updateTransactions:c}=z(),l=(0,P.useCallback)(async()=>{let e=s.getSelectedRowModel().rows.map(e=>e.original.id);await c({transactionIds:e,fields:{counterpartyId:t}}),n(!1)},[c,n,s,t]);return(0,P.useEffect)(()=>{e.length===0&&n(!1)},[e.length,n]),e.length?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(g,{className:`flex flex-row items-center justify-between`,children:[(0,F.jsx)(v,{children:`Transactions`}),(0,F.jsx)(y,{onClick:l,children:`Approve selected`})]}),(0,F.jsx)(j,{children:(0,F.jsxs)(k,{children:[(0,F.jsx)(x,{children:s.getHeaderGroups().map(e=>(0,F.jsx)(E,{children:e.headers.map(e=>(0,F.jsx)(w,{children:e.isPlaceholder?null:C(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,F.jsx)(T,{children:s.getRowModel().rows.map(e=>(0,F.jsx)(E,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,F.jsx)(D,{children:C(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})]}):null}export{I as n,L as r,V as t};