Create new component TrackerTagList
This commit is contained in:
@ -1,15 +1,11 @@
|
||||
import moment from "moment";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { HexColorPicker } from "react-colorful";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
|
||||
import {
|
||||
activeLoader,
|
||||
addNewTagToProject,
|
||||
deleteTagProject,
|
||||
filterCreatedByMe,
|
||||
filteredExecutorTasks,
|
||||
filteredParticipateTasks,
|
||||
getBoarderLoader,
|
||||
getProjectBoard,
|
||||
@ -41,11 +37,10 @@ import { ProfileBreadcrumbs } from "@components/ProfileBreadcrumbs/ProfileBreadc
|
||||
import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader";
|
||||
import TrackerSelectColumn from "@components/TrackerSelectColumn/TrackerSelectColumn";
|
||||
import TrackerSelectExecutor from "@components/TrackerSelectExecutor/TrackerSelectExecutor";
|
||||
import TrackerTagList from "@components/TrackerTagList/TrackerTagList";
|
||||
|
||||
import arrow from "assets/icons/arrows/arrowRight.png";
|
||||
import arrowDown from "assets/icons/arrows/selectArrow.png";
|
||||
import category from "assets/icons/category.svg";
|
||||
import close from "assets/icons/close.png";
|
||||
import commentsBoard from "assets/icons/commentsBoard.svg";
|
||||
import del from "assets/icons/delete.svg";
|
||||
import edit from "assets/icons/edit.svg";
|
||||
@ -71,15 +66,8 @@ export const ProjectTracker = () => {
|
||||
const [modalActiveTicket, setModalActiveTicket] = useState(false);
|
||||
const [selectedTicket, setSelectedTicket] = useState({});
|
||||
const [personListOpen, setPersonListOpen] = useState(false);
|
||||
const [tags, setTags] = useState({
|
||||
open: false,
|
||||
add: false,
|
||||
edit: false
|
||||
});
|
||||
const [acceptModalOpen, setAcceptModalOpen] = useState(false);
|
||||
const [currentColumnDelete, setCurrentColumnDelete] = useState(null);
|
||||
const [color, setColor] = useState("#aabbcc");
|
||||
const [tagInfo, setTagInfo] = useState({ description: "", name: "" });
|
||||
const [checkBoxParticipateTasks, setCheckBoxParticipateTasks] =
|
||||
useState(false);
|
||||
const [filteredNoTasks, setFilteredNoTasks] = useState(false);
|
||||
@ -294,81 +282,6 @@ export const ProjectTracker = () => {
|
||||
dispatch(setProjectBoardFetch(projectId.id));
|
||||
}
|
||||
|
||||
function addNewTag() {
|
||||
apiRequest("/mark/create", {
|
||||
method: "POST",
|
||||
data: {
|
||||
title: tagInfo.description,
|
||||
slug: tagInfo.name,
|
||||
color: color,
|
||||
status: 1
|
||||
}
|
||||
}).then((data) => {
|
||||
apiRequest("/mark/attach", {
|
||||
method: "POST",
|
||||
data: {
|
||||
mark_id: data.id,
|
||||
entity_type: 1,
|
||||
entity_id: projectId.id
|
||||
}
|
||||
}).then((data) => {
|
||||
dispatch(addNewTagToProject(data.mark));
|
||||
setTags((prevState) => ({
|
||||
...prevState,
|
||||
add: false
|
||||
}));
|
||||
showNotification({
|
||||
show: true,
|
||||
text: "Тег успешно создан",
|
||||
type: "success"
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function editTag() {
|
||||
apiRequest("/mark/update", {
|
||||
method: "PUT",
|
||||
data: {
|
||||
mark_id: tagInfo.editMarkId,
|
||||
title: tagInfo.description,
|
||||
slug: tagInfo.name,
|
||||
color: color
|
||||
}
|
||||
}).then(() => {
|
||||
dispatch(setProjectBoardFetch(projectId.id));
|
||||
setTags((prevState) => ({
|
||||
...prevState,
|
||||
edit: false
|
||||
}));
|
||||
setTagInfo({ description: "", name: "" });
|
||||
setColor("#aabbcc");
|
||||
showNotification({
|
||||
show: true,
|
||||
text: "Тег успешно изменён",
|
||||
type: "success"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function deleteTag(tagId) {
|
||||
apiRequest("/mark/detach", {
|
||||
method: "DELETE",
|
||||
data: {
|
||||
mark_id: tagId,
|
||||
entity_type: 1,
|
||||
entity_id: projectId.id
|
||||
}
|
||||
}).then(() => {
|
||||
dispatch(deleteTagProject(tagId));
|
||||
showNotification({
|
||||
show: true,
|
||||
text: "Тег удален",
|
||||
type: "success"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const initListeners = () => {
|
||||
document.addEventListener("click", closeByClickingOut);
|
||||
};
|
||||
@ -388,20 +301,6 @@ export const ProjectTracker = () => {
|
||||
setPersonListOpen(false);
|
||||
}
|
||||
|
||||
if (
|
||||
event &&
|
||||
!path.find(
|
||||
(div) =>
|
||||
div.classList &&
|
||||
(div.classList.contains("tasks__head__tags") ||
|
||||
div.classList.contains("tags__list"))
|
||||
)
|
||||
) {
|
||||
setTags({ open: false, add: false, edit: false });
|
||||
setTagInfo({ description: "", name: "" });
|
||||
setColor("#aabbcc");
|
||||
}
|
||||
|
||||
if (
|
||||
event &&
|
||||
!path.find(
|
||||
@ -567,150 +466,8 @@ export const ProjectTracker = () => {
|
||||
setSelectedExecutor={setSelectedExecutor}
|
||||
/>
|
||||
|
||||
<div className="tasks__head__tags">
|
||||
<div
|
||||
className="tags__add"
|
||||
onClick={() => {
|
||||
setTags((prevState) => ({
|
||||
...prevState,
|
||||
open: !tags.open
|
||||
}));
|
||||
}}
|
||||
>
|
||||
<p>Список тегов</p>
|
||||
<img
|
||||
className={tags.open ? "open" : ""}
|
||||
src={arrowDown}
|
||||
alt="arrow"
|
||||
/>
|
||||
</div>
|
||||
{tags.open && (
|
||||
<div className="tags__list">
|
||||
{!tags.add && !tags.edit && (
|
||||
<div
|
||||
className="add-new-tag"
|
||||
onClick={() =>
|
||||
setTags((prevState) => ({
|
||||
...prevState,
|
||||
add: true
|
||||
}))
|
||||
}
|
||||
>
|
||||
<p>Добавить новый тег</p>
|
||||
<span>+</span>
|
||||
</div>
|
||||
)}
|
||||
{!tags.add && !tags.edit && (
|
||||
<div className="tags__list__created">
|
||||
{projectBoard.mark.map((tag) => {
|
||||
return (
|
||||
<div className="tag-item" key={tag.id}>
|
||||
<div className="tag-item__info">
|
||||
<span
|
||||
className="tag-item__color"
|
||||
style={{ background: tag.color }}
|
||||
/>
|
||||
<div>
|
||||
<span className="tag-item__info__name">
|
||||
{tag.slug}
|
||||
</span>
|
||||
<p className="tag-item__description">
|
||||
{tag.title}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="tag-item__images">
|
||||
<img
|
||||
src={edit}
|
||||
alt="edit"
|
||||
onClick={() => {
|
||||
setTags((prevState) => ({
|
||||
...prevState,
|
||||
edit: true
|
||||
}));
|
||||
setTagInfo({
|
||||
description: tag.title,
|
||||
name: tag.slug,
|
||||
editMarkId: tag.id
|
||||
});
|
||||
setColor(tag.color);
|
||||
}}
|
||||
/>
|
||||
<img
|
||||
onClick={() => deleteTag(tag.id)}
|
||||
className="delete"
|
||||
src={close}
|
||||
alt="delete"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{(tags.add || tags.edit) && (
|
||||
<div className="form-tag">
|
||||
<input
|
||||
className="form-tag__input"
|
||||
placeholder="Описание метки"
|
||||
maxLength="25"
|
||||
value={tagInfo.description}
|
||||
onChange={(e) =>
|
||||
setTagInfo((prevState) => ({
|
||||
...prevState,
|
||||
description: e.target.value
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<input
|
||||
className="form-tag__input"
|
||||
placeholder="Тег"
|
||||
value={tagInfo.name}
|
||||
maxLength="10"
|
||||
onChange={(e) =>
|
||||
setTagInfo((prevState) => ({
|
||||
...prevState,
|
||||
name: e.target.value
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<HexColorPicker color={color} onChange={setColor} />
|
||||
<button
|
||||
onClick={() => {
|
||||
tags.add ? addNewTag() : editTag();
|
||||
}}
|
||||
className={
|
||||
tagInfo.name && tagInfo.description
|
||||
? "form-tag__btn"
|
||||
: "form-tag__btn disable"
|
||||
}
|
||||
>
|
||||
{tags.add ? "Добавить" : "Изменить"}
|
||||
</button>
|
||||
{(tags.add || tags.edit) && (
|
||||
<button
|
||||
className={"form-tag__btn"}
|
||||
onClick={() => {
|
||||
setTags((prevState) => ({
|
||||
...prevState,
|
||||
add: false,
|
||||
edit: false
|
||||
}));
|
||||
setTagInfo({
|
||||
description: "",
|
||||
name: ""
|
||||
});
|
||||
setColor("#aabbcc");
|
||||
}}
|
||||
>
|
||||
Отмена
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<TrackerTagList projectBoard={projectBoard} />
|
||||
|
||||
<Link to="/profile/tracker" className="tasks__head__back">
|
||||
<p>К списку проектов</p>
|
||||
<img src={arrow} alt="arrow" />
|
||||
|
Reference in New Issue
Block a user