박권수

feat. 의사 회원가입시, 면허증 등록으로 변경 완료

1 -import React, { useState, useEffect } from "react"; 1 +import React, { useState, useEffect, useRef } from "react";
2 import { RouteComponentProps } from 'react-router-dom'; 2 import { RouteComponentProps } from 'react-router-dom';
3 3
4 import { useRecoilValue, useRecoilState } from "recoil"; 4 import { useRecoilValue, useRecoilState } from "recoil";
...@@ -26,7 +26,6 @@ const RegisterContainer = (props : RegisterProps) => { ...@@ -26,7 +26,6 @@ const RegisterContainer = (props : RegisterProps) => {
26 password : '', 26 password : '',
27 passwordCheck : '', 27 passwordCheck : '',
28 info : { 28 info : {
29 - doctorLicense : File,
30 hospitalNm : '', 29 hospitalNm : '',
31 hospitalAddr : '', 30 hospitalAddr : '',
32 contact : '', 31 contact : '',
...@@ -34,6 +33,8 @@ const RegisterContainer = (props : RegisterProps) => { ...@@ -34,6 +33,8 @@ const RegisterContainer = (props : RegisterProps) => {
34 doctorNm : '', 33 doctorNm : '',
35 }, 34 },
36 }); 35 });
36 + const [doctorInfoFile, setDoctorInfoFile] = useState<FileList | null>(null);
37 + const doctorInfoFile_Select = useRef(null);
37 38
38 const [page, setPage] = useState<number>(1); 39 const [page, setPage] = useState<number>(1);
39 const [error, setError] = useState<string | null>(null); 40 const [error, setError] = useState<string | null>(null);
...@@ -79,9 +80,8 @@ const RegisterContainer = (props : RegisterProps) => { ...@@ -79,9 +80,8 @@ const RegisterContainer = (props : RegisterProps) => {
79 setError('비밀번호가 일치하지 않습니다.') 80 setError('비밀번호가 일치하지 않습니다.')
80 } else setError(null); 81 } else setError(null);
81 } else if(page === 2) { 82 } else if(page === 2) {
82 - if(!registerForm.info.doctorLicense.length && 83 + if(!doctorInfoFile) {
83 - !validator.isAlphanumeric(registerForm.info.doctorLicense)) { 84 + setError('의사 자격 인증 파일을 첨부해야 합니다.');
84 - setError('의사 자격 번호를 입력해야 합니다.');
85 } else if(registerForm.info.doctorNm.length < 2) { 85 } else if(registerForm.info.doctorNm.length < 2) {
86 setError('의사 이름을 올바르게 입력해야 합니다.'); 86 setError('의사 이름을 올바르게 입력해야 합니다.');
87 } else if(!registerForm.info.contact) { 87 } else if(!registerForm.info.contact) {
...@@ -121,13 +121,7 @@ const RegisterContainer = (props : RegisterProps) => { ...@@ -121,13 +121,7 @@ const RegisterContainer = (props : RegisterProps) => {
121 }; 121 };
122 122
123 const onSetDoctorLicense = (e : React.ChangeEvent<HTMLInputElement>) => { 123 const onSetDoctorLicense = (e : React.ChangeEvent<HTMLInputElement>) => {
124 - setRegisterForm({ 124 + setDoctorInfoFile(e.target.files);
125 - ...registerForm,
126 - info : {
127 - ...registerForm.info,
128 - doctorLicense : e.target.value,
129 - },
130 - });
131 }; 125 };
132 126
133 const onSetHospitalNm = (e : React.ChangeEvent<HTMLInputElement>) => { 127 const onSetHospitalNm = (e : React.ChangeEvent<HTMLInputElement>) => {
...@@ -237,16 +231,21 @@ const RegisterContainer = (props : RegisterProps) => { ...@@ -237,16 +231,21 @@ const RegisterContainer = (props : RegisterProps) => {
237 Data.append('doctorNm', registerForm.info.doctorNm); 231 Data.append('doctorNm', registerForm.info.doctorNm);
238 Data.append('doctorType', registerForm.info.doctorType); 232 Data.append('doctorType', registerForm.info.doctorType);
239 233
240 - Data.append('doctorInfoFile', registerForm.info.doctorLicense[0]); 234 + Data.append('doctorInfoFile', doctorInfoFile ? doctorInfoFile[0] : '');
241 235
242 236
243 const onRegisterDoctor = async () => { 237 const onRegisterDoctor = async () => {
238 + //로딩 진행
239 + setLoading(true);
240 +
244 try { 241 try {
245 const result = await authApi.registerDoctor(Data); 242 const result = await authApi.registerDoctor(Data);
246 if(result.data === 'Created') { 243 if(result.data === 'Created') {
244 + setLoading(false);
247 Alert.onSuccess('회원가입 성공, 관리자의 승인을 대기하세요.', () => props.history.push('/login')); 245 Alert.onSuccess('회원가입 성공, 관리자의 승인을 대기하세요.', () => props.history.push('/login'));
248 } 246 }
249 } catch(e : any) { 247 } catch(e : any) {
248 + setLoading(false);
250 Alert.onError(e.response.data.error, () => null); 249 Alert.onError(e.response.data.error, () => null);
251 } 250 }
252 }; 251 };
...@@ -265,7 +264,7 @@ const RegisterContainer = (props : RegisterProps) => { ...@@ -265,7 +264,7 @@ const RegisterContainer = (props : RegisterProps) => {
265 264
266 useEffect(() => { 265 useEffect(() => {
267 validateRegisterForm(); 266 validateRegisterForm();
268 - }, [registerForm, page]); 267 + }, [registerForm, doctorInfoFile, page]);
269 268
270 useEffect(() => { 269 useEffect(() => {
271 if(selectHospital) { 270 if(selectHospital) {
...@@ -306,6 +305,8 @@ const RegisterContainer = (props : RegisterProps) => { ...@@ -306,6 +305,8 @@ const RegisterContainer = (props : RegisterProps) => {
306 <Header {...props}/> 305 <Header {...props}/>
307 <RegisterPresenter 306 <RegisterPresenter
308 registerForm = {registerForm} 307 registerForm = {registerForm}
308 + doctorInfoFile = {doctorInfoFile}
309 + doctorInfoFile_Select = {doctorInfoFile_Select}
309 page = {page} 310 page = {page}
310 error = {error} 311 error = {error}
311 312
......
...@@ -10,13 +10,13 @@ const uncheck = '/static/img/uncheck.png' ...@@ -10,13 +10,13 @@ const uncheck = '/static/img/uncheck.png'
10 const next = '/static/img/next.png'; 10 const next = '/static/img/next.png';
11 const prev = '/static/img/prev.png'; 11 const prev = '/static/img/prev.png';
12 12
13 +
13 interface RegisterProps { 14 interface RegisterProps {
14 registerForm : { 15 registerForm : {
15 userId : string; 16 userId : string;
16 password : string; 17 password : string;
17 passwordCheck : string; 18 passwordCheck : string;
18 info : { 19 info : {
19 - doctorLicense : string;
20 hospitalNm : string; 20 hospitalNm : string;
21 hospitalAddr : string; 21 hospitalAddr : string;
22 contact : string; 22 contact : string;
...@@ -24,6 +24,8 @@ interface RegisterProps { ...@@ -24,6 +24,8 @@ interface RegisterProps {
24 doctorNm : string; 24 doctorNm : string;
25 }, 25 },
26 }; 26 };
27 + doctorInfoFile : FileList | null;
28 + doctorInfoFile_Select : any;
27 page : number; 29 page : number;
28 error : string | null; 30 error : string | null;
29 31
...@@ -148,8 +150,7 @@ const RegisterPresenter = (props : RegisterProps) => { ...@@ -148,8 +150,7 @@ const RegisterPresenter = (props : RegisterProps) => {
148 </styled.ModalButton> 150 </styled.ModalButton>
149 </styled.ModalButtonWrapper> 151 </styled.ModalButtonWrapper>
150 </> 152 </>
151 - </Modal> 153 + </Modal> : null
152 - :null
153 } 154 }
154 <styled.RegisterWrapper> 155 <styled.RegisterWrapper>
155 <styled.RegisterBackButtonWrapper> 156 <styled.RegisterBackButtonWrapper>
...@@ -204,11 +205,19 @@ const RegisterPresenter = (props : RegisterProps) => { ...@@ -204,11 +205,19 @@ const RegisterPresenter = (props : RegisterProps) => {
204 <> 205 <>
205 <styled.RegisterInputWrapper> 206 <styled.RegisterInputWrapper>
206 <styled.RegisterInputText>의사 자격증 번호</styled.RegisterInputText> 207 <styled.RegisterInputText>의사 자격증 번호</styled.RegisterInputText>
207 - <styled.RegisterInput 208 + <input type = 'file'
208 - placeholder = "Doctor's License" 209 + style = {{ display : 'none' }}
209 - value = {props.registerForm.info.doctorLicense}
210 onChange = {props.onSetDoctorLicense} 210 onChange = {props.onSetDoctorLicense}
211 + ref = {props.doctorInfoFile_Select}
211 /> 212 />
213 + <styled.RegisterFileUploadWrapper>
214 + <styled.RegisterFileUploadButton onClick = {() => props.doctorInfoFile_Select.current.click()}>
215 + 파일 첨부
216 + </styled.RegisterFileUploadButton>
217 + <styled.RegisterFileUploadInfoText>
218 + {props.doctorInfoFile ? props.doctorInfoFile[0].name : ''}
219 + </styled.RegisterFileUploadInfoText>
220 + </styled.RegisterFileUploadWrapper>
212 </styled.RegisterInputWrapper> 221 </styled.RegisterInputWrapper>
213 <styled.RegisterInputWrapper> 222 <styled.RegisterInputWrapper>
214 <styled.RegisterInputText>이름</styled.RegisterInputText> 223 <styled.RegisterInputText>이름</styled.RegisterInputText>
......
...@@ -314,6 +314,55 @@ export const RegisterInput = styled.input ` ...@@ -314,6 +314,55 @@ export const RegisterInput = styled.input `
314 } 314 }
315 `; 315 `;
316 316
317 +export const RegisterFileUploadWrapper = styled.div `
318 + width : 80%;
319 + display : flex;
320 + flex-direction : row;
321 +
322 + justify-content : flex-start;
323 + align-items : center;
324 +
325 + border : none;
326 + background-color : transparent;
327 +`;
328 +
329 +export const RegisterFileUploadButton = styled.button `
330 + display : flex;
331 + flex-direction : row;
332 +
333 + justify-content : center;
334 + align-items : center;
335 +
336 + border-radius : 3px;
337 + border : 1px solid #343434;
338 + background-color : transparent;
339 + color : #343434;
340 +
341 + padding : 3px 4px;
342 +
343 + font-size : 12px;
344 + font-weight : 600;
345 +
346 + cursor : pointer;
347 + transition : .25s all;
348 +
349 + &:hover {
350 + border : 1px solid #337DFF;
351 + color : #fff;
352 + background-color : #337DFF;
353 + }
354 +
355 + margin : 0 5% 0 0;
356 +
357 +`;
358 +
359 +export const RegisterFileUploadInfoText = styled.div `
360 + font-size : 12px;
361 + font-weight : 600;
362 +
363 + color : #337DFF;
364 +`;
365 +
317 export const RegisterInputSearchButton = styled.button ` 366 export const RegisterInputSearchButton = styled.button `
318 position : absolute; 367 position : absolute;
319 368
......