|
| 1 | +import { useAtomValue, useSetAtom } from 'jotai'; |
| 2 | +import { useForm } from 'react-hook-form'; |
| 3 | + |
| 4 | +import { userEmailAtom, userModeAtom } from '@/shared/atom'; |
| 5 | +import { Button, Input } from '@/shared/ui'; |
| 6 | +import type { User } from '@/shared/types'; |
| 7 | +import { useUserJoin } from '../api'; |
| 8 | + |
| 9 | +export default function JoinForm() { |
| 10 | + const setUserMode = useSetAtom(userModeAtom); |
| 11 | + const { kakaoEmail } = useAtomValue(userEmailAtom); |
| 12 | + const { mutate } = useUserJoin(); |
| 13 | + const { register, handleSubmit } = useForm<User>({ |
| 14 | + defaultValues: { |
| 15 | + kakaoEmail: kakaoEmail, |
| 16 | + name: '', |
| 17 | + collegeMajorName: '컴퓨터공학전공', |
| 18 | + studentEmail: 'faker@kyonggi.ac.kr', |
| 19 | + walletAddress: '0x1234abcd5678', |
| 20 | + keyId: 'kas-key-id', |
| 21 | + krn: 'krn:1001:abcd', |
| 22 | + }, |
| 23 | + }); |
| 24 | + |
| 25 | + return ( |
| 26 | + <form |
| 27 | + className="flex flex-col gap-y-12" |
| 28 | + onSubmit={handleSubmit(data => { |
| 29 | + mutate({ data }); |
| 30 | + })} |
| 31 | + > |
| 32 | + <div className="w-full space-y-3"> |
| 33 | + <Input |
| 34 | + intent="login" |
| 35 | + placeholder="이름" |
| 36 | + {...register('name', { required: true })} |
| 37 | + /> |
| 38 | + <Input intent="login" placeholder="비밀번호" type="password" /> |
| 39 | + </div> |
| 40 | + <div className="space-y-3"> |
| 41 | + <div className="flex items-center gap-3"> |
| 42 | + <div className="bg-s h-[0.5px] flex-1" /> |
| 43 | + <span className="text-s text-sm">가입 방식</span> |
| 44 | + <div className="bg-s h-[0.5px] flex-1" /> |
| 45 | + </div> |
| 46 | + <Button |
| 47 | + intent="login" |
| 48 | + className="py-[14px] text-lg" |
| 49 | + type="submit" |
| 50 | + onClick={() => { |
| 51 | + setUserMode({ mode: 'STUDENT' as const }); |
| 52 | + }} |
| 53 | + > |
| 54 | + 학생으로 시작하기 |
| 55 | + </Button> |
| 56 | + <Button |
| 57 | + intent="loginWhite" |
| 58 | + className="py-[14px] text-lg" |
| 59 | + type="submit" |
| 60 | + onClick={() => { |
| 61 | + setUserMode({ mode: 'ADMIN' as const }); |
| 62 | + }} |
| 63 | + > |
| 64 | + 관리자로 시작하기 |
| 65 | + </Button> |
| 66 | + </div> |
| 67 | + </form> |
| 68 | + ); |
| 69 | +} |
0 commit comments