@@ -11,7 +11,7 @@ import React, { useCallback } from "react";
11
11
import { zodResolver } from "@hookform/resolvers/zod" ;
12
12
import { useForm } from "react-hook-form" ;
13
13
import { z } from "zod" ;
14
- import { UserProfile } from "@/types/User" ;
14
+ import { UserProfile , UserProfileSchema } from "@/types/User" ;
15
15
16
16
import { Form } from "@/components/ui/form" ;
17
17
import { Button } from "@/components/ui/button" ;
@@ -20,9 +20,7 @@ import { RadioGroupInput } from "@/components/form/RadioGroupInput";
20
20
import { useToast } from "@/hooks/use-toast" ;
21
21
import { editUserProfile } from "@/services/userService" ;
22
22
import { useRouter } from "next/navigation" ;
23
- import { LanguageEnum } from "@/types/Languages" ;
24
23
import { ProficiencyEnum } from "@/types/Proficiency" ;
25
- import { RoleEnum } from "@/types/Role" ;
26
24
27
25
interface EditProfileModalProps {
28
26
isOpen : boolean ;
@@ -33,12 +31,7 @@ interface EditProfileModalProps {
33
31
const FormSchema = z . object ( {
34
32
displayName : z . string ( ) . min ( 1 , "Display Name is required" ) ,
35
33
username : z . string ( ) . min ( 1 , "Username is required" ) ,
36
- email : z . string ( ) . email ( "Invalid email format" ) ,
37
- roles : z . array ( RoleEnum ) ,
38
34
proficiency : ProficiencyEnum ,
39
- languages : z . array ( LanguageEnum ) ,
40
- isOnboarded : z . boolean ( ) ,
41
- profilePictureUrl : z . string ( ) ,
42
35
} ) ;
43
36
44
37
export function EditProfile ( {
@@ -54,14 +47,20 @@ export function EditProfile({
54
47
defaultValues : {
55
48
displayName : userProfile . displayName ,
56
49
username : userProfile . username ,
57
- email : userProfile . email ,
58
50
proficiency : userProfile . proficiency ,
59
51
} ,
60
52
} ) ;
61
53
54
+ const { handleSubmit } = form ;
55
+
62
56
const onSubmit = useCallback (
63
57
async ( data : z . infer < typeof FormSchema > ) => {
64
- const response = await editUserProfile ( data ) ;
58
+ const newProfielUser = UserProfileSchema . parse ( {
59
+ ...userProfile ,
60
+ ...data ,
61
+ } ) ;
62
+
63
+ const response = await editUserProfile ( newProfielUser ) ;
65
64
66
65
if ( response . statusCode !== 200 ) {
67
66
toast ( {
@@ -80,7 +79,7 @@ export function EditProfile({
80
79
}
81
80
} ,
82
81
83
- [ toast , setIsOpen , router ]
82
+ [ toast , setIsOpen , router , userProfile ]
84
83
) ;
85
84
86
85
return (
@@ -90,37 +89,9 @@ export function EditProfile({
90
89
< DialogTitle className = "text-primary" > Edit Profile</ DialogTitle >
91
90
< Form { ...form } >
92
91
< form
93
- onSubmit = { form . handleSubmit ( onSubmit ) }
92
+ onSubmit = { handleSubmit ( onSubmit ) }
94
93
className = "flex flex-col space-y-4"
95
94
>
96
- { /* Profile Image Upload */ }
97
- { /*<FormLabel className="pt-8">Profile Image</FormLabel>
98
- <div className="flex flex-row justify-center items-center p-2">
99
- <input
100
- type="file"
101
- className="hidden"
102
- id="profile-upload"
103
- accept="image/*"
104
- />
105
-
106
- <Avatar>
107
- <AvatarImage/>
108
- <AvatarFallback className="text-base font-normal text-foreground">
109
- <CodeXml/>
110
- </AvatarFallback>
111
- </Avatar>
112
-
113
- <div className="pl-6">
114
- <label
115
- htmlFor="profile-upload"
116
- className="bg-background-200 text-sm rounded-lg font-bold p-2 cursor-pointer"
117
- >
118
- Upload Image
119
- </label>
120
- <DialogDescription className="pt-2">.png, .jpeg files up to 2MB. Recommended size is 256x256px.</DialogDescription>
121
- </div>
122
- </div> */ }
123
-
124
95
{ /* Display Name */ }
125
96
< TextInput
126
97
label = "Display Name"
@@ -141,9 +112,6 @@ export function EditProfile({
141
112
</ p >
142
113
) }
143
114
144
- { /* Email */ }
145
- { /* <TextInput label="Email" name="email" placeholder="Email" /> */ }
146
-
147
115
{ /* Proficiency Radio Buttons */ }
148
116
< RadioGroupInput
149
117
label = "Proficiency"
0 commit comments