정의왕

Set input data form(not complete)

This diff is collapsed. Click to expand it.
...@@ -6,11 +6,18 @@ ...@@ -6,11 +6,18 @@
6 "@testing-library/jest-dom": "^5.15.0", 6 "@testing-library/jest-dom": "^5.15.0",
7 "@testing-library/react": "^11.2.7", 7 "@testing-library/react": "^11.2.7",
8 "@testing-library/user-event": "^12.8.3", 8 "@testing-library/user-event": "^12.8.3",
9 + "axios": "^0.24.0",
10 + "http-proxy-middleware": "^2.0.1",
9 "node-sass": "^6.0.1", 11 "node-sass": "^6.0.1",
10 "react": "^17.0.2", 12 "react": "^17.0.2",
11 "react-dom": "^17.0.2", 13 "react-dom": "^17.0.2",
14 + "react-redux": "^7.2.6",
12 "react-router-dom": "^6.0.2", 15 "react-router-dom": "^6.0.2",
13 "react-scripts": "4.0.3", 16 "react-scripts": "4.0.3",
17 + "redux": "^4.1.2",
18 + "redux-promise": "^0.6.0",
19 + "redux-promise-middleware": "^6.1.2",
20 + "redux-thunk": "^2.4.1",
14 "semantic-ui-css": "^2.4.1", 21 "semantic-ui-css": "^2.4.1",
15 "semantic-ui-react": "^2.0.4", 22 "semantic-ui-react": "^2.0.4",
16 "web-vitals": "^1.1.2" 23 "web-vitals": "^1.1.2"
......
...@@ -9,21 +9,6 @@ ...@@ -9,21 +9,6 @@
9 name="description" 9 name="description"
10 content="Web site created using create-react-app" 10 content="Web site created using create-react-app"
11 /> 11 />
12 - <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13 - <!--
14 - manifest.json provides metadata used when your web app is installed on a
15 - user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16 - -->
17 - <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18 - <!--
19 - Notice the use of %PUBLIC_URL% in the tags above.
20 - It will be replaced with the URL of the `public` folder during the build.
21 - Only files inside the `public` folder can be referenced from the HTML.
22 -
23 - Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24 - work correctly both with client-side routing and a non-root public URL.
25 - Learn how to configure a non-root public URL by running `npm run build`.
26 - -->
27 <title>React App</title> 12 <title>React App</title>
28 </head> 13 </head>
29 <body> 14 <body>
......
1 -{
2 - "short_name": "React App",
3 - "name": "Create React App Sample",
4 - "icons": [
5 - {
6 - "src": "favicon.ico",
7 - "sizes": "64x64 32x32 24x24 16x16",
8 - "type": "image/x-icon"
9 - },
10 - {
11 - "src": "logo192.png",
12 - "type": "image/png",
13 - "sizes": "192x192"
14 - },
15 - {
16 - "src": "logo512.png",
17 - "type": "image/png",
18 - "sizes": "512x512"
19 - }
20 - ],
21 - "start_url": ".",
22 - "display": "standalone",
23 - "theme_color": "#000000",
24 - "background_color": "#ffffff"
25 -}
1 -//import React, {useState} from "react";
2 import {BrowserRouter as Router, Route, Routes, Link} from "react-router-dom"; 1 import {BrowserRouter as Router, Route, Routes, Link} from "react-router-dom";
3 -import MainPage from "./component/views/LandingPage/MainPage"; 2 +import MainPage from "./component/views/MainPage/MainPage";
4 import LoginPage from "./component/views/LoginPage/LoginPage"; 3 import LoginPage from "./component/views/LoginPage/LoginPage";
5 import RegisterPage from "./component/views/RegisterPage/RegisterPage"; 4 import RegisterPage from "./component/views/RegisterPage/RegisterPage";
6 import "./static/fonts/font.css"; 5 import "./static/fonts/font.css";
6 +import LandingPage from "./component/views/LandingPage/LandingPage";
7 +
7 function App () { 8 function App () {
8 return ( 9 return (
9 <Router> 10 <Router>
10 <div> 11 <div>
11 - {}
12 <Routes> 12 <Routes>
13 - <Route exact path = "/main" element={<MainPage/>}/> 13 + <Route exact path = "/" element={<LandingPage/>}/>
14 - <Route exact path = "/login" element={<LoginPage/>}/> 14 + <Route exact path = "/login" element={<LoginPage/>}/>
15 - <Route exact path = "/register" element={<RegisterPage/>}/> 15 + <Route exact path = "/main" element={<MainPage/>}/>
16 + <Route exact path = "/register" element={<RegisterPage/>}/>
16 </Routes> 17 </Routes>
17 </div> 18 </div>
18 </Router> 19 </Router>
......
1 +export const LOGIN_USER = "login_user";
...\ No newline at end of file ...\ No newline at end of file
1 +import Axios from 'axios';
2 +import { LOGIN_USER } from './types';
3 +
4 +export function loginUser(dataToSubmit) {
5 +
6 + const request = Axios.post('/api/users/login', dataToSubmit)
7 + .then( response => response.data )
8 + return {
9 + type: LOGIN_USER,
10 + payload: request
11 + }
12 +}
...\ No newline at end of file ...\ No newline at end of file
1 +import { combineReducers } from 'redux';
2 +import user from './user_reducer';
3 +
4 +const rootReducer = combineReducers({
5 + user
6 +})
7 +
8 +export default rootReducer;
1 +import {
2 + LOGIN_USER
3 +} from '../_actions/types';
4 +
5 +export default function (state = {}, action) {
6 + switch (action.type) {
7 + case LOGIN_USER:
8 + return { ...state, loginSuccess: action.payload }
9 + break;
10 +
11 + default:
12 + return state;
13 + }
14 +}
...\ No newline at end of file ...\ No newline at end of file
1 +import React, { useEffect } from 'react'
2 +import axios from 'axios'
3 +// import { response } from 'express'
4 +
5 +function LandingPage() {
6 +
7 + useEffect(() => {
8 + axios.get('/api/hello')
9 + .then(response => console.log(response.data))
10 + }, [])
11 +
12 + return (
13 + <div>
14 + LandingPage
15 + </div>
16 + )
17 +}
18 +
19 +export default LandingPage
20 +
1 -import React, { useState } from "react"; 1 +import React, {useEffect, useState} from "react";
2 +import Axios from 'axios'
3 +import {Link} from "react-router-dom";
2 import "../style/LoginPage.scss"; 4 import "../style/LoginPage.scss";
3 import { Icon, Input } from "semantic-ui-react" 5 import { Icon, Input } from "semantic-ui-react"
4 import { useNavigate } from "react-router-dom"; 6 import { useNavigate } from "react-router-dom";
7 +import {useDispatch} from "react-redux";
8 +import { loginUser } from '../../../_actions/user_action'
5 9
6 -function LoginPage() { 10 +function LoginPage(props) {
11 + const dispatch = useDispatch();
7 const navigate = useNavigate(); 12 const navigate = useNavigate();
8 13
9 - const [Email, setEmail] = useState(""); 14 + const [Id, setId] = useState("");
10 const [Password, setPassword] = useState(""); 15 const [Password, setPassword] = useState("");
11 16
12 const onIdHandler = (event) => { 17 const onIdHandler = (event) => {
13 - setEmail(event.currentTarget.value); 18 + setId(event.currentTarget.value);
14 }; 19 };
15 const onPasswordHandler = (event) => { 20 const onPasswordHandler = (event) => {
16 setPassword(event.currentTarget.value); 21 setPassword(event.currentTarget.value);
17 }; 22 };
18 const onSubmitHandler = (event) => { 23 const onSubmitHandler = (event) => {
19 event.preventDefault(); 24 event.preventDefault();
20 - console.log("Email", Email); 25 + console.log("ID", Id);
21 console.log("Password", Password); 26 console.log("Password", Password);
27 + let body = {
28 + email: Id,
29 + password: Password
30 + }
31 + dispatch(loginUser(body))
32 + .then(response => {
33 + if (response.payload.loginSuccess) {
34 + props.history.push('/main')
35 + }
36 + else{
37 + alert('Error')
38 + }
39 + })
40 +
22 }; 41 };
23 42
24 const goToRegister = () => { 43 const goToRegister = () => {
25 navigate('/register'); 44 navigate('/register');
26 } 45 }
27 -
28 return ( 46 return (
29 <div id="body"> 47 <div id="body">
30 <div className="login-form"> 48 <div className="login-form">
...@@ -34,9 +52,9 @@ function LoginPage() { ...@@ -34,9 +52,9 @@ function LoginPage() {
34 <Input 52 <Input
35 icon={<Icon name='at'/>} 53 icon={<Icon name='at'/>}
36 iconPosition='left' 54 iconPosition='left'
37 - placeholder="Email" 55 + placeholder="ID"
38 type="text" 56 type="text"
39 - value={Email} 57 + value={Id}
40 autoComplete="off" 58 autoComplete="off"
41 onChange={onIdHandler}/> 59 onChange={onIdHandler}/>
42 </div> 60 </div>
......
1 import {Button, Grid, Image, Segment} from "semantic-ui-react" 1 import {Button, Grid, Image, Segment} from "semantic-ui-react"
2 import "../style/MainPage.scss"; 2 import "../style/MainPage.scss";
3 +import {useNavigate} from "react-router-dom";
4 +
3 function MainPage() { 5 function MainPage() {
6 + const navigate = useNavigate();
7 + const goToLogin = () =>{
8 + navigate('/login');
9 + }
4 return ( 10 return (
5 <div id="Main"> 11 <div id="Main">
6 <div className="Main-header"> 12 <div className="Main-header">
...@@ -8,7 +14,7 @@ function MainPage() { ...@@ -8,7 +14,7 @@ function MainPage() {
8 <h1>Tunnel</h1> 14 <h1>Tunnel</h1>
9 </div> 15 </div>
10 <div className="None-title"> 16 <div className="None-title">
11 - <Button className="ui right floated button"> 17 + <Button className="ui right floated button" onClick={()=>goToLogin()}>
12 Logout 18 Logout
13 </Button> 19 </Button>
14 </div> 20 </div>
......
1 import React, {useCallback, useState} from "react"; 1 import React, {useCallback, useState} from "react";
2 import "../style/RegisterPage.scss"; 2 import "../style/RegisterPage.scss";
3 -import { Form, Message, Button, Icon, Input } from "semantic-ui-react"; 3 +import { Button, Icon, Input } from "semantic-ui-react";
4 -import backgroundImg from "../images/register_background.png";
5 4
6 function RegisterPage() { 5 function RegisterPage() {
7 - const [Email, setEmail] = useState(""); 6 + const [Id, setId] = useState("");
8 const [Password, setPassword] = useState(""); 7 const [Password, setPassword] = useState("");
9 const [PasswordCheck,setPasswordCheck] = useState(""); 8 const [PasswordCheck,setPasswordCheck] = useState("");
10 const [Personality, setPersonality] = useState(""); 9 const [Personality, setPersonality] = useState("");
11 const [PasswordError,setPasswordError] = useState(false); 10 const [PasswordError,setPasswordError] = useState(false);
12 11
13 const onIdHandler = (event) => { 12 const onIdHandler = (event) => {
14 - setEmail(event.currentTarget.value); 13 + setId(event.currentTarget.value);
15 }; 14 };
16 const onPasswordHandler = (event) => { 15 const onPasswordHandler = (event) => {
17 setPassword(event.currentTarget.value); 16 setPassword(event.currentTarget.value);
...@@ -25,14 +24,15 @@ function RegisterPage() { ...@@ -25,14 +24,15 @@ function RegisterPage() {
25 },[PasswordCheck]); 24 },[PasswordCheck]);
26 const onSubmitHandler = useCallback((event) => { 25 const onSubmitHandler = useCallback((event) => {
27 event.preventDefault(); 26 event.preventDefault();
27 + console.log("ID", Id);
28 + console.log("Password", Password);
29 + console.log("MBTI", Personality);
28 if(Password !== PasswordCheck){ 30 if(Password !== PasswordCheck){
29 return setPasswordError(true); 31 return setPasswordError(true);
30 } 32 }
31 else{ 33 else{
32 return setPasswordError(false); 34 return setPasswordError(false);
33 } 35 }
34 - console.log("Email",Email);
35 - console.log("Password", Password);
36 },[Password,PasswordCheck]); 36 },[Password,PasswordCheck]);
37 37
38 return ( 38 return (
...@@ -46,12 +46,22 @@ function RegisterPage() { ...@@ -46,12 +46,22 @@ function RegisterPage() {
46 iconPosition='left' 46 iconPosition='left'
47 placeholder="Email" 47 placeholder="Email"
48 type="text" 48 type="text"
49 - value={Email} 49 + value={Id}
50 autoComplete="off" 50 autoComplete="off"
51 required onChange={onIdHandler}/> 51 required onChange={onIdHandler}/>
52 </div> 52 </div>
53 <div className="input-area"> 53 <div className="input-area">
54 <Input 54 <Input
55 + icon={<Icon name='heart'/>}
56 + iconPosition='left'
57 + placeholder="Your MBTI"
58 + type="text"
59 + value={Personality}
60 + autoComplete="off"
61 + onChange={onPersonalityHandler}/>
62 + </div>
63 + <div className="input-area">
64 + <Input
55 icon={<Icon name='lock'/>} 65 icon={<Icon name='lock'/>}
56 iconPosition='left' 66 iconPosition='left'
57 placeholder="Password" 67 placeholder="Password"
...@@ -61,14 +71,7 @@ function RegisterPage() { ...@@ -61,14 +71,7 @@ function RegisterPage() {
61 onChange={onPasswordHandler} 71 onChange={onPasswordHandler}
62 onFocus={()=>setPasswordError(false)}/> 72 onFocus={()=>setPasswordError(false)}/>
63 {PasswordError && 73 {PasswordError &&
64 - <Form error> 74 + <div>비밀번호 오류</div>
65 - <Message
66 - error
67 - header='Action Forbidden'
68 - content='You can only sign up for an account once with a given e-mail address.'
69 - />
70 - <Button>Submit</Button>
71 - </Form>
72 } 75 }
73 </div> 76 </div>
74 <div className="input-area"> 77 <div className="input-area">
...@@ -81,24 +84,12 @@ function RegisterPage() { ...@@ -81,24 +84,12 @@ function RegisterPage() {
81 autoComplete="off" 84 autoComplete="off"
82 onChange={onPasswordChkHandler} 85 onChange={onPasswordChkHandler}
83 onFocus={()=>setPasswordError(false)}/> 86 onFocus={()=>setPasswordError(false)}/>
84 -
85 - </div>
86 - <div className="input-area">
87 - <Input
88 - icon={<Icon name='heart'/>}
89 - iconPosition='left'
90 - placeholder="Your MBTI"
91 - type="text"
92 - value={Personality}
93 - autoComplete="off"
94 - onChange={onPersonalityHandler}/>
95 </div> 87 </div>
96 <div className="btn-area" > 88 <div className="btn-area" >
97 <Button className='register-btn' 89 <Button className='register-btn'
98 content='Sign up' 90 content='Sign up'
99 icon='signup' 91 icon='signup'
100 - size='small' 92 + size='small'/>
101 - iconPosition='left'/>
102 </div> 93 </div>
103 </form> 94 </form>
104 </div> 95 </div>
......
1 import React from 'react'; 1 import React from 'react';
2 import ReactDOM from 'react-dom'; 2 import ReactDOM from 'react-dom';
3 +import {Provider} from "react-redux";
3 import './index.css'; 4 import './index.css';
4 import App from './App'; 5 import App from './App';
5 import 'semantic-ui-css/semantic.min.css' 6 import 'semantic-ui-css/semantic.min.css'
7 +import {applyMiddleware, createStore} from "redux";
8 +import promiseMiddleware from 'redux-promise-middleware'
9 +import ReduxThunk from 'redux-thunk'
10 +import Reducer from './_reducers';
6 11
12 +const createStoreWithMiddleWare = applyMiddleware(promiseMiddleware, ReduxThunk)(createStore)
7 ReactDOM.render( 13 ReactDOM.render(
8 - <React.StrictMode> 14 + <Provider store={createStoreWithMiddleWare(Reducer,
9 - <App /> 15 + window.__REDUX_DEVTOOLS_EXTENSION__ &&
10 - </React.StrictMode>, 16 + window.__REDUX_DEVTOOLS_EXTENSION__()
17 + )}>
18 + <App />
19 + </Provider>,
11 document.getElementById('root') 20 document.getElementById('root')
12 ); 21 );
13 22
......
1 -<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
...\ No newline at end of file ...\ No newline at end of file
1 +const { createProxyMiddleware } = require('http-proxy-middleware');
2 +module.exports = function(app) {
3 + app.use(
4 + '/api',
5 + createProxyMiddleware({
6 + target: 'http://localhost:3000',
7 + changeOrigin: true,
8 + })
9 + );
10 +};
...\ No newline at end of file ...\ No newline at end of file