Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
vozmitelvlas committed Dec 15, 2024
1 parent 5e96acf commit dcab408
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 51 deletions.
25 changes: 9 additions & 16 deletions frontend/src/components/SignIn/SignIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,31 @@ 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();

const toTables = async () => {
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({
"[email protected]": false,
"[email protected]": false,
"[email protected]": 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({
// "[email protected]": false,
// "[email protected]": false,
// "[email protected]": false
// }))
// })

navigate("/tables");
} catch (error) {
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/Tables/MainHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
70 changes: 37 additions & 33 deletions frontend/src/components/Tables/Tables.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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");
}
};

Expand Down Expand Up @@ -173,34 +178,20 @@ 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);
}
}
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");
}

Expand All @@ -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")
Expand All @@ -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");
Expand Down Expand Up @@ -341,7 +345,7 @@ export default function Tables() {
}
</td>
<td>
<Button text={form.name} ></Button>
<Button text={form.tableName} ></Button>
</td>
<td className="text-center">
{
Expand Down Expand Up @@ -418,8 +422,8 @@ export default function Tables() {
</h3>
<form onSubmit={editForm}>
<div className="inputs">
<input className="text-field__input" placeholder="Новое название таблицы"></input>
<input className="text-field__input" placeholder="Новое название формы" ></input>
<input className="text-field__input" placeholder="Новое название таблицы"></input>
{/* <input name="redactors" className="text-field__input" placeholder="Новые, редакторы" ></input> */}
</div>
<div className="edit-modal__buttons">
Expand All @@ -445,12 +449,12 @@ export default function Tables() {
</tr>
</thead>
<tbody>
{Object.entries(allUsers).map(([mail, flag], ind) => (
{allUsers.map((user, ind) => (
<tr key={ind}>
<td className="text-center">
<input name={mail} data-flag={flag} className="checkbox" type="checkbox" />
<input name={user.email} className="checkbox" type="checkbox" />
</td>
<td>{mail}</td>
<td>{user.email}</td>
</tr>
))}
</tbody>
Expand Down

0 comments on commit dcab408

Please sign in to comment.