Skip to content

Commit

Permalink
Add delete tasklist action
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunkomath committed Jan 23, 2025
1 parent 38a62a0 commit 309f778
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
25 changes: 25 additions & 0 deletions app/(dashboard)/[tenant]/projects/[projectId]/tasklists/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,31 @@ export async function partialUpdateTaskList(
revalidatePath(`/${orgSlug}/projects/${updated.projectId}/tasklists`);
}

export async function deleteTaskList({
id,
projectId,
}: {
id: number;
projectId: number;
}) {
const { orgSlug } = await getOwner();
const db = await database();
const taskListDetails = db
.delete(taskList)
.where(eq(taskList.id, +id))
.returning()
.get();

await logActivity({
action: "deleted",
type: "tasklist",
message: `Deleted task list ${taskListDetails?.name}`,
projectId: +projectId,
});

revalidatePath(`/${orgSlug}/projects/${projectId}/tasklists`);
}

export async function createTask({
userId,
taskListId,
Expand Down
26 changes: 25 additions & 1 deletion components/project/tasklist/tasklist-header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"use client";

import { forkTaskList } from "@/app/(dashboard)/[tenant]/projects/[projectId]/tasklists/actions";
import {
deleteTaskList,
forkTaskList,
} from "@/app/(dashboard)/[tenant]/projects/[projectId]/tasklists/actions";
import { Button, buttonVariants } from "@/components/ui/button";
import {
DropdownMenu,
Expand Down Expand Up @@ -144,6 +147,27 @@ export const TaskListHeader = ({
Fork
</Button>
</DropdownMenuItem>
<DropdownMenuItem className="w-full p-0">
<Button
variant="destructive"
className="w-full"
onClick={async () => {
toast.promise(
deleteTaskList({
id: taskList.id,
projectId: taskList.projectId,
}),
{
loading: "Deleting task list...",
success: "Task list deleted.",
error: "Failed to delete task list.",
},
);
}}
>
Delete
</Button>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
Expand Down

0 comments on commit 309f778

Please sign in to comment.