-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinput-section.tsx
More file actions
76 lines (66 loc) · 1.83 KB
/
Copy pathinput-section.tsx
File metadata and controls
76 lines (66 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import Input from '@shared/components/input/input';
import * as styles from './input-section.css';
interface InputSectionProps {
name: string;
studentNum: string;
accessKey: string;
isErrorState: boolean;
onNameChange: (value: string) => void;
onStudentNumberChange: (value: string) => void;
onKeyChange: (value: string) => void;
}
const InputSection = ({
name,
studentNum,
accessKey,
isErrorState,
onNameChange,
onStudentNumberChange,
onKeyChange,
}: InputSectionProps) => {
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onNameChange(e.target.value);
};
const handleStudentNumChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
let filteredValue = value;
if (value.length <= 4) {
filteredValue = value.replace(/[^0-9]/g, '');
} else if (value.length > 4) {
const part1 = value.substring(0, 4).replace(/[^0-9]/g, '');
const part2 = value
.substring(4, 5)
.replace(/[^A-Za-z]/g, '')
.toUpperCase();
const part3 = value.substring(5, 9).replace(/[^0-9]/g, '');
filteredValue = `${part1}${part2}${part3}`;
}
onStudentNumberChange(filteredValue);
};
const handleKeyChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onKeyChange(e.target.value);
};
return (
<div className={styles.input}>
<Input
value={name}
onChange={handleNameChange}
placeholder="이름"
errorState={isErrorState}
/>
<Input
value={studentNum}
onChange={handleStudentNumChange}
placeholder="학번"
errorState={isErrorState}
/>
<Input
value={accessKey}
onChange={handleKeyChange}
placeholder="인증키"
errorState={isErrorState}
/>
</div>
);
};
export default InputSection;