import{aw as N,j as e,ax as m,aS as O,dj as y,aA as i,R as g,l as A,k as b,o as I,e9 as F,G as T,az as w,g as C,h as v,i as E}from"./app-BgLa5dit.js";import{O as o}from"./DG_07YWO.chunk.js";import{N as R}from"./cYylFKjg.chunk.js";import{O as f}from"./u6fIQ8Ti.chunk.js";function G(n){const s=N(),c=()=>s.dirty&&s.isValid&&!s.isSubmitting,r=s.isSubmitting;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pb-3",children:e.jsx("h2",{className:"h5 m-0",children:"Add New Organisation"})}),e.jsx(m,{label:"Name",type:"text",name:"name",id:"name",infoText:n.isSalesforceOrg&&"To change this organisation's name, please do so in Salesforce, then refresh this page.",disabled:n.isSalesforceOrg,placeholder:"Enter organisation name",value:s.values.name||""}),e.jsxs(m,{as:"select",label:"Type",name:"orgType",id:"orgType",value:s.values.orgType||"",children:[e.jsx("option",{value:"",children:"Select organisation type"}),O.getEnumKeys(o).map(t=>e.jsx("option",{value:o[t],children:t},t))]}),e.jsx(y,{variant:"dark",type:"submit",disabled:!c(),showSpinner:r,children:"Create"})]})}const k=i.object().shape({name:i.string().trim().max(255,"Name is too long").required("Name is required"),orgType:i.mixed(),salesforceAccountId:i.string().default("")}).noUnknown();function U(n){const[s,c]=g.useState(!1),[r,t]=g.useState(),l=A(),p=b(),d=I(!!n.accountId&&f.salesforceOrganisation(n.accountId,a=>{var u;return a.status===404?t("Salesforce customer could not be found"):t(((u=a==null?void 0:a.responseJSON)==null?void 0:u.message)??"An error occurred when trying to find this organisation in Salesforce")}));function h(a){return a?{name:a.name,orgType:o.Unclassified,salesforceAccountId:n.accountId}:{name:"",orgType:o.Unclassified}}function S(){l.error("Failed to create organisation. Please try again.")}function x(a){l.success("Organisation successfully created! You will be redirected to their page now"),C.trigger({application:E.ORGANISATIONS,action:v.System.ORGANISATION_MANAGE,args:[a.id]})}function j(a){p(f.createOrganisation(a,x,S))}return!n.accountId||d.hasCompleted?r?e.jsx(e.Fragment,{children:e.jsx("p",{className:"alert alert-danger",children:r})}):e.jsx(e.Fragment,{children:n.accountId||s?e.jsx(T,{initialValues:h(d.data),onSubmit:j,validationSchema:k,children:e.jsx(w,{children:e.jsx(G,{isSalesforceOrg:!!n.accountId})})}):e.jsx(R,{setCreateNonSfCustomer:c,label:"Organisation"})}):e.jsx("div",{className:"py-5",children:e.jsx(F,{})})}export{U as NewOrganisationView};
//# sourceMappingURL=Ddtllb06.chunk.js.map
