fix ModalTicket logic

This commit is contained in:
Никита Губарь 2024-07-25 18:17:39 +03:00
parent 7e64150378
commit ca0a509077
4 changed files with 364 additions and 285 deletions

View File

@ -122,15 +122,6 @@ export const ModalTiсket = ({
setShowModalToReport(!showModalToReport); setShowModalToReport(!showModalToReport);
}; };
const closeModal = () => {
setActive(false);
const currentUrl = window.location.pathname;
const newUrl = currentUrl.replace(/\/task\/\d+$/, "");
window.history.replaceState({}, "", newUrl);
document.body.style.overflow = "auto";
console.log(task);
};
const [isExpanded, setIsExpanded] = useState(false); const [isExpanded, setIsExpanded] = useState(false);
const toggleModalSize = () => { const toggleModalSize = () => {
@ -310,6 +301,17 @@ export const ModalTiсket = ({
}); });
} }
const closeModal = () => {
if (timerStart) {
stopTaskTimer();
}
setActive(false);
const currentUrl = window.location.pathname;
const newUrl = currentUrl.replace(/\/task\/\d+$/, "");
window.history.replaceState({}, "", newUrl);
document.body.style.overflow = "auto";
};
function taskExecutor(person) { function taskExecutor(person) {
apiRequest("/task/update-task", { apiRequest("/task/update-task", {
method: "PUT", method: "PUT",
@ -380,7 +382,22 @@ export const ModalTiсket = ({
} }
useEffect(() => { useEffect(() => {
if (active) {
setStartDate(task.dead_line ? new Date(task.dead_line) : new Date());
setTaskPriority(task.execution_priority);
setMembers(task.taskUsers);
setTaskTags(task.mark);
setExecutorId(task.executor_id);
setDeadLine(task.dead_line);
setExecutor(task.executor);
setInputsValue({
title: task.title,
description: task.description,
comment: ""
});
initListeners(); initListeners();
apiRequest( apiRequest(
`/comment/get-by-entity?entity_type=2&entity_id=${task.id}` `/comment/get-by-entity?entity_type=2&entity_id=${task.id}`
).then((res) => { ).then((res) => {
@ -396,8 +413,11 @@ export const ModalTiсket = ({
}, []); }, []);
setComments(comments); setComments(comments);
}); });
apiRequest(`/timer/get-by-entity?entity_type=2&entity_id=${task.id}`).then(
(res) => { apiRequest(
`/timer/get-by-entity?entity_type=2&entity_id=${task.id}`
).then((res) => {
if (Array.isArray(res)) {
let timerSeconds = 0; let timerSeconds = 0;
res.length && res.length &&
res.forEach((time) => { res.forEach((time) => {
@ -410,30 +430,38 @@ export const ModalTiсket = ({
updateTimerHours = Math.floor(timerSeconds / 60 / 60); updateTimerHours = Math.floor(timerSeconds / 60 / 60);
updateTimerMinute = Math.floor((timerSeconds / 60) % 60); updateTimerMinute = Math.floor((timerSeconds / 60) % 60);
updateTimerSec = timerSeconds % 60; updateTimerSec = timerSeconds % 60;
if (!time.stopped_at) { if (!time.stopped_at) {
setTimerStart(true); setTimerStart(true);
startTimer(); startTimer();
setTimerInfo(time); setTimerInfo(time);
} }
}); });
} else {
setCurrentTimerCount({
hours: 0,
minute: 0,
seconds: 0
});
} }
); });
apiRequest(`/file/get-by-entity?entity_type=2&entity_id=${task.id}`).then( apiRequest(`/file/get-by-entity?entity_type=2&entity_id=${task.id}`).then(
(res) => { (res) => {
if (Array.isArray(res)) { if (Array.isArray(res)) {
setTaskFiles(res); setTaskFiles(res);
} else {
setTaskFiles([]);
} }
} }
); );
if ( if (
localStorage.getItem("role_status") !== "18" && localStorage.getItem("role_status") !== "18" &&
Boolean( Array.isArray(correctProjectUsers) &&
!correctProjectUsers.find( !correctProjectUsers.find(
(item) => item.user_id === profileInfo.id_user (item) => item.user_id === profileInfo.id_user
) )
)
) { ) {
setCorrectProjectUsers((prevState) => [ setCorrectProjectUsers((prevState) => [
...prevState, ...prevState,
@ -446,16 +474,19 @@ export const ModalTiсket = ({
} }
]); ]);
} }
}, []); }
}, [active]);
useEffect(() => { useEffect(() => {
let tagIds = taskTags.map((tag) => tag.id); if (Array.isArray(taskTags)) {
const tagIds = taskTags.map((tag) => tag.id);
setCorrectProjectTags( setCorrectProjectTags(
projectMarks.reduce((acc, cur) => { projectMarks.reduce((acc, cur) => {
if (!tagIds.includes(cur.id)) acc.push(cur); if (!tagIds.includes(cur.id)) acc.push(cur);
return acc; return acc;
}, []) }, [])
); );
}
}, [taskTags]); }, [taskTags]);
async function handleUpload(event) { async function handleUpload(event) {
@ -534,13 +565,15 @@ export const ModalTiсket = ({
} }
useEffect(() => { useEffect(() => {
let ids = members.map((user) => user.user_id); if (Array.isArray(members)) {
const ids = members.map((user) => user.user_id);
setUsers( setUsers(
projectUsers.reduce((acc, cur) => { projectUsers.reduce((acc, cur) => {
if (!ids.includes(cur.user_id)) acc.push(cur); if (!ids.includes(cur.user_id)) acc.push(cur);
return acc; return acc;
}, []) }, [])
); );
}
}, [members]); }, [members]);
function copyTicketLink() { function copyTicketLink() {
@ -717,7 +750,7 @@ export const ModalTiсket = ({
)} )}
{/*<img src={taskImg} className="image-task"></img>*/} {/*<img src={taskImg} className="image-task"></img>*/}
</div> </div>
{Boolean(taskFiles.length) && ( {Boolean(taskFiles?.length) && (
<div className="task__files"> <div className="task__files">
{taskFiles.map((file) => { {taskFiles.map((file) => {
return ( return (
@ -877,7 +910,7 @@ export const ModalTiсket = ({
)} )}
</div> </div>
)} )}
{Boolean(members.length) && ( {Boolean(members?.length) && (
<div className="members"> <div className="members">
<h5>Участники:</h5> <h5>Участники:</h5>
<div className="members__list"> <div className="members__list">
@ -1009,7 +1042,8 @@ export const ModalTiсket = ({
<div className="workers_box-tag"> <div className="workers_box-tag">
<div className="tags"> <div className="tags">
<div className="tags__selected"> <div className="tags__selected">
{taskTags.map((tag) => { {Array.isArray(taskTags) &&
taskTags.map((tag) => {
return ( return (
<div <div
className="tags__selected__item" className="tags__selected__item"

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react"; import React, { forwardRef, useEffect, useState } from "react";
import { useDispatch } from "react-redux"; import { useDispatch } from "react-redux";
import { movePositionProjectTask } from "@redux/projectsTrackerSlice"; import { movePositionProjectTask } from "@redux/projectsTrackerSlice";
@ -14,7 +14,9 @@ import avatarMok from "assets/images/avatarMok.webp";
import "./trackerCardTask.scss"; import "./trackerCardTask.scss";
const TrackerCardTask = ({ const TrackerCardTask = forwardRef(
(
{
task, task,
projectBoard, projectBoard,
titleColor, titleColor,
@ -22,7 +24,9 @@ const TrackerCardTask = ({
openTicket, openTicket,
startWrapperIndexTest, startWrapperIndexTest,
setWrapperHover setWrapperHover
}) => { },
ref
) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const [taskHover, setTaskHover] = useState({}); const [taskHover, setTaskHover] = useState({});
@ -94,6 +98,7 @@ const TrackerCardTask = ({
return ( return (
<div <div
ref={ref}
key={task.id} key={task.id}
className={`tasks__board__item ${ className={`tasks__board__item ${
taskHover[task.id] ? "task__hover" : "" taskHover[task.id] ? "task__hover" : ""
@ -104,7 +109,7 @@ const TrackerCardTask = ({
onDragLeave={(e) => dragLeaveTaskHandler(e)} onDragLeave={(e) => dragLeaveTaskHandler(e)}
onDragEnd={() => dragEndTaskHandler()} onDragEnd={() => dragEndTaskHandler()}
onDrop={(e) => dragDropTaskHandler(e, task, column)} onDrop={(e) => dragDropTaskHandler(e, task, column)}
onClick={(e) => openTicket(e, task)} onClick={() => openTicket(task)}
> >
<div className="tasks__board__item__title"> <div className="tasks__board__item__title">
<p className="task__board__item__title">{task.title}</p> <p className="task__board__item__title">{task.title}</p>
@ -181,6 +186,9 @@ const TrackerCardTask = ({
/> />
</div> </div>
); );
}; }
);
TrackerCardTask.displayName = "TrackerCardTask";
export default TrackerCardTask; export default TrackerCardTask;

View File

@ -1,7 +1,7 @@
import moment from "moment"; import moment from "moment";
import React, { useEffect, useRef, useState } from "react"; import React, { useEffect, useRef, useState } from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { Link, useParams } from "react-router-dom"; import { Link, useLocation, useParams } from "react-router-dom";
import { import {
activeLoader, activeLoader,
@ -51,6 +51,8 @@ import avatarMok from "assets/images/avatarMok.webp";
export const ProjectTracker = () => { export const ProjectTracker = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const projectId = useParams(); const projectId = useParams();
const taskParams = useParams();
const taskRefs = useRef([]);
const [openColumnSelect, setOpenColumnSelect] = useState({}); const [openColumnSelect, setOpenColumnSelect] = useState({});
const [selectedTab, setSelectedTab] = useState(0); const [selectedTab, setSelectedTab] = useState(0);
@ -78,6 +80,29 @@ export const ProjectTracker = () => {
initListeners(); initListeners();
}, []); }, []);
useEffect(() => {
// const observer = new MutationObserver(() => {
// if (taskParams.taskId && taskRefs.current[taskParams.taskId]) {
// taskRefs.current[taskParams.taskId].click();
// console.log(taskRefs.current[taskParams.taskId]);
// }
// });
// observer.observe(document.body, { childList: true, subtree: true });
// return () => observer.disconnect();
if (projectBoard.columns && taskParams.taskId) {
for (const column of projectBoard.columns) {
const task = column.tasks.find((task) => task.id == taskParams.taskId);
if (task) {
openTicket(task);
return;
}
}
console.log(projectBoard);
}
}, [projectBoard]);
useEffect(() => { useEffect(() => {
let columnsTasksEmpty = true; let columnsTasksEmpty = true;
if (Object.keys(projectBoard).length) { if (Object.keys(projectBoard).length) {
@ -145,21 +170,32 @@ export const ProjectTracker = () => {
setPriorityTask(length); setPriorityTask(length);
} }
function openTicket(e, task) { const updateUrlWithTaskId = (taskId) => {
const currentUrl = window.location.pathname;
const taskUrlSegment = `/task/`;
if (currentUrl.includes(taskUrlSegment)) {
// Если URL содержит '/task/', заменяем старый ID на новый
const baseUrl = currentUrl.substring(
0,
currentUrl.indexOf(taskUrlSegment) + taskUrlSegment.length
);
const newUrl = `${baseUrl}${taskId}`;
window.history.pushState({}, "", newUrl);
} else {
// Если URL не содержит '/task/', добавляем '/task/${taskId}'
const newUrl = `${currentUrl}${taskUrlSegment}${taskId}`;
window.history.pushState({}, "", newUrl);
}
};
function openTicket(task) {
setSelectedTicket(task); setSelectedTicket(task);
setModalActiveTicket(true); setModalActiveTicket(true);
const currentUrl = window.location.pathname; updateUrlWithTaskId(task.id);
const newUrl = `${currentUrl}/task/${task.id}`;
window.history.pushState({}, "", newUrl);
document.body.style.overflow = "hidden"; document.body.style.overflow = "hidden";
} }
useEffect(() => {
const currentUrl = window.location.pathname;
const newUrl = currentUrl.replace(/\/task\/\d+$/, "");
window.history.replaceState({}, "", newUrl);
}, []);
function deleteColumn(column) { function deleteColumn(column) {
const priorityColumns = []; const priorityColumns = [];
apiRequest("/project-column/update-column", { apiRequest("/project-column/update-column", {
@ -421,8 +457,6 @@ export const ProjectTracker = () => {
</Link> </Link>
</div> </div>
</div> </div>
{Boolean(modalActiveTicket) && (
<ModalTicket <ModalTicket
active={modalActiveTicket} active={modalActiveTicket}
setActive={setModalActiveTicket} setActive={setModalActiveTicket}
@ -433,7 +467,6 @@ export const ProjectTracker = () => {
projectOwnerId={projectBoard.owner_id} projectOwnerId={projectBoard.owner_id}
projectMarks={projectBoard.mark} projectMarks={projectBoard.mark}
/> />
)}
<div className="tasks__container"> <div className="tasks__container">
{Boolean(projectBoard?.columns) && {Boolean(projectBoard?.columns) &&
@ -535,6 +568,9 @@ export const ProjectTracker = () => {
startWrapperIndexTest={startWrapperIndexTest} startWrapperIndexTest={startWrapperIndexTest}
task={task} task={task}
titleColor={titleColor} titleColor={titleColor}
ref={(el) => {
taskRefs.current[task.id] = el;
}}
/> />
); );
})} })}

View File

@ -24,6 +24,7 @@ export const DeveloperPage = () => {
return ( return (
<Routes> <Routes>
<Route exact path="/tracker/task/:id" element={<TicketFullScreen />} /> <Route exact path="/tracker/task/:id" element={<TicketFullScreen />} />
<Route <Route
exact exact
path="/tracker/project/:id/task/:taskId" path="/tracker/project/:id/task/:taskId"