|
1 | 1 | 'use client';
|
2 | 2 |
|
3 | 3 | import { useUser } from '@/app/_hooks';
|
| 4 | +import { Button } from '@zicdding-web/ui'; |
| 5 | +import { Input } from '@zicdding-web/ui/Input'; |
4 | 6 | import { useRouter } from 'next/navigation';
|
5 | 7 | import { useEffect } from 'react';
|
| 8 | +import { useForm } from 'react-hook-form'; |
6 | 9 |
|
7 |
| -export function MyInfo() { |
8 |
| - const { user, isLogged } = useUser(); |
| 10 | +function useLoginPageGuard(nextPage: string) { |
| 11 | + const { isLogged } = useUser(); |
9 | 12 | const router = useRouter();
|
10 | 13 |
|
11 | 14 | useEffect(() => {
|
12 | 15 | if (!isLogged) {
|
13 |
| - router.push('/login'); |
| 16 | + router.push(nextPage); |
14 | 17 | }
|
15 |
| - }, [isLogged, router]); |
| 18 | + }, [isLogged, router, nextPage]); |
| 19 | +} |
| 20 | + |
| 21 | +export function MyInfo({ mode }: { mode: 'view' | 'modify' }) { |
| 22 | + const router = useRouter(); |
| 23 | + const { user } = useUser(); |
| 24 | + const { register, getValues } = useForm<{ |
| 25 | + nickname: string; |
| 26 | + email: string; |
| 27 | + password: string; |
| 28 | + phoneNumber: string; |
| 29 | + }>({ |
| 30 | + defaultValues: { |
| 31 | + nickname: user?.nickname, |
| 32 | + email: user?.email, |
| 33 | + password: '**********', |
| 34 | + phoneNumber: user?.phone_num, |
| 35 | + }, |
| 36 | + }); |
| 37 | + |
| 38 | + useLoginPageGuard('/login'); |
16 | 39 |
|
17 | 40 | return (
|
18 | 41 | <div className="space-y-4 w-[420px] mx-auto my-0">
|
19 |
| - <div className="grid grid-cols-2 gap-4 items-center"> |
20 |
| - <label htmlFor="nickname" className="text-gray-700 font-bold"> |
21 |
| - 닉네임 |
22 |
| - </label> |
23 |
| - <input |
24 |
| - id="nickname" |
25 |
| - type="text" |
26 |
| - value={user?.nickname || ''} |
27 |
| - readOnly |
28 |
| - className="form-input w-full border-gray-300" |
29 |
| - /> |
30 |
| - </div> |
| 42 | + <div className="w-[200px] flex justify-center ml-auto mr-auto mb-8 flex-col"> |
| 43 | + <img src="/my/default-profile.png" alt="Profile" width="205" className="bg-gray-200 mb-10" /> |
31 | 44 |
|
32 |
| - <div className="grid grid-cols-2 gap-4 items-center"> |
33 |
| - <label htmlFor="email" className="text-gray-700 font-bold"> |
34 |
| - Email |
35 |
| - </label> |
36 |
| - <input |
37 |
| - id="email" |
38 |
| - type="email" |
39 |
| - value={user?.email || ''} |
40 |
| - readOnly |
41 |
| - className="form-input w-full border-gray-300" |
42 |
| - /> |
| 45 | + <Button className="w-full rounded-[20px]" onClick={() => alert('업로드 버튼이 눌렸습니다.')}> |
| 46 | + 업로드 |
| 47 | + </Button> |
43 | 48 | </div>
|
44 | 49 |
|
45 |
| - <div className="grid grid-cols-2 gap-4 items-center"> |
46 |
| - <label htmlFor="password" className="text-gray-700 font-bold"> |
47 |
| - 비밀번호 |
48 |
| - </label> |
49 |
| - <input |
50 |
| - id="password" |
51 |
| - type="password" |
52 |
| - value={isLogged ? '********' : ''} |
53 |
| - readOnly |
54 |
| - className="form-input w-full border-gray-300" |
55 |
| - /> |
56 |
| - </div> |
| 50 | + <Input |
| 51 | + id="nickname" |
| 52 | + label="닉네임" |
| 53 | + defaultValue={getValues('nickname')} |
| 54 | + disabled={mode === 'view'} |
| 55 | + required={true} |
| 56 | + inputClassName={mode === 'view' ? 'text-[#959595] bg-[#F4F4F4]' : 'bg-[#F4F4F4] text-[#959595]'} |
| 57 | + {...register('nickname')} |
| 58 | + /> |
57 | 59 |
|
58 |
| - <div className="grid grid-cols-2 gap-4 items-center"> |
59 |
| - <label htmlFor="phoneNumber" className="text-gray-700 font-bold"> |
60 |
| - 전화번호 |
61 |
| - </label> |
62 |
| - <input |
63 |
| - id="phoneNumber" |
64 |
| - type="tel" |
65 |
| - value={user?.phone_num || ''} |
66 |
| - readOnly |
67 |
| - className="form-input w-full border-gray-300" |
68 |
| - /> |
69 |
| - </div> |
| 60 | + <Input |
| 61 | + defaultValue={getValues('email')} |
| 62 | + label="Email" |
| 63 | + id="email" |
| 64 | + type="email" |
| 65 | + disabled={true} |
| 66 | + inputClassName={mode === 'view' ? 'text-[#959595] bg-[#F4F4F4]' : ''} |
| 67 | + {...register('email')} |
| 68 | + /> |
| 69 | + |
| 70 | + <Input |
| 71 | + defaultValue="**********" |
| 72 | + label="비밀번호" |
| 73 | + id="password" |
| 74 | + type="password" |
| 75 | + disabled={true} |
| 76 | + inputClassName={mode === 'view' ? 'text-[#959595] bg-[#F4F4F4]' : ''} |
| 77 | + {...register('password')} |
| 78 | + /> |
70 | 79 |
|
71 |
| - <div className="h-[80px]">{}</div> |
| 80 | + <Input |
| 81 | + defaultValue={getValues('phoneNumber')} |
| 82 | + label="전화번호" |
| 83 | + id="phoneNumber" |
| 84 | + type="tel" |
| 85 | + disabled={mode === 'view'} |
| 86 | + {...register('phoneNumber')} |
| 87 | + inputClassName={mode === 'view' ? 'text-[#959595] bg-[#F4F4F4]' : 'bg-[#F4F4F4]'} |
| 88 | + placeholder="010-0000-0000" |
| 89 | + /> |
72 | 90 |
|
73 |
| - <div className="flex justify-center "> |
74 |
| - <button |
75 |
| - type="button" |
76 |
| - className="bg-black text-white py-2 px-4 rounded font-bold text-lg w-[200px]" |
77 |
| - onClick={() => router.push('/my/modify')} |
78 |
| - > |
| 91 | + <div className="mb-20 w-full h-1" /> |
| 92 | + |
| 93 | + {mode === 'modify' ? ( |
| 94 | + <div className="flex justify-evenly"> |
| 95 | + <Button className="w-full mr-8 rounded-[20px]" onClick={() => alert('수정 버튼이 눌려졌습니다.')}> |
| 96 | + 수정하기 |
| 97 | + </Button> |
| 98 | + <Button className="w-full rounded-[20px]" onClick={() => router.back()}> |
| 99 | + 취소 |
| 100 | + </Button> |
| 101 | + </div> |
| 102 | + ) : ( |
| 103 | + <Button className="w-full rounded-[20px]" onClick={() => router.push('/my/modify')}> |
79 | 104 | 개인정보 수정
|
80 |
| - </button> |
81 |
| - </div> |
| 105 | + </Button> |
| 106 | + )} |
82 | 107 | </div>
|
83 | 108 | );
|
84 | 109 | }
|
0 commit comments