| Current Path : /home/users/unlimited/www/web.medimeet.codeskitter.site/assets/ |
| Current File : /home/users/unlimited/www/web.medimeet.codeskitter.site/assets/Profile-Bzg05Lgl.js |
import{av as b,a7 as x,r as v,ad as P,ai as E,aF as F,ah as g,j as e,O as _,B as u,e as C,i as R,Y as D,bB as B,d as I,E as U,bC as L,a3 as z,R as T,F as h,ao as a,ap as n,P as p,bD as w,Q as c,bE as A,bF as G,ar as N,l as M,f as Q,T as $}from"./index-CDlA-3aM.js";import{u as O}from"./index.esm-DVyQvRf9.js";import{I as j}from"./input-element-Bbt7yrud.js";import{T as V}from"./textarea-Dc-gtYUz.js";const S=async t=>{try{const s={phone:t},i=await b(x.token,"re_login_phone",s);if(i.status===!0){const m={...i.data,token:m.token};localStorage.setItem("user",JSON.stringify(m))}else console.error("Failed to update user data:",i.message||"Unknown error")}catch(s){console.error("Error updating user data:",s.message)}},Z=async t=>{const s=await b(x.token,"update_user",t);if(s.response!==200)throw new Error(s.message);return s};function J({img:t}){const s=v.useRef(null),i=P(),m=E(),r=F({mutationFn:async l=>{let d={id:x.id,image:l};await Z(d)},onSuccess:()=>{g(i,"success","Profile Picture Changed"),m.invalidateQueries("user"),S(x.phone)},onError:l=>{g(i,"error",l.message)}}),f=l=>{const d=l.target.files[0];d&&(["image/png","image/jpeg","image/svg+xml"].includes(d.type)?r.mutate(d):i({title:"Invalid file type.",description:"Please select a PNG, JPG, or SVG file.",status:"error",duration:3e3,isClosable:!0}))};return r.isPending?e.jsx(_,{}):e.jsx(u,{w:"100%",children:e.jsxs(u,{pos:"relative",w:"fit-content",children:[e.jsx(C,{src:`${R}/${t}`,w:32,h:32,fallbackSrc:"/user.png",borderRadius:"full",objectFit:"cover"}),e.jsx(D,{size:"sm",icon:e.jsx(B,{fontSize:20}),variant:"ghost",pos:"absolute",top:0,right:0,_hover:{background:"rgba(0, 0, 266, 0.5)",color:"#fff"},onClick:()=>s.current.click()}),e.jsx("input",{type:"file",ref:s,accept:".png, .jpg, .jpeg, .svg",style:{display:"none"},onChange:f})]})})}const W=async()=>(await Q(`get_user/${x.id}`)).data,K=async t=>{const s=await b(x.token,"update_user",t);if(s.response!==200)throw new Error(s.message);return s},Y=()=>{const t=E(),{data:s,isLoading:i,error:m}=I({queryKey:["user"],queryFn:W}),{register:r,handleSubmit:f,reset:l}=O(),d=P();v.useEffect(()=>{s&&l({f_name:s.f_name||"",l_name:s.l_name||"",email:s.email||"",phone:s.phone||"",gender:s.gender||"Male",dob:s.dob||"",city:s.city||"",state:s.state||"",postal_code:s.postal_code||"",address:s.address||""})},[s,l]);const y=F({mutationFn:async o=>{let q={...o,id:x.id};await K(q)},onSuccess:()=>{g(d,"success","User Details Updated"),t.invalidateQueries("user"),S(x.phone)},onError:o=>{g(d,"error",o.message)}}),k=o=>{y.mutate(o)};return i?e.jsx(_,{}):m?e.jsx(U,{}):e.jsx(e.Fragment,{children:s?e.jsx(u,{w:"full",bg:L("white","gray.800"),boxShadow:"xl",rounded:"lg",mt:5,borderRadius:8,overflow:"hidden",children:e.jsxs(z,{as:"form",onSubmit:f(k),mt:1,spacing:4,p:6,children:[e.jsx(J,{img:s==null?void 0:s.image}),e.jsx(T,{}),e.jsxs(h,{w:"full",gap:4,mt:2,flexDir:{base:"column",md:"row"},children:[e.jsxs(a,{id:"f_name",isRequired:!0,children:[e.jsx(n,{children:"First Name"}),e.jsxs(p,{children:[e.jsx(j,{pointerEvents:"none",children:e.jsx(w,{color:"gray.800"})}),e.jsx(c,{type:"text",...r("f_name",{required:!0})})]})]}),e.jsxs(a,{id:"l_name",isRequired:!0,children:[e.jsx(n,{children:"Last Name"}),e.jsxs(p,{children:[e.jsx(j,{pointerEvents:"none",children:e.jsx(w,{color:"gray.800"})}),e.jsx(c,{type:"text",...r("l_name",{required:!0})})]})]})]}),e.jsxs(h,{w:"full",gap:4,flexDir:{base:"column",md:"row"},children:[e.jsxs(a,{id:"phone",isRequired:!0,children:[e.jsx(n,{children:"Phone"}),e.jsxs(p,{children:[e.jsx(j,{pointerEvents:"none",children:e.jsx(A,{color:"gray.800"})}),e.jsx(c,{type:"tel",isReadOnly:!0,...r("phone",{required:!0})})]})]}),e.jsxs(a,{id:"email",children:[e.jsx(n,{children:"Email"}),e.jsxs(p,{children:[e.jsx(j,{pointerEvents:"none",children:e.jsx(G,{color:"gray.800"})}),e.jsx(c,{type:"email",...r("email",{pattern:{value:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,message:"Invalid email address"}})})]})]})]}),e.jsxs(h,{w:"full",gap:4,children:[e.jsxs(a,{id:"gender",isRequired:!0,children:[e.jsx(n,{children:"Gender"}),e.jsxs(N,{...r("gender",{required:!0}),children:[e.jsx("option",{value:"Male",children:"Male"}),e.jsx("option",{value:"Female",children:"Female"})]})]}),e.jsxs(a,{id:"dob",isRequired:!0,children:[e.jsx(n,{children:"Date of Birth"}),e.jsx(c,{type:"date",...r("dob",{required:!0}),onFocus:o=>o.target.showPicker(),onClick:o=>o.target.showPicker()})]})]}),e.jsxs(h,{w:"full",gap:2,flexDir:{base:"column",md:"row"},children:[e.jsxs(a,{id:"city",children:[e.jsx(n,{children:"City"}),e.jsx(c,{type:"text",...r("city")})]}),e.jsxs(a,{id:"state",children:[e.jsx(n,{children:"State"}),e.jsx(c,{type:"text",...r("state")})]}),e.jsxs(a,{id:"postal_code",children:[e.jsx(n,{children:"Postal Code"}),e.jsx(c,{type:"text",...r("postal_code")})]})]}),e.jsxs(a,{id:"address",children:[e.jsx(n,{children:"Address"}),e.jsx(V,{type:"text",...r("address")})]}),e.jsx(M,{size:"sm",type:"submit",w:"full",bg:"green.500",color:"white",rounded:"md",_hover:{bg:"green.600"},isLoading:y.isPending,children:"Update Profile"})]})}):null})};function re(){return e.jsxs(u,{pb:20,children:[" ",e.jsx(u,{bg:"primary.main",p:4,py:{base:"4",md:"10"},children:e.jsx(u,{className:"container",children:e.jsx($,{fontSize:{base:24,md:32},fontWeight:700,textAlign:"center",mt:0,color:"#fff",children:"User Profile"})})}),e.jsx(u,{className:"container",maxW:"700px",children:e.jsx(h,{gap:5,flexDir:{base:"column",md:"row"},children:e.jsx(u,{flex:1,children:e.jsx(Y,{})})})})]})}export{re as default};