Files
aso/public/dashboard/assets/Create.636f8f78.js
2023-02-15 10:47:39 +07:00

2 lines
7.5 KiB
JavaScript

import{a as P,r as h,b0 as ee,c as ae,d as se,e as le,Y as w,f as s,F as oe,S as y,j as n,B as I,R as k,$ as B,av as j,k as de,t as T,T as C,o as ne,ap as pe,aT as ie,C as me}from"./index.eaf14aef.js";import{P as he}from"./Page.c2cde06d.js";import{R as te,a as ge}from"./RHFDatepicker.9c747cd2.js";import{d as fe}from"./Add.abe475ec.js";import{C as O}from"./Card.4687a3ba.js";import{G as m}from"./Grid.dda358cb.js";import{A as R}from"./Autocomplete.9c94adb2.js";import{H as xe}from"./HeaderBreadcrumbs.91259cd4.js";import"./jsx-runtime_commonjs-proxy.20d2a437.js";import"./DialogContent.9d59da83.js";import"./DialogActions.f966c600.js";import"./Chip.35ff2c8a.js";const f=T(C)(({theme:d})=>({...d.typography.h6,marginBottom:d.spacing(2),marginTop:d.spacing(2)}));T("header")(({theme:d})=>({paddingBottom:d.spacing(5),display:"flex",alignItems:"center",justifyContent:"space-between"}));const q=T(C)(({theme:d})=>({...d.typography.h4,boxShadow:"none",fontWeight:700}));T(C)(({theme:d})=>({boxShadow:"none",paddingBottom:d.spacing(1)}));T(C)(({theme:d})=>({boxShadow:"none",paddingBottom:d.spacing(3)}));function ce({isEdit:d,currentPractitioner:e}){const c=P();h.exports.useState([]);const{enqueueSnackbar:g}=ee(),F=ae().shape({name:se().required("Name is required")}),x=h.exports.useMemo(()=>({id:e==null?void 0:e.id,name:(e==null?void 0:e.name)||"",email:(e==null?void 0:e.email)||"",phone:(e==null?void 0:e.phone)||"",address:(e==null?void 0:e.address)||"",birth_date:(e==null?void 0:e.birth_date)||"",gender:(e==null?void 0:e.gender)||"",description:(e==null?void 0:e.description)||"",birth_place:(e==null?void 0:e.birth_place)||"",active:(e==null?void 0:e.active)===1,avatar_url:(e==null?void 0:e.avatar_url)||"",doctor_id:(e==null?void 0:e.doctor_id)||"",organizations:(e==null?void 0:e.organizations)||[],specialities:(e==null?void 0:e.specialities)||[]}),[e]);console.log("currentPractitioner",e),console.log("defaultValues",x);const _=le({resolver:ne(F),defaultValues:x}),{reset:z,watch:N,control:be,setValue:Se,getValues:ve,setError:V,handleSubmit:E,formState:{isSubmitting:H}}=_;N(),h.exports.useEffect(()=>{d&&e&&z(x),d||z(x)},[d,e]);const M=async l=>{var i,p;try{const o=new FormData;if(o.append("name",l.name),o.append("gender",l.gender),o.append("address",l.address),o.append("birth_place",l.birth_place),o.append("birth_date",l.birth_date),o.append("email",l.email),o.append("phone",l.phone),t.forEach((v,u)=>{o.append(`practices[${u}][organization_id]`,v.organizationId),v.specialities.forEach((Z,r)=>{o.append(`practices[${u}][specialities][${r}][speciality_id]`,Z)})}),d){o.append("_method","PUT");const v=await w.post("/doctors/"+(e==null?void 0:e.id),o)}else{console.log("formData",o);const v=await w.post("/doctors",o)}z(),g(d?"Doctors Udpated Successfully!":"Doctors Created Successfully!",{variant:"success"}),c("/master/doctors")}catch(o){if(o&&o.response.status===422){console.log("error",o.response.data.errors);for(const[v,u]of Object.entries(o.response.data.errors))V(v,{message:u[0]}),g((i=u[0])!=null?i:"Failed Processing Request",{variant:"error"})}else g((p=o.message)!=null?p:"Failed Processing Request",{variant:"error"})}const a=document==null?void 0:document.querySelector("ascent");a!=null&&(a.innerHTML="")},[D,A]=h.exports.useState([]),[L,$]=h.exports.useState([]);h.exports.useEffect(()=>{w.get("/search-organizations").then(l=>{A(l.data.map(a=>({...a,name:a.name,value:a.id})))}),w.get("/search-specialities").then(l=>{$(l.data.map(a=>({...a,name:a.name,value:a.id})))})},[]);const b=(e==null?void 0:e.practices)||[],[t,S]=h.exports.useState([]);h.exports.useEffect(()=>{if(b.length>0){const l=b.map(a=>({organizationId:a.organization_id,specialities:a.specialities.map(i=>i.speciality_id)}));S(l)}else S([{organizationId:"",specialities:[]}])},[b&&b.length]),console.log("forms",t);const U=l=>{if(l===""||l===null)return{name:"",value:""};{const a=D.find(i=>i.id===l);return{name:a==null?void 0:a.name,value:l}}},G=l=>L.filter(a=>l.includes(a.value)),J=()=>{S([...t,{organizationId:"",specialities:[]}])};console.log("forms",t);const K=[{value:"male",label:"Laki-Laki"},{value:"female",label:"Perempuan"}];console.log("forms",t);const W=(l,a)=>{const i=[...t];i[l].organizationId=a.id,S(i)},Y=(l,a)=>{S(i=>(i[l].specialities=a.map(p=>p.value),[...i]))},Q=b.length>0?D.filter(l=>!b.some(a=>a.organization_id===l.id)):D.filter(l=>!t.some(a=>a.organizationId===l.id)),X=l=>{const a=[...t];a.splice(l,1),S(a)};return s(oe,{methods:_,onSubmit:E(M),children:s(y,{spacing:3,children:n(I,{sx:{width:"100%"},children:[n(O,{sx:{p:5},children:[s(q,{variant:"h5",children:"Informasi Umum"}),n(m,{container:!0,rowSpacing:1,columnSpacing:{xs:1,sm:2,md:3},sx:{mt:2},children:[n(m,{item:!0,xs:12,children:[s(f,{children:"Nama Dokter"}),s(k,{name:"name",placeholder:"Tuliskan Nama Dokter"})]}),n(m,{item:!0,xs:6,children:[s(f,{children:"Jenis Kelamin"}),n(te,{name:"gender",label:"Pilih Jenis Kelamin",children:[s("option",{value:""}),K.map((l,a)=>s("option",{value:l.value,children:l.label},a))]})]}),n(m,{item:!0,xs:6,children:[s(f,{children:"Alamat"}),s(k,{name:"address",placeholder:"Tuliskan Alamat"})]}),n(m,{item:!0,xs:6,children:[s(f,{children:"Tempat Lahir"}),s(k,{name:"birth_place",placeholder:"Tuliskan Tempat Lahir"})]}),n(m,{item:!0,xs:6,children:[s(f,{children:"Tanggal Lahir"}),s(ge,{name:"birth_date",placeholder:"Silahkan Pilih Tanggal Lahir"})]}),n(m,{item:!0,xs:6,children:[s(f,{children:"Email"}),s(k,{name:"email",placeholder:"Tuliskan Email",type:"email"})]}),n(m,{item:!0,xs:6,children:[s(f,{children:"No. Telp"}),s(k,{name:"phone",placeholder:"Tuliskan Nomor Telepon"})]})]})]}),n(O,{sx:{p:5,marginTop:2},children:[n(y,{spacing:3,direction:"row",justifyContent:"space-between",children:[s(q,{variant:"h5",children:"Tempat Praktik"}),s(B,{variant:"contained",color:"primary",size:"small",sx:{boxShadow:"none"},onClick:J,startIcon:s(fe,{}),children:"Tambah Tempat Praktik"})]}),t.map((l,a)=>{var i;return s("div",{children:n(I,{sx:{mt:3},children:[n(y,{spacing:3,direction:"row",justifyContent:"space-between",children:[s(f,{}),a!==0&&s(B,{sx:{color:"red",m:1},"aria-label":"close",onClick:()=>X(a),children:"Delete"})]}),n(m,{container:!0,rowSpacing:1,columnSpacing:{xs:1,sm:2,md:3},children:[s(m,{item:!0,xs:6,children:s(R,{options:Q,value:(i=U(l.organizationId))!=null?i:"",getOptionLabel:p=>p.name,isOptionEqualToValue:(p,o)=>p.value===o.value,onChange:(p,o)=>W(a,o),renderInput:p=>s(j,{...p,label:"Rumah Sakit",variant:"outlined"})})}),s(m,{item:!0,xs:6,children:l.specialities&&s(R,{multiple:!0,options:L,value:G(l.specialities),getOptionLabel:p=>p.name,onChange:(p,o)=>Y(a,o),renderInput:p=>s(j,{...p,label:"Spesialis",variant:"outlined"})})})]})]})},a)})]}),s(I,{sx:{width:"100%",mt:5},children:s(y,{alignItems:"center",justifyContent:"end",direction:{xs:"column",md:"row"},sx:{width:1,textAlign:{xs:"center",md:"left"}},children:s(m,{item:!0,xs:12,md:4,children:s(de,{sx:{boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.1)"},type:"submit",variant:"contained",size:"large",loading:H,children:d?"Simpan Perubahan":"Simpan"})})})})]})})})}function Be(){var x;const{themeStretch:d}=pe(),{id:e}=ie(),c=!!e,[g,F]=h.exports.useState();return h.exports.useEffect(()=>{c&&w.get("/doctors/"+e).then(_=>{F(_.data)})},[e]),s(he,{title:"Membership: Create a new Dokter",children:n(me,{maxWidth:d?!1:"xl",children:[s(y,{direction:"row",alignItems:"center",children:s(xe,{heading:c?"Manage Dokter":"Manage a new Dokter",links:[{name:"Master",href:"/master"},{name:"Doctors",href:"/master/doctors"},{name:c?(x=g==null?void 0:g.name)!=null?x:"":"Create"}]})}),s(ce,{isEdit:c,currentPractitioner:g})]})})}export{Be as default};