|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useAuth } from "@/hooks/useAuth"; |
| 4 | +import { type SignupSchema, signupSchema } from "@/schemas/authSchema"; |
| 5 | +import { userRoles } from "@/constants/userRoles"; |
| 6 | +import { zodResolver } from "@hookform/resolvers/zod"; |
| 7 | +import Link from "next/link"; |
| 8 | +import { useForm } from "react-hook-form"; |
| 9 | +import Image from "next/image"; |
| 10 | + |
| 11 | +export default function OwnerSignupPage() { |
| 12 | + const { signup, isSignupPending } = useAuth(); |
| 13 | + const { |
| 14 | + register, |
| 15 | + handleSubmit, |
| 16 | + formState: { errors }, |
| 17 | + } = useForm<SignupSchema>({ |
| 18 | + resolver: zodResolver(signupSchema), |
| 19 | + defaultValues: { |
| 20 | + role: userRoles.OWNER, |
| 21 | + storeName: "", |
| 22 | + storePhoneNumber: "", |
| 23 | + location: "", |
| 24 | + }, |
| 25 | + mode: "all", |
| 26 | + }); |
| 27 | + |
| 28 | + const onSubmit = (data: SignupSchema) => { |
| 29 | + signup(data); |
| 30 | + }; |
| 31 | + |
| 32 | + return ( |
| 33 | + <div className="flex min-h-screen items-center justify-center bg-gradient-to-r from-lime-200 to-lime-300 px-4 py-12 sm:px-6 lg:px-8"> |
| 34 | + <div className="w-full max-w-md space-y-8 rounded-lg bg-white p-8 shadow-lg"> |
| 35 | + <div> |
| 36 | + <h2 className="text-center text-3xl font-bold tracking-tight text-gray-900">사장님 회원가입</h2> |
| 37 | + <p className="mt-2 text-center text-sm text-gray-600"> |
| 38 | + 이미 계정이 있으신가요?{" "} |
| 39 | + <Link href="/login" className="font-medium text-lime-600 hover:text-lime-500"> |
| 40 | + 로그인하기 |
| 41 | + </Link> |
| 42 | + </p> |
| 43 | + </div> |
| 44 | + <form className="mt-8 space-y-6" onSubmit={handleSubmit(onSubmit)} noValidate> |
| 45 | + <div className="space-y-4 rounded-md"> |
| 46 | + <input type="hidden" {...register("role")} value={userRoles.OWNER} /> |
| 47 | + <div> |
| 48 | + <input |
| 49 | + {...register("email")} |
| 50 | + type="email" |
| 51 | + className="relative block w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:border-lime-500 focus:outline-none focus:ring-lime-500 sm:text-sm" |
| 52 | + placeholder="이메일" |
| 53 | + /> |
| 54 | + {errors.email && <p className="mt-1 text-sm text-red-600">{errors.email.message}</p>} |
| 55 | + </div> |
| 56 | + <div> |
| 57 | + <input |
| 58 | + {...register("name")} |
| 59 | + type="text" |
| 60 | + className="relative block w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:border-lime-500 focus:outline-none focus:ring-lime-500 sm:text-sm" |
| 61 | + placeholder="이름" |
| 62 | + /> |
| 63 | + {errors.name && <p className="mt-1 text-sm text-red-600">{errors.name.message}</p>} |
| 64 | + </div> |
| 65 | + <div> |
| 66 | + <input |
| 67 | + {...register("nickname")} |
| 68 | + type="text" |
| 69 | + className="relative block w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:border-lime-500 focus:outline-none focus:ring-lime-500 sm:text-sm" |
| 70 | + placeholder="닉네임" |
| 71 | + /> |
| 72 | + {errors.nickname && <p className="mt-1 text-sm text-red-600">{errors.nickname.message}</p>} |
| 73 | + </div> |
| 74 | + <div> |
| 75 | + <input |
| 76 | + {...register("password")} |
| 77 | + type="password" |
| 78 | + className="relative block w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:border-lime-500 focus:outline-none focus:ring-lime-500 sm:text-sm" |
| 79 | + placeholder="비밀번호" |
| 80 | + /> |
| 81 | + {errors.password && <p className="mt-1 text-sm text-red-600">{errors.password.message}</p>} |
| 82 | + </div> |
| 83 | + <div> |
| 84 | + <input |
| 85 | + {...register("confirmPassword")} |
| 86 | + type="password" |
| 87 | + className="relative block w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:border-lime-500 focus:outline-none focus:ring-lime-500 sm:text-sm" |
| 88 | + placeholder="비밀번호 확인" |
| 89 | + /> |
| 90 | + {errors.confirmPassword && <p className="mt-1 text-sm text-red-600">{errors.confirmPassword.message}</p>} |
| 91 | + </div> |
| 92 | + <div> |
| 93 | + <input |
| 94 | + {...register("storeName")} |
| 95 | + type="text" |
| 96 | + className="relative block w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:border-lime-500 focus:outline-none focus:ring-lime-500 sm:text-sm" |
| 97 | + placeholder="가게 이름" |
| 98 | + /> |
| 99 | + {errors.storeName && <p className="mt-1 text-sm text-red-600">{errors.storeName.message}</p>} |
| 100 | + </div> |
| 101 | + <div> |
| 102 | + <input |
| 103 | + {...register("storePhoneNumber")} |
| 104 | + type="tel" |
| 105 | + className="relative block w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:border-lime-500 focus:outline-none focus:ring-lime-500 sm:text-sm" |
| 106 | + placeholder="가게 전화번호 (예: 02-1234-5678)" |
| 107 | + /> |
| 108 | + {errors.storePhoneNumber && ( |
| 109 | + <p className="mt-1 text-sm text-red-600">{errors.storePhoneNumber.message}</p> |
| 110 | + )} |
| 111 | + </div> |
| 112 | + <div> |
| 113 | + <input |
| 114 | + {...register("location")} |
| 115 | + type="text" |
| 116 | + className="relative block w-full rounded-lg border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:border-lime-500 focus:outline-none focus:ring-lime-500 sm:text-sm" |
| 117 | + placeholder="가게 위치" |
| 118 | + /> |
| 119 | + {errors.location && <p className="mt-1 text-sm text-red-600">{errors.location.message}</p>} |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + <div> |
| 123 | + <button |
| 124 | + type="submit" |
| 125 | + disabled={isSignupPending} |
| 126 | + className="group relative flex w-full justify-center rounded-lg bg-lime-600 px-4 py-2 text-sm font-medium text-white hover:bg-lime-700 focus:outline-none focus:ring-2 focus:ring-lime-500 focus:ring-offset-2 disabled:bg-lime-300" |
| 127 | + > |
| 128 | + {isSignupPending ? "회원가입 중..." : "회원가입"} |
| 129 | + </button> |
| 130 | + </div> |
| 131 | + <div className="flex justify-center space-x-4"> |
| 132 | + <button> |
| 133 | + <Image src="/icons/social/social_google.svg" width={72} height={72} alt="구글 로그인" /> |
| 134 | + </button> |
| 135 | + <Link |
| 136 | + href={`https://kauth.kakao.com/oauth/authorize?client_id=${process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY}&redirect_uri=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI}&response_type=code`} |
| 137 | + > |
| 138 | + <Image src="/icons/social/social_kakao.svg" width={72} height={72} alt="카카오 로그인" /> |
| 139 | + </Link> |
| 140 | + </div> |
| 141 | + </form> |
| 142 | + </div> |
| 143 | + </div> |
| 144 | + ); |
| 145 | +} |
0 commit comments