diff --git a/frontend/src/components/SignIn/SignIn.jsx b/frontend/src/components/SignIn/SignIn.jsx index f20cb76..149abb7 100644 --- a/frontend/src/components/SignIn/SignIn.jsx +++ b/frontend/src/components/SignIn/SignIn.jsx @@ -3,13 +3,14 @@ import "./SignIn.css"; import YandexIcon from "/Yandex_icon.svg"; import { useState } from "react"; import axios from "axios"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { setBrokers } from "../store/broker-slice.jsx"; import { setUsers } from "../store/user-slice.jsx"; export default function SignIn() { const dispatch = useDispatch(); const [input, setInput] = useState(""); + let forms = useSelector((state) => state.broker.brokers); const navigate = useNavigate(); @@ -17,24 +18,16 @@ export default function SignIn() { localStorage.setItem("mail", input); try { let user = await axios.get(`http://localhost:8080/users/${input}`, { mail: input }) - + let foundItem = {} await axios.get(`http://localhost:8080/forms/${input}`).then((res) => { dispatch(setBrokers(res.data)); - dispatch(setUsers({ - "sashaOwner@mail.ru": false, - "senyaRedactor@mail.ru": false, - "vlas_vozmitel@mail.ru": false - })) + foundItem = res.data.find(item => item.ownerEmail === input); + }) + + await axios.get(`http://localhost:8080/forms/available/redactors/${foundItem.id}`).then((res) => { + console.log("res - ", res.data); + dispatch(setUsers(res.data)) }) - // let id = 0 - // await axios.get(`http://localhost:8080/forms/available/redactors/${id}`).then((res) => { - // console.log("res - ", res.data); - // dispatch(setUsers({ - // "sashaOwner@mail.ru": false, - // "senyaRedactor@mail.ru": false, - // "vlas_vozmitel@mail.ru": false - // })) - // }) navigate("/tables"); } catch (error) { diff --git a/frontend/src/components/Tables/MainHeader.jsx b/frontend/src/components/Tables/MainHeader.jsx index 51a9adf..e431315 100644 --- a/frontend/src/components/Tables/MainHeader.jsx +++ b/frontend/src/components/Tables/MainHeader.jsx @@ -4,11 +4,9 @@ import searchIcon from "/search.svg"; import { useState } from "react"; import { useDispatch } from "react-redux"; import { setBrokers } from "../store/broker-slice.jsx" -import { useSelector } from "react-redux"; export default function MainHeader() { const dispatch = useDispatch(); - let forms = useSelector((state) => state.broker.brokers); // Стартовые значения параметров const initialValues = { diff --git a/frontend/src/components/Tables/Tables.jsx b/frontend/src/components/Tables/Tables.jsx index 6adaf25..4d8d0dc 100644 --- a/frontend/src/components/Tables/Tables.jsx +++ b/frontend/src/components/Tables/Tables.jsx @@ -17,6 +17,7 @@ import edit from "/edit.svg" import "./dropMenu.css" import addRedactor from "/addRedactor.svg" import { getCurrentDate } from "./utils.jsx"; +import { useEffect } from "react"; export default function Tables() { const dispatch = useDispatch(); @@ -101,6 +102,7 @@ export default function Tables() { fileInputRef.current.click(); }; const handleFileChange = async (event) => { + console.log("asdasd"); const selectedFile = event.target.files[0]; if (selectedFile) { const formData = new FormData(); @@ -124,10 +126,13 @@ export default function Tables() { const deleteForm = async () => { if (activeForm) { console.log("удаляем activeForm и загружаем оставшиеся", activeForm); - await axios.delete(`http://localhost:8080/forms/${activeForm.id}}`); - + console.log("activeForm.id", activeForm.id); + await axios.delete(`http://localhost:8080/forms/${activeForm.id}`); const res = await axios.get(`http://localhost:8080/forms/${mail}`); dispatch(setBrokers(res.data)); + + let redactorsModalWindow = document.querySelector(".delete-modal-overlay") + redactorsModalWindow.classList.add("delete-modal-overlay_hidden"); } }; @@ -173,13 +178,13 @@ export default function Tables() { deleteModalWindow.classList.remove("delete-modal-overlay_hidden"); } if (tableBut) { - let { id, name } = activeForm; + let { id, tableName } = activeForm; try { const response = await fetch(`http://localhost:8080/forms/table/${id}`); const arrayBuffer = await response.arrayBuffer(); let data = new Uint8Array(arrayBuffer); dispatch(setXlsx(data)); - dispatch(setName(name)); + dispatch(setName(tableName)); navigate('/xlsx/' + id) } catch (error) { console.error("Ошибка", error); @@ -187,20 +192,6 @@ export default function Tables() { } if (editImg) { let editModalWindow = document.querySelector(".edit-modal-overlay"); - let editModal = editModalWindow.querySelector(".edit-modal") - - let error = editModal.querySelector("span") - if (error) { - console.log("asd"); - error.innerText = `${Math.random()}` - } - else { - let errorSpan = document.createElement("span") - errorSpan.className = "error-message-block" - errorSpan.innerText = "Ошибка" - console.log("editModal", editModal); - editModal.insertAdjacentElement("beforeend", errorSpan) - } editModalWindow.classList.remove("edit-modal-overlay_hidden"); } @@ -224,22 +215,30 @@ export default function Tables() { saveBut.setAttribute("data-create", "true") console.log("saveBut", saveBut); } - const editForm = (event) => { + const editForm = async (event) => { event.preventDefault() - console.log(event.target); - let editInfo = event.target.querySelectorAll(".text-field__input") - const values = Array.from(editInfo).map(input => input.value); - const formData = Object.fromEntries(values.map((value, index) => [`${index === 0 ? 'tableName' : 'formName'}`, value])); + if (activeForm) { + let editInfo = event.target.querySelectorAll(".text-field__input") + const values = Array.from(editInfo).map(input => input.value); - console.log("Изменяем форму", formData); + const formData = Object.fromEntries(values.map((value, index) => [`${index === 0 ? 'formName' : 'tableName'}`, value])); + formData["formId"] = activeForm.id - editInfo.forEach((input) => { - input.value = '' - }) + await axios.patch(`http://localhost:8080/forms/update`, formData); + const res = await axios.get(`http://localhost:8080/forms/${mail}`); + dispatch(setBrokers(res.data)); + console.log("new ---", res.data); + editInfo.forEach((input) => { + input.value = '' + }) + + let editModalWindow = document.querySelector(".edit-modal-overlay"); + editModalWindow.classList.add("edit-modal-overlay_hidden"); + } } - const saveRedactors = (event) => { + const saveRedactors = async (event) => { event.preventDefault() let saveBut = event.target let redactorsModalWindow = event.target.closest(".redactors-modal-overlay") @@ -254,6 +253,11 @@ export default function Tables() { setNewValues({ ...newValues, "redactors": namesNewRedactors }); } else { + if (activeForm) { + await axios.patch(`http://localhost:8080/forms/redactors`, { redactors: namesNewRedactors, formId: activeForm.id }); + const res = await axios.get(`http://localhost:8080/forms/${mail}`); + dispatch(setBrokers(res.data)); + } console.log("[В таблице] newRedactors - ", namesNewRedactors); console.log("[В таблице] отправляем косте запрос и получаем новый forms"); @@ -341,7 +345,7 @@ export default function Tables() { }