UNPKG

@accounter/client

Version:
1 lines • 7.95 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{Ma as r}from"./error-handling-Ba16dd60.js";import{s as i,t as a}from"./routes-BB3QY9SQ.js";import{ft as o,ht as s,mt as c}from"./select-CGZdhlc6.js";import{$ as l,A as u,D as d,Ft as f,I as p,Yn as m,ct as h,n as g,ut as _,wt as v,zt as y}from"./common-1Fu9tchs.js";import{n as b,r as x,t as S}from"./similar-transactions-modal-Bny3Pq_X.js";import{t as C}from"./button-DUNsVBiu.js";import{Bc as w,Ul as T,Zc as E,a as D,c as O,d as k,i as A,n as j,o as M,r as N,s as P,t as F}from"./table-Bh5lVpZi.js";var I=e(n(),1),L=t(),R=({transaction:e})=>{let t=`effectiveDate`in e?e.effectiveDate:void 0;return(0,L.jsxs)(`div`,{className:`flex flex-col justify-center`,children:[(0,L.jsx)(`div`,{children:t&&T(new Date(t),`dd/MM/yy`)}),e.sourceEffectiveDate&&(0,L.jsxs)(`div`,{className:`text-xs text-gray-500`,children:[`(Originally `,T(new Date(e.sourceEffectiveDate),`dd/MM/yy`),`)`]})]})},z=({transaction:e})=>{let t=`eventDate`in e?e.eventDate:void 0;return(0,L.jsx)(`div`,{className:`flex flex-col justify-center`,children:t&&T(new Date(t),`dd/MM/yy`)})},B=({transaction:e})=>{let t=`amount`in e?e.amount:void 0,{isFee:n}=e;return(0,L.jsxs)(`div`,{style:{color:Number(t?.raw)>0?`green`:`red`,whiteSpace:`nowrap`},children:[t?.formatted,n&&(0,L.jsx)(w,{variant:`secondary`,className:`ml-2 text-xs font-semibold`,children:`Fee`}),(0,L.jsx)(`br`,{}),e.cryptoExchangeRate&&(0,L.jsxs)(`span`,{style:{color:`gray`,marginLeft:`0.5rem`},children:[`(Rate: ${e.cryptoExchangeRate.rate})`,(0,L.jsx)(`br`,{}),t?.raw?`${m(t.raw*e.cryptoExchangeRate.rate)}$`:null]})]})},V=({transaction:e})=>{let{account:t}=e,n=b(t.type),r=x(t.type),i=t.name;return(0,L.jsxs)(`div`,{className:`flex flex-col justify-center`,children:[(0,L.jsx)(`p`,{children:(0,L.jsx)(h,{content:r,children:n})}),(0,L.jsx)(`p`,{children:i})]})},H=({transaction:e})=>{let t=`sourceDescription`in e?e.sourceDescription:`Missing`;return(0,L.jsx)(`div`,{className:`flex flex-wrap`,children:(0,L.jsx)(`div`,{className:`flex flex-col justify-center`,children:t})})},U=({transaction:e})=>(0,L.jsx)(`div`,{className:`flex flex-wrap`,children:(0,L.jsx)(`div`,{className:`flex flex-col justify-center`,children:e.referenceKey})});function W({transaction:e,onChange:t}){let{id:n,counterparty:r,missingInfoSuggestions:o,id:c,sourceDescription:d,enableEdit:f}=e,p=!!o?.business&&f,m=p?o?.business?.name:`Missing`,g=p?o?.business?.id:null,y=r?.name??m,[b,x]=(0,I.useState)(!1),{updateTransaction:w,fetching:T}=v(),E=(0,I.useCallback)(async e=>{await w({transactionId:c,fields:{counterpartyId:e}}),x(!0)},[c,w]),D=(0,I.useCallback)(async e=>{await E(e),t?.()},[E,t]),{selectableBusinesses:O,fetching:k}=_(),[A,j]=(0,I.useState)(g??null),[M,N]=(0,I.useState)(d);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`div`,{className:`flex flex-wrap flex-col justify-center`,children:r?.id?(0,L.jsx)(i,{to:a.BUSINESSES.DETAIL(r.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:y}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(l,{options:O,value:A,onChange:j,search:M,onSearchChange:N,placeholder:`Choose or create a business`,empty:M?(0,L.jsx)(u,{description:M,onAdd:D}):null}),(0,L.jsx)(h,{content:`Approve`,children:(0,L.jsx)(C,{variant:`outline`,size:`icon`,onClick:()=>A&&E(A),disabled:T||k||!A,children:(0,L.jsx)(s,{className:`size-4`})})})]})}),(0,L.jsx)(S,{transactionId:n,counterpartyId:r?.id??A,open:b,onOpenChange:x,onClose:t})]})}var G=[{accessorKey:`counterparty.name`,header:({column:e})=>(0,L.jsxs)(C,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Counterparty`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,L.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,L.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,L.jsx)(W,{transaction:e.original})},{accessorKey:`eventDate`,sortFn:e=>`eventDate`in e.original&&e.original.eventDate?new Date(e.original.eventDate).getTime():0,header:({column:e})=>(0,L.jsxs)(C,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Event Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,L.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,L.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,L.jsx)(z,{transaction:e.original})},{accessorKey:`effectiveDate`,sortFn:e=>`effectiveDate`in e.original&&e.original.effectiveDate?new Date(e.original.effectiveDate).getTime():0,header:({column:e})=>(0,L.jsxs)(C,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Debit Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,L.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,L.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,L.jsx)(R,{transaction:e.original})},{accessorKey:`amount.raw`,header:({column:e})=>(0,L.jsxs)(C,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,L.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,L.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,L.jsx)(B,{transaction:e.original})},{accessorKey:`account.name`,header:({column:e})=>(0,L.jsxs)(C,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,L.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,L.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,L.jsx)(V,{transaction:e.original})},{accessorKey:`sourceDescription`,header:({column:e})=>(0,L.jsxs)(C,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Description`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,L.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,L.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,L.jsx)(H,{transaction:e.original})},{accessorKey:`referenceKey`,header:({column:e})=>(0,L.jsxs)(C,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Reference#`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,L.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,L.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,L.jsx)(U,{transaction:e.original})}],K={accessorKey:`id`,header:`Actions`,cell:({row:e})=>e.original.enableEdit?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(f,{onClick:()=>e.original.editTransaction(e.original.id),tooltip:`Edit Transaction`}),(0,L.jsx)(d,{chargeId:e.original.chargeId,transactionId:e.original.id,onDone:e.original.onUpdate})]}):e.original.enableChargeLink?(0,L.jsx)(y,{chargeId:e.original.chargeId}):null},q=({transactionsProps:e,onChange:t,enableEdit:n,enableChargeLink:i})=>{let[a,o]=(0,I.useState)(void 0),[s,c]=(0,I.useState)([]),l=(0,I.useMemo)(()=>e.map(e=>E(r,e)),[e]),u=(0,I.useMemo)(()=>l.map(e=>({...e,editTransaction:o,onUpdate:t||(()=>{}),enableEdit:n,enableChargeLink:i})),[l,n,i,t]),d=(0,I.useMemo)(()=>n||i?[...G,K]:G,[n,i]),f=O({features:P,data:u,columns:d,onSortingChange:c,state:{sorting:s},initialState:{pagination:{pageIndex:0,pageSize:100},sorting:[{id:`eventDate`,desc:!0}]}});return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(F,{children:[(0,L.jsx)(D,{children:f.getHeaderGroups().map(e=>(0,L.jsx)(M,{children:e.headers.map(e=>(0,L.jsx)(A,{colSpan:e.colSpan,children:e.isPlaceholder?null:k(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,L.jsx)(j,{children:f.getRowModel().rows?.length?f.getRowModel().rows.map(e=>(0,L.jsx)(M,{children:e.getVisibleCells().map(e=>(0,L.jsx)(N,{children:k(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,L.jsx)(M,{children:(0,L.jsx)(N,{colSpan:G.length,className:`h-24 text-center`,children:`No results.`})})})]}),f.getPageCount()>1&&(0,L.jsx)(`div`,{className:`flex items-center justify-end space-x-2 py-4`,children:(0,L.jsx)(g,{currentPageIndex:f.state.pagination.pageIndex,totalPages:f.getPageCount(),onChange:e=>f.setPageIndex(e)})}),(0,L.jsx)(p,{transactionID:a,close:()=>o(void 0),onChange:t??(()=>{})})]})};export{V as a,R as c,H as i,W as n,B as o,U as r,z as s,q as t};