@accounter/client
Version:
Accounter client application
1 lines • 2.91 kB
JavaScript
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{I as r,Yo as i,r as a}from"./error-handling-C2WP9OW-.js";import{dt as o}from"./select--D-3UcF0.js";import{L as s,St as c,T as l}from"./common-Ba8DOj18.js";import{t as u}from"./arrow-up-down-BOLlgevB.js";import{c as d}from"./separator-YxKc_C_z.js";import{t as f}from"./button-DUNsVBiu.js";import{a as p,c as m,d as h,i as g,n as _,o as v,r as y,s as b,t as x}from"./table-M99ToVB3.js";import{t as S}from"./page-layout-CbMLHRAP.js";var C=e(n(),1),w=t(),T=[{id:`key`,accessorKey:`key`,cell:({row:e})=>(0,w.jsx)(y,{children:e.original.key}),header:({column:e})=>(0,w.jsxs)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Key`,(0,w.jsx)(u,{})]})},{id:`name`,accessorKey:`name`,cell:({row:e})=>(0,w.jsx)(y,{children:e.original.name}),header:({column:e})=>(0,w.jsxs)(f,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Name`,(0,w.jsx)(u,{})]})},{id:`defaultIrsCode`,accessorKey:`defaultIrsCode`,cell:({row:e})=>(0,w.jsx)(y,{className:`flex flex-wrap gap-1 p-1`,children:e.original.defaultIrsCode&&(0,w.jsx)(f,{variant:`outline`,disabled:!0,className:`p-1 w-15`,children:e.original.defaultIrsCode})}),header:`Default IRS Code`},{id:`edit`,cell:({row:e})=>(0,w.jsx)(s,{sortCodeKey:e.original.key,ownerId:e.original.ownerId,onAdd:e.original.refetchSortCodes})}],E=()=>{let[{data:e,fetching:t,error:n},s]=i({query:r}),{setFiltersContext:u}=(0,C.useContext)(d),f=(0,C.useMemo)(()=>e?.allSortCodes?.map(e=>({...e,refetchSortCodes:s}))??[],[e?.allSortCodes,s]),E=m({features:b,data:f,columns:T,initialState:{pagination:{pageIndex:0,pageSize:100}}}),D=E.getPageOptions();return(0,C.useEffect)(()=>{u((0,w.jsx)(`div`,{className:`flex items-center justify-end gap-10 space-x-2 py-4`,children:(0,w.jsx)(c,{table:E})}))},[u,E,D]),(0,C.useEffect)(()=>{n&&(console.error(`Error fetching sort codes`,n),a.error(`Error`,{description:`Error fetching sort codes`}))},[n]),(0,w.jsx)(S,{title:`Sort Codes (${f.length})`,description:`All sort codes`,headerActions:(0,w.jsx)(l,{onAdd:()=>s()}),children:t?(0,w.jsx)(`div`,{className:`flex flex-row justify-center`,children:(0,w.jsx)(o,{className:`h-10 w-10 animate-spin mr-2`})}):(0,w.jsx)(`div`,{className:`flex flex-col gap-4 rounded-md border`,children:(0,w.jsxs)(x,{children:[(0,w.jsx)(p,{children:E.getHeaderGroups().map(e=>(0,w.jsx)(v,{children:e.headers.map(e=>(0,w.jsx)(g,{children:e.isPlaceholder?null:h(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,w.jsx)(_,{children:E.getRowModel().rows.length===0?(0,w.jsx)(v,{children:(0,w.jsx)(y,{colSpan:T.length,className:`text-center py-8`,children:`No sort codes found`})}):E.getRowModel().rows.map(e=>(0,w.jsx)(v,{children:e.getVisibleCells().map(e=>(0,w.jsx)(y,{children:h(e.column.columnDef.cell,e.getContext())},e.id))},e.id))})]})})})};export{E as SortCodes};