|
1 | 1 | import useInputs from '../../hooks/useInput'; |
2 | 2 | import { FormContainer, InputContainer } from './LoginFormPresenter'; |
3 | | -// import { useLoadingContext } from '../../contexts/LoadingContext'; |
4 | | -import { Spinner } from '../Spinner'; |
| 3 | +import { useLoadingContext } from '../../contexts/LoadingContext'; |
5 | 4 | import axios from 'axios'; |
6 | 5 |
|
7 | 6 | // 수정 중 |
8 | 7 | // pw 안보이게 수정필요 |
9 | 8 | 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(); |
12 | 14 |
|
13 | 15 | const onsubmit = (e: any) => { |
14 | 16 | e.preventDefault(); |
15 | | - // setLoading(true); |
16 | | - const form = new FormData(); |
17 | | - form.append('username', userId); |
18 | | - form.append('password', userPw); |
19 | 17 |
|
20 | 18 | if (userId && userPw) { |
21 | 19 | console.log(userId, userPw); |
| 20 | + setLoading(true); |
22 | 21 | 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 | + }) |
24 | 26 | .then((res) => { |
25 | 27 | // 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'); |
34 | 32 | } |
35 | 33 | }) |
36 | 34 | .catch((err) => { |
37 | | - //setLoading(false); |
38 | | - console.log(err); |
| 35 | + setLoading(false); |
| 36 | + window.alert('회원정보가 일치하지 않습니다.'); |
39 | 37 | }); |
40 | 38 | } |
41 | 39 | }; |
42 | 40 |
|
| 41 | + const spinnerTest = () => { |
| 42 | + setLoading(!loading); |
| 43 | + }; |
| 44 | + |
43 | 45 | 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 | + </> |
62 | 64 | ); |
63 | 65 | }; |
64 | 66 |
|
|
0 commit comments