7 lines
4.1 KiB
JavaScript
7 lines
4.1 KiB
JavaScript
import{c as e,H as T,bD as _,z as w,u as R,bq as k,p as u,r as E,dz as I,e as H,j as f,ae as N,fe as U,ff as L,fg as M,fh as $,fi as F,S as j,O as A,bP as G,dj as O,bj as Q,Z as q,bp as V,h as S,bQ as Z,T as J,br as K,bS as W,by as X,bT as Y,az as ee,fj as se}from"./bundle.2fc363c8.js";import{P as te,a as ne,b as ae,r as re}from"./bundle.373821fa.js";import{a as z}from"./bundle.fbd2c935.js";function C(s){const{children:c,renderBasePanel:o}=s;return o?e(te,{defaultSize:50,minSize:25,children:c}):e(T,{children:c})}function oe(s){const{children:c,renderBasePanelGroup:o}=s;return o?e(ne,{direction:"horizontal",className:"gap-4 mt-4",children:c}):e("div",{className:"flex flex-col gap-4",children:c})}const ce=_(ae)`
|
||
background-color: ${s=>s.theme.backgroundColor};
|
||
&:hover {
|
||
background-color: ${s=>s.theme.hoverColor};
|
||
}
|
||
`;function ie(s){const c=w(),{renderBasePanelResizeHandler:o}=s;return o?e(ce,{className:"flex items-center",theme:{hoverColor:"#3366CC",backgroundColor:c.$5},style:{width:"2.5px"}}):e(T,{})}function le(s){var l;const[c]=R(),o=k(),{documents:a}=s,y=u.useRef(null),[p,d]=u.useState(""),[h,x]=u.useState(!1),[i,m]=u.useState(0),[g,b]=u.useState(!1),n=()=>{var r;const t=(r=a[i])==null?void 0:r.type;return t==="png"||t==="jpg"||t==="gif"||t==="webp"||t==="tiff"},P=()=>{var r;return((r=a[i])==null?void 0:r.type)==="pdf"};return u.useEffect(()=>{var t;return a.length&&(x(!0),b(!1),a[i]?o.fetchQuery(["/api/v1/documents",(t=a[i])==null?void 0:t.hash],()=>{var r;return E("GET",H("/documents/:hash",{hash:(r=a[i])==null?void 0:r.hash}),{headers:I()},{responseType:"arraybuffer"})},{staleTime:1/0}).then(r=>{const v=new Blob([r.data],{type:r.headers["content-type"]});n()?d(URL.createObjectURL(v)):!z&&y.current&&P()?y.current.src=URL.createObjectURL(v):b(!0)}).finally(()=>x(!1)):m(0)),()=>{d(""),x(!1),b(!1)}},[a,i]),z?e("p",{children:"Unable to preview PDF. "}):f(T,{children:[a.length?f("div",{className:"flex flex-col",children:[!h&&f("div",{className:"flex self-end pb-1",children:[e(N,{className:"cursor-pointer",element:U,size:25,onClick:()=>m(0)}),e(N,{className:"cursor-pointer",element:L,size:25,onClick:()=>i!==0&&m(t=>t-1)}),e(N,{className:"cursor-pointer",element:M,size:25,onClick:()=>i!==a.length-1&&m(t=>t+1)}),e(N,{className:"cursor-pointer",element:$,size:25,onClick:()=>m(a.length-1)})]}),n()&&!h&&!g&&e("img",{className:"w-full",src:p}),e("iframe",{ref:y,width:"100%",height:h||!P()||g?0:1500}),g&&e("div",{className:"flex h-full justify-center items-center",children:e(F,{type:(l=a[i])==null?void 0:l.type,size:150})})]}):f("div",{className:"flex justify-center",children:[c("no_records_found"),"."]}),h&&e("div",{className:"flex justify-center items-center h-full",children:e(j,{})})]})}function fe(){const[s]=R(),{documentTitle:c}=A("edit_expense"),{id:o}=G(),a=O(),y=w(),{data:p}=Q({id:o}),d=re.useMediaQuery({query:"(min-width: 1024px)"}),h=q(),x=V(),i=[{name:s("expenses"),href:"/expenses"},{name:s("edit_expense"),href:S("/expenses/:id/edit",{id:o})}],m=[{name:s("edit"),href:S("/expenses/:id/edit",{id:o})},{name:s("documents"),href:S("/expenses/:id/documents",{id:o}),formatName:()=>e(Z,{numberOfDocuments:n==null?void 0:n.documents.length})}],[g,b]=u.useState(),[n,P]=u.useState(),[l,t]=u.useState(!1),[r,v]=u.useState("by_rate"),B=se({setErrors:b});return u.useEffect(()=>{p&&(P(p),v(p.calculate_tax_by_amount?"by_amount":"by_rate"))},[p]),e(J,{title:c,breadcrumbs:i,...(h("edit_expense")||x(n))&&n&&{navigationTopRight:e(K,{resource:n,onSaveClick:()=>B(n),actions:a,disableSaveButton:!n,cypressRef:"expenseActionDropdown"})},children:n?f("div",{className:"space-y-4",children:[e(W,{tabs:m,rightSide:f("div",{className:"flex items-center justify-end space-x-3",children:[e("span",{className:"text-sm",children:s("preview")}),e(X,{checked:l,onValueChange:D=>t(D)})]})}),f(oe,{renderBasePanelGroup:l&&d,children:[e(C,{renderBasePanel:l&&d,children:e(Y,{context:{errors:g,setErrors:b,expense:n,setExpense:P,taxInputType:r,setTaxInputType:v,isPreviewMode:l}})}),e(ie,{renderBasePanelResizeHandler:l&&d}),l&&!d&&e(ee,{className:"pt-4",withoutPadding:!0,borderColor:y.$5}),e(C,{renderBasePanel:l&&d,children:l&&e(le,{documents:n.documents})})]})]}):e(j,{})})}export{fe as default};
|