harperdb
Version:
HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.
2 lines (1 loc) • 3.53 kB
JavaScript
import{Y as k,Z as C,_ as F,$ as n,a0 as v,a1 as U,a2 as S,a3 as z,a4 as E,a5 as I,a6 as L,a7 as O,a8 as f,a9 as M,aa as e,ab as V,ac as p,ad as x,ae as o,af as i,ag as l,ah as w,ai as q,aj as A}from"./index-CkEccPko.js";async function R(a){const{id:d,newPassword:r,confirmNewPassword:c,...t}=a,m={...t};r&&r===c&&(m.password=r);const{data:u}=await C.patch(`/User/${d}`,m);return u}function $(){return k({mutationFn:a=>R(a)})}const B=F({id:n(),firstname:n({error:"Please enter your first name."}).min(2,{error:"First name is required."}).max(50,{error:"First name must be less than 50 characters."}),lastname:n({error:"Please enter your last name."}).min(2,{error:"Last name is required."}).max(50,{error:"Last name must be less than 50 characters."}),newPassword:n({error:"Please enter your new password."}).min(8,{error:"Password must be 8 characters or more."}).or(n().max(0)),confirmNewPassword:n().optional()}).refine(a=>a.newPassword===a.confirmNewPassword,{error:"Passwords do not match",path:["confirmNewPassword"]});function K(){const a=v(),d=U(),{user:r}=S(),c=z({resolver:E(B),defaultValues:{confirmNewPassword:"",firstname:r?.firstname||"",id:r?.id||"",lastname:r?.lastname||"",newPassword:""}}),{control:t,handleSubmit:m,reset:u,formState:{defaultValues:b,isDirty:P,isValid:N}}=c,{mutate:h,isPending:g}=$(),y=I.useCallback(async s=>{s&&h(s,{onSuccess:j=>{u({...b,...j}),L.updateUserForEntity(O,j),s.newPassword?(f.success("Profile updated successfully!",{description:"Please sign in with your new password."}),M(),d({to:"/sign-in"}),a.invalidate()):f.success("Profile updated successfully!")}})},[b,d,u,a,h]);return e.jsxs("div",{className:"mt-20 px-4 pt-4 md:px-12",children:[e.jsx("h2",{className:"text-2xl font-light",children:"Profile"}),e.jsx(V,{...c,children:e.jsxs("form",{onSubmit:m(y),className:"grid gap-4 my-4",children:[e.jsx(p,{control:t,name:"firstname",render:({field:s})=>e.jsxs(x,{children:[e.jsx(o,{className:"pb-1",children:"First Name"}),e.jsx(i,{children:e.jsx(l,{type:"text",className:"bg-purple-400 border-purple-400 dark:bg-black dark:border-black",autoCapitalize:"words",...s})}),e.jsx(w,{})]})}),e.jsx(p,{control:t,name:"lastname",render:({field:s})=>e.jsxs(x,{children:[e.jsx(o,{className:"pb-1",children:"Last Name"}),e.jsx(i,{children:e.jsx(l,{type:"text",className:"bg-purple-400 border-purple-400 dark:bg-black dark:border-black",autoCapitalize:"words",...s})}),e.jsx(w,{})]})}),e.jsx(o,{className:"pb-1",children:"Email"}),e.jsx(i,{children:e.jsx(l,{type:"email",enterKeyHint:"next",autoComplete:"email",autoCapitalize:"none",value:r?.email||"",disabled:!0,readOnly:!0})}),e.jsx(p,{control:t,name:"newPassword",render:({field:s})=>e.jsxs(x,{children:[e.jsx(o,{className:"pb-1",children:"New Password"}),e.jsx(i,{children:e.jsx(l,{type:"password",placeholder:"Optional",className:"bg-purple-400 border-purple-400 dark:bg-black dark:border-black",autoComplete:"new-password",autoCapitalize:"none",...s})}),e.jsx(w,{})]})}),e.jsx(p,{control:t,name:"confirmNewPassword",render:({field:s})=>e.jsxs(x,{children:[e.jsx(o,{className:"pb-1",children:"Confirm New Password"}),e.jsx(i,{children:e.jsx(l,{type:"password",className:"bg-purple-400 border-purple-400 dark:bg-black dark:border-black",autoComplete:"new-password",autoCapitalize:"none",...s})}),e.jsx(w,{})]})}),e.jsx("div",{className:"flex justify-between w-full",children:e.jsxs(q,{type:"submit",variant:"submit",className:"rounded-full",disabled:g||!P||!N,children:[e.jsx(A,{})," Update Profile"]})})]})})]})}export{K as ProfileIndex};