Skip to content

Commit a524a9d

Browse files
committed
Update UserProfile import and handle user profile data
1 parent 8b3df2a commit a524a9d

File tree

1 file changed

+11
-43
lines changed

1 file changed

+11
-43
lines changed

frontend/src/app/profile/_components/EditProfile.tsx

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import React, { useCallback } from "react";
1111
import { zodResolver } from "@hookform/resolvers/zod";
1212
import { useForm } from "react-hook-form";
1313
import { z } from "zod";
14-
import { UserProfile } from "@/types/User";
14+
import { UserProfile, UserProfileSchema } from "@/types/User";
1515

1616
import { Form } from "@/components/ui/form";
1717
import { Button } from "@/components/ui/button";
@@ -20,9 +20,7 @@ import { RadioGroupInput } from "@/components/form/RadioGroupInput";
2020
import { useToast } from "@/hooks/use-toast";
2121
import { editUserProfile } from "@/services/userService";
2222
import { useRouter } from "next/navigation";
23-
import { LanguageEnum } from "@/types/Languages";
2423
import { ProficiencyEnum } from "@/types/Proficiency";
25-
import { RoleEnum } from "@/types/Role";
2624

2725
interface EditProfileModalProps {
2826
isOpen: boolean;
@@ -33,12 +31,7 @@ interface EditProfileModalProps {
3331
const FormSchema = z.object({
3432
displayName: z.string().min(1, "Display Name is required"),
3533
username: z.string().min(1, "Username is required"),
36-
email: z.string().email("Invalid email format"),
37-
roles: z.array(RoleEnum),
3834
proficiency: ProficiencyEnum,
39-
languages: z.array(LanguageEnum),
40-
isOnboarded: z.boolean(),
41-
profilePictureUrl: z.string(),
4235
});
4336

4437
export function EditProfile({
@@ -54,14 +47,20 @@ export function EditProfile({
5447
defaultValues: {
5548
displayName: userProfile.displayName,
5649
username: userProfile.username,
57-
email: userProfile.email,
5850
proficiency: userProfile.proficiency,
5951
},
6052
});
6153

54+
const { handleSubmit } = form;
55+
6256
const onSubmit = useCallback(
6357
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);
6564

6665
if (response.statusCode !== 200) {
6766
toast({
@@ -80,7 +79,7 @@ export function EditProfile({
8079
}
8180
},
8281

83-
[toast, setIsOpen, router]
82+
[toast, setIsOpen, router, userProfile]
8483
);
8584

8685
return (
@@ -90,37 +89,9 @@ export function EditProfile({
9089
<DialogTitle className="text-primary">Edit Profile</DialogTitle>
9190
<Form {...form}>
9291
<form
93-
onSubmit={form.handleSubmit(onSubmit)}
92+
onSubmit={handleSubmit(onSubmit)}
9493
className="flex flex-col space-y-4"
9594
>
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-
12495
{/* Display Name */}
12596
<TextInput
12697
label="Display Name"
@@ -141,9 +112,6 @@ export function EditProfile({
141112
</p>
142113
)}
143114

144-
{/* Email */}
145-
{/* <TextInput label="Email" name="email" placeholder="Email" /> */}
146-
147115
{/* Proficiency Radio Buttons */}
148116
<RadioGroupInput
149117
label="Proficiency"

0 commit comments

Comments
 (0)