edit check list item
This commit is contained in:
@@ -2,7 +2,7 @@ import { Edit } from "iconsax-react";
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ModalConfrim from "../../../../../components/ModalConfrim";
|
||||
import { toast } from '../../../../../components/Toast';
|
||||
import { toast } from "../../../../../components/Toast";
|
||||
import ProgressBar from "../../../../../components/ProgressBar";
|
||||
import { ErrorType } from "../../../../../helpers/types";
|
||||
import { useDeleteCheckListItem, useUpdateCheckListItem } from "../../../task/hooks/useTaskData";
|
||||
@@ -37,12 +37,23 @@ const CheckLists = ({
|
||||
const doneCount = completedCheckListItemCount ?? items.filter((item) => item.checked).length;
|
||||
const progress = totalCount > 0 ? Math.round((doneCount / totalCount) * 100) : 0;
|
||||
|
||||
const handleToggle = (id: string, checked: boolean) => {
|
||||
const handleToggle = (id: string, title: string, checked: boolean) => {
|
||||
updateCheckListItem.mutate(
|
||||
{ id, params: { isDone: !checked }, taskId },
|
||||
{ id, params: { title, isDone: !checked, taskId }, taskId },
|
||||
{
|
||||
onError: (error: ErrorType) => {
|
||||
toast(error.response?.data?.error.message[0], 'error');
|
||||
toast(error.response?.data?.error.message[0], "error");
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const handleSave = (id: string, title: string, checked: boolean) => {
|
||||
updateCheckListItem.mutate(
|
||||
{ id, params: { title, isDone: checked, taskId }, taskId },
|
||||
{
|
||||
onError: (error: ErrorType) => {
|
||||
toast(error.response?.data?.error.message[0], "error");
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -58,7 +69,7 @@ const CheckLists = ({
|
||||
setDeleteItemId(null);
|
||||
},
|
||||
onError: (error: ErrorType) => {
|
||||
toast(error.response?.data?.error.message[0], 'error');
|
||||
toast(error.response?.data?.error.message[0], "error");
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -84,9 +95,10 @@ const CheckLists = ({
|
||||
key={item.id}
|
||||
title={item.title}
|
||||
checked={item.checked}
|
||||
onToggle={() => handleToggle(item.id, item.checked)}
|
||||
onEdit={() => {}}
|
||||
onToggle={() => handleToggle(item.id, item.title, item.checked)}
|
||||
onSave={(title) => handleSave(item.id, title, item.checked)}
|
||||
onDelete={() => setDeleteItemId(item.id)}
|
||||
isSaving={updateCheckListItem.isPending}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user