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,
|
2023-05-05 14:48:45 +03:00
|
|
|
setProject,
|
2023-05-03 16:47:20 +03:00
|
|
|
setProjectBoardFetch,
|
2023-05-08 00:41:39 +03:00
|
|
|
editProjectName
|
2023-05-03 16:47:20 +03:00
|
|
|
} from "../../../redux/projectsTrackerSlice";
|
2023-04-10 21:22:22 +03:00
|
|
|
|
2023-05-05 16:10:25 +03:00
|
|
|
import "./trackerModal.scss";
|
2023-04-10 21:22:22 +03:00
|
|
|
|
2023-05-05 16:10:25 +03:00
|
|
|
export const TrackerModal = ({
|
2023-05-05 14:48:45 +03:00
|
|
|
active,
|
|
|
|
setActive,
|
|
|
|
selectedTab,
|
|
|
|
defautlInput,
|
|
|
|
titleProject,
|
2023-05-08 00:41:39 +03:00
|
|
|
projectId
|
2023-05-05 14:48:45 +03:00
|
|
|
}) => {
|
2023-05-03 16:47:20 +03:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
const projectBoard = useSelector(getProjectBoard);
|
|
|
|
|
|
|
|
const modalType = useSelector(getValueModalType);
|
|
|
|
|
2023-05-05 14:48:45 +03:00
|
|
|
const [emailWorker, setEmailWorker] = useState("");
|
2023-05-08 00:41:39 +03:00
|
|
|
const [projectName, setProjectName] = useState(defautlInput);
|
2023-05-05 14:48:45 +03:00
|
|
|
const [valueColumn, setValueColumn] = useState("");
|
|
|
|
const [nameProject, setNameProject] = useState("");
|
|
|
|
|
2023-05-03 16:47:20 +03:00
|
|
|
const [valueTiket, setValueTiket] = useState("");
|
|
|
|
const [descriptionTicket, setDescriptionTicket] = useState("");
|
|
|
|
|
|
|
|
function createTab() {
|
2023-05-05 14:48:45 +03:00
|
|
|
if (!valueColumn) {
|
2023-05-03 16:47:20 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
apiRequest("/project-column/create-column", {
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
project_id: projectBoard.id,
|
2023-05-05 14:48:45 +03:00
|
|
|
title: valueColumn,
|
2023-05-03 16:47:20 +03:00
|
|
|
},
|
|
|
|
}).then((res) => {
|
|
|
|
dispatch(setProjectBoardFetch(projectBoard.id));
|
|
|
|
});
|
2023-05-05 14:48:45 +03:00
|
|
|
setValueColumn("");
|
2023-05-03 16:47:20 +03:00
|
|
|
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-08 00:41:39 +03:00
|
|
|
function editProject() {
|
|
|
|
apiRequest("/project/update", {
|
|
|
|
method: "PUT",
|
|
|
|
data: {
|
|
|
|
project_id: projectId,
|
|
|
|
name: projectName
|
|
|
|
},
|
|
|
|
}).then((res) => {
|
|
|
|
setActive(false)
|
|
|
|
dispatch(editProjectName({id: projectId, name: projectName}))
|
|
|
|
});
|
2023-05-05 00:50:48 +03:00
|
|
|
}
|
|
|
|
|
2023-05-05 14:48:45 +03:00
|
|
|
function createProject() {
|
|
|
|
if (nameProject === "") {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
apiRequest("/project/create", {
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
user_id: localStorage.getItem("id"),
|
|
|
|
name: nameProject,
|
2023-05-08 00:41:39 +03:00
|
|
|
status: 19,
|
2023-05-05 14:48:45 +03:00
|
|
|
},
|
|
|
|
}).then((res) => {
|
|
|
|
const result = { ...res, columns: [] };
|
|
|
|
dispatch(setProject(result));
|
|
|
|
setActive(false);
|
|
|
|
setNameProject("");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={active ? "modal-add active" : "modal-add"}
|
|
|
|
onClick={() => setActive(false)}
|
|
|
|
>
|
|
|
|
<div className="modal-add__content" onClick={(e) => e.stopPropagation()}>
|
|
|
|
{modalType === "addWorker" && (
|
|
|
|
<div>
|
2023-05-03 16:47:20 +03:00
|
|
|
<div className="title-project">
|
|
|
|
<h4>Добавьте участника</h4>
|
|
|
|
<p className="title-project__decs">Введите имя или e-mail </p>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
2023-05-05 14:48:45 +03:00
|
|
|
value={emailWorker}
|
|
|
|
onChange={(e) => setEmailWorker(e.target.value)}
|
2023-05-05 16:10:25 +03:00
|
|
|
/>
|
2023-05-03 16:47:20 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-05 14:48:45 +03:00
|
|
|
<button
|
|
|
|
className="button-add"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
setActive(false);
|
|
|
|
}}
|
|
|
|
>
|
2023-05-03 16:47:20 +03:00
|
|
|
Добавить
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-05-05 14:48:45 +03:00
|
|
|
)}
|
|
|
|
{modalType === "createTiketProject" && (
|
|
|
|
<div>
|
2023-05-03 16:47:20 +03:00
|
|
|
<div className="title-project">
|
|
|
|
<h4>Введите название и описание задачи</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={valueTiket}
|
|
|
|
onChange={(e) => setValueTiket(e.target.value)}
|
|
|
|
placeholder="Название задачи"
|
2023-05-05 16:10:25 +03:00
|
|
|
/>
|
2023-05-03 16:47:20 +03:00
|
|
|
</div>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={descriptionTicket}
|
|
|
|
onChange={(e) => setDescriptionTicket(e.target.value)}
|
|
|
|
placeholder="Описание задачи"
|
2023-05-05 16:10:25 +03:00
|
|
|
/>
|
2023-05-03 16:47:20 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={createTiket}>
|
|
|
|
Создать
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-05-05 14:48:45 +03:00
|
|
|
)}
|
|
|
|
{modalType === "editProject" && (
|
|
|
|
<div>
|
2023-05-03 22:06:19 +03:00
|
|
|
<div className="title-project">
|
|
|
|
<h4>Введите новое название</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
2023-05-08 00:41:39 +03:00
|
|
|
value={projectName}
|
|
|
|
onChange={(e) => setProjectName(e.target.value)}
|
2023-05-05 16:10:25 +03:00
|
|
|
/>
|
2023-05-03 22:06:19 +03:00
|
|
|
</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>
|
|
|
|
</div>
|
2023-05-05 14:48:45 +03:00
|
|
|
)}
|
|
|
|
{modalType === "createProject" && (
|
|
|
|
<div>
|
|
|
|
<div className="title-project">
|
|
|
|
<h4>{titleProject}</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={nameProject}
|
|
|
|
onChange={(e) => setNameProject(e.target.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={createProject}>
|
|
|
|
Создать
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{modalType === "addSubtask" && (
|
|
|
|
<div>
|
|
|
|
<div className="title-project subtask">
|
|
|
|
<h4>
|
|
|
|
Вы добавляете подзадачу{" "}
|
|
|
|
<p>в колонку(id) задачи "{defautlInput}"</p>
|
|
|
|
</h4>
|
|
|
|
<p className="title-project__decs">Введите текст</p>
|
|
|
|
<div>
|
|
|
|
<textarea className="title-project__textarea"></textarea>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={(e) => e.preventDefault()}>
|
|
|
|
Добавить
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{modalType === "createColumn" && (
|
|
|
|
<div>
|
|
|
|
<div className="title-project">
|
|
|
|
<h4>Введите название колонки</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={valueColumn}
|
|
|
|
onChange={(e) => setValueColumn(e.target.value)}
|
2023-05-05 16:10:25 +03:00
|
|
|
/>
|
2023-05-05 14:48:45 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={createTab}>
|
|
|
|
Создать
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{/* TODO: fix state */}
|
|
|
|
{modalType === "editColumn" && (
|
|
|
|
<div>
|
2023-05-04 18:38:56 +03:00
|
|
|
<div className="title-project">
|
|
|
|
<h4>Введите новое название</h4>
|
|
|
|
<div className="input-container">
|
|
|
|
<input
|
|
|
|
className="name-project"
|
|
|
|
value={defautlInput}
|
|
|
|
onChange={(e) => setValueTiket(e.target.value)}
|
2023-05-05 16:10:25 +03:00
|
|
|
/>
|
2023-05-04 18:38:56 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button className="button-add" onClick={(e) => e.preventDefault()}>
|
|
|
|
Сохранить
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-05-05 14:48:45 +03:00
|
|
|
)}
|
2023-05-03 16:47:20 +03:00
|
|
|
|
2023-05-05 14:48:45 +03:00
|
|
|
<span className="exit" onClick={() => setActive(false)}></span>
|
|
|
|
</div>
|
2023-04-10 21:22:22 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-05-05 16:10:25 +03:00
|
|
|
export default TrackerModal;
|