2023-05-03 16:47:20 +03:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
import { apiRequest } from "../../../api/request";
|
|
|
|
import {
|
|
|
|
getProjectBoard,
|
|
|
|
getValueModalType,
|
|
|
|
setProjectBoardFetch,
|
|
|
|
} from "../../../redux/projectsTrackerSlice";
|
2023-04-10 21:22:22 +03:00
|
|
|
|
|
|
|
import "./modalAdd.scss";
|
|
|
|
|
2023-05-03 22:06:19 +03:00
|
|
|
export const ModalAdd = ({ active, setActive, selectedTab, defautlInput }) => {
|
2023-05-03 16:47:20 +03:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
const projectBoard = useSelector(getProjectBoard);
|
|
|
|
|
|
|
|
const modalType = useSelector(getValueModalType);
|
|
|
|
|
|
|
|
const [valueTiket, setValueTiket] = useState("");
|
|
|
|
const [valueColl, setValueColl] = useState("");
|
|
|
|
const [descriptionTicket, setDescriptionTicket] = useState("");
|
|
|
|
|
|
|
|
function createTab() {
|
|
|
|
if (!valueColl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
apiRequest("/project-column/create-column", {
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
project_id: projectBoard.id,
|
|
|
|
title: valueColl,
|
|
|
|
},
|
|
|
|
}).then((res) => {
|
|
|
|
dispatch(setProjectBoardFetch(projectBoard.id));
|
|
|
|
});
|
|
|
|
setValueColl("");
|
|
|
|
setActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createTiket() {
|
|
|
|
if (!valueTiket || !descriptionTicket) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
apiRequest("/task/create-task", {
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
project_id: projectBoard.id,
|
|
|
|
title: valueTiket,
|
|
|
|
description: descriptionTicket,
|
|
|
|
status: 1,
|
|
|
|
user_id: localStorage.getItem("id"),
|
|
|
|
column_id: selectedTab,
|
|
|
|
},
|
|
|
|
}).then((res) => {
|
|
|
|
dispatch(setProjectBoardFetch(projectBoard.id));
|
|
|
|
});
|
|
|
|
|
|
|
|
setActive(false);
|
|
|
|
setValueTiket("");
|
|
|
|
setDescriptionTicket("");
|
|
|
|
}
|
|
|
|
|
2023-05-05 00:50:48 +03:00
|
|
|
function editProject() {
|
|
|
|
}
|
|
|
|
|
2023-05-03 16:47:20 +03:00
|
|
|
function getModal() {
|
|
|
|
switch (modalType) {
|
|
|
|
case "createColumn":
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="modal-add__content"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
|
|
|
<div className="title-project">
|
|
|
|
<h4>Введите название колонки</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={valueColl}
|
|
|
|
onChange={(e) => setValueColl(e.target.value)}
|
|
|
|
></input>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={createTab}>
|
|
|
|
Создать
|
|
|
|
</button>
|
|
|
|
<span className="exit" onClick={() => setActive(false)}></span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
case "addWorker":
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="modal-add__content"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
|
|
|
<div className="title-project">
|
|
|
|
<h4>Добавьте участника</h4>
|
|
|
|
<p className="title-project__decs">Введите имя или e-mail </p>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={valueTiket}
|
|
|
|
onChange={(e) => setValueTiket(e.target.value)}
|
|
|
|
></input>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={(e) => e.preventDefault()}>
|
|
|
|
Добавить
|
|
|
|
</button>
|
|
|
|
<span className="exit" onClick={() => setActive(false)}></span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
case "createTiketProject":
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="modal-add__content"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
|
|
|
<div className="title-project">
|
|
|
|
<h4>Введите название и описание задачи</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={valueTiket}
|
|
|
|
onChange={(e) => setValueTiket(e.target.value)}
|
|
|
|
placeholder="Название задачи"
|
|
|
|
></input>
|
|
|
|
</div>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={descriptionTicket}
|
|
|
|
onChange={(e) => setDescriptionTicket(e.target.value)}
|
|
|
|
placeholder="Описание задачи"
|
|
|
|
></input>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={createTiket}>
|
|
|
|
Создать
|
|
|
|
</button>
|
|
|
|
<span className="exit" onClick={() => setActive(false)}></span>
|
|
|
|
</div>
|
|
|
|
);
|
2023-05-03 22:06:19 +03:00
|
|
|
case "editProject":
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="modal-add__content"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
|
|
|
<div className="title-project">
|
|
|
|
<h4>Введите новое название</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={defautlInput}
|
|
|
|
onChange={(e) => setValueTiket(e.target.value)}
|
|
|
|
></input>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-05 00:50:48 +03:00
|
|
|
<button className="button-add" onClick={editProject}>
|
2023-05-04 09:49:39 +03:00
|
|
|
Сохранить
|
2023-05-03 22:06:19 +03:00
|
|
|
</button>
|
|
|
|
<span className="exit" onClick={() => setActive(false)}></span>
|
|
|
|
</div>
|
|
|
|
);
|
2023-05-04 18:38:56 +03:00
|
|
|
case "editColumn":
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="modal-add__content"
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
|
|
|
<div className="title-project">
|
|
|
|
<h4>Введите новое название</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={defautlInput}
|
|
|
|
onChange={(e) => setValueTiket(e.target.value)}
|
|
|
|
></input>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={(e) => e.preventDefault()}>
|
|
|
|
Сохранить
|
|
|
|
</button>
|
|
|
|
<span className="exit" onClick={() => setActive(false)}></span>
|
|
|
|
</div>
|
|
|
|
);
|
2023-05-03 16:47:20 +03:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-10 21:22:22 +03:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={active ? "modal-add active" : "modal-add"}
|
|
|
|
onClick={() => setActive(false)}
|
|
|
|
>
|
2023-05-03 16:47:20 +03:00
|
|
|
{getModal()}
|
2023-04-10 21:22:22 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ModalAdd;
|