2 lines
1.7 KiB
JavaScript
2 lines
1.7 KiB
JavaScript
import{O as S,u as N,a8 as T,bJ as y,bK as B,h as _,p as r,cI as E,j as o,T as j,c as t,cJ as k,cK as A,cL as P,cM as D,cN as I,bb as J,bc as d,r as K,e as L,a7 as M}from"./bundle.62072914.js";function q(){var f,p;const{documentTitle:v}=S("new_client"),[n]=N(),x=T(),[g]=y(),w=B(),C=[{name:n("clients"),href:"/clients"},{name:n("new_client"),href:_("/clients/create")}],[e,c]=r.useState(),[s,a]=r.useState(),[i,b]=r.useState([{first_name:"",last_name:"",email:"",phone:"",send_email:!1}]),{data:u}=E({});r.useEffect(()=>{u&&c({...u.data,group_settings_id:g.get("group")||""})},[u]);const m=async()=>{if(J.set(e,"contacts",i),d.processing(),a(void 0),!((e==null?void 0:e.name)!=""||i[0].first_name!=""||i[0].last_name!=""))return a({message:n("invalid_name // needs translation"),errors:{name:[n("please_enter_a_client_or_contact_name")]}}),d.error(),m;await w(!0),K("POST",L("/api/v1/clients"),e).then(l=>{d.success("created_client"),M(["clients"]),x(_("/clients/:id",{id:l.data.data.id}))}).catch(l=>{var h;((h=l.response)==null?void 0:h.status)===422&&(a(l.response.data),d.dismiss())})};return o(j,{title:v,breadcrumbs:C,onSaveClick:m,children:[s?t(k,{errors:s,entity:"client",withoutTopMessage:!!((f=s.errors)!=null&&f.id),withoutListBullets:!!((p=s.errors)!=null&&p.id)}):null,o("div",{className:"flex flex-col xl:flex-row xl:gap-4",children:[o("div",{className:"w-full xl:w-1/2",children:[t(A,{client:e,setClient:c,setErrors:a,errors:s}),t("div",{className:"mt-5",children:t(P,{client:e,setClient:c,setErrors:a,errors:s})})]}),o("div",{className:"w-full xl:w-1/2",children:[t(D,{contacts:i,setContacts:b,setErrors:a,errors:s}),t("div",{className:"mt-5",children:t(I,{client:e,setClient:c,setErrors:a,errors:s})})]})]})]})}export{q as default};
|