@accounter/client
Version:
2 lines (1 loc) • 5.96 kB
JavaScript
import{v as j,g as C,h2 as b,r as g,t as p,i as S,j as a,ai as m,h3 as k,h4 as v,u as A,h5 as I,D as M,x as R,y as N,c as B,aF as f,bY as $,c5 as E,c6 as F,al as V,am as K,B as U,K as _,bO as H,bP as L,bQ as T,bR as P,c2 as y,bS as O,bT as Q,p as w,w as D}from"./index-DRqooPz9.js";import{B as x}from"./building-2-CWrl-iq9.js";const W=[["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"}]],q=j("badge-question-mark",W);const Y=[["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"}]],Z=j("bitcoin",Y),z="updateTransaction",ne=()=>{const[{fetching:e},s]=C(b),n=g.useCallback(async i=>{const d=`Error updating transaction ID [${i.transactionId}]`,c=`${z}-${i.transactionId}`;p.loading("Updating Transaction",{id:c});try{const l=await s(i),o=S(l,d,c,"updateTransaction");if(o)return p.success("Success",{id:c,description:"Transaction updated"}),o.updateTransaction}catch(l){console.error(`${d}: ${l}`),p.error("Error",{id:c,description:d,duration:1e5,closeButton:!0})}},[s]);return{fetching:e,updateTransaction:n}},ce=e=>{switch(e){case m.BankAccount:return a.jsx(x,{className:"h-5 w-5"});case m.CreditCard:return a.jsx(k,{className:"h-5 w-5"});case m.CryptoWallet:return a.jsx(Z,{className:"h-5 w-5"});case m.BankDepositAccount:return a.jsx(x,{className:"h-5 w-5"});case m.ForeignSecurities:return a.jsx(x,{className:"h-5 w-5"});default:return a.jsx(q,{className:"h-5 w-5"})}},G=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"}},J="updateTransactions",X=()=>{const[{fetching:e},s]=C(v),n=g.useCallback(async i=>{const d=Array.isArray(i.transactionIds)?i.transactionIds.join(", "):i.transactionIds,c=`Error updating transactions ID [${d}]`,l=`${J}-${d}`;p.loading("Updating Transactions",{id:l});try{const o=await s(i),u=S(o,c,l,"updateTransactions");if(u)return p.success("Success",{id:l,description:"Transactions updated"}),u.updateTransactions.transactions.map(h=>h.id)}catch(o){console.error(`${c}: ${o}`),p.error("Error",{id:l,description:c,duration:1e5,closeButton:!0})}},[s]);return{fetching:e,updateTransactions:n}},ee=[{id:"select",header:({table:e})=>a.jsx(w,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:s=>e.toggleAllPageRowsSelected(!!s),"aria-label":"Select all"}),cell:({row:e})=>a.jsx(w,{checked:e.getIsSelected(),onCheckedChange:s=>e.toggleSelected(!!s),"aria-label":"Select row"}),enableSorting:!1,enableHiding:!1},{accessorKey:"accountType",header:"Type",cell:({row:e})=>a.jsx("div",{children:e.getValue("accountType")})},{accessorKey:"accountName",header:"Account",cell:({row:e})=>a.jsx("div",{children:e.getValue("accountName")})},{accessorKey:"amountRaw",header:"Amount",cell:({row:e})=>a.jsx("div",{children:e.original.amountFormatted})},{accessorKey:"sourceDescription",header:"Description",cell:({row:e})=>a.jsx("div",{children:e.getValue("sourceDescription")})},{accessorKey:"eventDate",header:"Event Date",cell:({row:e})=>a.jsx("div",{children:D(e.getValue("eventDate"),"yyyy-MM-dd")})},{accessorKey:"valueDate",header:"Value Date",cell:({row:e})=>a.jsx("div",{children:e.getValue("valueDate")?D(e.getValue("valueDate"),"yyyy-MM-dd"):""})}];function oe({transactionId:e,counterpartyId:s,open:n,onOpenChange:i,onClose:d}){const[{data:c,fetching:l},o]=A({pause:!0,query:I,variables:{transactionId:e,withMissingInfo:!0}});g.useEffect(()=>{n&&s&&o()},[n,s,o,e]);const u=g.useCallback(r=>{i(r),n&&!r&&d?.()},[i,d,n]),h=g.useMemo(()=>{const r=c?.similarTransactions.map(t=>({id:t.id,amountRaw:t.amount.raw,amountFormatted:t.amount.formatted,sourceDescription:t.sourceDescription,eventDate:new Date(t.eventDate),valueDate:t.effectiveDate?new Date(t.effectiveDate):void 0,accountType:G(t.account.type),accountName:t.account.name}))??[];return c&&r.length===0&&u(!1),r},[c,u]);return a.jsx(M,{open:n&&!!s&&h.length>0,onOpenChange:u,children:a.jsx(R,{className:"overflow-scroll max-h-screen w-full sm:max-w-[640px] md:max-w-[768px] lg:max-w-[900px]",children:a.jsx(N,{fallback:a.jsx("div",{children:"Error fetching similar transactions"}),children:l?a.jsx(B,{}):s?a.jsx(ae,{data:h,counterpartyId:s,onOpenChange:u}):null})})})}function ae({data:e,counterpartyId:s,onOpenChange:n}){const[i,d]=f.useState([]),[c,l]=f.useState({}),o=$({data:e,columns:ee,onSortingChange:d,getCoreRowModel:F(),getSortedRowModel:E(),onRowSelectionChange:l,state:{sorting:i,rowSelection:c}}),{updateTransactions:u}=X(),h=g.useCallback(async()=>{const r=o.getSelectedRowModel().rows.map(t=>t.original.id);await u({transactionIds:r,fields:{counterpartyId:s}}),n(!1)},[u,n,o,s]);return g.useEffect(()=>{e.length===0&&n(!1)},[e.length,n]),e.length?a.jsxs(a.Fragment,{children:[a.jsxs(V,{className:"flex flex-row items-center justify-between",children:[a.jsx(K,{children:"Transactions"}),a.jsx(U,{onClick:h,children:"Approve selected"})]}),a.jsx(_,{children:a.jsxs(H,{children:[a.jsx(L,{children:o.getHeaderGroups().map(r=>a.jsx(T,{children:r.headers.map(t=>a.jsx(P,{children:t.isPlaceholder?null:y(t.column.columnDef.header,t.getContext())},t.id))},r.id))}),a.jsx(O,{children:o.getRowModel().rows.map(r=>a.jsx(T,{"data-state":r.getIsSelected()&&"selected",children:r.getVisibleCells().map(t=>a.jsx(Q,{children:y(t.column.columnDef.cell,t.getContext())},t.id))},r.id))})]})})]}):null}export{oe as S,G as a,ce as g,ne as u};