Showing
5 changed files
with
33 additions
and
41 deletions
1 | import React, { useCallback, useState } from "react"; | 1 | import React, { useCallback, useState } from "react"; |
2 | -import { useDispatch } from "react-redux"; | 2 | +import { register } from "../../../modules/user.js"; |
3 | -import { register } from "../../../modules/user"; | 3 | +import "../style/RegisterPage.scss"; |
4 | -import "../style/RegisterPage.scss" | 4 | +import { useDispatch, useSelector } from "react-redux"; |
5 | +import { useNavigate } from "react-router-dom"; | ||
5 | 6 | ||
6 | function RegisterPage(props) { | 7 | function RegisterPage(props) { |
7 | const dispatch = useDispatch(); | 8 | const dispatch = useDispatch(); |
9 | + const naviagte = useNavigate(); | ||
10 | + | ||
11 | + const registerResult = useSelector(state => state.user.registerSuccess); | ||
8 | 12 | ||
9 | const [Name, setName] = useState(""); | 13 | const [Name, setName] = useState(""); |
10 | const [Sex, setSex] = useState(""); | 14 | const [Sex, setSex] = useState(""); |
... | @@ -98,20 +102,20 @@ function RegisterPage(props) { | ... | @@ -98,20 +102,20 @@ function RegisterPage(props) { |
98 | id: Id, | 102 | id: Id, |
99 | password: Password, | 103 | password: Password, |
100 | gender: Sex, | 104 | gender: Sex, |
105 | + }; | ||
106 | + | ||
107 | + dispatch(register(UserData)); | ||
108 | + | ||
109 | + if (registerResult) { | ||
110 | + alert('회원가입에 성공하였습니다.'); | ||
111 | + naviagte('/login'); | ||
112 | + } else { | ||
113 | + alert('회원가입에 실패하였습니다.'); | ||
101 | } | 114 | } |
115 | + | ||
116 | + }; | ||
102 | 117 | ||
103 | - dispatch(register(UserData) | 118 | + }, [checkIdError, checkNameError, checkPasswordError, checkRegisterError, checkSexError, Password, PasswordCheck, Sex, dispatch, registerResult]); |
104 | - .then(res => { | ||
105 | - if (res.payload.success) { | ||
106 | - props.history.push('/login'); | ||
107 | - } else { | ||
108 | - alert(res.payload.error); | ||
109 | - } | ||
110 | - }) | ||
111 | - ); | ||
112 | - } | ||
113 | - | ||
114 | - }, [checkIdError, checkNameError, checkPasswordError, checkRegisterError, checkSexError, Password, PasswordCheck, Sex]); | ||
115 | 119 | ||
116 | return ( | 120 | return ( |
117 | <div id="body"> | 121 | <div id="body"> | ... | ... |
... | @@ -14,12 +14,10 @@ const store = createStore(rootReducer, composeWithDevTools()); | ... | @@ -14,12 +14,10 @@ const store = createStore(rootReducer, composeWithDevTools()); |
14 | const root = ReactDOM.createRoot(document.getElementById('root')); | 14 | const root = ReactDOM.createRoot(document.getElementById('root')); |
15 | root.render( | 15 | root.render( |
16 | <Provider store={store}> | 16 | <Provider store={store}> |
17 | - <React.StrictMode> | 17 | + <BrowserRouter> |
18 | - <BrowserRouter> | 18 | + <App /> |
19 | - <App /> | 19 | + </BrowserRouter> |
20 | - </BrowserRouter> | 20 | + </Provider>, |
21 | - </React.StrictMode> | ||
22 | - </Provider> | ||
23 | ); | 21 | ); |
24 | 22 | ||
25 | // If you want to start measuring performance in your app, pass a function | 23 | // If you want to start measuring performance in your app, pass a function | ... | ... |
1 | import axios from 'axios'; | 1 | import axios from 'axios'; |
2 | 2 | ||
3 | const REGISTER = 'user/REGISTER'; | 3 | const REGISTER = 'user/REGISTER'; |
4 | -const LOGIN = 'user/LOGIN' | 4 | +const LOGIN = 'user/LOGIN'; |
5 | - | ||
6 | -const InitialState = { | ||
7 | - logged: false, | ||
8 | - name: 'test', | ||
9 | - id: 'test123', | ||
10 | - password: 'test1111~', | ||
11 | - gender: '1', | ||
12 | -}; | ||
13 | 5 | ||
14 | export function register(data) { | 6 | export function register(data) { |
15 | - const req = axios.post('http://localhost:4000/register', data) | 7 | + const req = axios.post('http://localhost:4000/api/register', data) |
16 | .then(res => res.data); | 8 | .then(res => res.data); |
17 | 9 | ||
18 | return { | 10 | return { |
19 | type: REGISTER, | 11 | type: REGISTER, |
20 | payload: req, | 12 | payload: req, |
21 | } | 13 | } |
22 | -}; | 14 | +} |
23 | 15 | ||
24 | export function login(data) { | 16 | export function login(data) { |
25 | - const req = axios.post('http://localhost:4000/login', data) | 17 | + const req = axios.post('http://localhost:4000/api/login', data) |
26 | .then(res => res.date); | 18 | .then(res => res.date); |
27 | 19 | ||
28 | return { | 20 | return { |
29 | type: LOGIN, | 21 | type: LOGIN, |
30 | payload: req, | 22 | payload: req, |
31 | } | 23 | } |
32 | -}; | 24 | +} |
33 | 25 | ||
34 | export default function (state = {}, action) { | 26 | export default function (state = {}, action) { |
35 | switch (action.type) { | 27 | switch (action.type) { |
36 | case REGISTER: | 28 | case REGISTER: |
37 | - return {...state, success: action.payload}; | 29 | + return { ...state, registerSuccess: action.payload }; |
38 | - break; | ||
39 | case LOGIN: | 30 | case LOGIN: |
40 | - return {...state, loginSuccess: action.payload}; | 31 | + return { ...state, loginSuccess: action.payload }; |
41 | - break; | ||
42 | default: | 32 | default: |
43 | return state; | 33 | return state; |
44 | } | 34 | } |
45 | -}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
35 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -2,7 +2,7 @@ const { createProxyMiddleware } = require("http-proxy-middleware"); | ... | @@ -2,7 +2,7 @@ const { createProxyMiddleware } = require("http-proxy-middleware"); |
2 | 2 | ||
3 | module.exports = function(app) { | 3 | module.exports = function(app) { |
4 | app.use( | 4 | app.use( |
5 | - createProxyMiddleware('/', { | 5 | + createProxyMiddleware('/api', { |
6 | target: 'http://localhost:4000', //접속하려는 서버의 루트 URL | 6 | target: 'http://localhost:4000', //접속하려는 서버의 루트 URL |
7 | changeOrigin: true | 7 | changeOrigin: true |
8 | }) | 8 | }) | ... | ... |
-
Please register or login to post a comment