registration fix
All checks were successful
publish-main / release-image (push) Successful in 1m11s

This commit is contained in:
Ivan 2024-04-14 15:01:04 +03:00
parent ea0b47a061
commit 695cc690d9
Signed by untrusted user who does not match committer: ppechenkoo
GPG Key ID: 0C191B86D9582583
4 changed files with 144 additions and 140 deletions

View File

@ -3,13 +3,13 @@ import { Outlet, useNavigate } from "react-router-dom";
import { FormsData, UserData, TypeAnswerData, answersData } from "./context"; import { FormsData, UserData, TypeAnswerData, answersData } from "./context";
import { useCookies } from "react-cookie"; import { useCookies } from "react-cookie";
import { globalRender } from "./router/protectedRouting.js"; import { globalRender } from "./router/protectedRouting.js";
import { verifyUserApi } from "./hooks/api/enterAccountApi.js" import { verifyUserApi } from "./hooks/api/enterAccountApi.js";
import classes from "./assets/styles/app.module.scss" import classes from "./assets/styles/app.module.scss";
import NavBar from "./components/NavBar.jsx"; import NavBar from "./components/NavBar.jsx";
import 'bootstrap/dist/css/bootstrap.min.css'; import "bootstrap/dist/css/bootstrap.min.css";
import InputText from "./components/typeAnswer/InputText.jsx"; import InputText from "./components/typeAnswer/InputText.jsx";
import TextArea from "./components/typeAnswer/TextArea.jsx"; import TextArea from "./components/typeAnswer/TextArea.jsx";
import YesNo from "./components/typeAnswer/YesNo.jsx" import YesNo from "./components/typeAnswer/YesNo.jsx";
import InputDate from "./components/typeAnswer/InputDate.jsx"; import InputDate from "./components/typeAnswer/InputDate.jsx";
import InputMultipleRadio from "./components/typeAnswer/InputMultipleRadio.jsx"; import InputMultipleRadio from "./components/typeAnswer/InputMultipleRadio.jsx";
import InputRadio from "./components/typeAnswer/InputRadio.jsx"; import InputRadio from "./components/typeAnswer/InputRadio.jsx";
@ -17,61 +17,63 @@ import DropDownList from "./components/typeAnswer/DropDownList.jsx";
import InputFile from "./components/typeAnswer/InputFile.jsx"; import InputFile from "./components/typeAnswer/InputFile.jsx";
const App = () => { const App = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const [forms, setForms] = useState([]); const [forms, setForms] = useState([]);
const [user, setUser] = useState(false); const [user, setUser] = useState(false);
const [answersList, setAnswersList] = useState([]); const [answersList, setAnswersList] = useState([]);
const [listTypeAnswer, setListTypeAnswer] = useState([ const [listTypeAnswer, setListTypeAnswer] = useState([
{id: 1, text: 'Краткий ответ', typeTag: InputText}, { id: 1, text: "Краткий ответ", typeTag: InputText },
{id: 2, text: 'Расширенный ответ', typeTag: TextArea}, { id: 2, text: "Расширенный ответ", typeTag: TextArea },
{id: 3, text: 'Выбор из вариантов', typeTag: InputRadio}, { id: 3, text: "Выбор из вариантов", typeTag: InputRadio },
{id: 4, text: 'Множественный выбор', typeTag: InputMultipleRadio}, { id: 4, text: "Множественный выбор", typeTag: InputMultipleRadio },
{id: 5, text: 'Выпадающий список', typeTag: DropDownList}, { id: 5, text: "Выпадающий список", typeTag: DropDownList },
{id: 6, text: 'Да/Нет', typeTag: YesNo}, { id: 6, text: "Да/Нет", typeTag: YesNo },
{id: 7, text: 'Файл', typeTag: InputFile}, { id: 7, text: "Файл", typeTag: InputFile },
{id: 8, text: 'Дата', typeTag: InputDate} { id: 8, text: "Дата", typeTag: InputDate },
]); ]);
// useEffect(() => globalRender(window.location.pathname, user, navigate)); // useEffect(() => globalRender(window.location.pathname, user, navigate));
const [cookies, _, __] = useCookies(["user"]); const [cookies, _, __] = useCookies(["user"]);
useEffect(() => { useEffect(() => {
async function verifyUser() { async function verifyUser() {
const response = await verifyUserApi(cookies.token); const response = await verifyUserApi(cookies.token);
console.log("app", user);
if (response) { if (response) {
if (response.status === 200) { if (response.status === 200) {
setUser(response.data); setUser(response.data);
} } else {
else { console.log(response);
console.log(response)
}
}
} }
}
}
verifyUser(); verifyUser();
}, []) }, []);
return ( return (
<UserData.Provider value={{ user, setUser }}> <UserData.Provider value={{ user, setUser }}>
<answersData.Provider value={{ answersList, setAnswersList }}> <answersData.Provider value={{ answersList, setAnswersList }}>
<FormsData.Provider value={{ forms, setForms }}> <FormsData.Provider value={{ forms, setForms }}>
<TypeAnswerData.Provider value={{ listTypeAnswer, setListTypeAnswer }}> <TypeAnswerData.Provider
<div className={classes.main}> value={{ listTypeAnswer, setListTypeAnswer }}
<div className={classes.container}> >
<div className={classes.header}> <div className={classes.main}>
<NavBar navigate={navigate} auth={user} setAuth={setUser}/> <div className={classes.container}>
</div> <div className={classes.header}>
<div className={classes.content}> <NavBar navigate={navigate} auth={user} setAuth={setUser} />
<Outlet/> </div>
</div> <div className={classes.content}>
</div> <Outlet />
</div> </div>
</TypeAnswerData.Provider> </div>
</FormsData.Provider> </div>
</answersData.Provider> </TypeAnswerData.Provider>
</UserData.Provider> </FormsData.Provider>
) </answersData.Provider>
} </UserData.Provider>
);
};
export default App; export default App;

