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 ModalWindow from "@/components/ui/Modal";
|
||||||
import { withTitle } from "@/constructors/Component";
|
import { withTitle } from "@/constructors/Component";
|
||||||
import { UrlsTitle } from "@/enums/urls";
|
import { UrlsTitle } from "@/enums/urls";
|
||||||
|
import apiClient from "@/services/api";
|
||||||
import { cn } from "@/utils/class-merge";
|
import { cn } from "@/utils/class-merge";
|
||||||
import { PlusIcon } from "@heroicons/react/20/solid";
|
import { PlusIcon } from "@heroicons/react/20/solid";
|
||||||
import {
|
import {
|
||||||
@@ -29,16 +30,15 @@ import { Nullable } from "primereact/ts-helpers";
|
|||||||
import { SubmitHandler, useForm } from "react-hook-form";
|
import { SubmitHandler, useForm } from "react-hook-form";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
import {
|
import {
|
||||||
ITask,
|
|
||||||
ITaskForm,
|
|
||||||
IApiResponse,
|
IApiResponse,
|
||||||
ICreateTaskResponse,
|
ICreateTaskResponse,
|
||||||
ITaskDetails,
|
|
||||||
IDeleteTaskResponse,
|
IDeleteTaskResponse,
|
||||||
IEditTaskResponse,
|
IEditTaskResponse,
|
||||||
|
ITask,
|
||||||
|
ITaskDetails,
|
||||||
|
ITaskForm,
|
||||||
} from "./profile_tasks.dto";
|
} from "./profile_tasks.dto";
|
||||||
import classes from "./profile_tasks.module.scss";
|
import classes from "./profile_tasks.module.scss";
|
||||||
import apiClient from "@/services/api";
|
|
||||||
|
|
||||||
const ProfileTasks: FunctionComponent = () => {
|
const ProfileTasks: FunctionComponent = () => {
|
||||||
const [openModal, setIsOpen] = useState(false); // Открыта модалка
|
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 {
|
try {
|
||||||
await apiClient(`/api/update_task/${taskId}/`, {
|
await apiClient(`/api/tasks/toggle_complete_task/${taskId}/`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
body: JSON.stringify({ isCompleted }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await fetchTasks();
|
setTasks((prevTasks) =>
|
||||||
|
prevTasks.map((task) => (task.id === taskId ? { ...task, checked: !task.checked } : task))
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to mark task:", error);
|
console.error("Failed to mark task:", error);
|
||||||
}
|
}
|
||||||
@@ -614,7 +615,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
checked={task.checked}
|
checked={task.checked}
|
||||||
overdue={task.date < new Date()}
|
overdue={task.date < new Date()}
|
||||||
onClick={() => handleViewTask(task.id)}
|
onClick={() => handleViewTask(task.id)}
|
||||||
onMarkClick={() => handleMarkTask(task.id, !task.checked)}
|
onMarkClick={() => handleMarkTask(task.id)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -630,7 +631,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
key={task.id}
|
key={task.id}
|
||||||
checked={task.checked}
|
checked={task.checked}
|
||||||
onClick={() => handleViewTask(task.id)}
|
onClick={() => handleViewTask(task.id)}
|
||||||
onMarkClick={() => handleMarkTask(task.id, !task.checked)}
|
onMarkClick={() => handleMarkTask(task.id)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -644,7 +645,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
key={task.id}
|
key={task.id}
|
||||||
checked={task.checked}
|
checked={task.checked}
|
||||||
onClick={() => handleViewTask(task.id)}
|
onClick={() => handleViewTask(task.id)}
|
||||||
onMarkClick={() => handleMarkTask(task.id, !task.checked)}
|
onMarkClick={() => handleMarkTask(task.id)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -691,7 +692,7 @@ const ProfileTasks: FunctionComponent = () => {
|
|||||||
checked={task.checked}
|
checked={task.checked}
|
||||||
overdue={task.date < new Date()}
|
overdue={task.date < new Date()}
|
||||||
onClick={() => handleViewTask(task.id)}
|
onClick={() => handleViewTask(task.id)}
|
||||||
onMarkClick={() => handleMarkTask(task.id, !task.checked)}
|
onMarkClick={() => handleMarkTask(task.id)}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in New Issue
Block a user