Skip to content
Open
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
1 change: 1 addition & 0 deletions src/components/recruit/RecruitBasicInfoSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function RecruitBasicInfoSection({ title, form, errors, hasSubmitted, onC
value={form.name}
onChange={onChange}
required
maxLength={8}
inputClassName="w-full max-w-[617px]"
error={hasSubmitted ? errors.name : ''}
/>
Expand Down
37 changes: 37 additions & 0 deletions src/pages/visitor/RecruitPage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useEffect } from 'react';

import { RecruitApplyInfoSection } from '@/components/recruit/RecruitApplyInfoSection';
import { RecruitBasicInfoSection } from '@/components/recruit/RecruitBasicInfoSection';
import { RecruitConfirmModal } from '@/components/recruit/RecruitConfirmModal';
import { RecruitPrivacyAgreementSection } from '@/components/recruit/RecruitPrivacyAgreementSection';
import { useRecruitForm } from '@/hooks/useRecruitForm';
import { ROUTES } from '@/constants/routes';

const TEXT = {
titleAccent: '신입 부원',
Expand All @@ -16,6 +19,9 @@ const TEXT = {

const majorOptions = ['응용소프트웨어공학과'];

const LEAVE_CONFIRM_MESSAGE =
'입력하신 정보는 저장되지 않습니다.\n페이지를 이동하시겠습니까?';

function RecruitPage() {
const {
form,
Expand All @@ -30,6 +36,37 @@ function RecruitPage() {
closeConfirm,
} = useRecruitForm();

const isDirty = Object.values(form).some((value) => value !== '');

useEffect(() => {
if (!isDirty) return;

const handleLeavePage = (event) => {
const link = event.target.closest('a[href]');

if (!link || link.pathname === ROUTES.RECRUIT || link.pathname === ROUTES.RECRUIT_COMPLETE) {
return;
}

if (!window.confirm(LEAVE_CONFIRM_MESSAGE)) {
event.preventDefault();
}
};

const handleBeforeUnload = (event) => {
event.preventDefault();
event.returnValue = '';
};

document.addEventListener('click', handleLeavePage, true);
window.addEventListener('beforeunload', handleBeforeUnload);

return () => {
document.removeEventListener('click', handleLeavePage, true);
window.removeEventListener('beforeunload', handleBeforeUnload);
};
}, [isDirty]);

return (
<section className="min-h-screen min-w-[320px] bg-brand-soft px-4 py-10 sm:px-8">
<div className="mx-auto w-full max-w-[1253px]">
Expand Down