diff --git a/src/pages/ProjectTracker/ProjectTracker.js b/src/pages/ProjectTracker/ProjectTracker.js
new file mode 100644
index 00000000..3af6307f
--- /dev/null
+++ b/src/pages/ProjectTracker/ProjectTracker.js
@@ -0,0 +1,417 @@
+import React, {useEffect, useRef, useState} from "react";
+import {Link} from "react-router-dom";
+import { ProfileHeader } from "../../components/ProfileHeader/ProfileHeader";
+import { ProfileBreadcrumbs } from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs";
+import { Footer } from "../../components/Footer/Footer";
+
+import { useDispatch, useSelector } from "react-redux";
+import {getProjectBoard, moveProjectTask, setProjectBoardFetch, setToggleTab} from "../../redux/projectsTrackerSlice";
+
+import ModalTicket from "../../components/UI/ModalTicket/ModalTicket";
+import ModalAdd from "../../components/UI/ModalAdd/ModalAdd";
+
+import project from "../../images/trackerProject.svg";
+import tasks from "../../images/trackerTasks.svg";
+import archive from "../../images/archiveTracker.svg";
+import avatarTest from "../../images/AvatarTest .png";
+import selectArrow from "../../images/select.svg";
+import commentsBoard from "../../images/commentsBoard.svg";
+import filesBoard from "../../images/filesBoard.svg";
+import arrow from "../../images/arrowCalendar.png";
+
+import {apiRequest} from "../../api/request";
+import { Navigation } from "../../components/Navigation/Navigation";
+
+export const ProjectTracker = () => {
+ const dispatch = useDispatch();
+ const currentUrl = useState(window.location.pathname)
+ const projectId = currentUrl[0].split('/').at(-1)
+
+ useEffect(() => {
+ dispatch(setProjectBoardFetch(projectId))
+ }, [])
+
+ // Modal State
+ const [modalActiveTicket, setModalActiveTicket] = useState(false);
+ const [selectedTicket, setSelectedTicket] = useState({});
+ const [modalAddWorker, setModalAddWorker] = useState(false);
+ const [modalCreateColl, setModalCreateColl] = useState(false);
+ const [modalCreateTiket, setModalCreateTiket] = useState(false);
+ const [valueTiket, setValueTiket] = useState("");
+ const [descriptionTicket, setDescriptionTicket] = useState("")
+ const [valueColl, setValueColl] = useState("");
+ //
+
+ const [selectedTab, setSelectedTab] = useState(0);
+
+ const startWrapperIndexTest = useRef({})
+ const [wrapperHover, setWrapperHover] = useState([
+ false,
+ false,
+ false,
+ false,
+ ]);
+
+ const projectBoard = useSelector(getProjectBoard);
+
+ // function toggleMoreTasks(columnId) {
+ // setTabTaskMok((prevArray) =>
+ // prevArray.map((elem, index) => {
+ // if (columnId === index) {
+ // return { ...elem, open: !elem.open };
+ // } else {
+ // return elem;
+ // }
+ // })
+ // );
+ // }
+
+ function dragStartHandler(e, task, columnId) {
+ startWrapperIndexTest.current = { task: task, index: columnId };
+ setTimeout(() => {
+ e.target.classList.add("tasks__board__item__hide");
+ }, 0);
+ }
+
+ function dragEndHandler(e) {
+ setWrapperHover((prevArray) =>
+ prevArray.map((elem) => {
+ return false;
+ })
+ );
+ e.target.classList.remove("tasks__board__item__hide");
+ }
+
+ function dragOverHandler(e) {
+ e.preventDefault();
+ }
+
+ function dragEnterHandler(columnId) {
+ if (columnId === startWrapperIndexTest.current.index) {
+ return;
+ }
+ setWrapperHover((prevArray) =>
+ prevArray.map((elem, index) => {
+ if (index === columnId) {
+ return true;
+ } else {
+ return false;
+ }
+ })
+ );
+ }
+ function dragDropHandler(e, columnId) {
+ e.preventDefault();
+ if (startWrapperIndexTest.current.index === columnId) {
+ return;
+ }
+ setWrapperHover((prevArray) =>
+ prevArray.map((elem) => {
+ return false;
+ })
+ );
+
+ if (columnId !== startWrapperIndexTest.current.index) {
+ dispatch(moveProjectTask({startWrapperIndex: startWrapperIndexTest.current, columnId}))
+ }
+ }
+
+ function selectedTabTask(columnId) {
+ setSelectedTab(columnId);
+ setModalCreateTiket(true);
+ }
+
+ function openTicket(e, task) {
+ setSelectedTicket(task);
+ setModalActiveTicket(true);
+ }
+
+ 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))
+ })
+
+ setModalCreateTiket(false);
+ setValueTiket("");
+ setDescriptionTicket("")
+ }
+
+ 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("");
+ setModalCreateColl(false);
+ }
+
+ return (
+
+
+
+
+
+
+
Управление проектами с трекером
+
+
+
+
+
dispatch(setToggleTab(1))}
+ >
+
+
Проекты
+
+
dispatch(setToggleTab(2))}
+ >
+
+
Все мои задачи
+
+
dispatch(setToggleTab(3))}
+ >
+
+
Архив
+
+
+
+
+
+
+
Проект : {projectBoard.name}
+
+
+
+
Введите название колонки
+
+ setValueColl(e.target.value)}
+ >
+
+
+
+
+
+
+
+
Добавьте участника
+
+ Введите имя или e-mail{" "}
+
+
+ setValueTiket(e.target.value)}
+ >
+
+
+
+
+
+
+
setModalCreateColl(true)}>+
+
добавить колонку
+
+
+
+
+
+9
+
+ +
+
+
добавить участника
+
+
+
Участвую
+
+
+
+
Мои
+
+
+
+
Вернуться на проекты
+
+
+
+
+
+
+
+
+
+
Введите название и описание задачи
+
+ setValueTiket(e.target.value)}
+ placeholder='Название задачи'
+ >
+
+
+ setDescriptionTicket(e.target.value)}
+ placeholder='Описание задачи'
+ >
+
+
+
+
+
+
+ {Boolean(projectBoard?.columns) && Boolean(projectBoard.columns.length) && projectBoard.columns.map((column) => {
+ return (
+
dragOverHandler(e)}
+ onDragEnter={(e) => dragEnterHandler(column.id)}
+ onDrop={(e) => dragDropHandler(e, column.id)}
+ className={`tasks__board ${
+ column.tasks.length >= 3 ? "tasks__board__more" : ""
+ } ${
+ wrapperHover[column.id] ? "tasks__board__hover" : ""
+ }`}
+ >
+
+ {/*
*/}
+
+ {column.title}
+
+
+ selectedTabTask(column.id)}
+ >
+ +
+
+ ...
+
+
+ {column.tasks.map((task, index) => {
+ if (index > 2) {
+ if (!column.open) {
+ return;
+ }
+ }
+ return (
+
+ dragStartHandler(e, task, column.id)
+ }
+ onDragEnd={(e) => dragEndHandler(e)}
+ onClick={(e) => openTicket(e, task)}
+ >
+
+
+ {task.description}
+
+
+
+
+
{task.comments} коментариев
+
+
+
+
{task.files} файлов
+
+ {/*
*/}
+ {/*
*/}
+ {/*
*/}
+ {/*
*/}
+
+
+ );
+ })}
+ {column.tasks.length > 3 && (
+
toggleMoreTasks(column.id)}
+ >
+ {column.open ? "-" : "+"}
+
+ )}
+
+ );
+ })}
+
+
+
+
+
+
+ );
+};
diff --git a/src/pages/Tracker/Tracker.js b/src/pages/Tracker/Tracker.js
index 4535d567..39e89014 100644
--- a/src/pages/Tracker/Tracker.js
+++ b/src/pages/Tracker/Tracker.js
@@ -1,141 +1,31 @@
-import React, { useEffect, useState } from "react";
+import React, {useEffect, useState} from "react";
import { ProfileHeader } from "../../components/ProfileHeader/ProfileHeader";
import { ProfileBreadcrumbs } from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs";
import { Footer } from "../../components/Footer/Footer";
import { useDispatch, useSelector } from "react-redux";
-import { getProjects } from "../../redux/projectsTrackerSlice";
+import { setAllProjects, getProjects, setToggleTab, getToggleTab } from "../../redux/projectsTrackerSlice";
-import ModalTicket from "../../components/UI/ModalTicket/ModalTicket";
import ModalCreate from "../../components/UI/ModalCreate/ModalCreate";
-import ModalAdd from "../../components/UI/ModalAdd/ModalAdd";
import ProjectTiket from "../../components/ProjectTiket/ProjectTiket";
import project from "../../images/trackerProject.svg";
import tasks from "../../images/trackerTasks.svg";
import archive from "../../images/archiveTracker.svg";
import avatarTest from "../../images/AvatarTest .png";
-import selectArrow from "../../images/select.svg";
-import commentsBoard from "../../images/commentsBoard.svg";
-import filesBoard from "../../images/filesBoard.svg";
import search from "../../images/serchIcon.png";
import noProjects from "../../images/noProjects.png";
-import arrow from "../../images/arrowCalendar.png";
-import "./tracker.scss";
+import {apiRequest} from "../../api/request";
import { Navigation } from "../../components/Navigation/Navigation";
-export const Tracker = () => {
- const [toggleTab, setToggleTab] = useState(1);
- const [tabTaskMok, setTabTaskMok] = useState([
- {
- name: "Открытые",
- open: false,
- tasks: [
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 1,
- },
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 2,
- },
- ],
- },
- {
- name: "В процессе",
- open: false,
- tasks: [
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 3,
- },
- ],
- },
- {
- name: "На проверке",
- open: false,
- tasks: [
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 4,
- },
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 5,
- },
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 6,
- },
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 9,
- },
- ],
- },
- {
- name: "Готово",
- open: false,
- tasks: [
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 7,
- },
- {
- task: "PR - 2245",
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 12,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: 8,
- },
- ],
- },
- ]);
+import "./tracker.scss";
+export const Tracker = () => {
+ const dispatch = useDispatch();
+ const projects = useSelector(getProjects);
+ const tab = useSelector(getToggleTab)
const [allTasks] = useState([
{
name: "PR - 2245",
@@ -359,116 +249,18 @@ export const Tracker = () => {
const [filterCompleteTasks, setFilterCompleteTasks] = useState(completeTasks);
// Modal State
- const [modalActiveTicket, setModalActiveTicket] = useState(false);
- const [indexTicket, setIndexTicket] = useState(0);
- const [modalAddWorker, setModalAddWorker] = useState(false);
const [modalCreateProject, setModalCreateProject] = useState(false);
- const [modalCreateColl, setModalCreateColl] = useState(false);
- const [modalCreateTiket, setModalCreateTiket] = useState(false);
- const [valueTiket, setValueTiket] = useState("");
- const [valueColl, setValueColl] = useState("");
- //
- const [projectTasksOpen, setProjectTasksOpen] = useState(false);
-
- const [selectedTab, setSelectedTab] = useState({
- name: "",
- indexTab: 0,
- task: [],
- });
-
- const [startWrapperIndex, setStartWrapperIndex] = useState(null);
- const [wrapperHover, setWrapperHover] = useState([
- false,
- false,
- false,
- false,
- ]);
-
- const projects = useSelector(getProjects);
+ useEffect(() => {
+ apiRequest(`/project/project-list?user_id=${localStorage.getItem('id')}&expand=columns`).then((el) => {
+ dispatch(setAllProjects(el.projects))
+ })
+ }, [])
const toggleTabs = (index) => {
- if (projectTasksOpen) {
- setProjectTasksOpen(false);
- }
- setToggleTab(index);
+ dispatch(setToggleTab(index))
};
- function toggleMoreTasks(wrapperIndex) {
- setTabTaskMok((prevArray) =>
- prevArray.map((elem, index) => {
- if (wrapperIndex === index) {
- return { ...elem, open: !elem.open };
- } else {
- return elem;
- }
- })
- );
- }
-
- function dragStartHandler(e, task, wrapperIndex) {
- setStartWrapperIndex({ task: task, index: wrapperIndex });
- setTimeout(() => {
- e.target.classList.add("tasks__board__item__hide");
- }, 0);
- }
-
- function dragEndHandler(e) {
- setWrapperHover((prevArray) =>
- prevArray.map((elem) => {
- return false;
- })
- );
- e.target.classList.remove("tasks__board__item__hide");
- }
-
- function dragOverHandler(e) {
- e.preventDefault();
- }
-
- function dragEnterHandler(wrapperIndex) {
- if (wrapperIndex === startWrapperIndex.index) {
- return;
- }
- setWrapperHover((prevArray) =>
- prevArray.map((elem, index) => {
- if (index === wrapperIndex) {
- return true;
- } else {
- return false;
- }
- })
- );
- }
-
- function dragDropHandler(e, wrapperIndex) {
- e.preventDefault();
- if (startWrapperIndex.index === wrapperIndex) {
- return;
- }
- setWrapperHover((prevArray) =>
- prevArray.map((elem) => {
- return false;
- })
- );
- setTabTaskMok((prevArray) =>
- prevArray.map((elem, index) => {
- if (index === wrapperIndex) {
- return { ...elem, tasks: [...elem.tasks, startWrapperIndex.task] };
- } else if (index === startWrapperIndex.index) {
- return {
- ...elem,
- tasks: elem.tasks.filter((item) => {
- return item.id !== startWrapperIndex.task.id;
- }),
- };
- } else {
- return elem;
- }
- })
- );
- }
-
function filterArchiveTasks(e) {
setFilterCompleteTasks(
completeTasks.filter((item) => {
@@ -487,55 +279,6 @@ export const Tracker = () => {
);
}
- function selectedTabTask(e, wrapperIndex, name, tasks) {
- let tab = { name: name, indexTab: wrapperIndex, task: tasks };
- setSelectedTab(tab);
- setModalCreateTiket(true);
- }
-
- function openTicket(e, iTicket) {
- setIndexTicket(iTicket);
- setModalActiveTicket(true);
- }
-
- function createTiket() {
- tabTaskMok.filter((item) => {
- if (item.name == selectedTab.name) {
- let idItem = 0;
-
- item.tasks.forEach((item) => {
- idItem = item.id;
- });
-
- let newTiket = {
- task: valueTiket,
- description: "Сверстать часть таблицы. Сверстать часть таблицы",
- comments: 0,
- files: 0,
- avatarCreated: avatarTest,
- avatarDo: avatarTest,
- id: idItem + 1,
- };
-
- item.tasks.push(newTiket);
- }
- });
- setModalCreateTiket(false);
- setValueTiket("");
- }
-
- function createTab() {
- let newTab = {
- name: valueColl,
- open: false,
- tasks: [],
- };
-
- tabTaskMok.unshift(newTab);
- setValueColl("");
- setModalCreateColl(false);
- }
-
return (
@@ -554,21 +297,21 @@ export const Tracker = () => {
toggleTabs(1)}
>
Проекты
toggleTabs(2)}
>
Все мои задачи
toggleTabs(3)}
>
@@ -578,7 +321,7 @@ export const Tracker = () => {
{
/>
{Boolean(projects.length) &&
- !projectTasksOpen &&
projects.map((project, index) => {
return (
);
})}
- {!Boolean(projects.length) && !projectTasksOpen && (
+ {!Boolean(projects.length) && (
@@ -620,7 +361,7 @@ export const Tracker = () => {
)}
- {Boolean(projects.length) && !projectTasksOpen && (
+ {Boolean(projects.length) && (
-
-
-
Проект : Разработка трекера
-
-
-
-
Введите название колонки
-
- setValueColl(e.target.value)}
- >
-
-
-
-
-
-
-
-
Добавьте участника
-
- Введите имя или e-mail{" "}
-
-
- setValueTiket(e.target.value)}
- >
-
-
-
-
-
-
-
setModalCreateColl(true)}>+
-
добавить задачу в проект
-
-
-
-
-
+9
-
- +
-
-
добавить участника в проект
-
-
-
Учавствую
-
-
-
-
Мои
-
-
-
setProjectTasksOpen(false)}
- >
-
Вернуться на проекты
-
-
-
-
-
-
-
-
-
-
Введите название карточки
-
- setValueTiket(e.target.value)}
- >
-
-
-
-
-
-
- {tabTaskMok.map((section, wrapperIndex) => {
- return (
-
dragOverHandler(e)}
- onDragEnter={(e) => dragEnterHandler(wrapperIndex)}
- onDrop={(e) => dragDropHandler(e, wrapperIndex)}
- className={`tasks__board ${
- section.tasks.length >= 3 ? "tasks__board__more" : ""
- } ${
- wrapperHover[wrapperIndex] ? "tasks__board__hover" : ""
- }`}
- >
-
-
- {section.name}
-
-
-
- selectedTabTask(
- e,
- wrapperIndex,
- section.name,
- section.tasks
- )
- }
- >
- +
-
- ...
-
-
- {section.tasks.map((task, index) => {
- if (index > 2) {
- if (!section.open) {
- return;
- }
- }
- return (
-
- dragStartHandler(e, task, wrapperIndex)
- }
- onDragEnd={(e) => dragEndHandler(e)}
- onClick={(e) => openTicket(e, index)}
- >
-
-
- {task.description}
-
-
-
-
-
{task.comments} коментариев
-
-
-
-
{task.files} файлов
-
-
-
-
-
-
-
- );
- })}
- {section.tasks.length > 3 && (
-
toggleMoreTasks(wrapperIndex)}
- >
- {section.open ? "-" : "+"}
-
- )}
-
- );
- })}
-
-
-
{
+ apiRequest(`/project/get-project?project_id=${id}&expand=columns`)
+);
+
export const projectsTrackerSlice = createSlice({
name: "projectsTracker",
initialState,
reducers: {
- setProject: (state, action) => {
- state.project.push(action.payload);
+ setAllProjects: (state, action) => {
+ state.projects = action.payload
},
+ setProject: (state, action) => {
+ state.projects.push(action.payload);
+ },
+ setToggleTab: (state, action) => {
+ state.toggleTab = action.payload
+ },
+ deleteProject: (state, action) => {
+ state.projects = state.projects.filter((project) => project.id !== action.payload.id)
+ },
+ moveProjectTask: (state, action) => {
+ state.projectBoard.columns.forEach((column, index) => {
+ if (column.id === action.payload.columnId) {
+ column.tasks.push(action.payload.startWrapperIndex.task)
+ apiRequest(`/task/update-task`, {
+ method: 'PUT',
+ data: {
+ task_id: action.payload.startWrapperIndex.task.id,
+ column_id: column.id
+ }
+ }).then((res) => {
+ })
+ }
+ if (column.id === action.payload.startWrapperIndex.index) {
+ state.projectBoard.columns[index].tasks = column.tasks.filter((task)=> task.id !== action.payload.startWrapperIndex.task.id);
+ }
+ })
+ }
},
+ extraReducers: {
+ [setProjectBoardFetch.fulfilled]: (state, action) => {
+ state.projectBoard = action.payload
+ }
+ }
});
-export const { setProject } = projectsTrackerSlice.actions;
+export const { setProject, deleteProject, setAllProjects, moveProjectTask, setToggleTab } = projectsTrackerSlice.actions;
-export const getProjects = (state) => state.tracker.project;
+export const getProjects = (state) => state.tracker.projects;
+export const getProjectBoard = (state) => state.tracker.projectBoard;
+export const getToggleTab = (state) => state.tracker.toggleTab
export default projectsTrackerSlice.reducer;