This commit is contained in:
parent
ea0b47a061
commit
695cc690d9
40
src/App.jsx
40
src/App.jsx
@ -3,13 +3,13 @@ import { Outlet, useNavigate } from "react-router-dom";
|
||||
import { FormsData, UserData, TypeAnswerData, answersData } from "./context";
|
||||
import { useCookies } from "react-cookie";
|
||||
import { globalRender } from "./router/protectedRouting.js";
|
||||
import { verifyUserApi } from "./hooks/api/enterAccountApi.js"
|
||||
import classes from "./assets/styles/app.module.scss"
|
||||
import { verifyUserApi } from "./hooks/api/enterAccountApi.js";
|
||||
import classes from "./assets/styles/app.module.scss";
|
||||
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 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 InputMultipleRadio from "./components/typeAnswer/InputMultipleRadio.jsx";
|
||||
import InputRadio from "./components/typeAnswer/InputRadio.jsx";
|
||||
@ -22,14 +22,14 @@ const App = () => {
|
||||
const [user, setUser] = useState(false);
|
||||
const [answersList, setAnswersList] = useState([]);
|
||||
const [listTypeAnswer, setListTypeAnswer] = useState([
|
||||
{id: 1, text: 'Краткий ответ', typeTag: InputText},
|
||||
{id: 2, text: 'Расширенный ответ', typeTag: TextArea},
|
||||
{id: 3, text: 'Выбор из вариантов', typeTag: InputRadio},
|
||||
{id: 4, text: 'Множественный выбор', typeTag: InputMultipleRadio},
|
||||
{id: 5, text: 'Выпадающий список', typeTag: DropDownList},
|
||||
{id: 6, text: 'Да/Нет', typeTag: YesNo},
|
||||
{id: 7, text: 'Файл', typeTag: InputFile},
|
||||
{id: 8, text: 'Дата', typeTag: InputDate}
|
||||
{ id: 1, text: "Краткий ответ", typeTag: InputText },
|
||||
{ id: 2, text: "Расширенный ответ", typeTag: TextArea },
|
||||
{ id: 3, text: "Выбор из вариантов", typeTag: InputRadio },
|
||||
{ id: 4, text: "Множественный выбор", typeTag: InputMultipleRadio },
|
||||
{ id: 5, text: "Выпадающий список", typeTag: DropDownList },
|
||||
{ id: 6, text: "Да/Нет", typeTag: YesNo },
|
||||
{ id: 7, text: "Файл", typeTag: InputFile },
|
||||
{ id: 8, text: "Дата", typeTag: InputDate },
|
||||
]);
|
||||
|
||||
// useEffect(() => globalRender(window.location.pathname, user, navigate));
|
||||
@ -38,25 +38,27 @@ const App = () => {
|
||||
useEffect(() => {
|
||||
async function verifyUser() {
|
||||
const response = await verifyUserApi(cookies.token);
|
||||
console.log("app", user);
|
||||
|
||||
if (response) {
|
||||
if (response.status === 200) {
|
||||
setUser(response.data);
|
||||
}
|
||||
else {
|
||||
console.log(response)
|
||||
} else {
|
||||
console.log(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
verifyUser();
|
||||
}, [])
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<UserData.Provider value={{ user, setUser }}>
|
||||
<answersData.Provider value={{ answersList, setAnswersList }}>
|
||||
<FormsData.Provider value={{ forms, setForms }}>
|
||||
<TypeAnswerData.Provider value={{ listTypeAnswer, setListTypeAnswer }}>
|
||||
<TypeAnswerData.Provider
|
||||
value={{ listTypeAnswer, setListTypeAnswer }}
|
||||
>
|
||||
<div className={classes.main}>
|
||||
<div className={classes.container}>
|
||||
<div className={classes.header}>
|
||||
@ -71,7 +73,7 @@ const App = () => {
|
||||
</FormsData.Provider>
|
||||
</answersData.Provider>
|
||||
</UserData.Provider>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
@ -4,24 +4,9 @@ import classes from "../assets/styles/components/navbar.module.scss";
|
||||
import { verifyUserApi } from "../hooks/api/enterAccountApi";
|
||||
|
||||
const NavBar = ({ navigate, auth, setAuth }) => {
|
||||
// const [cookies, _, __] = useCookies(["user"]);
|
||||
|
||||
// useEffect(() => {
|
||||
// async function verifyUser() {
|
||||
// const response = await verifyUserApi(cookies.token);
|
||||
|
||||
// if (response) {
|
||||
// if (response.status === 200) {
|
||||
// setAuth(response.data);
|
||||
// }
|
||||
// else {
|
||||
// console.log(response)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// verifyUser()
|
||||
// }, []);
|
||||
useEffect(() => {
|
||||
console.log("nav", auth);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={classes.main}>
|
||||
@ -29,23 +14,35 @@ const NavBar = ({navigate, auth, setAuth}) => {
|
||||
<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>}
|
||||
{auth ? (
|
||||
auth.is_admin ? (
|
||||
<span onClick={() => navigate("/forms")}>Мои формы</span>
|
||||
) : (
|
||||
<span></span>
|
||||
)
|
||||
) : (
|
||||
<span></span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className={classes.profile}>
|
||||
{auth ?
|
||||
{auth ? (
|
||||
<div className={classes.profile__authorized}>
|
||||
<span onClick={() => navigate("/profile")}>Профиль ({auth.login})</span>
|
||||
</div> :
|
||||
<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>}
|
||||
<span onClick={() => navigate("/enter")}>
|
||||
Вход <i class="fa-solid fa-arrow-right-to-bracket"></i>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default NavBar;
|
@ -1,14 +1,18 @@
|
||||
const constructorAnswerValidate = (state, messageReject = "Ошибка", messageResolve = undefined) => {
|
||||
return state ?
|
||||
{
|
||||
const constructorAnswerValidate = (
|
||||
state,
|
||||
messageReject = "Ошибка",
|
||||
messageResolve = undefined
|
||||
) => {
|
||||
return state
|
||||
? {
|
||||
status: true,
|
||||
message: messageResolve
|
||||
} :
|
||||
{
|
||||
message: messageResolve,
|
||||
}
|
||||
: {
|
||||
status: false,
|
||||
message: messageReject
|
||||
}
|
||||
}
|
||||
message: messageReject,
|
||||
};
|
||||
};
|
||||
|
||||
const totalRegisterValidate = (data) => {
|
||||
const listValidation = [
|
||||
@ -16,16 +20,19 @@ const totalRegisterValidate = (data) => {
|
||||
// constructorAnswerValidate(data.surname.length, "Обязательное поле."),
|
||||
// constructorAnswerValidate(data.email.length, "Обязательное поле."),
|
||||
// constructorAnswerValidate(data.phone.length, "Обязательное поле."),
|
||||
constructorAnswerValidate(data.password === data.repiedPassword, "Введенные пароли не совпадают."),
|
||||
constructorAnswerValidate(data.password >= 8, "Пароль должен иметь более 8 символов.")
|
||||
]
|
||||
constructorAnswerValidate(
|
||||
data.password === data.repiedPassword,
|
||||
"Введенные пароли не совпадают."
|
||||
),
|
||||
// constructorAnswerValidate(data.password >= 8, "Пароль должен иметь более 8 символов.")
|
||||
];
|
||||
|
||||
for (let value of listValidation) {
|
||||
if (!value.status) {
|
||||
return value
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return { status: true }
|
||||
}
|
||||
return { status: true };
|
||||
};
|
||||
|
||||
export { totalRegisterValidate, constructorAnswerValidate }
|
||||
export { totalRegisterValidate, constructorAnswerValidate };
|
||||
|
@ -49,18 +49,19 @@ const EnterAccount = () => {
|
||||
});
|
||||
|
||||
if (response.status === 200) {
|
||||
setUser({
|
||||
email: email,
|
||||
phone: phone,
|
||||
login: login,
|
||||
surname: surname,
|
||||
patronymic: patronymic,
|
||||
password: password,
|
||||
});
|
||||
// setUser({
|
||||
// email: email,
|
||||
// phone: phone,
|
||||
// login: login,
|
||||
// surname: surname,
|
||||
// patronymic: patronymic,
|
||||
// password: password,
|
||||
// });
|
||||
const responseMe = await verifyUserApi(response.data.token);
|
||||
setUser(responseMe.data);
|
||||
setCookie("token", response.data.token);
|
||||
cleanState();
|
||||
window.location.reload();
|
||||
// navigate("/");
|
||||
navigate("/");
|
||||
} else {
|
||||
console.log("Error");
|
||||
}
|
||||
@ -71,13 +72,10 @@ const EnterAccount = () => {
|
||||
|
||||
if (response.status === 200) {
|
||||
setCookie("token", response.data.token);
|
||||
const responseMe = await verifyUserApi(response.data.token);
|
||||
setUser(responseMe.data);
|
||||
cleanState();
|
||||
// setUser({
|
||||
// login: login
|
||||
// })
|
||||
window.location.reload();
|
||||
// navigate("/")
|
||||
// window.location.reload()
|
||||
navigate("/");
|
||||
} else {
|
||||
console.log(response);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user