Skip to content

Commit

Permalink
feat: can mark as done task in this week
Browse files Browse the repository at this point in the history
Clicking check icon button marks task as done. This removes it from
the This Week column and transfers it to the Done column.
  • Loading branch information
neldeles committed Jan 19, 2022
1 parent f0d4487 commit 4552cae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ export const handlers = [
});
}

if (task.status === "done") {
db.task.update({
where: {
id: {
equals: taskId,
},
},
data: {
...task,
},
});
}

return res(ctx.status(204));
}),
];
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function ThisWeekListItem({ task }: TListItemProps) {
// };
const queryClient = useQueryClient();

const moveToTodayMutation = useMutation(
const updateTaskMutation = useMutation(
(payload: TTask) => taskService.updateTask(payload),
{
onSuccess: () => {
Expand All @@ -92,13 +92,13 @@ export function ThisWeekListItem({ task }: TListItemProps) {
}
);

const handleMoveToToday = (task: TTask) => {
const handleUpdateTask = (task: TTask, newStatus: TTask["status"]) => {
const payload: TTask = {
...task,
status: "today",
status: newStatus,
};

moveToTodayMutation.mutate(payload);
updateTaskMutation.mutate(payload);
};

const handleDelete = (id: string) => {
Expand Down Expand Up @@ -150,12 +150,15 @@ export function ThisWeekListItem({ task }: TListItemProps) {
"hidden group-hover:flex group-hover:bg-gray-100"
)}
>
<IconButton disabled={doneIsClicked}>
<IconButton
disabled={doneIsClicked}
onClick={() => handleUpdateTask(task, "done")}
>
<Check />
</IconButton>
<IconButton
aria-label="move-right"
onClick={() => handleMoveToToday(task)}
onClick={() => handleUpdateTask(task, "today")}
>
<RightArrow />
</IconButton>
Expand Down

0 comments on commit 4552cae

Please sign in to comment.