Skip to content

Commit 6e10465

Browse files
authored
Merge pull request CEOS-Developers#8 from Team-MailedIt/nowkim
Nowkim
2 parents bf63905 + 7040473 commit 6e10465

5 files changed

Lines changed: 98 additions & 58 deletions

File tree

src/App.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { Route, Routes } from 'react-router';
2-
// import { useLoadingContext } from './contexts/LoadingContext';
2+
import { useLoadingContext } from './contexts/LoadingContext';
33

4-
import SignIn from '../src/pages/SignIn';
5-
import SignUp from '../src/pages/SignUp';
6-
import Vote from '../src/pages/Vote';
7-
import Result from '../src/pages/Result';
4+
import SignIn from './pages/SignIn';
5+
import SignUp from './pages/SignUp';
6+
import Vote from './pages/Vote';
7+
import Result from './pages/Result';
88

9-
// import { Spinner } from './components/Spinner';
9+
import { Spinner } from './components/Spinner';
1010

1111
function App() {
12-
// const { loading, setLoading }: any = useLoadingContext();
12+
const { loading }: any = useLoadingContext();
1313
return (
14-
<Routes>
15-
{/* {loading ? <Spinner /> : null} */}
16-
<Route path="/" element={<SignIn />} />
17-
<Route path="/signup" element={<SignUp />} />
18-
<Route path="/vote/:part" element={<Vote />} />
19-
<Route path="/result" element={<Result />} />
20-
</Routes>
14+
<>
15+
{loading ? <Spinner /> : null}
16+
<Routes>
17+
<Route path="/" element={<SignIn />} />
18+
<Route path="/signup" element={<SignUp />} />
19+
<Route path="/vote/:part" element={<Vote />} />
20+
<Route path="/result" element={<Result />} />
21+
</Routes>
22+
</>
2123
);
2224
}
2325

src/components/forms/LoginFormContainer.tsx

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,66 @@
11
import useInputs from '../../hooks/useInput';
22
import { FormContainer, InputContainer } from './LoginFormPresenter';
3-
// import { useLoadingContext } from '../../contexts/LoadingContext';
4-
import { Spinner } from '../Spinner';
3+
import { useLoadingContext } from '../../contexts/LoadingContext';
54
import axios from 'axios';
65

76
// 수정 중
87
// pw 안보이게 수정필요
98
const LoginFormContainer = () => {
10-
const [userId, setuserId] = useInputs('');
11-
const [userPw, setuserPw] = useInputs('');
9+
const [userId, setUserId] = useInputs('');
10+
const [userPw, setUserPw] = useInputs('');
11+
12+
// spinner 동작 setting
13+
const { loading, setLoading }: any = useLoadingContext();
1214

1315
const onsubmit = (e: any) => {
1416
e.preventDefault();
15-
// setLoading(true);
16-
const form = new FormData();
17-
form.append('username', userId);
18-
form.append('password', userPw);
1917

2018
if (userId && userPw) {
2119
console.log(userId, userPw);
20+
setLoading(true);
2221
axios
23-
.post('https://vote-mailedit.kro.kr/api/signup', form)
22+
.post('https://vote-mailedit.kro.kr/api/signin', {
23+
username: userId,
24+
password: userPw,
25+
})
2426
.then((res) => {
2527
// 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;
28+
setLoading(false);
29+
if (res.status === 200) {
30+
console.log(res.data);
31+
console.log('login success');
3432
}
3533
})
3634
.catch((err) => {
37-
//setLoading(false);
38-
console.log(err);
35+
setLoading(false);
36+
window.alert('회원정보가 일치하지 않습니다.');
3937
});
4038
}
4139
};
4240

41+
const spinnerTest = () => {
42+
setLoading(!loading);
43+
};
44+
4345
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>
46+
<>
47+
<FormContainer onSubmit={onsubmit}>
48+
<InputContainer
49+
type="text"
50+
placeholder="ID"
51+
value={userId}
52+
onChange={setUserId}
53+
/>
54+
<InputContainer
55+
type="password"
56+
placeholder="PASSWORD"
57+
value={userPw}
58+
onChange={setUserPw}
59+
/>
60+
<button>Let's start!</button>
61+
</FormContainer>
62+
<button onClick={spinnerTest}>spinner test</button>
63+
</>
6264
);
6365
};
6466

src/contexts/LoadingContext.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
// import React, { createContext, useState, useContext } from 'react';
2+
3+
// const LoadingContext = createContext({
4+
// state: { loading: false },
5+
// actions: { setLoading: () => {} },
6+
// });
7+
8+
// const LoadingProvider = ({ children }) => {
9+
// const [loading, setLoading] = useState(false);
10+
11+
// const loadingContextValue = {
12+
// state: { loading },
13+
// actions: { setLoading },
14+
// };
15+
16+
// return (
17+
// <LoadingContext.Provider value={loadingContextValue}>
18+
// {children}
19+
// </LoadingContext.Provider>
20+
// );
21+
// };
22+
// const useLoadingContext = () => useContext(LoadingContext);
23+
// export { LoadingProvider, useLoadingContext };
24+
// // const useLoadingContext = () => useContext(LoadingContext);
25+
26+
// // export { LoadingProvider, useLoadingContext };
27+
128
import { createContext, useState, useContext } from 'react';
229

330
const LoadingContext = createContext({});

src/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import ReactDOM from 'react-dom';
22
import { BrowserRouter } from 'react-router-dom';
33

4+
import { LoadingProvider } from './contexts/LoadingContext';
45
import GlobalStyle from './assets/styles/global-styles';
56
import App from './App';
67

78
ReactDOM.render(
8-
<BrowserRouter>
9-
<GlobalStyle />
10-
<App />
11-
</BrowserRouter>,
9+
<LoadingProvider>
10+
<BrowserRouter>
11+
<GlobalStyle />
12+
<App />
13+
</BrowserRouter>
14+
</LoadingProvider>,
1215
document.getElementById('root')
1316
);

src/pages/SignUp.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@ import useInputs from '../hooks/useInput';
88
const SignUp = () => {
99
const [userId, setuserId] = useInputs('');
1010
const [userPw, setuserPw] = useInputs('');
11-
const [field, setField] = useState('FE');
11+
const [part, setPart] = useState('');
1212

1313
const handleRadio = (e: any) => {
14-
setField(e.target.value);
14+
setPart(e.target.value);
1515
};
1616

1717
const onsubmit = (e: any) => {
1818
e.preventDefault();
1919
// body에 담아서 보낼 거 세팅 후 axios
20-
console.log('hi');
20+
const payload = {
21+
username: userId,
22+
password: userPw,
23+
part: part,
24+
};
25+
26+
console.log(payload);
2127
};
2228

2329
return (

0 commit comments

Comments
 (0)