File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ {
2+ "trailingComma": "es5",
3+ "tabWidth": 2,
4+ "semi": true,
5+ "singleQuote": true
6+ }
Original file line number Diff line number Diff line change 33 "version" : " 0.1.0" ,
44 "private" : true ,
55 "dependencies" : {
6+ "@material-ui/core" : " ^4.12.3" ,
67 "@testing-library/jest-dom" : " ^5.11.4" ,
78 "@testing-library/react" : " ^11.1.0" ,
89 "@testing-library/user-event" : " ^12.1.10" ,
1112 "@types/react" : " ^17.0.0" ,
1213 "@types/react-dom" : " ^17.0.0" ,
1314 "@types/styled-components" : " ^5.1.15" ,
15+ "axios" : " ^0.24.0" ,
1416 "react" : " ^17.0.2" ,
1517 "react-dom" : " ^17.0.2" ,
1618 "react-router-dom" : " ^6.0.2" ,
Original file line number Diff line number Diff line change 11import { Route , Routes } from 'react-router' ;
2+ // import { useLoadingContext } from './contexts/LoadingContext';
23
34import SignIn from '../src/pages/SignIn' ;
45import SignUp from '../src/pages/SignUp' ;
56import Vote from '../src/pages/Vote' ;
67import Result from '../src/pages/Result' ;
78
9+ // import { Spinner } from './components/Spinner';
10+
811function App ( ) {
12+ // const { loading, setLoading }: any = useLoadingContext();
913 return (
1014 < Routes >
15+ { /* {loading ? <Spinner /> : null} */ }
1116 < Route path = "/" element = { < SignIn /> } />
1217 < Route path = "/signup" element = { < SignUp /> } />
1318 < Route path = "/vote/:part" element = { < Vote /> } />
Original file line number Diff line number Diff line change 1+ import styled from 'styled-components' ;
2+ import CircularProgress from '@material-ui/core/CircularProgress' ;
3+
4+ export const Spinner = styled ( CircularProgress ) `
5+ position: absolute;
6+ top: 0;
7+ bottom: 0;
8+ left: 0;
9+ right: 0;
10+ margin: auto;
11+ z-index: 1000;
12+ & svg {
13+ color: #7945e2;
14+ }
15+ ` ;
Original file line number Diff line number Diff line change 1+ import useInputs from '../../hooks/useInput' ;
2+ import { FormContainer , InputContainer } from './LoginFormPresenter' ;
3+ // import { useLoadingContext } from '../../contexts/LoadingContext';
4+ import { Spinner } from '../Spinner' ;
5+ import axios from 'axios' ;
6+
7+ // 수정 중
8+ // pw 안보이게 수정필요
9+ const LoginFormContainer = ( ) => {
10+ const [ userId , setuserId ] = useInputs ( '' ) ;
11+ const [ userPw , setuserPw ] = useInputs ( '' ) ;
12+
13+ const onsubmit = ( e : any ) => {
14+ e . preventDefault ( ) ;
15+ // setLoading(true);
16+ const form = new FormData ( ) ;
17+ form . append ( 'username' , userId ) ;
18+ form . append ( 'password' , userPw ) ;
19+
20+ if ( userId && userPw ) {
21+ console . log ( userId , userPw ) ;
22+ axios
23+ . post ( 'https://vote-mailedit.kro.kr/api/signup' , form )
24+ . then ( ( res ) => {
25+ // setloading 풀어줘
26+ switch ( res . status ) {
27+ case 200 :
28+ console . log ( res . data ) ;
29+ console . log ( 'login success' ) ;
30+ break ;
31+ case 401 :
32+ console . log ( '일치하는 회원 없음' ) ;
33+ break ;
34+ }
35+ } )
36+ . catch ( ( err ) => {
37+ //setLoading(false);
38+ console . log ( err ) ;
39+ } ) ;
40+ }
41+ } ;
42+
43+ return (
44+ < FormContainer onSubmit = { onsubmit } >
45+ < Spinner />
46+ < InputContainer
47+ type = "text"
48+ className = "IdForm"
49+ placeholder = "ID"
50+ value = { userId }
51+ onChange = { setuserId }
52+ />
53+ < InputContainer
54+ type = "text"
55+ className = "PwForm"
56+ placeholder = "PASSWORD"
57+ value = { userPw }
58+ onChange = { setuserPw }
59+ />
60+ < button > Let's start!</ button >
61+ </ FormContainer >
62+ ) ;
63+ } ;
64+
65+ export default LoginFormContainer ;
Original file line number Diff line number Diff line change 1+ import styled from 'styled-components' ;
2+ import COLORS from '../../constants/colors' ;
3+
4+ export const FormContainer = styled . form `
5+ display: flex;
6+ flex-direction: column;
7+ align-items: center;
8+ justify-content: center;
9+ ` ;
10+
11+ export const InputContainer = styled . input `
12+ flex: 1;
13+ padding: 0.2rem;
14+ text-align: left;
15+ border: 1px solid ${ COLORS . lightGray } ;
16+ border-radius: 22px;
17+ ` ;
Original file line number Diff line number Diff line change 1- export { } ;
1+ import { createContext , useState , useContext } from 'react' ;
2+
3+ const LoadingContext = createContext ( { } ) ;
4+
5+ const LoadingProvider = ( { children } : any ) => {
6+ const [ loading , setLoading ] = useState ( '' ) ;
7+
8+ const loadingContextValue = {
9+ loading,
10+ setLoading,
11+ } ;
12+
13+ return (
14+ < LoadingContext . Provider value = { loadingContextValue } >
15+ { children }
16+ </ LoadingContext . Provider >
17+ ) ;
18+ } ;
19+
20+ const useLoadingContext = ( ) => useContext ( LoadingContext ) ;
21+
22+ export { LoadingProvider , useLoadingContext } ;
Original file line number Diff line number Diff line change 1+ import { useReducer } from 'react' ;
2+
3+ function reducer ( state : any , action : any ) {
4+ if ( action . type === 'change' ) {
5+ //console.log(action);
6+ return action . target . value ;
7+ } else {
8+ return '' ;
9+ }
10+ }
11+
12+ export default function useInputs ( initialForm : any ) {
13+ const [ state , dispatch ] = useReducer ( reducer , initialForm ) ;
14+ const onChange = ( e : any ) => {
15+ dispatch ( e ) ;
16+ } ;
17+ return [ state , onChange ] ;
18+ }
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { Link } from 'react-router-dom' ;
3+ import LoginFormContainer from '../components/forms/LoginFormContainer' ;
4+
15const SignIn = ( ) => {
2- return < > Sign In</ > ;
6+ // 페이지 진입 시 id 입력 form에 focus.
7+ // 전체 form도 묶어서 컴포넌트로 만들기
8+ // 각 input form 컴포넌트화하기
9+
10+ return (
11+ < div
12+ style = { {
13+ display : 'flex' ,
14+ alignItems : 'center' ,
15+ flexDirection : 'column' ,
16+ } }
17+ >
18+ < h1 > Log in</ h1 >
19+ < p > 15기 프론트/파트장 투표</ p >
20+ < LoginFormContainer />
21+ < div >
22+ < p > Don't have an account?</ p >
23+ < Link to = { '/signup' } >
24+ < p > Sign Up</ p >
25+ </ Link >
26+ </ div >
27+ </ div >
28+ ) ;
329} ;
430
531export default SignIn ;
Original file line number Diff line number Diff line change 1+ import { useState } from 'react' ;
2+ import {
3+ FormContainer ,
4+ InputContainer ,
5+ } from '../components/forms/LoginFormPresenter' ;
6+ import useInputs from '../hooks/useInput' ;
7+
18const SignUp = ( ) => {
2- return < > Sign Up</ > ;
9+ const [ userId , setuserId ] = useInputs ( '' ) ;
10+ const [ userPw , setuserPw ] = useInputs ( '' ) ;
11+ const [ field , setField ] = useState ( 'FE' ) ;
12+
13+ const handleRadio = ( e : any ) => {
14+ setField ( e . target . value ) ;
15+ } ;
16+
17+ const onsubmit = ( e : any ) => {
18+ e . preventDefault ( ) ;
19+ // body에 담아서 보낼 거 세팅 후 axios
20+ console . log ( 'hi' ) ;
21+ } ;
22+
23+ return (
24+ < div
25+ style = { {
26+ display : 'flex' ,
27+ alignItems : 'center' ,
28+ flexDirection : 'column' ,
29+ } }
30+ >
31+ < FormContainer onSubmit = { onsubmit } >
32+ < h2 > 이름</ h2 >
33+ < InputContainer
34+ type = "text"
35+ className = "IdForm"
36+ placeholder = "ID"
37+ value = { userId }
38+ onChange = { setuserId }
39+ />
40+ < h2 > 비밀번호</ h2 >
41+ < InputContainer
42+ type = "text"
43+ className = "PwForm"
44+ placeholder = "PASSWORD"
45+ value = { userPw }
46+ onChange = { setuserPw }
47+ />
48+ < div style = { { display : 'flex' , flexDirection : 'row' } } >
49+ < input type = "radio" name = "field" value = "FE" onClick = { handleRadio } /> { ' ' }
50+ 프론트
51+ < input
52+ type = "radio"
53+ name = "field"
54+ value = "BE"
55+ onClick = { handleRadio }
56+ /> { ' ' }
57+ 백엔드
58+ </ div >
59+ < button > 회원가입하기</ button >
60+ </ FormContainer >
61+ </ div >
62+ ) ;
363} ;
464
565export default SignUp ;
You can’t perform that action at this time.
0 commit comments