@accounter/client
Version:
Accounter client application
1 lines • 7.77 kB
JavaScript
import{n as e,r as t,t as n}from"./similar-transactions-modal-loymeogL.js";import{$ as r,B as i,C as a,Cd as o,G as s,Gc as c,H as l,Hn as u,Ht as d,K as f,Kl as p,Kn as m,Kt as h,Mn as g,Nd as _,Ot as v,Pl as y,Q as b,Rd as x,Tu as S,U as C,V as w,Vi as T,W as E,Xn as D,Y as O,_d as k,en as A,gd as j,ku as M,md as N,nn as P,q as F,st as I,ut as L}from"./index-DJOqGznr.js";var R=x(_(),1),z=S(),B=({transaction:e})=>{let t=`effectiveDate`in e?e.effectiveDate:void 0;return(0,z.jsxs)(`div`,{className:`flex flex-col justify-center`,children:[(0,z.jsx)(`div`,{children:t&&y(new Date(t),`dd/MM/yy`)}),e.sourceEffectiveDate&&(0,z.jsxs)(`div`,{className:`text-xs text-gray-500`,children:[`(Originally `,y(new Date(e.sourceEffectiveDate),`dd/MM/yy`),`)`]})]})},V=({transaction:e})=>{let t=`eventDate`in e?e.eventDate:void 0;return(0,z.jsx)(`div`,{className:`flex flex-col justify-center`,children:t&&y(new Date(t),`dd/MM/yy`)})},H=({transaction:e})=>{let t=`amount`in e?e.amount:void 0,{isFee:n}=e;return(0,z.jsxs)(`div`,{style:{color:Number(t?.raw)>0?`green`:`red`,whiteSpace:`nowrap`},children:[t?.formatted,n&&(0,z.jsx)(h,{variant:`secondary`,className:`ml-2 text-xs font-semibold`,children:`Fee`}),(0,z.jsx)(`br`,{}),e.cryptoExchangeRate&&(0,z.jsxs)(`span`,{style:{color:`gray`,marginLeft:`0.5rem`},children:[`(Rate: ${e.cryptoExchangeRate.rate})`,(0,z.jsx)(`br`,{}),t?.raw?`${T(t.raw*e.cryptoExchangeRate.rate)}$`:null]})]})},U=({transaction:n})=>{let{account:r}=n,i=e(r.type),a=t(r.type),o=r.name;return(0,z.jsxs)(`div`,{className:`flex flex-col justify-center`,children:[(0,z.jsx)(`p`,{children:(0,z.jsx)(A,{content:a,children:i})}),(0,z.jsx)(`p`,{children:o})]})},W=({transaction:e})=>(0,z.jsx)(`div`,{className:`flex flex-wrap`,children:(0,z.jsx)(`div`,{className:`flex flex-col justify-center`,children:`sourceDescription`in e?e.sourceDescription:`Missing`})}),G=({transaction:e})=>(0,z.jsx)(`div`,{className:`flex flex-wrap`,children:(0,z.jsx)(`div`,{className:`flex flex-col justify-center`,children:e.referenceKey})});function K({transaction:e,onChange:t}){let{id:r,counterparty:i,missingInfoSuggestions:a,id:s,sourceDescription:c,enableEdit:l}=e,u=!!a?.business&&l,f=u?a?.business?.name:`Missing`,m=u?a?.business?.id:null,h=i?.name??f,[_,v]=(0,R.useState)(!1),{updateTransaction:y,fetching:b}=g(),x=(0,R.useCallback)(async e=>{await y({transactionId:s,fields:{counterpartyId:e}}),v(!0)},[s,y]),S=(0,R.useCallback)(async e=>{await x(e),t?.()},[x,t]),{selectableBusinesses:C,fetching:w}=P(),[T,E]=(0,R.useState)(m??null),[D,O]=(0,R.useState)(c);return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`flex flex-wrap flex-col justify-center`,children:i?.id?(0,z.jsx)(o,{to:M.BUSINESSES.DETAIL(i.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:h}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(d,{options:C,value:T,onChange:E,search:D,onSearchChange:O,placeholder:`Choose or create a business`,empty:D?(0,z.jsx)(L,{description:D,onAdd:S}):null}),(0,z.jsx)(A,{content:`Approve`,children:(0,z.jsx)(p,{variant:`outline`,size:`icon`,onClick:()=>T&&x(T),disabled:b||w||!T,children:(0,z.jsx)(k,{className:`size-4`})})})]})}),(0,z.jsx)(n,{transactionId:r,counterpartyId:i?.id??T,open:_,onOpenChange:v,onClose:t})]})}var q=[{accessorKey:`counterparty.name`,header:({column:e})=>(0,z.jsxs)(p,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Counterparty`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(N,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(j,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,z.jsx)(K,{transaction:e.original})},{accessorKey:`eventDate`,sortingFn:e=>`eventDate`in e.original&&e.original.eventDate?new Date(e.original.eventDate).getTime():0,header:({column:e})=>(0,z.jsxs)(p,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Event Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(N,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(j,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,z.jsx)(V,{transaction:e.original})},{accessorKey:`effectiveDate`,sortingFn:e=>`effectiveDate`in e.original&&e.original.effectiveDate?new Date(e.original.effectiveDate).getTime():0,header:({column:e})=>(0,z.jsxs)(p,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Debit Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(N,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(j,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,z.jsx)(B,{transaction:e.original})},{accessorKey:`amount.raw`,header:({column:e})=>(0,z.jsxs)(p,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(N,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(j,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,z.jsx)(H,{transaction:e.original})},{accessorKey:`account.name`,header:({column:e})=>(0,z.jsxs)(p,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(N,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(j,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,z.jsx)(U,{transaction:e.original})},{accessorKey:`sourceDescription`,header:({column:e})=>(0,z.jsxs)(p,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Description`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(N,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(j,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,z.jsx)(W,{transaction:e.original})},{accessorKey:`referenceKey`,header:({column:e})=>(0,z.jsxs)(p,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Reference#`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(N,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(j,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,z.jsx)(G,{transaction:e.original})}],J={accessorKey:`id`,header:`Actions`,cell:({row:e})=>e.original.enableEdit?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(u,{onClick:()=>e.original.editTransaction(e.original.id),tooltip:`Edit Transaction`}),(0,z.jsx)(I,{chargeId:e.original.chargeId,transactionId:e.original.id,onDone:e.original.onUpdate})]}):e.original.enableChargeLink?(0,z.jsx)(m,{chargeId:e.original.chargeId}):null},Y=({transactionsProps:e,onChange:t,enableEdit:n,enableChargeLink:o})=>{let[u,d]=(0,R.useState)(void 0),[p,m]=(0,R.useState)([]),h=(0,R.useMemo)(()=>e.map(e=>D(c,e)),[e]),g=F({data:(0,R.useMemo)(()=>h.map(e=>({...e,editTransaction:d,onUpdate:t||(()=>{}),enableEdit:n,enableChargeLink:o})),[h,n,o,t]),columns:(0,R.useMemo)(()=>n||o?[...q,J]:q,[n,o]),getCoreRowModel:O(),onSortingChange:m,getSortedRowModel:r(),getPaginationRowModel:b(),state:{sorting:p},initialState:{pagination:{pageIndex:0,pageSize:100},sorting:[{id:`eventDate`,desc:!0}]}});return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(i,{children:[(0,z.jsx)(E,{children:g.getHeaderGroups().map(e=>(0,z.jsx)(s,{children:e.headers.map(e=>(0,z.jsx)(C,{colSpan:e.colSpan,children:e.isPlaceholder?null:f(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,z.jsx)(w,{children:g.getRowModel().rows?.length?g.getRowModel().rows.map(e=>(0,z.jsx)(s,{children:e.getVisibleCells().map(e=>(0,z.jsx)(l,{children:f(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,z.jsx)(s,{children:(0,z.jsx)(l,{colSpan:q.length,className:`h-24 text-center`,children:`No results.`})})})]}),g.getPageCount()>1&&(0,z.jsx)(`div`,{className:`flex items-center justify-end space-x-2 py-4`,children:(0,z.jsx)(a,{currentPageIndex:g.getState().pagination.pageIndex,totalPages:g.getPageCount(),onChange:e=>g.setPageIndex(e)})}),(0,z.jsx)(v,{transactionID:u,close:()=>d(void 0),onChange:t??(()=>{})})]})};export{U as a,B as c,W as i,K as n,H as o,G as r,V as s,Y as t};