|
| 1 | +import { zodResolver } from '@hookform/resolvers/zod'; |
| 2 | +import pictureIcon from '@shared/assets/icons/common/picture.svg'; |
| 3 | +import logo from '@shared/assets/logo/logo.svg'; |
| 4 | +import { Button } from '@shared/ui/Button/Button'; |
| 5 | +import { Profile } from '@shared/ui/Profile'; |
| 6 | +import { DateField } from '@shared/ui/TextField'; |
| 7 | +import { TextField } from '@shared/ui/TextField/TextField'; |
| 8 | +import { signupSchema, type SignupFormData } from '@shared/utils/schemas'; |
| 9 | +import { useEffect, useRef, useState } from 'react'; |
| 10 | +import { useForm } from 'react-hook-form'; |
| 11 | +import { signupStyles } from './SignupPage.styles'; |
| 12 | +export default function SignupPage() { |
| 13 | + const [profileImage, setProfileImage] = useState<string | undefined>(); |
| 14 | + const fileInputRef = useRef<HTMLInputElement>(null); |
| 15 | + const { |
| 16 | + register, |
| 17 | + handleSubmit, |
| 18 | + formState: { errors }, |
| 19 | + } = useForm<SignupFormData>({ resolver: zodResolver(signupSchema) }); |
| 20 | + const onSubmit = (data: SignupFormData) => { |
| 21 | + void data; |
| 22 | + }; |
| 23 | + const handleSelectImage = () => { |
| 24 | + fileInputRef.current?.click(); |
| 25 | + }; |
| 26 | + const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => { |
| 27 | + const file = e.target.files?.[0]; |
| 28 | + if (!file) { |
| 29 | + return; |
| 30 | + } |
| 31 | + if (profileImage) { |
| 32 | + URL.revokeObjectURL(profileImage); |
| 33 | + } |
| 34 | + const imageUrl = URL.createObjectURL(file); |
| 35 | + setProfileImage(imageUrl); |
| 36 | + }; |
| 37 | + useEffect(() => { |
| 38 | + return () => { |
| 39 | + if (profileImage) { |
| 40 | + URL.revokeObjectURL(profileImage); |
| 41 | + } |
| 42 | + }; |
| 43 | + }, [profileImage]); |
| 44 | + return ( |
| 45 | + <form onSubmit={handleSubmit(onSubmit)} className={signupStyles.form}> |
| 46 | + {' '} |
| 47 | + <div className="flex w-full max-w-[1440px] flex-col items-center px-6 pb-24 md:px-[120px] md:pb-[258px]"> |
| 48 | + {' '} |
| 49 | + {/* ํค๋ */}{' '} |
| 50 | + <section className="flex w-full flex-col items-center gap-[10px] bg-green-50 px-6 py-10 md:px-[309px] md:py-[61px]"> |
| 51 | + {' '} |
| 52 | + <header className="flex flex-col items-center gap-[16px] md:flex-row md:gap-[35px]"> |
| 53 | + {' '} |
| 54 | + <img src={logo} alt="LOOPIT Logo" className="h-[36px] w-[192px]" />{' '} |
| 55 | + <div className="flex flex-col gap-[8px]"> |
| 56 | + {' '} |
| 57 | + <h1 className="typo-title-3 text-black">ํ์๊ฐ์
</h1>{' '} |
| 58 | + <p className="typo-body-1 text-black">๋ฃจํ ๊ฐ์
์ ์ํด ํ์๋ ์ ๋ณด๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.</p>{' '} |
| 59 | + </div>{' '} |
| 60 | + </header>{' '} |
| 61 | + </section>{' '} |
| 62 | + {/* ์ฝํ
์ธ */}{' '} |
| 63 | + <section className="mt-[80px] w-full"> |
| 64 | + {' '} |
| 65 | + <div className="flex w-full flex-col items-start gap-[67px] md:w-[1200px]"> |
| 66 | + {' '} |
| 67 | + {/* ํ๋กํ ์ฌ์ง */} |
| 68 | + <section className="flex h-[214px] w-full flex-col gap-[16px]"> |
| 69 | + <span className={signupStyles.sectionLabel}>ํ๋กํ ์ฌ์ง</span> |
| 70 | + <div className="flex w-full justify-center"> |
| 71 | + <button |
| 72 | + type="button" |
| 73 | + className="relative h-[182px] w-[182px] cursor-pointer" |
| 74 | + onClick={handleSelectImage} |
| 75 | + > |
| 76 | + <Profile size="lg" image={profileImage} className="h-[182px] w-[182px]" /> |
| 77 | + <div className="absolute right-0 bottom-0 flex h-[40px] w-[40px] items-center justify-center rounded-full border border-[var(--color-gray-300)] bg-white"> |
| 78 | + <img src={pictureIcon} alt="์ฌ์ง ์ ํ" className="h-[40px] w-[40px]" /> |
| 79 | + </div> |
| 80 | + <input |
| 81 | + ref={fileInputRef} |
| 82 | + type="file" |
| 83 | + accept="image/*" |
| 84 | + className="hidden" |
| 85 | + onChange={handleImageChange} |
| 86 | + /> |
| 87 | + </button> |
| 88 | + </div> |
| 89 | + </section> |
| 90 | + {/* ์ด๋ฉ์ผ */}{' '} |
| 91 | + <section className="flex w-full flex-col gap-[16px]"> |
| 92 | + {' '} |
| 93 | + <span className={signupStyles.sectionLabel}>์ด๋ฉ์ผ</span>{' '} |
| 94 | + <TextField |
| 95 | + placeholder="์ด๋ฉ์ผ์ ์
๋ ฅํด์ฃผ์ธ์" |
| 96 | + {...register('email')} |
| 97 | + error={Boolean(errors.email)} |
| 98 | + helperText={errors.email?.message} |
| 99 | + />{' '} |
| 100 | + </section>{' '} |
| 101 | + {/* ์ด๋ฆ */}{' '} |
| 102 | + <section className="flex w-full flex-col gap-[16px]"> |
| 103 | + {' '} |
| 104 | + <span className={signupStyles.sectionLabel}>์ด๋ฆ</span>{' '} |
| 105 | + <TextField |
| 106 | + placeholder="์ด๋ฆ์ ์
๋ ฅํด์ฃผ์ธ์" |
| 107 | + {...register('name')} |
| 108 | + error={Boolean(errors.name)} |
| 109 | + helperText={errors.name?.message} |
| 110 | + />{' '} |
| 111 | + </section>{' '} |
| 112 | + {/* ์๋
์์ผ */}{' '} |
| 113 | + <section className="flex w-full flex-col gap-[16px]"> |
| 114 | + {' '} |
| 115 | + <span className={signupStyles.sectionLabel}>์๋
์์ผ</span>{' '} |
| 116 | + <DateField |
| 117 | + {...register('birthDate')} |
| 118 | + error={Boolean(errors.birthDate)} |
| 119 | + helperText={errors.birthDate?.message} |
| 120 | + />{' '} |
| 121 | + </section>{' '} |
| 122 | + {/* ๋๋ค์ */}{' '} |
| 123 | + <section className="flex w-full flex-col gap-[16px]"> |
| 124 | + {' '} |
| 125 | + <span className={signupStyles.sectionLabel}>๋๋ค์</span>{' '} |
| 126 | + <TextField |
| 127 | + placeholder="2~20์์ ๋๋ค์" |
| 128 | + {...register('nickname')} |
| 129 | + error={Boolean(errors.nickname)} |
| 130 | + helperText={errors.nickname?.message} |
| 131 | + />{' '} |
| 132 | + </section>{' '} |
| 133 | + </div>{' '} |
| 134 | + </section>{' '} |
| 135 | + {/* ํ์๊ฐ์
๋ฒํผ */}{' '} |
| 136 | + <section className="mt-[127px] flex w-full justify-center md:justify-end"> |
| 137 | + {' '} |
| 138 | + <Button variant="fill" size="auto" className="w-full max-w-[286px]" type="submit"> |
| 139 | + {' '} |
| 140 | + ํ์๊ฐ์
์๋ฃ{' '} |
| 141 | + </Button>{' '} |
| 142 | + </section>{' '} |
| 143 | + </div>{' '} |
| 144 | + </form> |
| 145 | + ); |
| 146 | +} |
0 commit comments