From ca18031388a69fd1cc679d02e1bf714bb94f371d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 15 Mar 2025 04:32:52 +0000 Subject: [PATCH] Refactor ProfileManagement page Splits the ProfileManagement page into smaller components for better organization and maintainability. No functionality was changed. --- src/components/profile/PasswordChangeForm.tsx | 181 +++++++++++ src/components/profile/ProfileForm.tsx | 92 ++++++ src/components/profile/ProfileHeader.tsx | 46 +++ src/pages/ProfileManagement.tsx | 290 +----------------- 4 files changed, 326 insertions(+), 283 deletions(-) create mode 100644 src/components/profile/PasswordChangeForm.tsx create mode 100644 src/components/profile/ProfileForm.tsx create mode 100644 src/components/profile/ProfileHeader.tsx diff --git a/src/components/profile/PasswordChangeForm.tsx b/src/components/profile/PasswordChangeForm.tsx new file mode 100644 index 0000000..9a437e7 --- /dev/null +++ b/src/components/profile/PasswordChangeForm.tsx @@ -0,0 +1,181 @@ + +import React, { useState } from 'react'; +import { Key, Eye, EyeOff } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useToast } from '@/hooks/use-toast'; +import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; + +const passwordFormSchema = z.object({ + currentPassword: z.string().min(6, { + message: '비밀번호는 6자 이상이어야 합니다.', + }), + newPassword: z.string().min(8, { + message: '새 비밀번호는 8자 이상이어야 합니다.', + }), + confirmPassword: z.string().min(8, { + message: '비밀번호 확인은 8자 이상이어야 합니다.', + }), +}).refine((data) => data.newPassword === data.confirmPassword, { + message: "비밀번호가 일치하지 않습니다.", + path: ["confirmPassword"], +}); + +type PasswordFormValues = z.infer; + +const PasswordChangeForm = () => { + const { toast } = useToast(); + const [showCurrentPassword, setShowCurrentPassword] = useState(false); + const [showNewPassword, setShowNewPassword] = useState(false); + const [showConfirmPassword, setShowConfirmPassword] = useState(false); + + const passwordForm = useForm({ + resolver: zodResolver(passwordFormSchema), + defaultValues: { + currentPassword: '', + newPassword: '', + confirmPassword: '', + }, + }); + + const onPasswordSubmit = (data: PasswordFormValues) => { + console.log('Password form submitted:', data); + // Here you would typically update the password + toast({ + title: "비밀번호 변경 완료", + description: "비밀번호가 성공적으로 변경되었습니다.", + }); + passwordForm.reset(); + }; + + return ( +
+

비밀번호 변경

+
+ + ( + + 현재 비밀번호 + +
+ + +
+
+ +
+ )} + /> + + ( + + 새 비밀번호 + +
+ + +
+
+ +
+ )} + /> + + ( + + 비밀번호 확인 + +
+ + +
+
+ +
+ )} + /> + + + + + + + + 비밀번호 변경 확인 + + 비밀번호를 변경하시겠습니까? 변경 후에는 새 비밀번호로 로그인해야 합니다. + + + + 취소 + + 변경 + + + + + + +
+ ); +}; + +export default PasswordChangeForm; diff --git a/src/components/profile/ProfileForm.tsx b/src/components/profile/ProfileForm.tsx new file mode 100644 index 0000000..106a1d3 --- /dev/null +++ b/src/components/profile/ProfileForm.tsx @@ -0,0 +1,92 @@ + +import React 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'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useToast } from '@/hooks/use-toast'; +import { useNavigate } from 'react-router-dom'; + +const profileFormSchema = z.object({ + name: z.string().min(2, { + message: '이름은 2글자 이상이어야 합니다.', + }), + email: z.string().email({ + message: '유효한 이메일 주소를 입력해주세요.', + }), +}); + +type ProfileFormValues = z.infer; + +const ProfileForm = () => { + const navigate = useNavigate(); + const { toast } = useToast(); + + const defaultValues: Partial = { + name: '홍길동', + email: 'honggildong@example.com', + }; + + const form = useForm({ + resolver: zodResolver(profileFormSchema), + defaultValues, + }); + + const onSubmit = (data: ProfileFormValues) => { + console.log('Form submitted:', data); + // Here you would typically update the profile data + // Show success message + toast({ + title: "프로필 업데이트 완료", + description: "프로필 정보가 성공적으로 업데이트되었습니다.", + }); + navigate('/settings'); + }; + + return ( +
+ + ( + + 이름 + + + + + + )} + /> + + ( + + 이메일 + + + + + + )} + /> + +
+ +
+ + + ); +}; + +export default ProfileForm; diff --git a/src/components/profile/ProfileHeader.tsx b/src/components/profile/ProfileHeader.tsx new file mode 100644 index 0000000..d5e88c8 --- /dev/null +++ b/src/components/profile/ProfileHeader.tsx @@ -0,0 +1,46 @@ + +import React from 'react'; +import { ArrowLeft, User, Camera } from 'lucide-react'; +import { useNavigate } from 'react-router-dom'; +import { Button } from '@/components/ui/button'; +import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; + +const ProfileHeader = () => { + const navigate = useNavigate(); + + return ( +
+
+ +

프로필 관리

+
+ + {/* User Profile Picture */} +
+
+ + + + + + + +
+
+
+ ); +}; + +export default ProfileHeader; diff --git a/src/pages/ProfileManagement.tsx b/src/pages/ProfileManagement.tsx index 8e5b564..63db985 100644 --- a/src/pages/ProfileManagement.tsx +++ b/src/pages/ProfileManagement.tsx @@ -1,292 +1,16 @@ -import React, { useState } from 'react'; -import { ArrowLeft, User, Camera, Mail, Key, Eye, EyeOff } from 'lucide-react'; -import { useNavigate } from 'react-router-dom'; -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; -import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; -import { useForm } from 'react-hook-form'; -import { z } from 'zod'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { useToast } from '@/hooks/use-toast'; -import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; - -const profileFormSchema = z.object({ - name: z.string().min(2, { - message: '이름은 2글자 이상이어야 합니다.', - }), - email: z.string().email({ - message: '유효한 이메일 주소를 입력해주세요.', - }), -}); - -const passwordFormSchema = z.object({ - currentPassword: z.string().min(6, { - message: '비밀번호는 6자 이상이어야 합니다.', - }), - newPassword: z.string().min(8, { - message: '새 비밀번호는 8자 이상이어야 합니다.', - }), - confirmPassword: z.string().min(8, { - message: '비밀번호 확인은 8자 이상이어야 합니다.', - }), -}).refine((data) => data.newPassword === data.confirmPassword, { - message: "비밀번호가 일치하지 않습니다.", - path: ["confirmPassword"], -}); - -type ProfileFormValues = z.infer; -type PasswordFormValues = z.infer; +import React from 'react'; +import ProfileHeader from '@/components/profile/ProfileHeader'; +import ProfileForm from '@/components/profile/ProfileForm'; +import PasswordChangeForm from '@/components/profile/PasswordChangeForm'; const ProfileManagement = () => { - const navigate = useNavigate(); - const { toast } = useToast(); - const [showCurrentPassword, setShowCurrentPassword] = useState(false); - const [showNewPassword, setShowNewPassword] = useState(false); - const [showConfirmPassword, setShowConfirmPassword] = useState(false); - - const defaultValues: Partial = { - name: '홍길동', - email: 'honggildong@example.com', - }; - - const form = useForm({ - resolver: zodResolver(profileFormSchema), - defaultValues, - }); - - const passwordForm = useForm({ - resolver: zodResolver(passwordFormSchema), - defaultValues: { - currentPassword: '', - newPassword: '', - confirmPassword: '', - }, - }); - - const onSubmit = (data: ProfileFormValues) => { - console.log('Form submitted:', data); - // Here you would typically update the profile data - // Show success message - toast({ - title: "프로필 업데이트 완료", - description: "프로필 정보가 성공적으로 업데이트되었습니다.", - }); - navigate('/settings'); - }; - - const onPasswordSubmit = (data: PasswordFormValues) => { - console.log('Password form submitted:', data); - // Here you would typically update the password - toast({ - title: "비밀번호 변경 완료", - description: "비밀번호가 성공적으로 변경되었습니다.", - }); - passwordForm.reset(); - }; - return (
- {/* Header */} -
-
- -

프로필 관리

-
- - {/* User Profile Picture */} -
-
- - - - - - - -
-
-
- - {/* Profile Form */} -
- - ( - - 이름 - - - - - - )} - /> - - ( - - 이메일 - - - - - - )} - /> - -
- -
- - - - {/* Password Change Section */} -
-

비밀번호 변경

-
- - ( - - 현재 비밀번호 - -
- - -
-
- -
- )} - /> - - ( - - 새 비밀번호 - -
- - -
-
- -
- )} - /> - - ( - - 비밀번호 확인 - -
- - -
-
- -
- )} - /> - - - - - - - - 비밀번호 변경 확인 - - 비밀번호를 변경하시겠습니까? 변경 후에는 새 비밀번호로 로그인해야 합니다. - - - - 취소 - - 변경 - - - - - - -
+ + +
);