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 { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
|
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 { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { useAuth } from '@/contexts/auth';
|
||||||
|
|
||||||
const profileFormSchema = z.object({
|
const profileFormSchema = z.object({
|
||||||
name: z.string().min(2, {
|
name: z.string().min(2, {
|
||||||
@@ -23,17 +24,26 @@ type ProfileFormValues = z.infer<typeof profileFormSchema>;
|
|||||||
const ProfileForm = () => {
|
const ProfileForm = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
const { user } = useAuth();
|
||||||
|
|
||||||
const defaultValues: Partial<ProfileFormValues> = {
|
|
||||||
name: '홍길동',
|
|
||||||
email: 'honggildong@example.com',
|
|
||||||
};
|
|
||||||
|
|
||||||
const form = useForm<ProfileFormValues>({
|
const form = useForm<ProfileFormValues>({
|
||||||
resolver: zodResolver(profileFormSchema),
|
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) => {
|
const onSubmit = (data: ProfileFormValues) => {
|
||||||
console.log('Form submitted:', data);
|
console.log('Form submitted:', data);
|
||||||
// Here you would typically update the profile data
|
// Here you would typically update the profile data
|
||||||
@@ -69,7 +79,7 @@ const ProfileForm = () => {
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>이메일</FormLabel>
|
<FormLabel>이메일</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input placeholder="이메일을 입력하세요" {...field} />
|
<Input placeholder="이메일을 입력하세요" {...field} readOnly />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|||||||
Reference in New Issue
Block a user