@accounter/client
Version:
Accounter client application
1 lines • 4.86 kB
JavaScript
import{s as e}from"./dist-BBBZL-zT.js";import{i as t,o as n}from"./utils-C9b7NsUD.js";import{N as r,_o as i,at as a,ci as o,ni as s,ri as c}from"./error-handling-DBz7h-2r.js";import{s as l,t as u}from"./routes-g2AjKuLo.js";import{a as d,c as f,d as p,f as m,i as h,n as g,o as _,p as v,r as y,s as b,t as x,ut as S}from"./select-D_LnCowF.js";import{Mt as C,Ut as w,Wt as T,dr as E,h as D,pr as O,tt as k,ur as A,wt as j}from"./common-3l1_jDFS.js";import{x as M}from"./separator-CH02FkEe.js";import{t as N}from"./button-DATCl8sW.js";import{a as P,b as F,g as I,i as L,it as R,n as z,o as B,r as V,t as H}from"./table-CZ9XLwX9.js";import{t as U}from"./subMonths-CpJQn_2t.js";import{x as W}from"./index-C5FJSqDD.js";import{r as G,t as K}from"./use-issue-monthly-documents-EZY0uYD-.js";var q=e(n(),1),J=t();function Y({issueMonth:e,clients:t,onAdd:n}){let[r,a]=(0,q.useState)(!1),[c,l]=(0,q.useState)(``),[{data:u},_]=i({query:s,variables:{issueMonth:e,clientId:c},pause:!r}),S=(0,q.useCallback)(e=>{l(e),_()},[_,l]);return(0,q.useEffect)(()=>{c!==``&&u&&(n(D(I(o,u.clientMonthlyChargeDraft))),a(!1))},[c,u,n]),(0,J.jsxs)(b,{open:r,onOpenChange:a,children:[(0,J.jsx)(v,{asChild:!0,children:(0,J.jsx)(N,{variant:`outline`,size:`icon`,children:(0,J.jsx)(M,{})})}),(0,J.jsxs)(f,{className:`w-[400px] max-w-screen-md`,children:[(0,J.jsx)(p,{children:(0,J.jsx)(m,{children:`Select document recipient`})}),(0,J.jsxs)(x,{onValueChange:S,children:[(0,J.jsx)(h,{children:(0,J.jsx)(d,{placeholder:`Recipient`})}),(0,J.jsx)(g,{children:t.map(e=>(0,J.jsx)(y,{value:e.id,children:e.name},e.id))})]})]})]})}var X=({drafts:e})=>{let[t,n]=(0,q.useState)(e.map(e=>D(I(o,e)))),[s,d]=(0,q.useState)(R(U(new Date,1),`yyyy-MM-dd`)),[{data:f},p]=i({query:c,variables:{issueMonth:s},pause:!0});(0,q.useEffect)(()=>{f?.periodicalDocumentDrafts&&n(f.periodicalDocumentDrafts.map(e=>D(I(o,e))))},[f,n]),(0,q.useEffect)(()=>{p()},[s,p]);let m=T({values:{generateDocumentsInfo:t}}),{issueDocuments:h}=K(),[{data:g}]=i({query:r}),{fields:v,append:y,remove:b,update:x}=w({control:m.control,name:`generateDocumentsInfo`}),M=m.watch(`generateDocumentsInfo`),F=(0,q.useMemo)(()=>v.map((e,t)=>({...e,...M[t],id:e.client?.id})),[v,M]),W=(0,q.useCallback)(e=>{h(e)},[h]),X=(0,q.useMemo)(()=>g?.allOpenContracts.filter(e=>e.billingCycle===a.Monthly&&!F.some(t=>t.client?.id===e.client.id)),[F,g]);return(0,J.jsx)(`div`,{className:`p-2`,children:(0,J.jsx)(C,{...m,children:(0,J.jsxs)(`form`,{onSubmit:m.handleSubmit(W),children:[(0,J.jsxs)(`div`,{className:`flex gap-2 items-center mb-4`,children:[(0,J.jsx)(_,{children:`Issue Month:`}),(0,J.jsx)(j,{value:new Date(s),onChange:e=>{d(R(new Date(e.getFullYear(),e.getMonth(),15),`yyyy-MM-dd`))},popoverProps:{withinPortal:!0}})]}),(0,J.jsxs)(H,{children:[(0,J.jsx)(P,{children:(0,J.jsxs)(B,{children:[(0,J.jsx)(L,{children:`Name`}),(0,J.jsx)(L,{children:`Document`}),(0,J.jsx)(L,{children:`Amount`}),(0,J.jsx)(L,{children:`Remark`}),(0,J.jsx)(L,{children:`Recipients`}),(0,J.jsx)(L,{})]})}),(0,J.jsx)(z,{children:F.map(({id:e,...t},n)=>(0,J.jsxs)(B,{children:[(0,J.jsx)(V,{children:(0,J.jsx)(l,{to:e?u.BUSINESSES.DETAIL(e):u.BUSINESSES.ALL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t.client?.name})}),(0,J.jsx)(V,{children:t.type}),(0,J.jsxs)(V,{children:[t.income?.[0]?.price,` `,t.income?.[0]?.currency]}),(0,J.jsx)(V,{children:(0,J.jsx)(`span`,{className:`text-sm text-gray-500 whitespace-normal max-w-50`,children:t.remarks})}),(0,J.jsx)(V,{children:(0,J.jsx)(`div`,{className:`flex flex-col`,children:t.client?.emails?.map(e=>(0,J.jsx)(`span`,{className:`text-sm text-gray-500`,children:e},e))})}),(0,J.jsx)(V,{children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsxs)(A,{children:[(0,J.jsx)(O,{asChild:!0,type:`button`,children:(0,J.jsx)(N,{className:`size-7.5`,variant:`secondary`,onClick:()=>b(n),children:(0,J.jsx)(S,{size:16})})}),(0,J.jsx)(E,{children:(0,J.jsx)(`p`,{children:`Remove document`})})]}),(0,J.jsx)(G,{draft:t,onApprove:e=>{m.setValue(`generateDocumentsInfo.${n}`,e,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),x(n,{...e})}})]})})]},e))})]}),(0,J.jsxs)(`div`,{className:`flex justify-between items-center mt-4`,children:[(0,J.jsx)(Y,{clients:X?.map(e=>({id:e.client.originalBusiness.id,name:e.client.originalBusiness.name}))??[],onAdd:y,issueMonth:s}),(0,J.jsx)(k,{onConfirm:m.handleSubmit(W),title:`Are you sure you want to issue ${F.length} documents?`,children:(0,J.jsx)(N,{children:`Issue`})})]})]})})})},Z=()=>{let{setFiltersContext:e}=(0,q.useContext)(W),[{data:t,fetching:n}]=i({query:c,variables:{issueMonth:R(U(new Date,1),`yyyy-MM-dd`)}});return(0,q.useEffect)(()=>{t?.periodicalDocumentDrafts||e(null)},[t,e]),n?(0,J.jsx)(F,{}):(0,J.jsx)(X,{drafts:t?.periodicalDocumentDrafts??[]})};export{Z as IssueDocuments};