Files
docker-invoiceninja/docker/app/public/bundle.cc530e89.js
2024-10-19 18:17:42 +00:00

8 lines
3.2 KiB
JavaScript

import{bD as P,u as v,z as j,p as d,f7 as B,j as p,c as t,bt as E,f8 as L,b$ as z,ae as A,b7 as R,J as U,bc as m,r as O,e as M,O as q,T as J,c9 as K,C as W}from"./bundle.2fc363c8.js";const X=P.div`
border-color: ${a=>a.theme.borderColor};
&:hover {
border-color: ${a=>a.theme.hoverBorderColor};
}
`;function G(a){const[c]=v(),{entity:f}=a,l=j(),[n,h]=d.useState([]),[y,b]=d.useState(),[i,u]=d.useState(new FormData),[F,w]=d.useState(!1),C=()=>{if(!F){if(!n.length){m.error("select_file");return}return m.processing(),w(!0),b(void 0),O("POST",M("/api/v1/edocument/upload"),i).then(e=>{var s;console.log(e),m.success(((s=e==null?void 0:e.data)==null?void 0:s.message)??"success")}).catch(e=>{var s;((s=e.response)==null?void 0:s.status)===422&&(m.dismiss(),b(e.response.data))}).finally(()=>{h([]),w(!1),u(new FormData)})}},_=()=>{n.forEach(e=>{i.append("documents[]",e)}),u(i)},N=e=>{const s=n.filter((o,g)=>e!==g),r=new FormData;r.append("import_type",f),r.append("_method","PUT"),h(s),u(r)},T=e=>new Promise(s=>{try{const r=new FileReader;r.onload=o=>{var D;const x=(((D=o.target)==null?void 0:D.result)||"").split(`
`);!x.length||x.length===1||x.length===2&&!x[1]?s(!1):s(!0)},r.readAsText(e)}catch{s(!1)}}),I=async e=>{for(let s=0;s<e.length;s++)if(!await T(e[s]))return!1;return!0},{getRootProps:S,getInputProps:$,isDragActive:k}=B({accept:{"application/xml":[".xml"]},onDrop:async e=>{if(await I(e))if(e.every(({type:o})=>o.includes(o))){let o=[];e.map(g=>{o=[...o,g]}),h(o),i.append("import_type",f),i.append("_method","PUT"),u(i)}else m.error("wrong_file_extension");else m.error("xml_lines_length")}});return d.useEffect(()=>{_()},[n]),d.useEffect(()=>()=>{h([]),u(new FormData)},[]),p("div",{className:"flex flex-col space-y-4",children:[t(E,{leftSide:c("xml_file"),children:n.length?t("ul",{className:"grid xs:grid-rows-6 lg:grid-cols-2 gap-3",children:n.map((e,s)=>p("li",{className:"flex items-center justify-between cursor-pointer p-2",style:{backgroundColor:l.$4},children:[e.name," - ",(e.size/1024).toPrecision(2)," KB"," ",t(A,{element:R,size:19,className:"cursor-pointer",onClick:()=>N(s)})]},s))}):p("div",{...S(),className:"flex flex-col md:flex-row md:items-center",children:[p(X,{className:"relative block w-full border-2 border-dashed rounded-lg p-12 text-center focus:outline-none focus:ring-2 focus:ring-offset-2",theme:{borderColor:l.$5,hoverBorderColor:l.$3},children:[t("input",{...$()}),t(L,{className:"mx-auto h-12 w-12",style:{color:l.$3,colorScheme:l.$0}}),t("span",{className:"mt-2 block text-sm font-medium",style:{color:l.$3,colorScheme:l.$0},children:c(k?"drop_file_here":"dropzone_default_message")})]}),y&&Object.keys(y.errors).map((e,s)=>t(z,{type:"danger",children:y.errors[e]},s))]})}),t("div",{className:"flex justify-end pr-5",children:t(U,{behavior:"button",onClick:C,disableWithoutIcon:!0,disabled:!n.length||F,children:c("import")})})]})}function Q(){const{t:a}=v(),{documentTitle:c}=q("import"),f=[{name:a("expenses"),href:"/expenses"},{name:a("import"),href:"/expenses/import"}];return t(J,{title:c,breadcrumbs:f,children:t("div",{className:"grid grid-cols-12",children:p("div",{className:"col-span-12 xl:col-span-10 space-y-4",children:[t(K,{entity:"expense",onSuccess:!1,type:"csv"}),t(W,{children:t(G,{entity:"expense",type:"xml"})})]})})})}export{Q as default};