Merge pull request #145 from apuc/registration

Registration
This commit is contained in:
NikoM1k 2023-11-05 20:42:47 +03:00 committed by GitHub
commit e0da5ed74a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 17 deletions

View File

@ -2,6 +2,8 @@ import React, { useState } from "react";
import { apiRequest } from "@api/request"; import { apiRequest } from "@api/request";
import { useNotification } from "@hooks/useNotification";
import BaseButton from "@components/Common/BaseButton/BaseButton"; import BaseButton from "@components/Common/BaseButton/BaseButton";
import ModalLayout from "@components/Common/ModalLayout/ModalLayout"; import ModalLayout from "@components/Common/ModalLayout/ModalLayout";
@ -18,6 +20,23 @@ export const ModalRegistration = ({ active, setActive }) => {
password: "", 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 = () => { const submitHandler = () => {
apiRequest("/register/sign-up", { apiRequest("/register/sign-up", {
method: "POST", method: "POST",
@ -26,8 +45,14 @@ export const ModalRegistration = ({ active, setActive }) => {
email: inputsValue.email, email: inputsValue.email,
password: inputsValue.password, password: inputsValue.password,
}, },
}).then((data) => { }).then(() => {
console.log(data); setActive(false);
resetInputsValue();
showNotification({
show: true,
text: "Аккаунт успешно создан",
type: "success",
});
}); });
}; };
return ( return (
@ -84,9 +109,14 @@ export const ModalRegistration = ({ active, setActive }) => {
</div> </div>
<div className="button-box"> <div className="button-box">
<BaseButton <BaseButton
onClick={() => submitHandler()} onClick={(e) => {
e.preventDefault();
submitHandler();
}}
styles={ styles={
inputsValue.userName && inputsValue.email && inputsValue.password inputsValue.userName &&
validateEmail(inputsValue.email) &&
inputsValue.password
? "button-box__submit" ? "button-box__submit"
: "button-box__submit disable" : "button-box__submit disable"
} }

View File

@ -73,8 +73,15 @@ export const Navigation = () => {
if (localStorage.getItem("role_status") === "18") { if (localStorage.getItem("role_status") === "18") {
return; return;
} }
if (Object.keys(profileInfo).length) {
return;
}
apiRequest(`/user/me`).then((profileInfo) => apiRequest(`/user/me`).then((profileInfo) =>
dispatch(setProfileInfo(profileInfo.userCard)) dispatch(
setProfileInfo(
profileInfo.userCard ? profileInfo.userCard : profileInfo
)
)
); );
}, [dispatch]); }, [dispatch]);
@ -93,12 +100,12 @@ export const Navigation = () => {
<div className="profileHeader__personalInfo"> <div className="profileHeader__personalInfo">
<h3 className="profileHeader__personalInfoName"> <h3 className="profileHeader__personalInfoName">
{user === "developer" ? profileInfo?.fio : ""} {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}
</h3> </h3>
<NavLink end to={"/profile"}> <NavLink end to={"/profile"}>
<img <img
src={ src={
profileInfo.photo ? urlForLocal(profileInfo.photo) : avatarMok profileInfo?.photo ? urlForLocal(profileInfo.photo) : avatarMok
} }
className="profileHeader__personalInfoAvatar" className="profileHeader__personalInfoAvatar"
alt="avatar" alt="avatar"

View File

@ -22,6 +22,8 @@ import { Navigation } from "@components/Navigation/Navigation";
import { ProfileBreadcrumbs } from "@components/ProfileBreadcrumbs/ProfileBreadcrumbs"; import { ProfileBreadcrumbs } from "@components/ProfileBreadcrumbs/ProfileBreadcrumbs";
import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader"; import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader";
import avatarMok from "assets/images/avatarMok.png";
import { ProfileCalendarComponent } from "./ProfileCalendarComponent"; import { ProfileCalendarComponent } from "./ProfileCalendarComponent";
import "./profileCalendar.scss"; import "./profileCalendar.scss";
@ -94,12 +96,15 @@ export const ProfileCalendar = () => {
<div className="summary__info"> <div className="summary__info">
<div className="summary__person"> <div className="summary__person">
<img <img
src={urlForLocal(profileInfo.photo)} src={
profileInfo?.photo ? urlForLocal(profileInfo.photo) : avatarMok
}
className="summary__avatar" className="summary__avatar"
alt="avatar" alt="avatar"
/> />
<p className="summary__name"> <p className="summary__name">
{profileInfo.fio}, {profileInfo.specification} разработчик {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username},{" "}
{profileInfo.specification} разработчик
</p> </p>
</div> </div>
<Link to="/report"> <Link to="/report">

View File

@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { NavLink, useNavigate } from "react-router-dom"; 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 { getRole } from "@redux/roleSlice";
import { apiRequest } from "@api/request"; import { apiRequest } from "@api/request";
@ -14,7 +14,7 @@ import "./profileHeader.scss";
export const ProfileHeader = () => { export const ProfileHeader = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const dispatch = useDispatch(); const dispatch = useDispatch();
const profileInfo = useSelector(getProfileInfo);
const userRole = useSelector(getRole); const userRole = useSelector(getRole);
const [user] = useState( const [user] = useState(
localStorage.getItem("role_status") === "18" ? "partner" : "developer" localStorage.getItem("role_status") === "18" ? "partner" : "developer"
@ -26,8 +26,15 @@ export const ProfileHeader = () => {
if (localStorage.getItem("role_status") === "18") { if (localStorage.getItem("role_status") === "18") {
return; return;
} }
if (Object.keys(profileInfo).length) {
return;
}
apiRequest(`/user/me`).then((profileInfo) => { apiRequest(`/user/me`).then((profileInfo) => {
dispatch(setProfileInfo(profileInfo.userCard)); dispatch(
setProfileInfo(
profileInfo.userCard ? profileInfo.userCard : profileInfo
)
);
}); });
}, [dispatch]); }, [dispatch]);

View File

@ -103,7 +103,7 @@ export const Profile = () => {
{user === "developer" ? ( {user === "developer" ? (
<span> <span>
<p>Добрый день,&nbsp;</p> <p>Добрый день,&nbsp;</p>
{profileInfo.fio} {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username}
</span> </span>
) : ( ) : (
"ООО НДВ Консалтинг" "ООО НДВ Консалтинг"
@ -113,7 +113,7 @@ export const Profile = () => {
<div className="summary__person"> <div className="summary__person">
<img <img
src={ src={
profileInfo.photo ? urlForLocal(profileInfo.photo) : avatarMok profileInfo?.photo ? urlForLocal(profileInfo.photo) : avatarMok
} }
className="summary__avatar" className="summary__avatar"
alt="avatar" alt="avatar"
@ -121,7 +121,8 @@ export const Profile = () => {
<p className="summary__name"> <p className="summary__name">
{user === "developer" ? ( {user === "developer" ? (
<span> <span>
{profileInfo.fio}, {profileInfo.specification} разработчик {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username},{" "}
{profileInfo?.specification} разработчик
</span> </span>
) : ( ) : (
"ООО НДВ Консалтинг" "ООО НДВ Консалтинг"

View File

@ -16,6 +16,7 @@ import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader";
import rightArrow from "assets/icons/arrows/arrowRight.svg"; import rightArrow from "assets/icons/arrows/arrowRight.svg";
import arrow from "assets/icons/arrows/left-arrow.png"; import arrow from "assets/icons/arrows/left-arrow.png";
import gitImgItem from "assets/icons/gitItemImg.svg"; import gitImgItem from "assets/icons/gitItemImg.svg";
import avatarMok from "assets/images/avatarMok.png";
import "./summary.scss"; import "./summary.scss";
@ -56,12 +57,17 @@ export const Summary = () => {
<div className={openGit ? "summary__info openGit" : "summary__info"}> <div className={openGit ? "summary__info openGit" : "summary__info"}>
<div className="summary__person"> <div className="summary__person">
<img <img
src={urlForLocal(profileInfo.photo)} src={
profileInfo?.photo
? urlForLocal(profileInfo.photo)
: avatarMok
}
className="summary__avatar" className="summary__avatar"
alt="avatar" alt="avatar"
/> />
<p className="summary__name"> <p className="summary__name">
{profileInfo.fio}, {profileInfo.specification} разработчик {profileInfo?.fio ? profileInfo?.fio : profileInfo?.username},{" "}
{profileInfo.specification} разработчик
</p> </p>
</div> </div>
{!openGit && ( {!openGit && (