UNPKG

@accounter/client

Version:
1 lines 4.59 kB
import{s as e}from"./dist-BbgEzppd.js";import{i as t,o as n}from"./utils-BUNz070n.js";import{O as r,Ya as i}from"./error-handling-AQOG1RNy.js";import{mt as a,pt as o}from"./select-6mBYg_R6.js";import{t as s}from"./bank-deposits-B-QBe3fn.js";import{t as c}from"./button-CBTN3XMQ.js";import{a as l,c as u,d,h as f,i as p,m,n as h,o as g,r as _,s as v,t as y,u as b}from"./table-BO0OUJta.js";import{I as x}from"./index-CzBF9w4Z.js";var S=e(n(),1),C=t();function w(){let[{data:e,fetching:t},n]=i({query:r}),[w,T]=(0,S.useState)([{id:`openDate`,desc:!1}]),E=(0,S.useMemo)(()=>(e?.allDeposits??[]).map(e=>({id:e.id,currency:e.currency,openDate:e.openDate,closeDate:e.closeDate??null,isOpen:e.isOpen,currencyError:e.currencyError??[],currentBalanceRaw:e.currentBalance?.raw??0,currentBalanceFormatted:e.currentBalance?.formatted??``,totalDepositRaw:e.totalDeposit?.raw??0,totalDepositFormatted:e.totalDeposit?.formatted??``,totalInterestRaw:e.totalInterest?.raw??0,totalInterestFormatted:e.totalInterest?.formatted??``})),[e]),D=(0,S.useRef)([{id:`expander`,header:()=>null,cell:({row:e})=>(0,C.jsx)(c,{variant:`ghost`,size:`icon`,onClick:()=>e.toggleExpanded(),"aria-label":e.getIsExpanded()?`Collapse`:`Expand`,children:e.getIsExpanded()?(0,C.jsx)(a,{}):(0,C.jsx)(o,{})}),enableSorting:!1},{accessorKey:`id`,header:`Deposit ID`,cell:e=>(0,C.jsx)(`span`,{className:`font-mono text-xs`,children:e.getValue()})},{accessorKey:`currency`,header:`Currency`},{accessorKey:`isOpen`,header:`Status`,cell:e=>e.getValue()?(0,C.jsx)(f,{className:`bg-green-600 text-white`,variant:`secondary`,children:`Open`}):(0,C.jsx)(f,{variant:`secondary`,children:`Closed`}),sortingFn:(e,t)=>Number(e.original.isOpen)-Number(t.original.isOpen)},{accessorKey:`openDate`,header:`Open Date`,cell:e=>(0,C.jsx)(`span`,{children:e.getValue()})},{accessorKey:`closeDate`,header:`Close Date`,cell:e=>(0,C.jsx)(`span`,{children:e.getValue()??`-`}),sortingFn:(e,t)=>{let n=e.original.closeDate??``,r=t.original.closeDate??``;return n.localeCompare(r)}},{id:`totalDeposit`,header:`Total Deposit`,accessorFn:e=>e.totalDepositRaw,cell:e=>(0,C.jsx)(`span`,{className:`tabular-nums`,children:e.row.original.totalDepositFormatted}),sortingFn:(e,t)=>e.original.totalDepositRaw-t.original.totalDepositRaw},{id:`currentBalance`,header:`Current Balance`,accessorFn:e=>e.currentBalanceRaw,cell:e=>(0,C.jsx)(`span`,{className:`tabular-nums`,children:e.row.original.currentBalanceFormatted}),sortingFn:(e,t)=>e.original.currentBalanceRaw-t.original.currentBalanceRaw},{id:`totalInterest`,header:`Total Interest`,accessorFn:e=>e.totalInterestRaw,cell:e=>(0,C.jsx)(`span`,{className:`tabular-nums`,children:e.row.original.totalInterestFormatted}),sortingFn:(e,t)=>e.original.totalInterestRaw-t.original.totalInterestRaw}]).current,O=u({data:E,columns:D,state:{sorting:w},onSortingChange:T,getCoreRowModel:b(),getSortedRowModel:m(),getExpandedRowModel:d(),getRowCanExpand:()=>!0});return(0,C.jsxs)(`div`,{className:`max-w-[95vw]`,children:[(0,C.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,C.jsx)(`h1`,{className:`text-2xl font-semibold`,children:`Bank Deposits`})}),(0,C.jsx)(`div`,{className:`mt-6 overflow-hidden rounded-md border`,children:(0,C.jsxs)(y,{children:[(0,C.jsx)(l,{children:O.getHeaderGroups().map(e=>(0,C.jsx)(g,{children:e.headers.map(e=>(0,C.jsx)(p,{colSpan:e.colSpan,children:e.isPlaceholder?null:v(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,C.jsx)(h,{children:t?(0,C.jsx)(g,{children:(0,C.jsx)(_,{colSpan:D.length,className:`h-24 text-center`,children:`Loading...`})}):O.getRowModel().rows?.length?O.getRowModel().rows.map(e=>(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(g,{"data-state":e.getIsSelected()&&`selected`,children:e.getVisibleCells().map(e=>(0,C.jsx)(_,{children:v(e.column.columnDef.cell,e.getContext())},e.id))},e.id),e.getIsExpanded()?(0,C.jsx)(g,{children:(0,C.jsxs)(_,{colSpan:D.length,children:[e.original.currencyError.length>0&&(0,C.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 rounded-md border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-800`,children:[(0,C.jsx)(x,{className:`size-4`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`font-medium`,children:`Currency Conflict`}),(0,C.jsxs)(`div`,{className:`opacity-90`,children:[`Affected transaction IDs: `,e.original.currencyError.join(`, `)]})]})]}),(0,C.jsx)(s,{depositId:e.original.id,enableReassign:!0,refetch:n})]})}):null]})):(0,C.jsx)(g,{children:(0,C.jsx)(_,{colSpan:D.length,className:`h-24 text-center`,children:`No results.`})})})]})})]})}export{w as DepositsScreen};