From cb9e1bd2660537dca9dd40b72b8865fdef951a78 Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Wed, 7 May 2025 11:57:35 +0300 Subject: [PATCH] feat: mark task change --- src/pages/profile_tasks.tsx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/pages/profile_tasks.tsx b/src/pages/profile_tasks.tsx index 18da63d..d5c4967 100644 --- a/src/pages/profile_tasks.tsx +++ b/src/pages/profile_tasks.tsx @@ -8,6 +8,7 @@ import Dialog from "@/components/ui/Dialog"; import ModalWindow from "@/components/ui/Modal"; import { withTitle } from "@/constructors/Component"; import { UrlsTitle } from "@/enums/urls"; +import apiClient from "@/services/api"; import { cn } from "@/utils/class-merge"; import { PlusIcon } from "@heroicons/react/20/solid"; import { @@ -29,16 +30,15 @@ import { Nullable } from "primereact/ts-helpers"; import { SubmitHandler, useForm } from "react-hook-form"; import { v4 as uuid } from "uuid"; import { - ITask, - ITaskForm, IApiResponse, ICreateTaskResponse, - ITaskDetails, IDeleteTaskResponse, IEditTaskResponse, + ITask, + ITaskDetails, + ITaskForm, } from "./profile_tasks.dto"; import classes from "./profile_tasks.module.scss"; -import apiClient from "@/services/api"; const ProfileTasks: FunctionComponent = () => { const [openModal, setIsOpen] = useState(false); // Открыта модалка @@ -278,14 +278,15 @@ const ProfileTasks: FunctionComponent = () => { } }; - const handleMarkTask = async (taskId: string, isCompleted: boolean) => { + const handleMarkTask = async (taskId: string) => { try { - await apiClient(`/api/update_task/${taskId}/`, { + await apiClient(`/api/tasks/toggle_complete_task/${taskId}/`, { method: "PATCH", - body: JSON.stringify({ isCompleted }), }); - await fetchTasks(); + setTasks((prevTasks) => + prevTasks.map((task) => (task.id === taskId ? { ...task, checked: !task.checked } : task)) + ); } catch (error) { console.error("Failed to mark task:", error); } @@ -614,7 +615,7 @@ const ProfileTasks: FunctionComponent = () => { checked={task.checked} overdue={task.date < new Date()} onClick={() => handleViewTask(task.id)} - onMarkClick={() => handleMarkTask(task.id, !task.checked)} + onMarkClick={() => handleMarkTask(task.id)} /> ))} @@ -630,7 +631,7 @@ const ProfileTasks: FunctionComponent = () => { key={task.id} checked={task.checked} onClick={() => handleViewTask(task.id)} - onMarkClick={() => handleMarkTask(task.id, !task.checked)} + onMarkClick={() => handleMarkTask(task.id)} /> ))} @@ -644,7 +645,7 @@ const ProfileTasks: FunctionComponent = () => { key={task.id} checked={task.checked} onClick={() => handleViewTask(task.id)} - onMarkClick={() => handleMarkTask(task.id, !task.checked)} + onMarkClick={() => handleMarkTask(task.id)} /> ))} @@ -691,7 +692,7 @@ const ProfileTasks: FunctionComponent = () => { checked={task.checked} overdue={task.date < new Date()} onClick={() => handleViewTask(task.id)} - onMarkClick={() => handleMarkTask(task.id, !task.checked)} + onMarkClick={() => handleMarkTask(task.id)} /> )) ) : (