@accounter/client
Version:
Accounter client application
1 lines • 3.15 kB
JavaScript
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n,t as r}from"./utils-DdVdMk8X.js";import{C as i,Lo as a}from"./error-handling-Dpfd9svJ.js";import{_ as o,t as s}from"./routes-DUvpW9-n.js";import{ft as c,s as l}from"./select-CrsvQyhZ.js";import{H as u,Z as d,cn as f,st as p,w as m}from"./index-CL8-JoMZ.js";import{t as h}from"./use-url-query-BCNbSvLg.js";import{t as g}from"./page-layout-DoLDsSrs.js";import{t as _}from"./business-header-CYBXKl9H.js";var v=e(n(),1),y=t();function b({activePage:e,setPage:t,totalPages:n=1,businessName:r,setBusinessName:i}){let{get:a,set:o}=h(),[s,c]=(0,v.useState)(r);(0,v.useEffect)(()=>{let t=e>0?e.toFixed(0):void 0;t!==a(`page`)&&t!==`0`&&o(`page`,t)},[e,a,o]),(0,v.useEffect)(()=>{let e=setTimeout(()=>{i(s)},600);return()=>{clearTimeout(e)}},[s,i]);let u=e=>{c(e)};return(0,y.jsxs)(`div`,{className:`flex flex-row gap-5 items-center`,children:[(0,y.jsx)(m,{className:`flex-fit w-fit mx-0`,currentPageIndex:e,onChange:t,totalPages:n}),(0,y.jsx)(l,{className:`w-72`,placeholder:`Business Name`,defaultValue:r??void 0,onChange:e=>u(e.target.value===``?void 0:e.target.value)})]})}var x=()=>{let{get:e}=h(),[t,n]=(0,v.useState)(e(`page`)?Number(e(`page`)):0),[l,m]=(0,v.useState)(e(`name`)?e(`name`):void 0),{setFiltersContext:x}=(0,v.useContext)(f),[{data:S,fetching:C},w]=a({query:i,variables:{page:t,limit:100,name:l}}),T=o(),[E,D]=(0,v.useState)([]),O=(0,v.useCallback)((e,t)=>{E.map(e=>e.id).includes(e)?D(E.filter(t=>t.id!==e)):D([...E,{id:e,onChange:t}])},[E]);function k(){D([])}(0,v.useEffect)(()=>{x((0,y.jsxs)(`div`,{className:`flex flex-row gap-x-5`,children:[(0,y.jsx)(b,{activePage:t,setPage:n,businessName:l,setBusinessName:m,totalPages:S?.allBusinesses?.pageInfo.totalPages}),(0,y.jsx)(p,{selected:E,resetMerge:k})]}))},[S,t,l,x,n,m,E]);let A=S?.allBusinesses?.nodes.filter(e=>e.__typename===`LtdFinancialEntity`).sort((e,t)=>e.name.toLowerCase()>t.name.toLowerCase()?1:-1)??[],j=new Set(E.map(e=>e.id));return(0,y.jsx)(g,{title:`Businesses (${S?.allBusinesses?.pageInfo.totalRecords??``})`,description:`All businesses`,headerActions:(0,y.jsx)(`div`,{className:`flex items-center py-4 gap-4`,children:(0,y.jsx)(d,{description:``,onAdd:()=>w()})}),children:C?(0,y.jsx)(`div`,{className:`flex flex-row justify-center`,children:(0,y.jsx)(c,{className:r(`h-10 w-10 animate-spin mr-2`)})}):(0,y.jsx)(`div`,{className:`space-y-2`,children:A.map(e=>(0,y.jsx)(`div`,{className:`group relative border rounded-lg hover:shadow-md transition-shadow`,children:(0,y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`pl-4 flex items-center`,children:(0,y.jsx)(u,{checked:j.has(e.id),onCheckedChange:()=>{O(e.id,()=>{})},className:`h-4 w-4 rounded border-gray-300 cursor-pointer`,onClick:e=>e.stopPropagation()})}),(0,y.jsx)(`div`,{role:`button`,tabIndex:0,className:`flex-1 cursor-pointer`,onClick:()=>{T(s.BUSINESSES.DETAIL(e.id),{state:{from:s.BUSINESSES.ALL}})},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),T(s.BUSINESSES.DETAIL(e.id),{state:{from:s.BUSINESSES.ALL}}))},children:(0,y.jsx)(_,{data:e})})]})},e.id))})})};export{x as Businesses};