Skip to content

Commit

Permalink
hi-hyein#212 validateStore.js 제거 Validate.js 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazel-hi committed Sep 8, 2020
1 parent 126a5de commit fc5e432
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 70 deletions.
8 changes: 2 additions & 6 deletions packages/frontend/src/Components/popup/LayerFindPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import React, { Component } from "react";
// import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import TextField from "@material-ui/core/TextField";
import Button from "@material-ui/core/Button";
import { observer, inject } from "mobx-react";
import ShowHelperText from "../ShowHelperText";

@inject("validateStore")
@observer
import Validate from "../../utils/validate";
class LayerFindPassword extends Component {
state = {
email: {
Expand Down Expand Up @@ -34,13 +31,12 @@ class LayerFindPassword extends Component {

emailOnchange = (e) => {
const value = e.target.value;
this.props.validateStore.validateValue = value;

this.setState((prevState) => ({
email: {
...prevState.email,
value: value,
validate: this.props.validateStore.getValidate("MAIL"),
validate: Validate.getEmalValidate(value),
match: this.state.email.value ? null : null,
},
}));
Expand Down
10 changes: 3 additions & 7 deletions packages/frontend/src/Components/popup/LayerJoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import Checkbox from "@material-ui/core/Checkbox";
import AgreeLink from "../agree/AgreeLink";
import Service from "../agree/Service";
import Privacy from "../agree/Privacy";
import { observer, inject } from "mobx-react";
import ShowHelperText from "../ShowHelperText";
import Validate from "../../utils/validate";

@inject("validateStore")
@observer
class LayerJoin extends Component {
state = {
email: {
Expand Down Expand Up @@ -79,7 +77,6 @@ class LayerJoin extends Component {

emailOnChange = (e) => {
const value = e.target.value;
this.props.validateStore.validateValue = value;

this.setState((prevState) => ({
email: {
Expand All @@ -100,15 +97,14 @@ class LayerJoin extends Component {
email: {
...prevState.email,
overlapping: json,
validate: this.props.validateStore.getValidate("MAIL"),
validate: Validate.getEmalValidate(value),
},
}));
});
};

passwordOnChange = (e) => {
const value = e.target.value;
this.props.validateStore.validateValue = value;

this.setState((prevState) => ({
password: {
Expand All @@ -120,7 +116,7 @@ class LayerJoin extends Component {
this.setState((prevState) => ({
password: {
...prevState.password,
validate: this.props.validateStore.getValidate("PASSWORD"),
validate: Validate.getPasswordValidate(value),
},
}));
};
Expand Down
9 changes: 4 additions & 5 deletions packages/frontend/src/Components/popup/LayerLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import TextField from "@material-ui/core/TextField";
import Button from "@material-ui/core/Button";
import { observer, inject } from "mobx-react";
import ShowHelperText from "../ShowHelperText";
import Validate from "../../utils/validate";

@inject("loginStore", "validateStore")
@inject("loginStore")
@observer
class LayerLogin extends Component {
state = {
Expand Down Expand Up @@ -46,26 +47,24 @@ class LayerLogin extends Component {

userIdHandler = (e) => {
const value = e.target.value;
this.props.validateStore.validateValue = value;

this.setState((prevState) => ({
email: {
...prevState.email,
value: value,
validate: this.props.validateStore.getValidate("MAIL"),
validate: Validate.getEmalValidate(value),
},
}));
};

userPwHandler = (e) => {
const value = e.target.value;
this.props.validateStore.validateValue = value;

this.setState((prevState) => ({
password: {
...prevState.password,
value: value,
validate: this.props.validateStore.getValidate("PASSWORD"),
validate: Validate.getPasswordValidate(value),
},
}));
};
Expand Down
11 changes: 3 additions & 8 deletions packages/frontend/src/Components/popup/LayerModifyInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import React, { Component } from "react";
// import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import TextField from "@material-ui/core/TextField";
import Button from "@material-ui/core/Button";
import { observer, inject } from "mobx-react";
import ShowHelperText from "../ShowHelperText";

@inject("validateStore")
@observer
import Validate from "../../utils/validate";
class LayerModifyInfo extends Component {
state = {
signupDate: "",
Expand Down Expand Up @@ -69,21 +66,19 @@ class LayerModifyInfo extends Component {
// 이름 유효성 검사, state 저장
nameOnChange = (e) => {
const value = e.target.value;
this.props.validateStore.validateValue = value;

this.setState((prevState) => ({
name: {
...prevState.name,
value: value,
validate: this.props.validateStore.getValidate("NAME"),
validate: Validate.getNameValidate(value),
},
}));
};

// 비밀번호 유효성 검사, state 저장
passwordOnChange = (e) => {
const value = e.target.value;
this.props.validateStore.validateValue = value;

this.setState((prevState) => ({
password: {
Expand All @@ -93,7 +88,7 @@ class LayerModifyInfo extends Component {
}));

// 비밀번호 유효성검사
const validate = this.props.validateStore.getValidate("PASSWORD");
const validate = Validate.getPasswordValidate(value);
if (!validate) {
if (e.target.value.length <= 0) {
this.setState((prevState) => ({
Expand Down
18 changes: 8 additions & 10 deletions packages/frontend/src/Stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import SearchStore from "./searchStore";
import BtnStore from "./btnStore";
import loginStore from "./loginStore";
import PopupStore from "./popupStore";
import validateStore from "./validateStore";

class RootStore {
constructor() {
this.listStore = new ListStore(this);
this.searchStore = new SearchStore(this);
this.btnStore = new BtnStore(this);
this.loginStore = new loginStore(this);
this.popupStore = new PopupStore(this);
this.validateStore = new validateStore(this);
}
constructor() {
this.listStore = new ListStore(this);
this.searchStore = new SearchStore(this);
this.btnStore = new BtnStore(this);
this.loginStore = new loginStore(this);
this.popupStore = new PopupStore(this);
}
}

export default RootStore;
export default RootStore;
34 changes: 0 additions & 34 deletions packages/frontend/src/Stores/validateStore.js

This file was deleted.

16 changes: 16 additions & 0 deletions packages/frontend/src/utils/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const getEmalValidate = (value) => {
const format = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
return format.test(value);
};

const getPasswordValidate = (value) => {
const format = /^(?=[a-zA-Z0-9!@$%^*#])(?!.*[^a-zA-Z0-9!@$%^*#]).{6,15}$/;
return format.test(value);
};

const getNameValidate = (value) => {
const format = /^[가-힣a-zA-Z]{2,20}$/;
return format.test(value);
};

export default { getEmalValidate, getPasswordValidate, getNameValidate };

0 comments on commit fc5e432

Please sign in to comment.