UNPKG

@accounter/client

Version:
1 lines 5.8 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{r,t as i}from"./error-handling-CKe_iwSC.js";import{n as a}from"./loader-circle-CfW9jOIr.js";import{Ir as o,u as s,x as c}from"./common-C-xiqZIW.js";import{t as l}from"./building-2-Bwt8dSgl.js";import{c as u,f as d,l as f,p}from"./select-Zdatwv1b.js";import{t as m}from"./button-DUNsVBiu.js";import{Ul as h,a as g,c as _,d as v,i as y,n as b,o as x,r as S,s as C,t as w,tl as T}from"./table-8Lgrmlcz.js";import{t as E}from"./card-DR4aRSHr.js";import{Ea as D,as as O,os as k,wo as A,xr as j}from"./graphql-6Homw-Kt.js";var M=a(`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=a(`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 j.BankAccount:return(0,F.jsx)(l,{className:`h-5 w-5`});case j.CreditCard:return(0,F.jsx)(o,{className:`h-5 w-5`});case j.CryptoWallet:return(0,F.jsx)(N,{className:`h-5 w-5`});case j.BankDepositAccount:return(0,F.jsx)(l,{className:`h-5 w-5`});case j.ForeignSecurities:return(0,F.jsx)(l,{className:`h-5 w-5`});default:return(0,F.jsx)(M,{className:`h-5 w-5`})}},L=e=>{switch(e){case j.BankAccount:return`Bank Account`;case j.CreditCard:return`Credit Card`;case j.CryptoWallet:return`Crypto Wallet`;case j.BankDepositAccount:return`Bank Deposit Account`;case j.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,a=`Error updating transactions ID [${n}]`,o=`${R}-${n}`;r.loading(`Updating Transactions`,{id:o});try{let n=await t(e),s=i(n,a,o,`updateTransactions`);if(s)return r.success(`Success`,{id:o,description:`Transactions updated`}),s.updateTransactions.transactions.map(e=>e.id)}catch(e){console.error(`${a}: ${e}`),r.error(`Error`,{id:o,description:a,duration:1e5,closeButton:!0})}},[t])}},B=[{id:`select`,header:({table:e})=>(0,F.jsx)(c,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,F.jsx)(c,{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:h(e.getValue(`eventDate`),`yyyy-MM-dd`)})},{accessorKey:`valueDate`,header:`Value Date`,cell:({row:e})=>(0,F.jsx)(`div`,{children:e.getValue(`valueDate`)?h(e.getValue(`valueDate`),`yyyy-MM-dd`):``})}];function V({transactionId:e,counterpartyId:t,open:n,onOpenChange:r,onClose:i}){let[{data:a,fetching:o},c]=k({pause:!0,query:D,variables:{transactionId:e,withMissingInfo:!0}});(0,P.useEffect)(()=>{n&&t&&c()},[n,t,c,e]);let l=(0,P.useCallback)(e=>{r(e),n&&!e&&i?.()},[r,i,n]),d=(0,P.useMemo)(()=>{let e=a?.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 a&&e.length===0&&l(!1),e},[a,l]);return(0,F.jsx)(u,{open:n&&!!t&&d.length>0,onOpenChange:l,children:(0,F.jsx)(f,{className:`overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]`,children:(0,F.jsx)(s,{fallback:(0,F.jsx)(`div`,{children:`Error fetching similar transactions`}),children:o?(0,F.jsx)(T,{}):t?(0,F.jsx)(H,{data:d,counterpartyId:t,onOpenChange:l}):null})})})}function H({data:e,counterpartyId:t,onOpenChange:n}){let[r,i]=P.useState([]),[a,o]=P.useState({}),s=_({features:C,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)(d,{className:`flex flex-row items-center justify-between`,children:[(0,F.jsx)(p,{children:`Transactions`}),(0,F.jsx)(m,{onClick:l,children:`Approve selected`})]}),(0,F.jsx)(E,{children:(0,F.jsxs)(w,{children:[(0,F.jsx)(g,{children:s.getHeaderGroups().map(e=>(0,F.jsx)(x,{children:e.headers.map(e=>(0,F.jsx)(y,{children:e.isPlaceholder?null:v(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,F.jsx)(b,{children:s.getRowModel().rows.map(e=>(0,F.jsx)(x,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,F.jsx)(S,{children:v(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})]}):null}export{I as n,L as r,V as t};