fix profile
All checks were successful
publish-main / release-image (push) Successful in 7m10s

This commit is contained in:
kuwsh1n 2024-05-08 23:19:32 +03:00
parent e4dba30177
commit caf16c4ea9
5 changed files with 30 additions and 22 deletions

View File

@ -41,6 +41,7 @@ const App = () => {
if (response.status === 200) { if (response.status === 200) {
setUser(response.data); setUser(response.data);
console.log(response.data)
globalRender(window.location.pathname, response.data, navigate); globalRender(window.location.pathname, response.data, navigate);
} }
else { else {

View File

@ -8,6 +8,10 @@
border-radius: 5px; border-radius: 5px;
font-family: "Montserrat", sans-serif; font-family: "Montserrat", sans-serif;
} }
&__red {
color: white;
background-color: rgb(235, 130, 130);
}
&__green { &__green {
color: white; color: white;
background-color: rgb(150, 209, 158); background-color: rgb(150, 209, 158);

View File

@ -190,16 +190,16 @@ const NewForm = () => {
cleanStates(); cleanStates();
}; };
async function updateTitleForm() { // async function updateTitleForm() {
const response = await updateTitleFormApi(cookies.token, formId, newTitleForm); // const response = await updateTitleFormApi(cookies.token, formId, newTitleForm);
if (response.status === 200) { // if (response.status === 200) {
console.log(response) // console.log(response)
} // }
else { // else {
console.log(response) // console.log(response)
} // }
}; // };
async function updateOrderBlock() { async function updateOrderBlock() {
const response = await updateOrderBlockApi(cookies.token, formId, { const response = await updateOrderBlockApi(cookies.token, formId, {
@ -220,15 +220,13 @@ const NewForm = () => {
tListBlock.splice(dragElem, 1); tListBlock.splice(dragElem, 1);
}; };
tListBlock.forEach((value, i) => tListBlock[i].order = i) setListBlock(numberingBlocks(tListBlock, "order"));
setListBlock(tListBlock);
} }
}; };
async function saveForm() { async function saveForm() {
if (oldTitleFrom !== newTitleForm) { if (oldTitleFrom !== newTitleForm) {
await updateTitleForm() await updateTitleFormApi(cookies.token, formId, newTitleForm);
} }
cleanStates(); cleanStates();

View File

@ -108,19 +108,19 @@ const Profile = () => {
<span>Редактировать <i class="fa-solid fa-pen"></i></span> : <span>Редактировать <i class="fa-solid fa-pen"></i></span> :
<span>Сохранить <i class="fa-solid fa-floppy-disk"></i></span> <span>Сохранить <i class="fa-solid fa-floppy-disk"></i></span>
} }
backgroundColor={edit ? "rgb(200, 200, 200)" : ""} class={edit ? "main__white" : "main__green"}
click={() => editUser()}/> : <div>Запросите изменение профиля у администратора</div>} click={() => editUser()}/> : <div>Запросите изменение профиля у администратора</div>}
<MyButton <MyButton
text={ text={
<span>Выйти</span> <span>Выйти</span>
} }
backgroundColor={edit ? "rgb(252, 151, 151)" : ""} class={"main__red"}
click={() => exitAccount()}/> click={() => exitAccount()}/>
</div> </div>
</div> </div>
<div className={classes.profile__wrapper__body}> <div className={classes.profile__wrapper__body}>
{Object.keys(user).map(key => key !== "is_admin" ? <div className={classes.profile__wrapper__body__item}> {Object.keys(user).map(key => key !== "is_admin" && key !== "is_teacher" && key !== "id" ? <div className={classes.profile__wrapper__body__item}>
<div class="input-group mb-3"> <div class="input-group mb-3">
<span class="input-group-text">{key}</span> <span class="input-group-text">{key}</span>
<input <input

View File

@ -1,25 +1,30 @@
const protectedUrl = { const protectedUrl = {
notAuthorized: [ notAuthorized: [
"/forms", new RegExp("/forms"),
"/forms/edit", new RegExp("/forms/\\w+/edit"),
"/profile" new RegExp("/profile"),
new RegExp("/forms/\\w+/answers"),
new RegExp("/tokens/\\w+"),
], ],
Authorized: [ Authorized: [
"/enter" "/enter"
], ],
notRights: [ notRights: [
"/forms" new RegExp("/forms"),
new RegExp("/forms/\\w+/edit"),
new RegExp("/forms/\\w+/answers"),
new RegExp("/tokens/\\w+"),
] ]
} }
function globalRender(url, user, navigate) { function globalRender(url, user, navigate) {
if (!user && protectedUrl.notAuthorized.some(item => item === url)) { if (!user && protectedUrl.notAuthorized.some(item => url.match(item) ? url.match(item)[0] === url : false)) {
navigate("/enter") navigate("/enter")
} }
else if (user && protectedUrl.Authorized.some(item => item === url)) { else if (user && protectedUrl.Authorized.some(item => item === url)) {
navigate("/") navigate("/")
} }
else if (user && protectedUrl.notRights.some(item => item === url)) { else if (user && protectedUrl.notRights.some(item => url.match(item) ? url.match(item)[0] === url : false)) {
if (!user.is_admin) { if (!user.is_admin) {
navigate("/") navigate("/")
} }