-
+
+
-
-
+
Отправить заявку на регистрацию
-
- {loader &&
}
-
+
)
}
\ No newline at end of file
diff --git a/src/pages/Register.jsx b/src/pages/Register.jsx
index a84d68b..25d4f23 100644
--- a/src/pages/Register.jsx
+++ b/src/pages/Register.jsx
@@ -1,198 +1,101 @@
-import { Card, Form, Input, Select, Button, notification } from 'antd';
-import { UserOutlined,
+import { memo, useState } from 'react'
+import { Link, useHistory } from 'react-router-dom'
+import { Card, Form, Input, Select, Button } from 'antd'
+import {
+ UserOutlined,
LockOutlined,
EyeInvisibleOutlined,
- EyeTwoTone } from '@ant-design/icons'
-import logo from '../images/logo_32.png'
-import Loader from '../components/Loader'
-import { useState } from 'react'
-import { Link, useHistory } from "react-router-dom";
+ EyeTwoTone
+} from '@ant-design/icons'
import { AuthService } from '../services/api/'
-
-const openNotification = (message, type, title) => {
- notification[type]({
- message: title||'Ошибка',
- description: message,
- });
-};
-
-const { Option } = Select;
+import LoaderPortal from '../components/LoaderPortal'
+import { invokeWebApiWrapperAsync } from '../components/factory'
+import {
+ createLoginRules,
+ createPasswordRules,
+ emailRules,
+ loginRules,
+ nameRules,
+ passwordRules,
+ phoneRules
+} from '../utils/validationRules'
+import logo from '../images/logo_32.png'
const companies = [
- { name: "ООО «Газпромнефть-Хантос» ", value: 1 },
- { name: "АО «НафтаГаз»", value: 2 },
- { name: "ООО «Нафтагаз Бурение»", value: 3 },
- { name: "ООО «Газпромнефть-ННГ»", value: 4 }
-];
+ { label: 'ООО «Газпромнефть-Хантос» ', value: 1 },
+ { label: 'АО «НафтаГаз»', value: 2 },
+ { label: 'ООО «Нафтагаз Бурение»', value: 3 },
+ { label: 'ООО «Газпромнефть-ННГ»', value: 4 }
+]
-const showError = (isErrorVisible, errorObj) => {
- if (isErrorVisible)
- return Promise.reject(errorObj)
-
- return Promise.resolve()
-}
-
-const getValidationRules = (isRequired, message, isErrorVisible, errorObj) => {
- return [
- { required: isRequired, message: message },
- () => ({
- validator() {
- return showError(isErrorVisible, errorObj)
- }
- })
- ]
-}
-
-
-export default function Register() {
- const [loader, setLoader] = useState(false);
- const [isLengthErrorVisible, setIsLengthErrorVisible] = useState(false);
- const [isPasswordLengthErrorVisible, setIsPasswordLengthErrorVisible] = useState(false);
- const [isPasswordMismatchErrorVisible, setIsPasswordMismatchErrorVisible] = useState(false);
- const [selectedCompanyId, setSelectedCompanyId] = useState(companies[0].value);
- const history = useHistory();
- const [form] = Form.useForm();
-
- const logoIcon =
-
- const children = companies.map((line) => (
-
- ));
-
- const checkFormErrors = (formData) => {
- if(formData.login.length < 4 || formData.login.length > 50){
- setIsLengthErrorVisible(true)
- form.validateFields()
- return true
+const surnameRules = [...nameRules, { required: true, message: 'Пожалуйста, введите фамилию!' }]
+const regEmailRules = [{ required: true, message: 'Пожалуйста, введите email!' }, ...emailRules]
+const confirmPasswordRules = [
+ ...createPasswordRules,
+ { required: true, message: 'Пожалуйста, введите пароль повторно!' },
+ ({ getFieldValue }) => ({
+ validator(_, value) {
+ if (!value || getFieldValue('password') === value)
+ return Promise.resolve()
+ return Promise.reject(new Error('Пароли не совпадают!'))
}
+ })
+]
- if(formData.password.length < 4 || formData.password.length > 50) {
- setIsPasswordLengthErrorVisible(true)
- form.validateFields()
- return true
- }
+const logoIcon =
+const showPasswordIcon = visible => (visible ?
:
)
- if(formData.password !== formData.confirmPassword) {
- setIsPasswordMismatchErrorVisible(true)
- form.validateFields()
- return true
- }
+const createInput = (name, placeholder, rules, isPassword, dependencies) => (
+
+ {isPassword ? (
+ } iconRender={showPasswordIcon} />
+ ) : (
+ } />
+ )}
+
+)
- return false
- }
+export const Register = memo(() => {
+ const [showLoader, setShowLoader] = useState(false)
+ const history = useHistory()
- let handleRegister = async (formData) =>{
-
- if(checkFormErrors(formData))
- return
-
- formData.idCompany = +selectedCompanyId
-
- setLoader(true)
- try{
+ const handleRegister = (formData) => invokeWebApiWrapperAsync(
+ async () => {
await AuthService.register(formData)
- setLoader(false)
- openNotification("Заявка на регистрацию отправлена.", 'success')
- history.push("/login");
- }catch(e){
- openNotification(e.body, 'error')
- console.error(`Error ${e}`)
- setLoader(false)
- }
- }
-
- const createInput = (name, placeholder, isRequired, requiredValidationMessage, lengthValidationMessage) => {
-
- const rules = getValidationRules(true, requiredValidationMessage,
- isLengthErrorVisible, new Error(lengthValidationMessage))
-
- return (
-
- }
- onChange={() => {
- setIsLengthErrorVisible(false)
- form.validateFields()
- }}
- />
-
- )
- }
-
- const createPasswordInput = (name, message, errorObj, isErrorVisible, setIsErrorVisible) => {
- return (
-
- (visible ? : )}
- prefix={}
- onChange={() => {
- setIsErrorVisible(false)
- form.validateFields()
- }}
- />
-
- )
- }
+ history.push('/login')
+ },
+ setShowLoader,
+ `Ошибка отправки заявки на регистрацию`
+ )
return (
-
-
-
-
+
+
+
+
- {createInput('position', 'Должность',false)}
-
+ {createInput('position', 'Должность')}
-
-
+
+
-
-
+
Назад
-
- {loader &&
}
-
+
)
-}
\ No newline at end of file
+})
+
+export default Register
diff --git a/src/utils/validationRules.ts b/src/utils/validationRules.ts
index b439398..fb0fdf3 100644
--- a/src/utils/validationRules.ts
+++ b/src/utils/validationRules.ts
@@ -1,6 +1,6 @@
import { Rule } from 'rc-field-form/lib/interface'
-export const loginRules: Rule[] = [{
+export const createLoginRules: Rule[] = [{
min: 3,
max: 255,
message: 'Допустимая длина 3-255 символов'
@@ -10,6 +10,11 @@ export const loginRules: Rule[] = [{
message: 'Логин должен начинаться с русской или латинской буквы, содержать только (А-яA-z0-9_-.)!'
}]
+export const loginRules: Rule[] = [{
+ required: true,
+ message: 'Пожалуйста, введите имя пользователя'
+}]
+
export const nameRules: Rule[] = [{
min: 1,
max: 255,
@@ -31,5 +36,11 @@ export const emailRules: Rule[] = [{
export const passwordRules: Rule[] = [{
required: true,
- message: 'Поле не может быть пустым!'
+ message: 'Пожалуйста, введите пароль!'
+}]
+
+export const createPasswordRules: Rule[] = [{
+ min: 8,
+ max: 255,
+ message: 'Допустимая длина пароля 8-255'
}]