Skip to content

Commit ee7df29

Browse files
authored
feat: 이름 입력 오류 처리 및 에러 모달 개선 (#358)
1 parent cf2dd4a commit ee7df29

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

src/pages/ticket/components/inpur-section/input-section.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ const InputSection = ({
2222
onKeyChange,
2323
}: InputSectionProps) => {
2424
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
25-
const { value } = e.target;
26-
const koreanOnlyValue = value.replace(/[^---·]/g, '');
27-
onNameChange(koreanOnlyValue);
25+
onNameChange(e.target.value);
2826
};
2927

3028
const handleStudentNumChange = (e: React.ChangeEvent<HTMLInputElement>) => {

src/pages/ticket/components/modal-type/error-modal.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@ import Modal from '@shared/components/modal/modal';
22

33
interface ErrorModalProps {
44
onClose: () => void;
5+
isNameError?: boolean;
56
}
67

7-
const ErrorModal = ({ onClose }: ErrorModalProps) => {
8+
const ErrorModal = ({ onClose, isNameError = false }: ErrorModalProps) => {
89
return (
910
<Modal.Content>
1011
<Modal.Body>
11-
<Modal.Title>인증키 불일치</Modal.Title>
12+
<Modal.Title>
13+
{isNameError ? '입력 정보 오류' : '인증키 불일치'}
14+
</Modal.Title>
1215
<Modal.Description>
13-
유효하지 않은 인증키 입니다.
14-
<br />
15-
다시 시도해 주세요.
16+
{isNameError ? (
17+
<>
18+
이름과 학번을 다시 확인해주세요.
19+
<br />
20+
이름은 한글만 입력 가능합니다.
21+
</>
22+
) : (
23+
<>
24+
유효하지 않은 인증키 입니다.
25+
<br />
26+
다시 시도해 주세요.
27+
</>
28+
)}
1629
</Modal.Description>
1730
</Modal.Body>
1831
<Modal.Footer>

src/pages/ticket/components/ticketmodal.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import PremiumModal from './modal-type/premium-modal';
66
import SuccessModal from './modal-type/success-modal';
77

88
interface TicketModalProps {
9-
modalType: 'confirm' | 'success' | 'error' | 'premium' | null;
9+
modalType: 'confirm' | 'success' | 'error' | 'nameError' | 'premium' | null;
1010
name: string;
1111
studentNumber: string;
1212
onClose: () => void;
@@ -41,6 +41,13 @@ const TicketModal = ({
4141
);
4242
case 'error':
4343
return <ErrorModal onClose={onClose} />;
44+
case 'nameError':
45+
return (
46+
<ErrorModal
47+
onClose={onClose}
48+
isNameError={true}
49+
/>
50+
);
4451
case 'premium':
4552
return <PremiumModal {...sharedProps} />;
4653
default:

src/pages/ticket/hooks/use-ticket-form.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ interface TicketForm {
1313
key: string;
1414
}
1515

16-
type ModalType = 'confirm' | 'success' | 'error' | 'premium' | null;
16+
type ModalType =
17+
| 'confirm'
18+
| 'success'
19+
| 'error'
20+
| 'nameError'
21+
| 'premium'
22+
| null;
1723

1824
export const useTicketForm = () => {
1925
const queryClient = useQueryClient();
@@ -40,7 +46,7 @@ export const useTicketForm = () => {
4046
TICKET_MUTATION_OPTIONS.MEMBER_LEVEL_UP(),
4147
);
4248

43-
const isErrorState = modalType === 'error';
49+
const isErrorState = modalType === 'error' || modalType === 'nameError';
4450

4551
useEffect(() => {
4652
if (memberRaffleProfile?.result) {
@@ -81,11 +87,18 @@ export const useTicketForm = () => {
8187

8288
const handleConfirm = useCallback(async () => {
8389
try {
90+
// 한글 이름 유효성 검사
91+
const koreanNameRegex = /^[---\s]+$/;
92+
if (!koreanNameRegex.test(form.name.trim())) {
93+
setModalType('nameError');
94+
return;
95+
}
96+
8497
// UI level을 서버 level로 변환 (UI level과 동일)
8598
const serverLevel = selectedLevel;
8699

87100
const response = await levelUpMutation.mutateAsync({
88-
name: form.name,
101+
name: form.name.trim(),
89102
studentId: form.studentNum,
90103
authenticationKey: form.key,
91104
level: serverLevel,
@@ -99,7 +112,7 @@ export const useTicketForm = () => {
99112
// Lv.3 응모 시 자동으로 Lv.4도 응모
100113
if (selectedLevel === 3) {
101114
await levelUpMutation.mutateAsync({
102-
name: form.name,
115+
name: form.name.trim(),
103116
studentId: form.studentNum,
104117
authenticationKey: form.key,
105118
level: 4, // Lv.4

0 commit comments

Comments
 (0)