@@ -16,6 +16,9 @@ import { cn } from "@/lib/utils"
1616import { ButtonLoader } from "@/components/ui/button-loader"
1717import RecycleBinDialog from "@/feature/quote/dialog/recycle-bin.dialog"
1818import NavigationComponent from "@/feature/user/component/navigation"
19+ import { useUpdateUser } from "@/feature/user/hook/use-update-user.hook"
20+ import { toast } from "sonner"
21+ import { toastConfig } from "@/components/ui/sonner"
1922
2023const profileFormSchema = z . object ( {
2124 name : z . string ( ) . min ( 1 , "name should not be empty" ) ,
@@ -29,24 +32,28 @@ const Me = () => {
2932 const { decodedToken, isExpired } = useJwt < User > ( token ) ;
3033
3134 const { data : user , isPending, invalidateQueries } = useGetUser ( { _id : decodedToken ?. _id } )
35+ const { updateUser } = useUpdateUser ( )
3236
33- const { control, reset, formState : { isDirty } , handleSubmit } = useForm ( {
37+ const { control, reset, formState : { isDirty } , handleSubmit, getValues } = useForm ( {
3438 defaultValues : {
3539 name : '' ,
3640 email : ''
3741 } ,
3842 resolver : zodResolver ( profileFormSchema )
3943 } )
4044
41- useEffect ( ( ) => {
42- reset ( {
43- name : user ?. name || "" ,
44- email : user ?. email || "" ,
45- } )
46- } , [ user ] )
4745
48- const onSubmit = ( values : z . infer < typeof profileFormSchema > ) => {
46+ const onSubmit = async ( values : z . infer < typeof profileFormSchema > ) => {
47+ console . log ( { values } ) ;
4948
49+ if ( ! user ?. _id ) {
50+ toast . warning ( "No user found" , toastConfig )
51+ return
52+ }
53+ await updateUser ( {
54+ _id : user ?. _id ,
55+ name : values . name
56+ } )
5057 }
5158
5259 const onLogout = ( ) => {
@@ -57,6 +64,13 @@ const Me = () => {
5764 } )
5865 }
5966
67+ useEffect ( ( ) => {
68+ reset ( {
69+ name : user ?. name || "" ,
70+ email : user ?. email || "" ,
71+ } )
72+ } , [ user ] )
73+
6074 return (
6175 < div
6276 className = 'w-full h-dvh flex justify-self-center md:w-3/4 overflow-hidden' >
@@ -70,7 +84,7 @@ const Me = () => {
7084 className = "w-full "
7185 >
7286 < div className = 'flex p-4 bg-background flex-row sticky top-0 z-10 justify-between items-center' >
73- < NavigationComponent />
87+ < NavigationComponent />
7488 </ div >
7589 { /* <Separator className="bg-border" /> */ }
7690
@@ -96,18 +110,21 @@ const Me = () => {
96110 >
97111 Logout
98112 </ Button >
99- { /* {
113+ {
100114 ( isDirty ) && (
101115 < Button
102116 variant = "outline"
103- size={'sm'}
117+ onClick = { ( ) => {
118+ onSubmit ( getValues ( ) )
119+ }
120+ } size = { 'sm' }
104121 className = "text-xs px-2 py-0"
105122 aria-label = 'save-profile-button'
106123 title = 'save-profile-button' >
107124 Save changes
108125 </ Button >
109126 )
110- } */ }
127+ }
111128 </ div >
112129
113130 </ div >
@@ -171,13 +188,14 @@ const Me = () => {
171188 </ p >
172189 < div className = "flex justify-between items-center text-center " >
173190 < p className = " text-sm" >
174- Sync
191+ Sync
175192 </ p >
176- { /* <Button variant="outline" size="icon"
193+ < Button variant = "outline" size = "icon"
194+ disabled
177195 aria-label = 'sync-button'
178196 title = 'sync-button' >
179197 < CloudBackupIcon />
180- </Button> */ }
198+ </ Button >
181199 </ div >
182200 < div className = "flex justify-between items-center text-sm " >
183201 Cloud Container
0 commit comments