Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions src/app/(non-header)/signup/components/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,23 @@ export default function SignupForm() {
passwordConfirmation: '',
});

const hasErrors = Object.values(errors).some((msg) => msg !== '');
const isAllFilled = email && nickname && password && passwordConfirmation;
const isDisabled = !isAllFilled || hasErrors;
const validateAll = () => ({
email: validateEmail(email),
nickname: validateNickname(nickname),
password: validatePassword(password),
passwordConfirmation: validatePasswordConfirmation(
passwordConfirmation,
password,
),
});

const hasErrors = (errs: typeof errors) =>
Object.values(errs).some((msg) => msg !== '');

const isAllFilled = () =>
email && nickname && password && passwordConfirmation;

const disabled = !isAllFilled() || hasErrors(errors);

const [errorPopupOpen, setErrorPopupOpen] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
Expand All @@ -85,6 +99,22 @@ export default function SignupForm() {
}
}, [state, setUser]);

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();

const newErrors = validateAll();
setErrors(newErrors);

if (!isAllFilled() || hasErrors(newErrors)) return;

const formData = new FormData();
formData.append('email', email);
formData.append('nickname', nickname);
formData.append('password', password);

formAction(formData);
};

/**
* 카카오 회원가입 버튼 클릭 시 실행되는 함수입니다.
* 환경변수에서 리디렉션 URI와 클라이언트 ID를 읽어,
Expand Down Expand Up @@ -121,7 +151,7 @@ export default function SignupForm() {
</Link>
</div>

<form action={formAction}>
<form onSubmit={handleSubmit}>
<div className='flex flex-col gap-28'>
<Input
required
Expand Down Expand Up @@ -192,7 +222,7 @@ export default function SignupForm() {
<Button
variant='primary'
className='h-48 rounded-md'
disabled={isDisabled}
disabled={disabled}
type='submit'
>
회원가입 하기
Expand Down
1 change: 1 addition & 0 deletions src/components/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function Popup({
'text-md h-42 w-138 rounded-lg font-medium md:h-48 md:w-120 md:self-end md:text-lg',
)}
onClick={onClose}
autoFocus
>
확인
</Button>
Expand Down