View File

@ -3,49 +3,46 @@ import { useCookies } from "react-cookie";
import classes from "../assets/styles/components/navbar.module.scss"; import classes from "../assets/styles/components/navbar.module.scss";
import { verifyUserApi } from "../hooks/api/enterAccountApi"; import { verifyUserApi } from "../hooks/api/enterAccountApi";
const NavBar = ({navigate, auth, setAuth}) => { const NavBar = ({ navigate, auth, setAuth }) => {
// const [cookies, _, __] = useCookies(["user"]); useEffect(() => {
console.log("nav", auth);
});
// useEffect(() => { return (
// async function verifyUser() { <div className={classes.main}>
// const response = await verifyUserApi(cookies.token); <div className={classes.wrapper}>
<div className={classes.menu}>
// if (response) { <div className={classes.menu__authorized}>
// if (response.status === 200) { <span onClick={() => navigate("/")}>Главная</span>
// setAuth(response.data); {auth ? (
// } auth.is_admin ? (
// else { <span onClick={() => navigate("/forms")}>Мои формы</span>
// console.log(response) ) : (
// } <span></span>
// } )
// } ) : (
<span></span>
// verifyUser() )}
// }, []); </div>
return (
<div className={classes.main}>
<div className={classes.wrapper}>
<div className={classes.menu}>
<div className={classes.menu__authorized}>
<span onClick={() => navigate("/")}>Главная</span>
{auth ?
auth.is_admin ? <span onClick={() => navigate("/forms")}>Мои формы</span> : <span></span> :
<span></span>}
</div>
</div>
<div className={classes.profile}>
{auth ?
<div className={classes.profile__authorized}>
<span onClick={() => navigate("/profile")}>Профиль ({auth.login})</span>
</div> :
<div className={classes.profile__nonAuthorized}>
<span onClick={() => navigate("/enter")}>Вход <i class="fa-solid fa-arrow-right-to-bracket"></i></span>
</div>}
</div>
</div>
</div> </div>
) <div className={classes.profile}>
} {auth ? (
<div className={classes.profile__authorized}>
<span onClick={() => navigate("/profile")}>
Профиль ({auth.login})
</span>
</div>
) : (
<div className={classes.profile__nonAuthorized}>
<span onClick={() => navigate("/enter")}>
Вход <i class="fa-solid fa-arrow-right-to-bracket"></i>
</span>
</div>
)}
</div>
</div>
</div>
);
};
export default NavBar; export default NavBar;

View File

@ -1,31 +1,38 @@
const constructorAnswerValidate = (state, messageReject = "Ошибка", messageResolve = undefined) => { const constructorAnswerValidate = (
return state ? state,
{ messageReject = "Ошибка",
status: true, messageResolve = undefined
message: messageResolve ) => {
} : return state
{ ? {
status: false, status: true,
message: messageReject message: messageResolve,
} }
} : {
status: false,
message: messageReject,
};
};
const totalRegisterValidate = (data) => { const totalRegisterValidate = (data) => {
const listValidation = [ const listValidation = [
constructorAnswerValidate(data.login.length, "Обязательное поле."), constructorAnswerValidate(data.login.length, "Обязательное поле."),
// constructorAnswerValidate(data.surname.length, "Обязательное поле."), // constructorAnswerValidate(data.surname.length, "Обязательное поле."),
// constructorAnswerValidate(data.email.length, "Обязательное поле."), // constructorAnswerValidate(data.email.length, "Обязательное поле."),
// constructorAnswerValidate(data.phone.length, "Обязательное поле."), // constructorAnswerValidate(data.phone.length, "Обязательное поле."),
constructorAnswerValidate(data.password === data.repiedPassword, "Введенные пароли не совпадают."), constructorAnswerValidate(
constructorAnswerValidate(data.password >= 8, "Пароль должен иметь более 8 символов.") data.password === data.repiedPassword,
] "Введенные пароли не совпадают."
),
// constructorAnswerValidate(data.password >= 8, "Пароль должен иметь более 8 символов.")
];
for (let value of listValidation) { for (let value of listValidation) {
if (!value.status) { if (!value.status) {
return value return value;
}
} }
return { status: true } }
} return { status: true };
};
export { totalRegisterValidate, constructorAnswerValidate } export { totalRegisterValidate, constructorAnswerValidate };

View File

@ -49,18 +49,19 @@ const EnterAccount = () => {
}); });
if (response.status === 200) { if (response.status === 200) {
setUser({ // setUser({
email: email, // email: email,
phone: phone, // phone: phone,
login: login, // login: login,
surname: surname, // surname: surname,
patronymic: patronymic, // patronymic: patronymic,
password: password, // password: password,
}); // });
const responseMe = await verifyUserApi(response.data.token);
setUser(responseMe.data);
setCookie("token", response.data.token); setCookie("token", response.data.token);
cleanState(); cleanState();
window.location.reload(); navigate("/");
// navigate("/");
} else { } else {
console.log("Error"); console.log("Error");
} }
@ -71,13 +72,10 @@ const EnterAccount = () => {
if (response.status === 200) { if (response.status === 200) {
setCookie("token", response.data.token); setCookie("token", response.data.token);
const responseMe = await verifyUserApi(response.data.token);
setUser(responseMe.data);
cleanState(); cleanState();
// setUser({ navigate("/");
// login: login
// })
window.location.reload();
// navigate("/")
// window.location.reload()
} else { } else {
console.log(response); console.log(response);
} }