'use client'; import './style.scss'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { useState, useEffect, useRef } from 'react'; import { Checkbox } from '@/components/ui/checkbox'; import { Dialog, DialogTrigger } from '@/components/ui/dialog'; import TermsDialog from '@/app/component/TermsDialog'; import { VerificationType } from '@/constants/common'; import { fetchApi } from '@/lib/utils/client'; import { RegisterRequest } from '@/types/request/auth'; import { RegisterResponse } from '@/types/response/auth'; export default function Page() { const router = useRouter(); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [rePassword, setRePassword] = useState(''); const [agree1, setAgree1] = useState(false); const [agree2, setAgree2] = useState(false); const emailRef = useRef(null); const passwordRef = useRef(null); const rePasswordRef = useRef(null); useEffect(() => { if (error) { alert(error); setError(''); } }, [error]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { if (email.length < 1) { emailRef.current?.focus(); throw new Error('이메일을 입력해주세요.'); } if (password.length < 1) { passwordRef.current?.focus(); throw new Error('비밀번호를 입력해주세요.'); } if (rePassword.length < 1) { rePasswordRef.current?.focus(); throw new Error('비밀번호 확인을 입력해주세요.'); } if (password !== rePassword) { throw new Error('비밀번호가 서로 일치하지 않습니다.'); } if (!agree1 || !agree2) { throw new Error('모든 필수 약관에 동의해주세요.'); } await new Promise(resolve => setTimeout(resolve, 500)); const res = await fetchApi('/api/auth/register', { method: 'POST', body: { Email: email, Password: password, IsPolicyAgree: agree1, IsPrivacyAgree: agree2 } as RegisterRequest }); // 시간 제한 생성 const expiration: string = (Date.now() + 10 * 60 * 1000).toString(); const callbackURL: string = location.pathname; sessionStorage.setItem('type', VerificationType.Registration.toString()); sessionStorage.setItem('expiration', expiration); sessionStorage.setItem('callbackURL', callbackURL); sessionStorage.setItem('email', email); if (res.data!.isRegisterEmailAuth) { // 이메일 인증 필요 router.push('/approval'); } else { // 회원가입 완료 router.push('/welcome'); } } catch (err) { if (err instanceof Error) { setError(err.message); } } finally { setLoading(false); } } return ( <>
회원가입
{ process.env.NEXT_PUBLIC_SITE_NAME } 에 오신 것을 환영합니다.
빠르고 간단하게 회원가입을 진행하세요.

가입 확인을 위해 유효한 이메일을 입력해주세요.
비밀번호는 최소 8자 이상 입력해주세요.
setEmail(e.target.value)} autoComplete="off" /> setPassword(e.target.value)} /> setRePassword(e.target.value)} />

회원가입 약관
원활한 서비스 이용을 위해 약관 동의가 필요합니다.
약관 내용을 자세히 확인하신 후 동의해주세요.

setAgree1(Boolean(checked))} />

이용약관 에 동의합니다.

setAgree2(Boolean(checked))} />

개인정보처리방침 에 동의합니다.

취소
); }