@accounter/client
Version:
Accounter client application
1 lines • 5.77 kB
JavaScript
import{s as e}from"./dist-BmACi7k_.js";import{i as t,o as n}from"./utils-BxkqV8PM.js";import{Ro as r,ca as i,oo as a,r as o,t as s,xr as c,zo as l}from"./error-handling-sQ-z99nE.js";import{c as u,f as d,gt as f,l as p,p as m}from"./select-KYQbDWZT.js";import{Fr as h,u as g,x as _}from"./common-DtK-TFhT.js";import{t as v}from"./building-2-pI6DOFoz.js";import{t as y}from"./button-BZ6z_NAl.js";import{Kl as b,a as x,c as S,i as C,il as w,m as T,n as E,o as D,r as O,s as k,t as A,u as j}from"./table-D4eAFW7G.js";import{t as M}from"./card-BRoEyy6u.js";var N=f(`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=f(`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 c.BankAccount:return(0,I.jsx)(v,{className:`h-5 w-5`});case c.CreditCard:return(0,I.jsx)(h,{className:`h-5 w-5`});case c.CryptoWallet:return(0,I.jsx)(P,{className:`h-5 w-5`});case c.BankDepositAccount:return(0,I.jsx)(v,{className:`h-5 w-5`});case c.ForeignSecurities:return(0,I.jsx)(v,{className:`h-5 w-5`});default:return(0,I.jsx)(N,{className:`h-5 w-5`})}},R=e=>{switch(e){case c.BankAccount:return`Bank Account`;case c.CreditCard:return`Credit Card`;case c.CryptoWallet:return`Crypto Wallet`;case c.BankDepositAccount:return`Bank Deposit Account`;case c.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=s(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)(_,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,I.jsx)(_,{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:b(e.getValue(`eventDate`),`yyyy-MM-dd`)})},{accessorKey:`valueDate`,header:`Value Date`,cell:({row:e})=>(0,I.jsx)(`div`,{children:e.getValue(`valueDate`)?b(e.getValue(`valueDate`),`yyyy-MM-dd`):``})}];function H({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,F.useEffect)(()=>{n&&t&&c()},[n,t,c,e]);let d=(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&&d(!1),e},[o,d]);return(0,I.jsx)(u,{open:n&&!!t&&f.length>0,onOpenChange:d,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)(g,{fallback:(0,I.jsx)(`div`,{children:`Error fetching similar transactions`}),children:s?(0,I.jsx)(w,{}):t?(0,I.jsx)(U,{data:f,counterpartyId:t,onOpenChange:d}):null})})})}function U({data:e,counterpartyId:t,onOpenChange:n}){let[r,i]=F.useState([]),[a,o]=F.useState({}),s=S({data:e,columns:V,onSortingChange:i,getCoreRowModel:j(),getSortedRowModel:T(),onRowSelectionChange:o,state:{sorting:r,rowSelection:a}}),{updateTransactions:c}=B(),l=(0,F.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,F.useEffect)(()=>{e.length===0&&n(!1)},[e.length,n]),e.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(d,{className:`flex flex-row items-center justify-between`,children:[(0,I.jsx)(m,{children:`Transactions`}),(0,I.jsx)(y,{onClick:l,children:`Approve selected`})]}),(0,I.jsx)(M,{children:(0,I.jsxs)(A,{children:[(0,I.jsx)(x,{children:s.getHeaderGroups().map(e=>(0,I.jsx)(D,{children:e.headers.map(e=>(0,I.jsx)(C,{children:e.isPlaceholder?null:k(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,I.jsx)(E,{children:s.getRowModel().rows.map(e=>(0,I.jsx)(D,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,I.jsx)(O,{children:k(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})]}):null}export{L as n,R as r,H as t};