feat: mark task change
This commit is contained in:
@@ -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)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -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)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -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)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -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)}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user