Fix profile information display
The user's actual name and email address should be displayed in the profile management section, not the default "홍길동".
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
|
||||
@@ -8,6 +8,7 @@ import { z } from 'zod';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '@/contexts/auth';
|
||||
|
||||
const profileFormSchema = z.object({
|
||||
name: z.string().min(2, {
|
||||
@@ -23,17 +24,26 @@ type ProfileFormValues = z.infer<typeof profileFormSchema>;
|
||||
const ProfileForm = () => {
|
||||
const navigate = useNavigate();
|
||||
const { toast } = useToast();
|
||||
|
||||
const defaultValues: Partial<ProfileFormValues> = {
|
||||
name: '홍길동',
|
||||
email: 'honggildong@example.com',
|
||||
};
|
||||
const { user } = useAuth();
|
||||
|
||||
const form = useForm<ProfileFormValues>({
|
||||
resolver: zodResolver(profileFormSchema),
|
||||
defaultValues,
|
||||
defaultValues: {
|
||||
name: '',
|
||||
email: '',
|
||||
},
|
||||
});
|
||||
|
||||
// 로그인된 사용자 정보로 폼 값 설정
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
form.reset({
|
||||
name: user.user_metadata?.username || '',
|
||||
email: user.email || '',
|
||||
});
|
||||
}
|
||||
}, [user, form]);
|
||||
|
||||
const onSubmit = (data: ProfileFormValues) => {
|
||||
console.log('Form submitted:', data);
|
||||
// Here you would typically update the profile data
|
||||
@@ -69,7 +79,7 @@ const ProfileForm = () => {
|
||||
<FormItem>
|
||||
<FormLabel>이메일</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="이메일을 입력하세요" {...field} />
|
||||
<Input placeholder="이메일을 입력하세요" {...field} readOnly />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
Reference in New Issue
Block a user