3
3
import {
4
4
Dialog ,
5
5
DialogContent ,
6
- DialogDescription ,
7
6
DialogHeader ,
8
7
DialogTitle ,
9
8
} from "@/components/ui/dialog" ;
@@ -20,6 +19,8 @@ import { RadioGroupInput } from "@/components/form/RadioGroupInput";
20
19
import { useToast } from "@/hooks/use-toast" ;
21
20
import { Avatar , AvatarFallback , AvatarImage } from "@/components/ui/avatar" ;
22
21
import { CodeXml } from "lucide-react" ;
22
+ import { updateProfile } from "@/services/profileService" ;
23
+ import { useRouter } from "next/navigation" ;
23
24
24
25
interface EditProfileModalProps {
25
26
isOpen : boolean ;
@@ -36,7 +37,7 @@ const FormSchema = z.object({
36
37
displayName : z . string ( ) . min ( 1 , "Display Name is required" ) ,
37
38
username : z . string ( ) . min ( 1 , "Username is required" ) ,
38
39
email : z . string ( ) . email ( "Invalid email format" ) ,
39
- proficiency : z . enum ( [ "Beginner" , "Intermediate" , "Expert " ] ) ,
40
+ proficiency : z . enum ( [ "Beginner" , "Intermediate" , "Advanced " ] ) ,
40
41
} ) ;
41
42
42
43
export function EditProfile ( {
@@ -45,6 +46,7 @@ export function EditProfile({
45
46
userProfile,
46
47
} : EditProfileModalProps ) {
47
48
const { toast } = useToast ( ) ;
49
+ const router = useRouter ( ) ;
48
50
49
51
const form = useForm < z . infer < typeof FormSchema > > ( {
50
52
resolver : zodResolver ( FormSchema ) ,
@@ -57,14 +59,26 @@ export function EditProfile({
57
59
58
60
const onSubmit = useCallback (
59
61
async ( data : z . infer < typeof FormSchema > ) => {
60
- console . log ( "Form data:" , data ) ;
61
- toast ( {
62
- title : "Profile updated!" ,
63
- description : "Your profile has been updated successfully." ,
64
- } ) ;
65
- setIsOpen ( false ) ;
62
+ const response = await updateProfile ( data ) ;
63
+
64
+ if ( response . statusCode !== 200 ) {
65
+ toast ( {
66
+ variant : "destructive" ,
67
+ title : "Error updating profile" ,
68
+ description : response . message ,
69
+ } ) ;
70
+ return ;
71
+ } else {
72
+ toast ( {
73
+ title : "Profile updated!" ,
74
+ description : "Your profile has been updated successfully." ,
75
+ } ) ;
76
+ setIsOpen ( false ) ;
77
+ router . refresh ( ) ;
78
+ }
66
79
} ,
67
- [ toast , setIsOpen ]
80
+
81
+ [ toast , setIsOpen , router ]
68
82
) ;
69
83
70
84
return (
@@ -78,8 +92,8 @@ export function EditProfile({
78
92
className = "flex flex-col space-y-4"
79
93
>
80
94
{ /* Profile Image Upload */ }
81
- < FormLabel className = "pt-8" > Profile Image</ FormLabel >
82
- < div className = "flex flex-row justify-center items-center p-2" >
95
+ { /* <FormLabel className="pt-8">Profile Image</FormLabel>
96
+ <div className="flex flex-row justify-center items-center p-2">
83
97
<input
84
98
type="file"
85
99
className="hidden"
@@ -103,7 +117,7 @@ export function EditProfile({
103
117
</label>
104
118
<DialogDescription className="pt-2">.png, .jpeg files up to 2MB. Recommended size is 256x256px.</DialogDescription>
105
119
</div>
106
- </ div >
120
+ </div> */ }
107
121
108
122
{ /* Display Name */ }
109
123
< TextInput label = "Display Name" name = "displayName" placeholder = "Display Name" />
@@ -117,7 +131,7 @@ export function EditProfile({
117
131
) }
118
132
119
133
{ /* Email */ }
120
- < TextInput label = "Email" name = "email" placeholder = "Email" />
134
+ { /* <TextInput label="Email" name="email" placeholder="Email" /> */ }
121
135
122
136
{ /* Proficiency Radio Buttons */ }
123
137
< RadioGroupInput
@@ -126,7 +140,7 @@ export function EditProfile({
126
140
options = { [
127
141
{ value : "Beginner" , optionLabel : "Beginner" } ,
128
142
{ value : "Intermediate" , optionLabel : "Intermediate" } ,
129
- { value : "Expert " , optionLabel : "Expert " } ,
143
+ { value : "Advanced " , optionLabel : "Advanced " } ,
130
144
] }
131
145
/>
132
146
0 commit comments