Showing
8 changed files
with
177 additions
and
16 deletions
1 | import { client } from './client'; | 1 | import { client } from './client'; |
2 | +import { RecoilState } from 'recoil'; | ||
2 | 3 | ||
3 | export default { | 4 | export default { |
4 | - | 5 | + getDoctorRegReqList : (token : RecoilState<any>) => { |
6 | + return client.get('/manage/doctor', { | ||
7 | + headers : { | ||
8 | + Authorization : token, | ||
9 | + }, | ||
10 | + }); | ||
11 | + }, | ||
12 | + getDoctorRegReqDetail : (token : RecoilState<any>, doctorId : string) => { | ||
13 | + return client.get(`/manage/doctor/${doctorId}`, { | ||
14 | + headers : { | ||
15 | + Authorization : token, | ||
16 | + }, | ||
17 | + }); | ||
18 | + }, | ||
19 | + acceotDoctorRegReq : (token : RecoilState<any>, Data : FormData) => { | ||
20 | + return client.post('/manage/doctor/accept', Data, { | ||
21 | + headers : { | ||
22 | + Authorization : token, | ||
23 | + }, | ||
24 | + }); | ||
25 | + }, | ||
26 | + rejectDoctorRegReq : (token : RecoilState<any>, Data : FormData) => { | ||
27 | + return client.post('/manage/doctor/reject', Data, { | ||
28 | + headers : { | ||
29 | + Authorization : token, | ||
30 | + }, | ||
31 | + }); | ||
32 | + }, | ||
5 | }; | 33 | }; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | import axios, { AxiosInstance } from 'axios'; | 1 | import axios, { AxiosInstance } from 'axios'; |
2 | - | 2 | +import { baseURL } from '../config/config'; |
3 | -require('dotenv').config(); | ||
4 | -const { BASE_URL } = process.env; | ||
5 | 3 | ||
6 | export const client : AxiosInstance = axios.create({ | 4 | export const client : AxiosInstance = axios.create({ |
7 | - baseURL : BASE_URL, | 5 | + baseURL, |
8 | headers: { | 6 | headers: { |
9 | 'Content-Type': 'application/json', | 7 | 'Content-Type': 'application/json', |
10 | 'Access-Control-Allow-Origin': '*', | 8 | 'Access-Control-Allow-Origin': '*', |
... | @@ -20,6 +18,7 @@ client.interceptors.response.use( | ... | @@ -20,6 +18,7 @@ client.interceptors.response.use( |
20 | return response; | 18 | return response; |
21 | }, | 19 | }, |
22 | function (error) { | 20 | function (error) { |
21 | + console.log(error); | ||
23 | return error; | 22 | return error; |
24 | } | 23 | } |
25 | ); | 24 | ); | ... | ... |
web/src/config/config.ts
0 → 100644
1 | +export const baseURL = 'http://localhost:4000/api'; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | import React, { useState, useEffect } from 'react'; | 1 | import React, { useState, useEffect } from 'react'; |
2 | import { RouteComponentProps } from 'react-router-dom'; | 2 | import { RouteComponentProps } from 'react-router-dom'; |
3 | 3 | ||
4 | +import { useRecoilState } from 'recoil'; | ||
5 | +import * as recoilUtil from '../../util/recoilUtil'; | ||
6 | + | ||
4 | import LoginPresenter from './LoginPresenter'; | 7 | import LoginPresenter from './LoginPresenter'; |
5 | 8 | ||
6 | -import { authApi } from 'api'; | 9 | +import { authApi } from '../../api'; |
10 | + | ||
7 | 11 | ||
8 | type LoginProps = RouteComponentProps | 12 | type LoginProps = RouteComponentProps |
9 | 13 | ||
10 | const LoginContainer = (props : LoginProps) => { | 14 | const LoginContainer = (props : LoginProps) => { |
15 | + | ||
16 | + const [loginForm, setLoginForm] = useState({ | ||
17 | + userId : '', | ||
18 | + password : '', | ||
19 | + }); | ||
20 | + const [token, setToken] = useRecoilState(recoilUtil.token); | ||
21 | + | ||
22 | + const onSetUserId = (e : React.ChangeEvent<HTMLInputElement>) => { | ||
23 | + setLoginForm({ | ||
24 | + ...loginForm, | ||
25 | + userId : e.target.value, | ||
26 | + }); | ||
27 | + }; | ||
28 | + | ||
29 | + const onSetPassword = (e : React.ChangeEvent<HTMLInputElement>) => { | ||
30 | + setLoginForm({ | ||
31 | + ...loginForm, | ||
32 | + password : e.target.value, | ||
33 | + }); | ||
34 | + }; | ||
35 | + | ||
36 | + const onLogin = async () => { | ||
37 | + const data : FormData = new FormData(); | ||
38 | + data.append('userId', loginForm.userId); | ||
39 | + data.append('password', loginForm.password); | ||
40 | + | ||
41 | + try { | ||
42 | + const result : any = await authApi.login(data); | ||
43 | + if(result.token) { | ||
44 | + setToken(result.token); | ||
45 | + props.history.push('/'); | ||
46 | + } | ||
47 | + } catch(e) { | ||
48 | + console.log(e); | ||
49 | + } | ||
50 | + | ||
51 | + }; | ||
52 | + | ||
53 | + useEffect(() => { | ||
54 | + console.log('loginPage'); | ||
55 | + }, []); | ||
56 | + | ||
11 | return ( | 57 | return ( |
12 | <LoginPresenter | 58 | <LoginPresenter |
13 | - temp = {'hi'} | 59 | + loginForm = {loginForm} |
60 | + onSetUserId = {onSetUserId} | ||
61 | + onSetPassword = {onSetPassword} | ||
62 | + onLogin = {onLogin} | ||
14 | /> | 63 | /> |
15 | ) | 64 | ) |
16 | }; | 65 | }; | ... | ... |
... | @@ -3,13 +3,51 @@ import React from 'react'; | ... | @@ -3,13 +3,51 @@ import React from 'react'; |
3 | import * as styled from './LoginStyled'; | 3 | import * as styled from './LoginStyled'; |
4 | 4 | ||
5 | interface LoginProps { | 5 | interface LoginProps { |
6 | - temp : string; | 6 | + loginForm : { |
7 | + userId : string, | ||
8 | + password : string, | ||
9 | + }; | ||
10 | + onSetUserId : React.ChangeEventHandler<HTMLInputElement>; | ||
11 | + onSetPassword : React.ChangeEventHandler<HTMLInputElement>; | ||
12 | + onLogin : React.MouseEventHandler<HTMLButtonElement>; | ||
7 | } | 13 | } |
8 | 14 | ||
9 | const LoginPresenter = (props : LoginProps) => { | 15 | const LoginPresenter = (props : LoginProps) => { |
10 | return ( | 16 | return ( |
11 | <styled.Container> | 17 | <styled.Container> |
12 | - This is Login Page {props.temp} | 18 | + <styled.LoginWrapper> |
19 | + <styled.LoginInputWrapper> | ||
20 | + <styled.LoginEachInputWrapper> | ||
21 | + <styled.LoginInputText | ||
22 | + > | ||
23 | + 로그인 이메일 | ||
24 | + </styled.LoginInputText> | ||
25 | + <styled.LoginInput | ||
26 | + type = 'text' | ||
27 | + value = {props.loginForm.userId} | ||
28 | + onChange = {props.onSetUserId} | ||
29 | + | ||
30 | + /> | ||
31 | + </styled.LoginEachInputWrapper> | ||
32 | + <styled.LoginEachInputWrapper> | ||
33 | + <styled.LoginInputText> | ||
34 | + 비밀번호 | ||
35 | + </styled.LoginInputText> | ||
36 | + <styled.LoginInput | ||
37 | + type = 'password' | ||
38 | + value = {props.loginForm.password} | ||
39 | + onChange = {props.onSetPassword} | ||
40 | + /> | ||
41 | + </styled.LoginEachInputWrapper> | ||
42 | + </styled.LoginInputWrapper> | ||
43 | + <styled.LoginButtonWrapper> | ||
44 | + <styled.LoginButton | ||
45 | + onClick = {props.onLogin} | ||
46 | + > | ||
47 | + 로그인 | ||
48 | + </styled.LoginButton> | ||
49 | + </styled.LoginButtonWrapper> | ||
50 | + </styled.LoginWrapper> | ||
13 | </styled.Container> | 51 | </styled.Container> |
14 | ); | 52 | ); |
15 | }; | 53 | }; | ... | ... |
1 | import styled from 'styled-components'; | 1 | import styled from 'styled-components'; |
2 | 2 | ||
3 | export const Container = styled.div ` | 3 | export const Container = styled.div ` |
4 | + width : 1180px; | ||
5 | +`; | ||
6 | + | ||
7 | +export const LoginWrapper = styled.div ` | ||
8 | + width : 50%; | ||
9 | + border : 1px solid; | ||
10 | + display : flex; | ||
11 | + flex-direction : column; | ||
12 | + justify-content : center; | ||
13 | + align-items : center; | ||
14 | + padding : 20px 3px; | ||
15 | +`; | ||
16 | + | ||
17 | +export const LoginInputWrapper = styled.div ` | ||
18 | + margin : 10px 0; | ||
19 | + width : 30%; | ||
20 | +`; | ||
21 | + | ||
22 | +export const LoginEachInputWrapper = styled.div ` | ||
23 | + display : flex; | ||
24 | + flex-direction : column; | ||
25 | + justify-content : center; | ||
26 | + align-items : center; | ||
27 | +`; | ||
28 | + | ||
29 | +export const LoginInputText = styled.div ` | ||
30 | + margin : 5px 0; | ||
31 | + | ||
32 | + text-align : center; | ||
33 | +`; | ||
34 | + | ||
35 | +export const LoginInput = styled.input ` | ||
36 | + border : 1px solid; | ||
37 | + height : 30px; | ||
38 | + width : 100%; | ||
39 | +`; | ||
40 | + | ||
41 | +export const LoginButtonWrapper = styled.div ` | ||
42 | + width: 30%; | ||
43 | + display : flex; | ||
44 | + flex-direction : row; | ||
45 | + justify-content : center; | ||
46 | + align-items : center; | ||
47 | +`; | ||
4 | 48 | ||
49 | +export const LoginButton = styled.button ` | ||
50 | + margin : 5px 0 5px 0; | ||
5 | `; | 51 | `; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -6,25 +6,25 @@ import MainPresenter from './MainPresenter'; | ... | @@ -6,25 +6,25 @@ import MainPresenter from './MainPresenter'; |
6 | import { useRecoilState, useRecoilValue } from 'recoil'; | 6 | import { useRecoilState, useRecoilValue } from 'recoil'; |
7 | import * as recoilUtil from '../../util/recoilUtil'; | 7 | import * as recoilUtil from '../../util/recoilUtil'; |
8 | 8 | ||
9 | -import { doctorApi, managerApi, userApi, authApi } from 'api'; | 9 | +import { doctorApi, managerApi, userApi, authApi } from '../../api'; |
10 | 10 | ||
11 | 11 | ||
12 | type MainProps = RouteComponentProps | 12 | type MainProps = RouteComponentProps |
13 | 13 | ||
14 | const MainContainer = (props : MainProps) => { | 14 | const MainContainer = (props : MainProps) => { |
15 | 15 | ||
16 | - const [token, setToken] = useRecoilState(recoilUtil.token); | 16 | + const token = useRecoilValue(recoilUtil.token); |
17 | const userType = useRecoilValue(recoilUtil.userType); | 17 | const userType = useRecoilValue(recoilUtil.userType); |
18 | 18 | ||
19 | useEffect(() => { | 19 | useEffect(() => { |
20 | - if (!token) { | 20 | + if(!token || token.length) { |
21 | - console.log('no Token'); | 21 | + props.history.push('/login'); |
22 | } | 22 | } |
23 | }, []); | 23 | }, []); |
24 | 24 | ||
25 | return ( | 25 | return ( |
26 | <MainPresenter | 26 | <MainPresenter |
27 | - temp = {'hi'} | 27 | + userType = {userType} |
28 | /> | 28 | /> |
29 | ); | 29 | ); |
30 | }; | 30 | }; | ... | ... |
... | @@ -4,13 +4,13 @@ import * as styled from './MainStyled'; | ... | @@ -4,13 +4,13 @@ import * as styled from './MainStyled'; |
4 | 4 | ||
5 | 5 | ||
6 | interface MainProps { | 6 | interface MainProps { |
7 | - temp : string; | 7 | + userType : string; |
8 | } | 8 | } |
9 | 9 | ||
10 | const MainPresenter = (props : MainProps) => { | 10 | const MainPresenter = (props : MainProps) => { |
11 | return ( | 11 | return ( |
12 | <styled.Container> | 12 | <styled.Container> |
13 | - This is Main Page {props.temp} | 13 | + This is Main Page {props.userType} |
14 | </styled.Container> | 14 | </styled.Container> |
15 | ) | 15 | ) |
16 | }; | 16 | }; | ... | ... |
-
Please register or login to post a comment