@@ -5,10 +5,10 @@ import BaseListItem from '../../components/listItem/baseListItem/BaseListItem';
55import Modal from '../../components/modal/Modal' ;
66import { useSelector } from 'react-redux' ;
77import { studentManageApi } from '../../api/studentManageApi' ;
8+ import axios from 'axios' ;
89
910export default function StaffStudentManage ( ) {
1011 const courseId = useSelector ( ( state ) => state . auth . user . courseId ) ;
11- console . log ( courseId ) ;
1212 const [ openModal , setOpenModal ] = useState ( false ) ;
1313 const [ students , setStudents ] = useState ( [ ] ) ;
1414 const statusMap = {
@@ -33,6 +33,60 @@ export default function StaffStudentManage() {
3333 fetchStudents ( ) ;
3434 } , [ ] ) ;
3535
36+ const [ newStudent , setNewStudent ] = useState ( {
37+ name : '' ,
38+ email : '' ,
39+ phone : '' ,
40+ tagTitle : '수강중' ,
41+ } ) ;
42+
43+ const [ errors , setErrors ] = useState ( {
44+ name : '' ,
45+ email : '' ,
46+ phone : '' ,
47+ } ) ;
48+
49+ const nameRegex = / ^ [ 가 - 힣 ] + $ / ;
50+ const emailRegex = / ^ [ a - z A - Z 0 - 9 . _ % + - ] + @ [ a - z A - Z 0 - 9 . - ] + \. [ a - z A - Z ] { 2 , } $ / ;
51+ const phoneRegex = / ^ 0 1 [ 0 - 9 ] - \d { 3 , 4 } - \d { 4 } $ / ;
52+ const BIRTHDAY_YEAR_LIST = Array . from ( { length : 50 } , ( _ , i ) => `${ i + 1980 } 년` ) ;
53+ const BIRTHDAY_MONTH_LIST = Array . from ( { length : 12 } , ( _ , i ) => `${ i + 1 } 월` ) ;
54+ const BIRTHDAY_DAY_LIST = Array . from ( { length : 31 } , ( _ , i ) => `${ i + 1 } 일` ) ;
55+
56+ const handleChange = ( e ) => {
57+ const { name, value } = e . target ;
58+
59+ let errorMessage = '' ;
60+
61+ if ( name === 'name' ) {
62+ if ( ! nameRegex . test ( value ) ) {
63+ errorMessage = '이름은 한글만 입력 가능합니다.' ;
64+ }
65+ }
66+
67+ if ( name === 'email' ) {
68+ if ( ! emailRegex . test ( value ) ) {
69+ errorMessage = '유효한 이메일 주소를 입력해주세요.' ;
70+ }
71+ }
72+
73+ if ( name === 'phone' ) {
74+ if ( ! phoneRegex . test ( value ) ) {
75+ errorMessage = '유효한 전화번호 형식(예: 010-1234-1234)을 입력해주세요.' ;
76+ }
77+ }
78+
79+ setErrors ( ( prevErrors ) => ( {
80+ ...prevErrors ,
81+ [ name ] : errorMessage ,
82+ } ) ) ;
83+
84+ setNewStudent ( ( prevState ) => ( {
85+ ...prevState ,
86+ [ name ] : value ,
87+ } ) ) ;
88+ } ;
89+
3690 const handleTagChange = ( index , newTagTitle ) => {
3791 setStudents ( ( prevStudents ) =>
3892 prevStudents . map ( ( student , i ) =>
@@ -45,22 +99,90 @@ export default function StaffStudentManage() {
4599
46100 const closeModalHandler = ( ) => setOpenModal ( false ) ;
47101
102+ // const handleChange = (e) => {
103+ // const { name, value } = e.target;
104+ // console.log(value);
105+ // console.log(name);
106+
107+ // setNewStudent((preState) => ({
108+ // ...preState,
109+ // [name]: value,
110+ // }));
111+ // };
112+
113+ const handleSubmit = async ( e ) => {
114+ e . preventDefault ( ) ;
115+ console . log ( newStudent ) ;
116+ } ;
117+
118+
119+
48120 const inputBox = (
49121 < >
50- < div className = { styles . inputContainer } >
51- < label > 이름</ label >
52- < input className = { styles . smallInputBox } placeholder = "이름을 입력해주세요." > </ input >
53- < label > 연락처</ label >
54- < input className = { styles . smallInputBox } placeholder = "연락처를 입력해주세요." > </ input >
55- < label > 생년월일</ label >
56- < div className = { styles . birthdate } >
57- < input className = { styles . smallInputBox } > </ input >
58- < input className = { styles . smallInputBox } > </ input >
59- < input className = { styles . smallInputBox } > </ input >
122+ < form onSubmit = { handleSubmit } >
123+ < div className = { styles . inputContainer } >
124+ < label > 이름</ label >
125+ < input
126+ className = { styles . smallInputBox }
127+ name = "name"
128+ type = "text"
129+ placeholder = "이름을 입력해주세요."
130+ onChange = { handleChange }
131+ content = ""
132+ > </ input >
133+ < div className = { styles . regexFont } >
134+ { errors . name && < p style = { { color : 'red' } } > { errors . name } </ p > }
135+ </ div >
136+
137+ < label > 연락처</ label >
138+ < input
139+ className = { styles . smallInputBox }
140+ name = "phone"
141+ type = "text"
142+ placeholder = "연락처를 입력해주세요."
143+ onChange = { handleChange }
144+ > </ input >
145+ < div className = { styles . regexFont } >
146+ { errors . phone && < p style = { { color : 'red' } } > { errors . phone } </ p > }
147+ </ div >
148+
149+ < label > 생년월일</ label >
150+ < div class = "info" id = "info__birth" className = { styles . birthdate } >
151+ < select className = { styles . smallInputBox } >
152+ { BIRTHDAY_YEAR_LIST . map ( ( year , index ) => (
153+ < option key = { index } > { year } </ option >
154+ ) ) }
155+ </ select >
156+ < select className = { styles . smallInputBox } >
157+ { BIRTHDAY_MONTH_LIST . map ( ( month , index ) => (
158+ < option key = { index } > { month } </ option >
159+ ) ) }
160+ </ select >
161+ < select className = { styles . smallInputBox } >
162+ { BIRTHDAY_DAY_LIST . map ( ( day , index ) => (
163+ < option key = { index } > { day } </ option >
164+ ) ) }
165+ </ select >
166+ </ div >
167+
168+ < label > 이메일</ label >
169+ < input
170+ className = { styles . smallInputBox }
171+ name = "email"
172+ type = "text"
173+ placeholder = "이메일을 입력해주세요."
174+ onChange = { handleChange }
175+ > </ input >
176+ < div className = { styles . regexFont } >
177+ { errors . email && < p style = { { color : 'red' } } > { errors . email } </ p > }
178+ </ div >
60179 </ div >
61- < label > 이메일</ label >
62- < input className = { styles . smallInputBox } placeholder = "이메일을 입력해주세요." > </ input >
63- </ div >
180+ < div className = { styles . MainButton } >
181+ < button type = "submit" className = { styles . button } >
182+ 등록
183+ </ button >
184+ </ div >
185+ </ form >
64186 </ >
65187 ) ;
66188
@@ -82,9 +204,11 @@ export default function StaffStudentManage() {
82204 />
83205 ) ) }
84206 </ div >
207+
85208 < div >
86209 < Modal
87- mainText = "등록"
210+ // mainText="등록"
211+ // mainClick={handleClick}
88212 content = { inputBox }
89213 isOpen = { openModal }
90214 onClose = { closeModalHandler }
0 commit comments