editProjectName

This commit is contained in:
Николай Полтщук 2023-05-08 00:41:39 +03:00
parent 84647c8257
commit 46a8373d00
4 changed files with 59 additions and 70 deletions

View File

@ -71,6 +71,7 @@ export const ProjectTiket = ({ project, index }) => {
active={modalAdd}
setActive={setModalAdd}
defautlInput={project.name}
projectId={project.id}
></TrackerModal>
<ModalSelect active={modalSelect}>

View File

@ -7,6 +7,7 @@ import {
getValueModalType,
setProject,
setProjectBoardFetch,
editProjectName
} from "../../../redux/projectsTrackerSlice";
import "./trackerModal.scss";
@ -17,6 +18,7 @@ export const TrackerModal = ({
selectedTab,
defautlInput,
titleProject,
projectId
}) => {
const dispatch = useDispatch();
const projectBoard = useSelector(getProjectBoard);
@ -24,7 +26,7 @@ export const TrackerModal = ({
const modalType = useSelector(getValueModalType);
const [emailWorker, setEmailWorker] = useState("");
const [ProjectName, setProjectName] = useState(defautlInput);
const [projectName, setProjectName] = useState(defautlInput);
const [valueColumn, setValueColumn] = useState("");
const [nameProject, setNameProject] = useState("");
@ -73,10 +75,17 @@ export const TrackerModal = ({
setDescriptionTicket("");
}
function editProject() {}
function editProjectName(value) {
setProjectName(value);
function editProject() {
apiRequest("/project/update", {
method: "PUT",
data: {
project_id: projectId,
name: projectName
},
}).then((res) => {
setActive(false)
dispatch(editProjectName({id: projectId, name: projectName}))
});
}
function createProject() {
@ -88,7 +97,7 @@ export const TrackerModal = ({
data: {
user_id: localStorage.getItem("id"),
name: nameProject,
status: 1,
status: 19,
},
}).then((res) => {
const result = { ...res, columns: [] };
@ -162,8 +171,8 @@ export const TrackerModal = ({
<div className="input-container">
<input
className="name-project"
value={ProjectName}
onChange={(e) => editProjectName(e.target.value)}
value={projectName}
onChange={(e) => setProjectName(e.target.value)}
/>
</div>
</div>

View File

@ -38,45 +38,9 @@ export const Tracker = () => {
const [allTasks, setAllTasks] = useState([]);
const [filteredAllTasks, setFilteredAllTasks] = useState([]);
const [loader, setLoader] = useState(false);
const [filterCompleteTasks, setFilterCompleteTasks] = useState([]);
// const [allCompletedTasks, setAllCompletedTasks] = useState([])
const [archiveProjects] = useState([
{
name: "Будущее России",
date: "7 марта 2023 г",
},
{
name: "Будущее России",
date: "7 марта 2023 г",
},
]);
const [completeTasks] = useState([
{
name: "PR - 2245",
description: "Сверстать часть таблицы. Сверстать часть таблицы",
dateComplete: "7 марта 2023 г",
avatarDo: avatarTest,
project: "Будущее России",
},
{
name: "PR - 2245",
description: "Сверстать часть таблицы. Сверстать часть таблицы",
dateComplete: "7 марта 2023 г",
avatarDo: avatarTest,
project: "Будущее России",
},
{
name: "PR - 2245",
description: "Сверстать часть таблицы. Сверстать часть таблицы",
dateComplete: "7 марта 2023 г",
avatarDo: avatarTest,
project: "Будущее России",
},
]);
const [filterCompleteTasks, setFilterCompleteTasks] = useState(completeTasks);
// Modal State
const [modalCreateProject, setModalCreateProject] = useState(false);
useEffect(() => {
@ -88,6 +52,11 @@ export const Tracker = () => {
).then((el) => {
dispatch(setAllProjects(el.projects));
setLoader(false);
// setAllCompletedTasks(el.projects.filter((project) => {
// if (project.status === 10 && project.columns.length) {
// return project
// }
// }).map((project) => { return project.columns}))
});
apiRequest(
`/task/get-user-tasks?user_id=${localStorage.getItem("id")}`
@ -120,21 +89,21 @@ export const Tracker = () => {
}
function filterArchiveTasks(e) {
setFilterCompleteTasks(
completeTasks.filter((item) => {
if (!e.target.value) {
return item;
}
if (
item.name.toLowerCase().startsWith(e.target.value.toLowerCase()) ||
item.description
.toLowerCase()
.startsWith(e.target.value.toLowerCase())
) {
return item;
}
})
);
// setFilterCompleteTasks(
// completeTasks.filter((item) => {
// if (!e.target.value) {
// return item;
// }
// if (
// item.name.toLowerCase().startsWith(e.target.value.toLowerCase()) ||
// item.description
// .toLowerCase()
// .startsWith(e.target.value.toLowerCase())
// ) {
// return item;
// }
// })
// );
}
return (
@ -340,19 +309,19 @@ export const Tracker = () => {
<div className="archive__projects">
<div className="archive__title">
<h3>Архив проектов:</h3>
<p>{archiveProjects.length} проект(ов)</p>
<p>{projects.filter((project) => project.status === 10).length} проект(ов)</p>
</div>
<div className="archive__tasksWrapper">
{Boolean(archiveProjects) ? (
archiveProjects.map((project, index) => {
return (
{Boolean(projects.filter((project) => project.status === 10).length) ? (
projects.map((project, index) => {
return project.status === 10 ? (
<div className="archive__completeTask" key={index}>
<div className="archive__completeTask__description">
<p>{project.name}</p>
<p className="date">{project.date}</p>
</div>
</div>
);
): '';
})
) : (
<div className="archive__noItem">

View File

@ -27,9 +27,11 @@ export const projectsTrackerSlice = createSlice({
state.toggleTab = action.payload;
},
deleteProject: (state, action) => {
state.projects = state.projects.filter(
(project) => project.id !== action.payload.id
);
state.projects.forEach((project) => {
if (project.id === action.payload.id) {
project.status = 10
}
})
},
activeLoader: (state) => {
state.boardLoader = true
@ -53,6 +55,13 @@ export const projectsTrackerSlice = createSlice({
}
});
},
editProjectName: (state, action) => {
state.projects.forEach((project) => {
if (project.id === action.payload.id) {
project.name = action.payload.name
}
})
},
modalToggle: (state, action) => {
state.modalType = action.payload;
},
@ -72,7 +81,8 @@ export const {
moveProjectTask,
setToggleTab,
modalToggle,
activeLoader
activeLoader,
editProjectName
} = projectsTrackerSlice.actions;
export const getProjects = (state) => state.tracker.projects;