Skip to content

Commit

Permalink
Merge pull request #185 from INFP-Study/feature/signupPeristalsis
Browse files Browse the repository at this point in the history
[FEATURE] E4-S4 ํšŒ์›๊ฐ€์ž… ์œ ํšจ์„ฑ ๊ฒ€์ฆ ๋ฐ  message ์ˆ˜์ • #130
  • Loading branch information
thyoondev authored Dec 11, 2021
2 parents 8abdd9c + f2d530c commit 8de2666
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 27 deletions.
12 changes: 10 additions & 2 deletions frontend/src/components/auth/sign-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,35 @@ const SNSLogin = styled.div`
padding: 30px;
`;

function SignIn() {
function SignIn({ handleChange, handleSignIn }) {
return (
<Wrapper>
<InnerWrapper>
<Title>{SIGN_IN}</Title>
<Div>
{EMAIL}
<Input
name="email"
placeholder="์ด๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
style={{ marginTop: '10px' }}
onChange={handleChange}
/>
</Div>
<Div>
{PASSWORD}
<Input.Password
name="password"
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
style={{ marginTop: '10px' }}
onChange={handleChange}
/>
</Div>
<Div>
<ButtonAntd type="primary" style={{ height: '44px' }}>
<ButtonAntd
type="primary"
style={{ height: '44px' }}
onClick={handleSignIn}
>
{SIGN_IN}
</ButtonAntd>
</Div>
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ export const EMPTY_EMAIL = '์ด๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.';
export const EMPTY_NICKNAME = '๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.';
export const EMPTY_PASSWORD = '๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.';
export const EMPTY_PASSWORD_CONFIRM = '๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.';
export const SIGN_IN_SUCCESS = '์”จ์•—์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.';
export const SIGN_UP_SUCCESS = 'ํšŒ์›๊ฐ€์ž…์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.';
export const REQUIRED_CHECK = 'ํ•„์ˆ˜ํ•ญ๋ชฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.';
export const EMAIL_CHECK = '์ด๋ฉ”์ผ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.';
export const PASSWORD_CHECK = '์ž…๋ ฅํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.';
export const NICKNAME_CHECK =
'๋‹‰๋„ค์ž„์€ ํ•œ๊ธ€, ์˜๋ฌธ, ์ˆซ์ž ์ตœ์†Œ 1๊ฐœ์ด์ƒ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” (๊ธธ์ด 2์ž~12์ž)';
export const PASSWORD_SAME_CHECK = '์ž…๋ ฅํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.';
export const PASSWORD_CHECK =
'๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์˜๋ฌธ, ์ˆซ์ž, ํŠน์ˆ˜๋ฌธ์ž๋ฅผ ํ˜ผํ•ฉํ•˜์—ฌ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” (๊ธธ์ด 8์ž~20์ž)';

export const HOME = 'ํ™ˆ์œผ๋กœ';
export const ERROR_CONTENT_F = '์ฐพ์„์ˆ˜ ์—†๋Š” ํŽ˜์ด์ง€ ์ž…๋‹ˆ๋‹ค.';
Expand Down
27 changes: 26 additions & 1 deletion frontend/src/containers/auth/sign-in-container.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { message } from 'antd';
import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import SignIn from '../../components/auth/sign-in';
import { signInSuccess } from '../../store/auth';

const Wrapper = styled.div`
width: 100%;
Expand All @@ -11,9 +13,32 @@ const Wrapper = styled.div`
`;

function SignInContainer() {
const dispatch = useDispatch();

const [info, setInfo] = useState({
email: '',
password: '',
});

const onChangeHandler = (e) => {
setInfo({
...info,
[e.target.name]: e.target.value,
});
};

const onSignInHandler = () => {
if (info.email === '') {
return message.error('์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.');
} else if (info.password === '') {
return message.error('๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.');
}
dispatch({ type: signInSuccess.type, data: info });
};

return (
<Wrapper>
<SignIn />
<SignIn handleChange={onChangeHandler} handleSignIn={onSignInHandler} />
</Wrapper>
);
}
Expand Down
36 changes: 27 additions & 9 deletions frontend/src/containers/auth/sign-up-container.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React, { useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { signUpSuccess } from '../../store/auth';
import { signUp } from '../../store/auth';
import SignUp from '../../components/auth/sign-up';
import { message } from 'antd';
import { EMAIL_CHECK, PASSWORD_CHECK } from '../../constants';
import {
EMAIL_CHECK,
NICKNAME_CHECK,
PASSWORD_CHECK,
PASSWORD_SAME_CHECK,
} from '../../constants';

const Wrapper = styled.div`
width: 100%;
Expand Down Expand Up @@ -34,8 +39,10 @@ function SignUpContainer() {

const onSignUpHandler = (e) => {
if (isEmail(info.email) === undefined) {
if (isSamePassword(info) === undefined) {
dispatch({ type: signUpSuccess.type, data: info });
if (isNickname(info.nickname) === undefined) {
if (isPassword(info) === undefined) {
dispatch({ type: signUp.type, data: info });
}
}
}
};
Expand All @@ -45,15 +52,26 @@ function SignUpContainer() {
const regExp =
/^(([^<>()\[\].,;:\s@"]+(\.[^<>()\[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i;
if (!regExp.test(email)) {
console.log(email);
return message.error(EMAIL_CHECK);
return message.error(EMAIL_CHECK, 5);
}
};

// ๋น„๋ฐ€๋ฒˆํ˜ธ
const isSamePassword = (info) => {
if (info.password !== info.passwordConfirm) {
// ๋‹‰๋„ค์ž„ ๊ฒ€์ฆ
const isNickname = (nickname) => {
const regExp = /^[๊ฐ€-ํžฃ|a-z|A-Z|0-9|]{2,12}$/;
if (!regExp.test(nickname)) {
return message.error(NICKNAME_CHECK, 10);
}
};

// ๋น„๋ฐ€๋ฒˆํ˜ธ ๊ฒ€์ฆ
const isPassword = (info) => {
const regExp =
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,20}$/;
if (!regExp.test(info.password)) {
return message.error(PASSWORD_CHECK);
} else if (info.password !== info.passwordConfirm) {
return message.error(PASSWORD_SAME_CHECK, 10);
}
};

Expand Down
32 changes: 21 additions & 11 deletions frontend/src/saga/auth.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
import { put } from 'redux-saga/effects';
import * as authStore from '../store/auth';
import { SIGN_UP_API } from '../utils/api/auth';
import { SIGN_IN_API, SIGN_UP_API } from '../utils/api/auth';
import axios from 'axios';
import { INNER_ERROR, SIGN_UP_SUCCESS } from '../constants';
import { INNER_ERROR, SIGN_IN_SUCCESS, SIGN_UP_SUCCESS } from '../constants';
import { finishLoading, startLoading } from '../store/loding';
import { notification } from 'antd';

// ๋กœ๊ทธ์ธ ์‚ฌ๊ฐ€ ์ˆ˜์ • ์˜ˆ์ •
function* signInSaga(action) {
/* let params = new URLSearchParams();
params.append('email', 'dawwdawdadawdaw');
params.append('password', '1234'); */
/* axios
try {
let params = new URLSearchParams();
params.append('email', '[email protected]');
params.append('password', '@test1234');
axios
.post('https://ciat-bakend.choicloudlab.com/api/v1/user/login', params)
.then((response) => {
console.log('Success');
console.log(response.status);
console.log(response.headers);
})
.catch((error) => {
console.log('error');
console.debug('error');
console.log(error.response.status);
}); */
});
} catch (error) {
console.debug(error);
} finally {
yield put(finishLoading(authStore.signInSuccess));
}
}

function* signUpSaga(action) {
try {
yield put(startLoading(authStore.signUpSuccess));
yield put(startLoading(authStore.signUp));
const { data } = yield axios.post(SIGN_UP_API, action.data);
yield put({ type: authStore.signUpSuccess, payload: data });
notification.success({
message: 'CIAT',
description: SIGN_UP_SUCCESS,
});

//์ˆ˜์ • ์˜ˆ์ •
window.location.href = '/';
setTimeout(() => {
window.location.href = '/';
}, 1500);
} catch (e) {
// ์ด๋ฉ”์ผ ์ค‘๋ณต ํ™•์ธ ๋กœ์ง ์ถ”๊ฐ€์˜ˆ์ •
alert('์ด๋ฏธ ๋“ฑ๋ก๋œ ์ด๋ฉ”์ผ์ž…๋‹ˆ๋‹ค.');
Expand All @@ -55,4 +65,4 @@ function* signUpSaga(action) {
}
}

export { signUpSaga };
export { signUpSaga, signInSaga };
20 changes: 17 additions & 3 deletions frontend/src/store/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { takeLatest } from 'redux-saga/effects';
import { createSlice } from '@reduxjs/toolkit';
import { signUpSaga } from '../saga/auth';
import { signUpSaga, signInSaga } from '../saga/auth';

const initialState = {
data: {
Expand All @@ -10,12 +10,14 @@ const initialState = {
passwordConfirm: '',
},
userId: '',
isLogin: '',
error: null,
};
const authSlice = createSlice({
name: 'auth',
initialState,
reducers: {
signUp: (state) => state,
signUpSuccess: (state, action) => {
state.userId = action.payload;
state.error = null;
Expand All @@ -26,15 +28,27 @@ const authSlice = createSlice({
console.debug('error', action.payload);
return state;
},
signInSuccess: (state, action) => {
state.isLogin = action.payload;
state.error = null;
return state;
},
signInFail: (state, action) => {
state.error = action.payload;
console.debug('error', action.payload);
return state;
},
},
});

const { actions, reducer: authReducer } = authSlice;

export const { signUpSuccess, signUpFail } = actions;
export const { signUp, signUpSuccess, signUpFail, signInSuccess, signInFail } =
actions;

export { authReducer };

export function* authSaga() {
yield takeLatest(signUpSuccess.type, signUpSaga);
yield takeLatest(signUp.type, signUpSaga);
yield takeLatest(signInSuccess.type, signInSaga);
}

0 comments on commit 8de2666

Please sign in to comment.