From 46a8373d005ba6d25a5ba28eb06bf22a3dd8bb73 Mon Sep 17 00:00:00 2001 From: M1kola Date: Mon, 8 May 2023 00:41:39 +0300 Subject: [PATCH] editProjectName --- src/components/ProjectTiket/ProjectTiket.jsx | 1 + .../UI/TrackerModal/TrackerModal.jsx | 25 ++++-- src/pages/Tracker/Tracker.js | 85 ++++++------------- src/redux/projectsTrackerSlice.js | 18 +++- 4 files changed, 59 insertions(+), 70 deletions(-) diff --git a/src/components/ProjectTiket/ProjectTiket.jsx b/src/components/ProjectTiket/ProjectTiket.jsx index caa5c354..c503fb82 100644 --- a/src/components/ProjectTiket/ProjectTiket.jsx +++ b/src/components/ProjectTiket/ProjectTiket.jsx @@ -71,6 +71,7 @@ export const ProjectTiket = ({ project, index }) => { active={modalAdd} setActive={setModalAdd} defautlInput={project.name} + projectId={project.id} > diff --git a/src/components/UI/TrackerModal/TrackerModal.jsx b/src/components/UI/TrackerModal/TrackerModal.jsx index 80b763bc..026d1093 100644 --- a/src/components/UI/TrackerModal/TrackerModal.jsx +++ b/src/components/UI/TrackerModal/TrackerModal.jsx @@ -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 = ({
editProjectName(e.target.value)} + value={projectName} + onChange={(e) => setProjectName(e.target.value)} />
diff --git a/src/pages/Tracker/Tracker.js b/src/pages/Tracker/Tracker.js index 532f0980..bbd14e32 100644 --- a/src/pages/Tracker/Tracker.js +++ b/src/pages/Tracker/Tracker.js @@ -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 = () => {

Архив проектов:

-

{archiveProjects.length} проект(ов)

+

{projects.filter((project) => project.status === 10).length} проект(ов)

- {Boolean(archiveProjects) ? ( - archiveProjects.map((project, index) => { - return ( + {Boolean(projects.filter((project) => project.status === 10).length) ? ( + projects.map((project, index) => { + return project.status === 10 ? (

{project.name}

{project.date}

- ); + ): ''; }) ) : (
diff --git a/src/redux/projectsTrackerSlice.js b/src/redux/projectsTrackerSlice.js index dbd62b2c..754adcc1 100644 --- a/src/redux/projectsTrackerSlice.js +++ b/src/redux/projectsTrackerSlice.js @@ -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;