UNPKG

@accounter/client

Version:
1 lines 5.58 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{t as a}from"./createLucideIcon-BK8Z-P8J.js";import{Lr as o,nt as s,u as c}from"./common-CXB0UgWw.js";import{t as l}from"./bitcoin-BgaLWnss.js";import{t as u}from"./building-2-DEOLLnGI.js";import{c as d,f,l as p,p as m}from"./select-DrAHsHyM.js";import{t as h}from"./button-DUNsVBiu.js";import{Kl as g,a as _,c as v,d as y,i as b,il as x,n as S,o as C,r as w,s as T,t as E}from"./table-Dje35oxp.js";import{t as D}from"./card-DR4aRSHr.js";import{Aa as O,Oo as k,ls as A,us as j,xr as M}from"./graphql-BIob9ctl.js";var N=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`}]]),P=e(n(),1),F=t(),I=e=>{switch(e){case M.BankAccount:return(0,F.jsx)(u,{className:`h-5 w-5`});case M.CreditCard:return(0,F.jsx)(o,{className:`h-5 w-5`});case M.CryptoWallet:return(0,F.jsx)(l,{className:`h-5 w-5`});case M.BankDepositAccount:return(0,F.jsx)(u,{className:`h-5 w-5`});case M.ForeignSecurities:return(0,F.jsx)(u,{className:`h-5 w-5`});default:return(0,F.jsx)(N,{className:`h-5 w-5`})}},L=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`}},R=`updateTransactions`,z=()=>{let[{fetching:e},t]=A(k);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)(s,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,F.jsx)(s,{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:g(e.getValue(`eventDate`),`yyyy-MM-dd`)})},{accessorKey:`valueDate`,header:`Value Date`,cell:({row:e})=>(0,F.jsx)(`div`,{children:e.getValue(`valueDate`)?g(e.getValue(`valueDate`),`yyyy-MM-dd`):``})}];function V({transactionId:e,counterpartyId:t,open:n,onOpenChange:r,onClose:i}){let[{data:a,fetching:o},s]=j({pause:!0,query:O,variables:{transactionId:e,withMissingInfo:!0}});(0,P.useEffect)(()=>{n&&t&&s()},[n,t,s,e]);let l=(0,P.useCallback)(e=>{r(e),n&&!e&&i?.()},[r,i,n]),u=(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)(d,{open:n&&!!t&&u.length>0,onOpenChange:l,children:(0,F.jsx)(p,{className:`overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]`,children:(0,F.jsx)(c,{fallback:(0,F.jsx)(`div`,{children:`Error fetching similar transactions`}),children:o?(0,F.jsx)(x,{}):t?(0,F.jsx)(H,{data:u,counterpartyId:t,onOpenChange:l}):null})})})}function H({data:e,counterpartyId:t,onOpenChange:n}){let[r,i]=P.useState([]),[a,o]=P.useState({}),s=v({features:T,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)(f,{className:`flex flex-row items-center justify-between`,children:[(0,F.jsx)(m,{children:`Transactions`}),(0,F.jsx)(h,{onClick:l,children:`Approve selected`})]}),(0,F.jsx)(D,{children:(0,F.jsxs)(E,{children:[(0,F.jsx)(_,{children:s.getHeaderGroups().map(e=>(0,F.jsx)(C,{children:e.headers.map(e=>(0,F.jsx)(b,{children:e.isPlaceholder?null:y(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,F.jsx)(S,{children:s.getRowModel().rows.map(e=>(0,F.jsx)(C,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,F.jsx)(w,{children:y(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})]}):null}export{I as n,L as r,V as t};