@accounter/client
Version:
Accounter client application
1 lines • 3.22 kB
JavaScript
import{s as e}from"./dist-BBBZL-zT.js";import{i as t,o as n,t as r}from"./utils-C9b7NsUD.js";import{C as i,_o as a}from"./error-handling-DBz7h-2r.js";import{_ as o,t as s}from"./routes-g2AjKuLo.js";import{dt as c}from"./select-D_LnCowF.js";import{A as l,n as u,nt as d,x as f}from"./common-3l1_jDFS.js";import{h as p}from"./separator-CH02FkEe.js";import{x as m}from"./index-C5FJSqDD.js";import{t as h}from"./use-url-query-BAiQvBd8.js";import{t as g}from"./page-layout-CzTbibUl.js";import{t as _}from"./business-header-CV00g6iv.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 l=e=>{c(e)};return(0,y.jsxs)(`div`,{className:`flex flex-row gap-5 items-center`,children:[(0,y.jsx)(u,{className:`flex-fit w-fit mx-0`,currentPageIndex:e,onChange:t,totalPages:n}),(0,y.jsx)(p,{className:`w-72`,placeholder:`Business Name`,defaultValue:r??void 0,onChange:e=>l(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),[u,p]=(0,v.useState)(e(`name`)?e(`name`):void 0),{setFiltersContext:x}=(0,v.useContext)(m),[{data:S,fetching:C},w]=a({query:i,variables:{page:t,limit:100,name:u}}),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:u,setBusinessName:p,totalPages:S?.allBusinesses?.pageInfo.totalPages}),(0,y.jsx)(d,{selected:E,resetMerge:k})]}))},[S,t,u,x,n,p,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)(l,{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)(f,{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};