Skip to content

Commit

Permalink
feature(FE) : register form 서버 연결 (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjh96 committed Feb 9, 2023
1 parent 55eedb3 commit 7e50ddf
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 29 deletions.
9 changes: 9 additions & 0 deletions client/src/apis/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import client from './client';

export const regiseterUser = async (data) => {
const response = await client.post('user/join', data);

return response;
};

export const login = async () => {};
62 changes: 47 additions & 15 deletions client/src/components/auth/register.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { inputForm } from '@/components/common';
import { regiseterUser } from '@/apis/auth';
import { navigate } from '@/core/router';
import { INPUT } from '@/constants/constant';
import { $ } from '@/utils';
import { _ } from '@/utils/customFx';

const register = () => {
const REGISTER_INPUT_TYPE = ['email', 'verificationCode', 'tel', 'password'];
const REGISTER_INPUT_TYPE = ['userName', 'email', 'verificationCode', 'tel', 'password'];
const emailReg = /^[a-zA-Z0-9+-_.]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
const codeReg = /^[0-9]{6}$/i;

let userData = {
name: '',
email: '',
verificationCode: '',
phoneNumber: '',
Expand All @@ -21,18 +25,25 @@ const register = () => {
<h5>기프티콘을 효율적으로 관리해보세요.</h5>
`;

const setUserData = ({ target }) => {
const setUserData = ({ target }, targets) => {
const dataType = _.getDataset(target, 'data-input');
const newUserData = { ...userData };
checkValidateAll(targets);

if (!target.validity.valid) return;

newUserData[dataType] = target.value;
userData = newUserData;

if (target.validity.valid) {
newUserData[dataType] = target.value;
userData = newUserData;
}
console.log(userData);
return userData;
};

const checkValidateAll = (targets) => {
if (![...targets].every((target) => target.validity.valid)) return;

$.qs('.auth-button').classList.add('active');
};

const addCodeForm = (e, resolve) => {
const formTarget = $.qs('#verification-code-input-section');

Expand All @@ -53,22 +64,35 @@ const register = () => {
};

const testValidation = ({ target }, type, reg) => {
if (target.type === 'tel') {
return putAutoHyphen(target);
}
if (target.type === 'tel') return putAutoHyphen(target);
const isValidate = reg.test(target.value);

changeButtonStatus(type, isValidate);
};

const handleClickSubmitButton = (e) => {
console.log(e);
e.stopPropagation();
e.preventDefault();

const { name, email, password, phoneNumber } = userData;
const data = { name, email, password, phoneNumber };

regiseterUser(data);
};

// prettier-ignore
const handleChangeInput = (target) =>
_.pipe(
$.findAll('.text-input'),
_.tap(
_.map((f) => $.on('change', setUserData)(f))
),
console.log)(target);
(targets) => _.map((f) => $.on('input', (e) => setUserData(e, targets))(f), targets),
([f]) => f)(target);

// prettier-ignore
const handleClickGoBack = (target) =>
_.pipe(
$.find('.left-arrow-button'),
$.on('click', () => navigate('/')))(target);

// prettier-ignore
const validateEmail = (target) =>
Expand All @@ -95,6 +119,12 @@ const register = () => {
$.find('#verification-code-input'),
$.on('input', (e) => testValidation(e, '.confirm-button', codeReg)))(target);

// prettier-ignore
const submitData = (target) =>
_.pipe(
$.find('.auth-button'),
$.on('click', (e) => handleClickSubmitButton(e)))(target);

// prettier-ignore
const render = () =>
new Promise(resolve =>
Expand All @@ -115,10 +145,12 @@ const register = () => {
_.go(
render(),
handleChangeInput,
handleClickGoBack,
validateEmail,
validatePhone,
sendVerificationCode(),
validateCode);
validateCode,
submitData);

return appendRegister;
};
Expand Down
7 changes: 7 additions & 0 deletions client/src/constants/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ const INPUT = [
dataType: 'email',
pattern: EMAIL_REG,
},
{
type: 'userName',
name: 'user-name-input',
label: '이름',
required: true,
dataType: 'userName',
},
];

export { SERVER_URL, INPUT };
13 changes: 0 additions & 13 deletions client/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import '@/styles/style.scss';
import { setScreenSize } from '@/utils';
import { navigateHome, navigateAuth, navigateMain, navigatePost } from '@/pages';
import { routes, navigate } from '@/core/router';
import { _ } from '@/utils/customFx';
// import client from '@/apis/client';

routes.push(
{ path: '/', component: navigateHome },
Expand All @@ -16,14 +14,3 @@ const path = window.location.pathname;
navigate(path);

window.addEventListener('resize', setScreenSize);

// client.get('cookie');

const test = async () => 'test';
const test2 = async () => 'test2';

const start = async () => {
_.go(await test(), console.log, test2, console.log);
};

// start();
1 change: 1 addition & 0 deletions client/src/styles/auth.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
align-items: center;

.white-header-section {
position: relative;
display: flex;
justify-content: center;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion client/src/styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
margin: 0;
padding: 0;
font-family: 'Nanum Gothic', sans-serif;
overflow: hidden;
overflow-x: hidden;
}

0 comments on commit 7e50ddf

Please sign in to comment.