diff --git a/src/components/Modal/ModalRegistration/ModalRegistration.jsx b/src/components/Modal/ModalRegistration/ModalRegistration.jsx index fe4926e1..bbe925d3 100644 --- a/src/components/Modal/ModalRegistration/ModalRegistration.jsx +++ b/src/components/Modal/ModalRegistration/ModalRegistration.jsx @@ -2,6 +2,8 @@ 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"; @@ -18,6 +20,23 @@ export const ModalRegistration = ({ active, setActive }) => { password: "", }); + const validateEmail = (email) => { + // регулярное выражение для проверки email + const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + + // возвращаем true, если email проходит проверку, и false, если нет + return re.test(email); + }; + + const resetInputsValue = () => { + setInputsValue({ + userName: "", + email: "", + password: "", + }); + }; + + const { showNotification } = useNotification(); const submitHandler = () => { apiRequest("/register/sign-up", { method: "POST", @@ -26,8 +45,14 @@ export const ModalRegistration = ({ active, setActive }) => { email: inputsValue.email, password: inputsValue.password, }, - }).then((data) => { - console.log(data); + }).then(() => { + setActive(false); + resetInputsValue(); + showNotification({ + show: true, + text: "Аккаунт успешно создан", + type: "success", + }); }); }; return ( @@ -84,9 +109,14 @@ export const ModalRegistration = ({ active, setActive }) => {
submitHandler()} + onClick={(e) => { + e.preventDefault(); + submitHandler(); + }} styles={ - inputsValue.userName && 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..b0c92e9b 100644 --- a/src/components/Navigation/Navigation.jsx +++ b/src/components/Navigation/Navigation.jsx @@ -73,8 +73,15 @@ 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 +100,12 @@ export const Navigation = () => {

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

avatar {
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..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, 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,15 @@ 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..e8be662a 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..8027eedb 100644 --- a/src/pages/Summary/Summary.js +++ b/src/pages/Summary/Summary.js @@ -16,6 +16,7 @@ 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"; @@ -56,12 +57,17 @@ export const Summary = () => {

avatar

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

{!openGit && (