@@ -3,23 +3,32 @@ import { useForm } from "react-hook-form";
33import { zodResolver } from "@hookform/resolvers/zod" ;
44import { format } from "date-fns" ;
55import { CalendarIcon } from "lucide-react" ;
6+ import { useTranslations } from "next-intl" ;
67import { Button } from "@/components/ui/Button" ;
78import { Input } from "@/components/ui/Input" ;
89import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from "@/components/ui/Select" ;
910import { Form , FormControl , FormField , FormItem , FormLabel , FormMessage } from "@/components/ui/Form" ;
1011import { Popover , PopoverContent , PopoverTrigger } from "@/components/ui/Popover" ;
1112import { Calendar } from "@/components/ui/Calendar" ;
12- import { profileFormSchema , ProfileFormType } from "@/domains/Profile" ;
13+ import { createProfileFormSchema , ProfileFormType } from "@/domains/Profile" ;
1314import { cn } from "@/lib/utils" ;
15+ import { useGetProfile } from "../hooks" ;
16+ import Loader from "@/components/common/Loader" ;
17+ import { useEffect } from "react" ;
1418
1519interface ProfileFormProps {
1620 activeTab : "account" | "information" ;
1721}
1822
1923const ProfileForm = ( { activeTab } : ProfileFormProps ) => {
24+ const t = useTranslations ( ) ;
25+ const profileFormSchema = createProfileFormSchema ( t ) ;
26+ const { data, isLoading } = useGetProfile ( ) ;
27+
2028 const form = useForm < ProfileFormType > ( {
2129 resolver : zodResolver ( profileFormSchema ) ,
2230 defaultValues : {
31+ username : "" ,
2332 fullname : "" ,
2433 date_of_birth : "" ,
2534 phone_number : "" ,
@@ -30,15 +39,49 @@ const ProfileForm = ({ activeTab }: ProfileFormProps) => {
3039 } ,
3140 } ) ;
3241
42+ useEffect ( ( ) => {
43+ if ( data ) {
44+ form . reset ( {
45+ username : data . username || "" ,
46+ fullname : data . fullname || "" ,
47+ date_of_birth : data . date_of_birth || "" ,
48+ phone_number : data . phone_number || "" ,
49+ address : data . address || "" ,
50+ github : data . github || "" ,
51+ linkedin : data . linkedin || "" ,
52+ personal_web : data . personal_web || "" ,
53+ } ) ;
54+ }
55+ } , [ data ] ) ;
56+
3357 const onSubmit = ( data : ProfileFormType ) => {
3458 // ! TODO handle query mutation
3559 console . log ( "Profile data:" , data ) ;
3660 } ;
3761
62+ console . log ( "dataaa" , data ) ;
63+ if ( isLoading ) {
64+ return < Loader /> ;
65+ }
66+
3867 const renderForm = ( ) => {
3968 if ( activeTab === "account" ) {
4069 return (
4170 < >
71+ < FormField
72+ control = { form . control }
73+ name = "username"
74+ render = { ( { field } ) => (
75+ < FormItem >
76+ < FormLabel > Username</ FormLabel >
77+ < FormControl >
78+ < Input placeholder = "Enter your username" { ...field } />
79+ </ FormControl >
80+ < FormMessage />
81+ </ FormItem >
82+ ) }
83+ />
84+
4285 < FormField
4386 control = { form . control }
4487 name = "fullname"
0 commit comments