UNPKG

@accounter/client

Version:
1 lines • 8.01 kB
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n}from"./utils-DdVdMk8X.js";import{ya as r}from"./error-handling-Dpfd9svJ.js";import{s as i,t as a}from"./routes-DUvpW9-n.js";import{gt as o,ht as s,pt as c}from"./select-CrsvQyhZ.js";import{n as l,r as u,t as d}from"./similar-transactions-modal-DD7YfdjJ.js";import{t as f}from"./button-Dzp2INW0.js";import{Lt as p,N as m,W as h,a as g,c as _,i as v,m as y,n as b,o as x,p as S,r as C,s as w,t as T,u as E}from"./table--bF0wbxq.js";import{Dt as D,Ht as O,J as k,Qt as A,Tt as j,Z as M,et as N,hr as P,mt as F,nn as I,w as L}from"./index-CL8-JoMZ.js";var R=e(n(),1),z=t(),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&&p(new Date(t),`dd/MM/yy`)}),e.sourceEffectiveDate&&(0,z.jsxs)(`div`,{className:`text-xs text-gray-500`,children:[`(Originally `,p(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&&p(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)(m,{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?`${P(t.raw*e.cryptoExchangeRate.rate)}$`:null]})]})},U=({transaction:e})=>{let{account:t}=e,n=l(t.type),r=u(t.type),i=t.name;return(0,z.jsxs)(`div`,{className:`flex flex-col justify-center`,children:[(0,z.jsx)(`p`,{children:(0,z.jsx)(j,{content:r,children:n})}),(0,z.jsx)(`p`,{children:i})]})},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:n,counterparty:r,missingInfoSuggestions:s,id:c,sourceDescription:l,enableEdit:u}=e,p=!!s?.business&&u,m=p?s?.business?.name:`Missing`,h=p?s?.business?.id:null,g=r?.name??m,[_,v]=(0,R.useState)(!1),{updateTransaction:y,fetching:b}=O(),x=(0,R.useCallback)(async e=>{await y({transactionId:c,fields:{counterpartyId:e}}),v(!0)},[c,y]),S=(0,R.useCallback)(async e=>{await x(e),t?.()},[x,t]),{selectableBusinesses:C,fetching:w}=D(),[T,E]=(0,R.useState)(h??null),[k,A]=(0,R.useState)(l);return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`flex flex-wrap flex-col justify-center`,children:r?.id?(0,z.jsx)(i,{to:a.BUSINESSES.DETAIL(r.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:g}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(F,{options:C,value:T,onChange:E,search:k,onSearchChange:A,placeholder:`Choose or create a business`,empty:k?(0,z.jsx)(M,{description:k,onAdd:S}):null}),(0,z.jsx)(j,{content:`Approve`,children:(0,z.jsx)(f,{variant:`outline`,size:`icon`,onClick:()=>T&&x(T),disabled:b||w||!T,children:(0,z.jsx)(o,{className:`size-4`})})})]})}),(0,z.jsx)(d,{transactionId:n,counterpartyId:r?.id??T,open:_,onOpenChange:v,onClose:t})]})}var q=[{accessorKey:`counterparty.name`,header:({column:e})=>(0,z.jsxs)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Counterparty`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(c,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(s,{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)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Event Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(c,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(s,{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)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Debit Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(c,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(s,{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)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(c,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(s,{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)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(c,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(s,{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)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Description`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(c,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(s,{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)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Reference#`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,z.jsx)(c,{className:`ml-2 h-4 w-4`}):(0,z.jsx)(s,{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)(A,{onClick:()=>e.original.editTransaction(e.original.id),tooltip:`Edit Transaction`}),(0,z.jsx)(k,{chargeId:e.original.chargeId,transactionId:e.original.id,onDone:e.original.onUpdate})]}):e.original.enableChargeLink?(0,z.jsx)(I,{chargeId:e.original.chargeId}):null},Y=({transactionsProps:e,onChange:t,enableEdit:n,enableChargeLink:i})=>{let[a,o]=(0,R.useState)(void 0),[s,c]=(0,R.useState)([]),l=(0,R.useMemo)(()=>e.map(e=>h(r,e)),[e]),u=_({data:(0,R.useMemo)(()=>l.map(e=>({...e,editTransaction:o,onUpdate:t||(()=>{}),enableEdit:n,enableChargeLink:i})),[l,n,i,t]),columns:(0,R.useMemo)(()=>n||i?[...q,J]:q,[n,i]),getCoreRowModel:E(),onSortingChange:c,getSortedRowModel:y(),getPaginationRowModel:S(),state:{sorting:s},initialState:{pagination:{pageIndex:0,pageSize:100},sorting:[{id:`eventDate`,desc:!0}]}});return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(T,{children:[(0,z.jsx)(g,{children:u.getHeaderGroups().map(e=>(0,z.jsx)(x,{children:e.headers.map(e=>(0,z.jsx)(v,{colSpan:e.colSpan,children:e.isPlaceholder?null:w(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,z.jsx)(b,{children:u.getRowModel().rows?.length?u.getRowModel().rows.map(e=>(0,z.jsx)(x,{children:e.getVisibleCells().map(e=>(0,z.jsx)(C,{children:w(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,z.jsx)(x,{children:(0,z.jsx)(C,{colSpan:q.length,className:`h-24 text-center`,children:`No results.`})})})]}),u.getPageCount()>1&&(0,z.jsx)(`div`,{className:`flex items-center justify-end space-x-2 py-4`,children:(0,z.jsx)(L,{currentPageIndex:u.getState().pagination.pageIndex,totalPages:u.getPageCount(),onChange:e=>u.setPageIndex(e)})}),(0,z.jsx)(N,{transactionID:a,close:()=>o(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};