From 98bf179b9e59871c33ed70a0397b0e510454b4d8 Mon Sep 17 00:00:00 2001 From: Mikola Date: Sat, 4 Nov 2023 02:39:58 +0300 Subject: [PATCH 1/4] registration --- .../ModalRegistration/ModalRegistration.jsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx index fe4926e1..dfa83684 100644 --- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx +++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx @@ -4,6 +4,7 @@ import { apiRequest } from "@api/request"; import BaseButton from "@components/Common/BaseButton/BaseButton"; import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; +import { useNotification } from "@hooks/useNotification"; import anyMoment from "assets/icons/anyMoment.svg"; import doc from "assets/icons/doc.svg"; @@ -17,7 +18,7 @@ export const ModalRegistration = ({ active, setActive }) => { email: "", password: "", }); - + const { showNotification } = useNotification(); const submitHandler = () => { apiRequest("/register/sign-up", { method: "POST", @@ -26,8 +27,13 @@ export const ModalRegistration = ({ active, setActive }) => { email: inputsValue.email, password: inputsValue.password, }, - }).then((data) => { - console.log(data); + }).then(() => { + setActive(false) + showNotification({ + show: true, + text: "Аккаунт успешно создан", + type: "success" + }); }); }; return ( @@ -84,7 +90,10 @@ export const ModalRegistration = ({ active, setActive }) => {
submitHandler()} + onClick={(e) => { + e.preventDefault() + submitHandler() + }} styles={ inputsValue.userName && inputsValue.email && inputsValue.password ? "button-box__submit" From 1e9ee3699d062ca904ba2bf05236929c41b43ff8 Mon Sep 17 00:00:00 2001 From: Mikola Date: Sat, 4 Nov 2023 02:44:40 +0300 Subject: [PATCH 2/4] registration --- .../ModalRegistration/ModalRegistration.jsx | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx index dfa83684..2fc4150e 100644 --- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx +++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx @@ -2,9 +2,10 @@ import React, { useState } from "react"; import { apiRequest } from "@api/request"; +import { useNotification } from "@hooks/useNotification"; + import BaseButton from "@components/Common/BaseButton/BaseButton"; import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; -import { useNotification } from "@hooks/useNotification"; import anyMoment from "assets/icons/anyMoment.svg"; import doc from "assets/icons/doc.svg"; @@ -18,6 +19,15 @@ export const ModalRegistration = ({ active, setActive }) => { email: "", password: "", }); + + const validateEmail = (email) => { + // регулярное выражение для проверки email + const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + + // возвращаем true, если email проходит проверку, и false, если нет + return re.test(email); + } + const { showNotification } = useNotification(); const submitHandler = () => { apiRequest("/register/sign-up", { @@ -28,11 +38,11 @@ export const ModalRegistration = ({ active, setActive }) => { password: inputsValue.password, }, }).then(() => { - setActive(false) + setActive(false); showNotification({ show: true, text: "Аккаунт успешно создан", - type: "success" + type: "success", }); }); }; @@ -91,11 +101,11 @@ export const ModalRegistration = ({ active, setActive }) => {
{ - e.preventDefault() - submitHandler() + e.preventDefault(); + submitHandler(); }} styles={ - inputsValue.userName && inputsValue.email && inputsValue.password + inputsValue.userName && validateEmail(inputsValue.email) && inputsValue.password ? "button-box__submit" : "button-box__submit disable" } From 321b84a80ef3ea22d26fe3caf80e1695edd25ad7 Mon Sep 17 00:00:00 2001 From: Mikola Date: Sun, 5 Nov 2023 20:41:40 +0300 Subject: [PATCH 3/4] registration --- .../Modal/ModalRegistration/ModalRegistration.jsx | 13 ++++++++++++- src/components/Navigation/Navigation.jsx | 9 ++++++--- src/components/ProfileCalendar/ProfileCalendar.jsx | 7 +++++-- src/components/ProfileHeader/ProfileHeader.jsx | 9 ++++++--- src/pages/Profile/Profile.js | 6 +++--- src/pages/Summary/Summary.js | 7 +++++-- 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx index 2fc4150e..1c6fba03 100644 --- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx +++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx @@ -26,6 +26,14 @@ export const ModalRegistration = ({ active, setActive }) => { // возвращаем true, если email проходит проверку, и false, если нет return re.test(email); + }; + + const resetInputsValue = () => { + setInputsValue({ + userName: "", + email: "", + password: "", + }) } const { showNotification } = useNotification(); @@ -39,6 +47,7 @@ export const ModalRegistration = ({ active, setActive }) => { }, }).then(() => { setActive(false); + resetInputsValue() showNotification({ show: true, text: "Аккаунт успешно создан", @@ -105,7 +114,9 @@ export const ModalRegistration = ({ active, setActive }) => { submitHandler(); }} styles={ - inputsValue.userName && validateEmail(inputsValue.email) && inputsValue.password + inputsValue.userName && + validateEmail(inputsValue.email) && + inputsValue.password ? "button-box__submit" : "button-box__submit disable" } diff --git a/src/components/Navigation/Navigation.jsx b/src/components/Navigation/Navigation.jsx index cbac4365..cac1c4ae 100644 --- a/src/components/Navigation/Navigation.jsx +++ b/src/components/Navigation/Navigation.jsx @@ -73,8 +73,11 @@ export const Navigation = () => { if (localStorage.getItem("role_status") === "18") { return; } + if (Object.keys(profileInfo).length) { + return; + } apiRequest(`/user/me`).then((profileInfo) => - dispatch(setProfileInfo(profileInfo.userCard)) + dispatch(setProfileInfo(profileInfo.userCard ? profileInfo.userCard : profileInfo)) ); }, [dispatch]); @@ -93,12 +96,12 @@ export const Navigation = () => {

- {user === "developer" ? profileInfo?.fio : ""} + {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}

avatar { @@ -94,12 +95,14 @@ export const ProfileCalendar = () => {
avatar

- {profileInfo.fio}, {profileInfo.specification} разработчик + {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}, {profileInfo.specification} разработчик

diff --git a/src/components/ProfileHeader/ProfileHeader.jsx b/src/components/ProfileHeader/ProfileHeader.jsx index 96daa0fe..dce0506f 100644 --- a/src/components/ProfileHeader/ProfileHeader.jsx +++ b/src/components/ProfileHeader/ProfileHeader.jsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { NavLink, useNavigate } from "react-router-dom"; -import { auth, setProfileInfo } from "@redux/outstaffingSlice"; +import {auth, getProfileInfo, setProfileInfo} from "@redux/outstaffingSlice"; import { getRole } from "@redux/roleSlice"; import { apiRequest } from "@api/request"; @@ -14,7 +14,7 @@ import "./profileHeader.scss"; export const ProfileHeader = () => { const navigate = useNavigate(); const dispatch = useDispatch(); - + const profileInfo = useSelector(getProfileInfo); const userRole = useSelector(getRole); const [user] = useState( localStorage.getItem("role_status") === "18" ? "partner" : "developer" @@ -26,8 +26,11 @@ export const ProfileHeader = () => { if (localStorage.getItem("role_status") === "18") { return; } + if (Object.keys(profileInfo).length) { + return; + } apiRequest(`/user/me`).then((profileInfo) => { - dispatch(setProfileInfo(profileInfo.userCard)); + dispatch(setProfileInfo(profileInfo.userCard ? profileInfo.userCard : profileInfo)) }); }, [dispatch]); diff --git a/src/pages/Profile/Profile.js b/src/pages/Profile/Profile.js index da2af30b..6ba757d1 100644 --- a/src/pages/Profile/Profile.js +++ b/src/pages/Profile/Profile.js @@ -103,7 +103,7 @@ export const Profile = () => { {user === "developer" ? (

Добрый день, 

- {profileInfo.fio} + {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}
) : ( "ООО НДВ Консалтинг" @@ -113,7 +113,7 @@ export const Profile = () => {
avatar {

{user === "developer" ? ( - {profileInfo.fio}, {profileInfo.specification} разработчик + {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}, {profileInfo?.specification} разработчик ) : ( "ООО НДВ Консалтинг" diff --git a/src/pages/Summary/Summary.js b/src/pages/Summary/Summary.js index 5e00d31d..8144a31c 100644 --- a/src/pages/Summary/Summary.js +++ b/src/pages/Summary/Summary.js @@ -18,6 +18,7 @@ import arrow from "assets/icons/arrows/left-arrow.png"; import gitImgItem from "assets/icons/gitItemImg.svg"; import "./summary.scss"; +import avatarMok from "assets/images/avatarMok.png"; export const Summary = () => { if (localStorage.getItem("role_status") === "18") { @@ -56,12 +57,14 @@ export const Summary = () => {

avatar

- {profileInfo.fio}, {profileInfo.specification} разработчик + {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}, {profileInfo.specification} разработчик

{!openGit && ( From 59fde487ea5a48d02313240e32485cadb5c4c4ea Mon Sep 17 00:00:00 2001 From: Mikola Date: Sun, 5 Nov 2023 20:42:03 +0300 Subject: [PATCH 4/4] registration --- .../Modal/ModalRegistration/ModalRegistration.jsx | 6 +++--- src/components/Navigation/Navigation.jsx | 6 +++++- src/components/ProfileCalendar/ProfileCalendar.jsx | 12 +++++++----- src/components/ProfileHeader/ProfileHeader.jsx | 8 ++++++-- src/pages/Profile/Profile.js | 3 ++- src/pages/Summary/Summary.js | 9 ++++++--- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx index 1c6fba03..bbe925d3 100644 --- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx +++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx @@ -33,8 +33,8 @@ export const ModalRegistration = ({ active, setActive }) => { userName: "", email: "", password: "", - }) - } + }); + }; const { showNotification } = useNotification(); const submitHandler = () => { @@ -47,7 +47,7 @@ export const ModalRegistration = ({ active, setActive }) => { }, }).then(() => { setActive(false); - resetInputsValue() + resetInputsValue(); showNotification({ show: true, text: "Аккаунт успешно создан", diff --git a/src/components/Navigation/Navigation.jsx b/src/components/Navigation/Navigation.jsx index cac1c4ae..b0c92e9b 100644 --- a/src/components/Navigation/Navigation.jsx +++ b/src/components/Navigation/Navigation.jsx @@ -77,7 +77,11 @@ export const Navigation = () => { return; } apiRequest(`/user/me`).then((profileInfo) => - dispatch(setProfileInfo(profileInfo.userCard ? profileInfo.userCard : profileInfo)) + dispatch( + setProfileInfo( + profileInfo.userCard ? profileInfo.userCard : profileInfo + ) + ) ); }, [dispatch]); diff --git a/src/components/ProfileCalendar/ProfileCalendar.jsx b/src/components/ProfileCalendar/ProfileCalendar.jsx index 9100e55f..55c701ff 100644 --- a/src/components/ProfileCalendar/ProfileCalendar.jsx +++ b/src/components/ProfileCalendar/ProfileCalendar.jsx @@ -22,8 +22,9 @@ import { Navigation } from "@components/Navigation/Navigation"; import { ProfileBreadcrumbs } from "@components/ProfileBreadcrumbs/ProfileBreadcrumbs"; import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader"; -import { ProfileCalendarComponent } from "./ProfileCalendarComponent"; import avatarMok from "assets/images/avatarMok.png"; + +import { ProfileCalendarComponent } from "./ProfileCalendarComponent"; import "./profileCalendar.scss"; export const ProfileCalendar = () => { @@ -95,14 +96,15 @@ export const ProfileCalendar = () => {
avatar

- {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}, {profileInfo.specification} разработчик + {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username},{" "} + {profileInfo.specification} разработчик

diff --git a/src/components/ProfileHeader/ProfileHeader.jsx b/src/components/ProfileHeader/ProfileHeader.jsx index dce0506f..ea7d98bd 100644 --- a/src/components/ProfileHeader/ProfileHeader.jsx +++ b/src/components/ProfileHeader/ProfileHeader.jsx @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { NavLink, useNavigate } from "react-router-dom"; -import {auth, getProfileInfo, setProfileInfo} from "@redux/outstaffingSlice"; +import { auth, getProfileInfo, setProfileInfo } from "@redux/outstaffingSlice"; import { getRole } from "@redux/roleSlice"; import { apiRequest } from "@api/request"; @@ -30,7 +30,11 @@ export const ProfileHeader = () => { return; } apiRequest(`/user/me`).then((profileInfo) => { - dispatch(setProfileInfo(profileInfo.userCard ? profileInfo.userCard : profileInfo)) + dispatch( + setProfileInfo( + profileInfo.userCard ? profileInfo.userCard : profileInfo + ) + ); }); }, [dispatch]); diff --git a/src/pages/Profile/Profile.js b/src/pages/Profile/Profile.js index 6ba757d1..e8be662a 100644 --- a/src/pages/Profile/Profile.js +++ b/src/pages/Profile/Profile.js @@ -121,7 +121,8 @@ export const Profile = () => {

{user === "developer" ? ( - {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}, {profileInfo?.specification} разработчик + {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username},{" "} + {profileInfo?.specification} разработчик ) : ( "ООО НДВ Консалтинг" diff --git a/src/pages/Summary/Summary.js b/src/pages/Summary/Summary.js index 8144a31c..8027eedb 100644 --- a/src/pages/Summary/Summary.js +++ b/src/pages/Summary/Summary.js @@ -16,9 +16,9 @@ import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader"; import rightArrow from "assets/icons/arrows/arrowRight.svg"; import arrow from "assets/icons/arrows/left-arrow.png"; import gitImgItem from "assets/icons/gitItemImg.svg"; +import avatarMok from "assets/images/avatarMok.png"; import "./summary.scss"; -import avatarMok from "assets/images/avatarMok.png"; export const Summary = () => { if (localStorage.getItem("role_status") === "18") { @@ -58,13 +58,16 @@ export const Summary = () => {

avatar

- {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}, {profileInfo.specification} разработчик + {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username},{" "} + {profileInfo.specification} разработчик

{!openGit && (