2023-05-17 02:51:31 +03:00
|
|
|
import React, {useEffect, useState} from "react";
|
2023-05-03 16:47:20 +03:00
|
|
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
import { apiRequest } from "../../../api/request";
|
2023-05-17 02:51:31 +03:00
|
|
|
import { urlForLocal } from '../../../helper'
|
2023-05-03 16:47:20 +03:00
|
|
|
import {
|
2023-05-16 00:24:52 +03:00
|
|
|
setColumnName,
|
2023-05-03 16:47:20 +03:00
|
|
|
getProjectBoard,
|
|
|
|
getValueModalType,
|
2023-05-05 14:48:45 +03:00
|
|
|
setProject,
|
2023-05-03 16:47:20 +03:00
|
|
|
setProjectBoardFetch,
|
2023-05-08 16:57:35 +03:00
|
|
|
editProjectName,
|
2023-05-16 00:24:52 +03:00
|
|
|
editColumnName,
|
|
|
|
getColumnName,
|
2023-05-23 23:02:39 +03:00
|
|
|
getColumnId,
|
|
|
|
addPersonToProject
|
2023-05-03 16:47:20 +03:00
|
|
|
} from "../../../redux/projectsTrackerSlice";
|
2023-04-10 21:22:22 +03:00
|
|
|
|
2023-05-17 02:51:31 +03:00
|
|
|
import arrowDown from "../../../images/selectArrow.png"
|
|
|
|
|
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 16:57:35 +03:00
|
|
|
projectId,
|
2023-05-17 02:51:31 +03:00
|
|
|
priorityTask
|
2023-05-05 14:48:45 +03:00
|
|
|
}) => {
|
2023-05-03 16:47:20 +03:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
const projectBoard = useSelector(getProjectBoard);
|
2023-05-16 00:24:52 +03:00
|
|
|
const columnName = useSelector(getColumnName);
|
|
|
|
const columnId = useSelector(getColumnId)
|
2023-05-03 16:47:20 +03:00
|
|
|
|
|
|
|
const modalType = useSelector(getValueModalType);
|
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("");
|
2023-05-17 02:51:31 +03:00
|
|
|
const [workers, setWorkers] = useState([])
|
|
|
|
const [selectWorkersOpen, setSelectWorkersOpen] = useState(false)
|
|
|
|
const [selectedWorker, setSelectedWorker] = useState(null)
|
2023-05-03 16:47:20 +03:00
|
|
|
|
|
|
|
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,
|
2023-05-17 02:51:31 +03:00
|
|
|
priority: priorityTask
|
2023-05-03 16:47:20 +03:00
|
|
|
},
|
|
|
|
}).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,
|
2023-05-08 16:57:35 +03:00
|
|
|
name: projectName,
|
2023-05-08 00:41:39 +03:00
|
|
|
},
|
|
|
|
}).then((res) => {
|
2023-05-08 16:57:35 +03:00
|
|
|
setActive(false);
|
|
|
|
dispatch(editProjectName({ id: projectId, name: projectName }));
|
2023-05-08 00:41:39 +03:00
|
|
|
});
|
2023-05-05 00:50:48 +03:00
|
|
|
}
|
|
|
|
|
2023-05-16 00:24:52 +03:00
|
|
|
function changeColumnName() {
|
|
|
|
apiRequest("/project-column/update-column", {
|
|
|
|
method: "PUT",
|
|
|
|
data: {
|
|
|
|
column_id: columnId,
|
|
|
|
title: columnName
|
|
|
|
}
|
|
|
|
}).then((res) => {
|
|
|
|
setActive(false);
|
|
|
|
dispatch(editColumnName({id: columnId, title: columnName}))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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("");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 02:51:31 +03:00
|
|
|
function addUserToProject() {
|
|
|
|
apiRequest("/project/add-user", {
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-05-23 23:02:39 +03:00
|
|
|
user_id: selectedWorker.user_id,
|
2023-05-17 02:51:31 +03:00
|
|
|
project_id: projectBoard.id
|
|
|
|
}
|
|
|
|
}).then((el) => {
|
2023-05-23 23:02:39 +03:00
|
|
|
dispatch(addPersonToProject(el))
|
2023-05-17 02:51:31 +03:00
|
|
|
setActive(false);
|
2023-05-23 23:02:39 +03:00
|
|
|
setSelectedWorker('')
|
2023-05-17 23:18:46 +03:00
|
|
|
setSelectWorkersOpen(false)
|
2023-05-17 02:51:31 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-05-17 23:18:46 +03:00
|
|
|
modalType === "addWorker" ? apiRequest('/project/my-employee').then((el) => {
|
|
|
|
let persons = el.managerEmployees
|
2023-05-23 23:02:39 +03:00
|
|
|
let ids = projectBoard.projectUsers.map((user) => user.user_id)
|
|
|
|
setWorkers(persons.reduce((acc, cur) => {
|
|
|
|
if (!ids.includes(cur.user_id)) acc.push(cur)
|
|
|
|
return acc
|
|
|
|
}, []))
|
2023-05-17 23:18:46 +03:00
|
|
|
}) : ''
|
2023-05-23 23:02:39 +03:00
|
|
|
}, [active])
|
|
|
|
|
2023-05-17 02:51:31 +03:00
|
|
|
|
2023-05-05 14:48:45 +03:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={active ? "modal-add active" : "modal-add"}
|
2023-05-17 23:18:46 +03:00
|
|
|
onClick={() => {
|
|
|
|
setActive(false)
|
|
|
|
setSelectWorkersOpen(false)
|
|
|
|
}}
|
2023-05-05 14:48:45 +03:00
|
|
|
>
|
|
|
|
<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>
|
2023-05-17 02:51:31 +03:00
|
|
|
{/*<div className="input-container">*/}
|
|
|
|
{/* <input*/}
|
|
|
|
{/* className="name-project"*/}
|
|
|
|
{/* value={emailWorker}*/}
|
|
|
|
{/* onChange={(e) => setEmailWorker(e.target.value)}*/}
|
|
|
|
{/* />*/}
|
|
|
|
{/*</div>*/}
|
|
|
|
<div className={selectWorkersOpen ? 'select__worker open' : 'select__worker'} onClick={() => setSelectWorkersOpen(!selectWorkersOpen)}>
|
|
|
|
<p>{selectedWorker ? selectedWorker.employee.fio : 'Выберите пользователя'}</p>
|
|
|
|
<img className='arrow' src={arrowDown} alt='arrow' />
|
|
|
|
{Boolean(selectWorkersOpen) &&
|
2023-05-23 23:02:39 +03:00
|
|
|
<div className='select__worker__dropDown'>
|
|
|
|
{Boolean(workers.length) ?
|
|
|
|
workers.map((worker) => {
|
|
|
|
if (worker === selectedWorker) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return <div className='worker' key={worker.id} onClick={() =>
|
|
|
|
{
|
|
|
|
setSelectedWorker(worker)
|
|
|
|
}
|
|
|
|
}>
|
|
|
|
<p>{worker.employee.fio}</p>
|
|
|
|
<img src={urlForLocal(worker.employee.avatar)} alt='avatar'/>
|
|
|
|
</div>
|
|
|
|
}) :
|
|
|
|
<div>Нет пользователей</div>
|
2023-05-17 02:51:31 +03:00
|
|
|
}
|
2023-05-23 23:02:39 +03:00
|
|
|
</div>
|
2023-05-17 02:51:31 +03:00
|
|
|
}
|
2023-05-03 16:47:20 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-05 14:48:45 +03:00
|
|
|
<button
|
|
|
|
className="button-add"
|
2023-05-17 02:51:31 +03:00
|
|
|
onClick={addUserToProject}
|
2023-05-05 14:48:45 +03:00
|
|
|
>
|
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>
|
|
|
|
)}
|
|
|
|
{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"
|
2023-05-16 00:24:52 +03:00
|
|
|
value={columnName}
|
|
|
|
onChange={(e) => dispatch(setColumnName(e.target.value))}
|
2023-05-05 16:10:25 +03:00
|
|
|
/>
|
2023-05-04 18:38:56 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-05-16 00:24:52 +03:00
|
|
|
<button className="button-add" onClick={changeColumnName}>
|
2023-05-04 18:38:56 +03:00
|
|
|
Сохранить
|
|
|
|
</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;
|