mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
2 lines
8.4 KiB
JavaScript
2 lines
8.4 KiB
JavaScript
import{n as L,bj as $,f as D,u as H,r as i,j as e,B as R,aQ as b,I as o,t as u}from"./index-Db-xuq0b.js";import{B as M}from"./badge-D7JvaQeJ.js";import{g as Q}from"./userService-BHeFzZdn.js";import{a as T}from"./employeePositionsService-CkHoE9xG.js";import{m,C as A}from"./proxy-i8Py-I0x.js";import{C as K}from"./chevron-left-DCpEaNzo.js";import{M as O}from"./mail-bwr0seHR.js";import{P as z}from"./phone-Ce15UUGI.js";import{R as G}from"./refresh-cw-JB7N413f.js";import{S as J}from"./save-BpdaNhEd.js";const V=n=>L({queryKey:["user",n],queryFn:async()=>(await Q(n)).data}),W=()=>{const{id:n}=$(),v=D(),{t:r}=H(),{data:d,refetch:F,isLoading:q}=V(n),[g,j]=i.useState(""),[c,k]=i.useState(""),[y,w]=i.useState(""),[h,P]=i.useState(""),[p,S]=i.useState(""),[U,C]=i.useState(!1),[s,B]=i.useState({}),[X,f]=i.useState("");i.useEffect(()=>{var a,t;if(d){const l=d;j(l.username??""),k(l.email??""),w(((a=l.name)==null?void 0:a.en)??""),P(((t=l.name)==null?void 0:t.am)??""),S(l.phoneNumber??"")}},[d]);const _={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.1}}},I=async a=>{a.preventDefault();const t={};if(c.trim()||(t.email=r("profile.emailRequired")),g.trim()||(t.userName=r("profile.usernameRequired")),p.trim()||(t.phoneNumber=r("profile.phoneRequired")),y.trim()||(t.englishName=r("profile.englishNameRequired")),h.trim()||(t.amharicName=r("profile.amharicNameRequired")),B(t),Object.keys(t).length>0)return;if(!/^(\+2519\d{8}|09\d{8})$/.test(p)){f(r("profile.invalidPhoneFormat")),u.error(r("profile.invalidPhoneFormat"),{description:r("profile.validPhoneFormat")});return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c)){f(r("profile.invalidEmailFormat")),u.error(r("profile.invalidEmailFormat"),{description:r("profile.validEmailFormat")});return}C(!0);try{await T({username:g,email:c,phoneNumber:p,name:{en:y,am:h}},n),u.success(r("profile.profileUpdateSuccess"),{description:r("profile.profileUpdated")}),F()}catch(N){const E=(N==null?void 0:N.message)||r("profile.profileUpdateFailed");f(E),u.error(r("profile.profileUpdateFailed"),{description:E})}finally{C(!1)}};if(q)return e.jsx("div",{children:"Loading..."});const x=d;return x?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-primary-50 to-primary-100/40 dark:from-gray-900 dark:to-gray-800",children:e.jsxs("div",{className:"container mx-auto px-4 py-6",children:[e.jsx(m.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"mb-6",children:e.jsxs(R,{onClick:()=>v(-1),variant:"ghost",className:"flex items-center gap-2 text-primary hover:text-primary-700 hover:bg-primary-300/20 dark:text-primary-300 dark:hover:text-primary-300 px-4 py-2 rounded-full transition-colors",children:[e.jsx(K,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium",children:r("common.back")})]})}),e.jsx("div",{className:"flex justify-center",children:e.jsxs(m.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{duration:.3},className:"w-full max-w-2xl bg-white dark:bg-gray-800 rounded-2xl shadow-xl overflow-hidden border border-gray-100 dark:border-gray-700",children:[e.jsx("div",{className:"relative bg-gradient-to-r from-primary to-primary-300 dark:from-primary-700 dark:to-primary-300 h-32",children:e.jsx("div",{className:"absolute -bottom-12 left-1/2 transform -translate-x-1/2",children:e.jsx(m.div,{whileHover:{scale:1.05},className:"relative h-24 w-24 rounded-full border-4 border-white dark:border-gray-800 bg-white dark:bg-gray-800 shadow-lg",children:e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary-300 to-primary dark:from-primary-300 dark:to-primary-700 rounded-full flex items-center justify-center",children:e.jsx(A,{className:"w-12 h-12 text-white"})})})})}),e.jsxs("div",{className:"pt-14 pb-6 px-6 text-center",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-800 dark:text-gray-100",children:x.name.en||"___"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-sm mt-1",children:r("profile.updateProfile")}),e.jsx("div",{className:"mt-3",children:e.jsx(M,{variant:"outline",className:`rounded-full px-3 py-1 text-xs font-medium ${x.status==="accepted"?"bg-primary-300/20 text-primary border-primary/30":"bg-gray-100 text-gray-600 border-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600"}`,children:r(`statusBar.${x.status||"___"}`)})})]}),e.jsx("div",{className:"px-6 pb-8",children:e.jsxs(m.form,{variants:_,initial:"hidden",animate:"show",className:"space-y-4",onSubmit:I,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 pl-1",children:r("profile.username")}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(b,{className:"h-4 w-4 text-gray-400 dark:text-gray-500"})}),e.jsx(o,{className:"pl-9 rounded-lg border-gray-300 dark:border-gray-600 focus:border-primary focus:ring-primary dark:bg-gray-700 dark:text-gray-100",value:g,onChange:a=>j(a.target.value)})]}),s.userName&&e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 pl-1",children:s.userName})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 pl-1",children:r("profile.englishName")}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(b,{className:"h-4 w-4 text-gray-400 dark:text-gray-500"})}),e.jsx(o,{className:"pl-9 rounded-lg border-gray-300 dark:border-gray-600 focus:border-primary focus:ring-primary dark:bg-gray-700 dark:text-gray-100",value:y,onChange:a=>w(a.target.value)})]}),s.englishName&&e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 pl-1",children:s.englishName})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 pl-1",children:r("profile.amharicName")}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(b,{className:"h-4 w-4 text-gray-400 dark:text-gray-500"})}),e.jsx(o,{className:"pl-9 rounded-lg border-gray-300 dark:border-gray-600 focus:border-primary focus:ring-primary dark:bg-gray-700 dark:text-gray-100",value:h,onChange:a=>P(a.target.value)})]}),s.amharicName&&e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 pl-1",children:s.amharicName})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 pl-1",children:r("profile.emailmsg")}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(O,{className:"h-4 w-4 text-gray-400 dark:text-gray-500"})}),e.jsx(o,{type:"email",className:"pl-9 rounded-lg border-gray-300 dark:border-gray-600 focus:border-primary focus:ring-primary dark:bg-gray-700 dark:text-gray-100",value:c,onChange:a=>k(a.target.value)})]}),s.email&&e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 pl-1",children:s.email})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 pl-1",children:r("profile.phoneNumber")}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(z,{className:"h-4 w-4 text-gray-400 dark:text-gray-500"})}),e.jsx(o,{type:"tel",className:"pl-9 rounded-lg border-gray-300 dark:border-gray-600 focus:border-primary focus:ring-primary dark:bg-gray-700 dark:text-gray-100",value:p,onChange:a=>S(a.target.value)})]}),s.phoneNumber&&e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 pl-1",children:s.phoneNumber})]}),e.jsx(m.div,{whileHover:{scale:1.01},whileTap:{scale:.99},className:"pt-4",children:e.jsx(R,{type:"submit",className:"w-full h-12 bg-gradient-to-r from-primary to-primary-300 hover:from-primary-700 hover:to-primary-300 text-white font-medium rounded-lg shadow-md transition-all duration-200",disabled:U,children:U?e.jsxs("span",{className:"flex items-center justify-center",children:[e.jsx(G,{className:"animate-spin h-5 w-5 mr-2"}),r("profile.updating"),"..."]}):e.jsxs("span",{className:"flex items-center justify-center",children:[e.jsx(J,{className:"w-4 h-4 mr-2"}),r("profile.updateProfile")]})})})]})})]})})]})}):e.jsx("div",{children:"User not found"})};function me(){return e.jsx(W,{})}export{me as default};
|