From 49f6ff04d0da06e88aad86478051c421570c49b8 Mon Sep 17 00:00:00 2001 From: Eliezer Steinbock <3090527+elie222@users.noreply.github.com> Date: Tue, 5 Nov 2024 22:56:54 -0500 Subject: [PATCH 1/2] Add more actions to categories --- apps/web/components/GroupedTable.tsx | 67 +++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/apps/web/components/GroupedTable.tsx b/apps/web/components/GroupedTable.tsx index 239f4b517..43e8af966 100644 --- a/apps/web/components/GroupedTable.tsx +++ b/apps/web/components/GroupedTable.tsx @@ -12,7 +12,14 @@ import { type ColumnDef, flexRender, } from "@tanstack/react-table"; -import { ArchiveIcon, ChevronRight, PencilIcon } from "lucide-react"; +import { + ArchiveIcon, + ChevronRight, + MoreVerticalIcon, + PencilIcon, + TagIcon, + TagsIcon, +} from "lucide-react"; import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table"; import type { Category } from "@prisma/client"; import { EmailCell } from "@/components/EmailCell"; @@ -41,6 +48,17 @@ import { import { getGmailSearchUrl, getGmailUrl } from "@/utils/url"; import { MessageText } from "@/components/Typography"; import { CreateCategoryDialog } from "@/app/(app)/smart-categories/CreateCategoryButton"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuPortal, + DropdownMenuSub, + DropdownMenuSubTrigger, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { useLabels, type UserLabel } from "@/hooks/useLabels"; +import { LabelsSubMenu } from "@/components/LabelsSubMenu"; const COLUMNS = 4; @@ -172,6 +190,8 @@ export function GroupedTable({ const [selectedCategoryName, setSelectedCategoryName] = useQueryState("categoryName"); + const { userLabels: labels } = useLabels(); + return ( <> @@ -204,6 +224,7 @@ export function GroupedTable({ }} onArchiveAll={onArchiveAll} onEditCategory={onEditCategory} + labels={labels} /> {isCategoryExpanded && ( void; onArchiveAll: () => void; onEditCategory: () => void; @@ -346,10 +369,44 @@ function GroupRow({ - + + + + + + + + Edit Prompt + + + + Auto archive + + + + + + Auto archive and label + + + {}} /> + + + + + + + Auto label + + + {}} /> + + + +
@@ -223,6 +218,22 @@ export function GroupedTable({ setSelectedCategoryName(categoryName); }; + const onRemoveAllFromCategory = async () => { + const yes = confirm( + "This will remove all emails from this category. You can re-categorize them later. Do you want to continue?", + ); + if (!yes) return; + const result = await removeAllFromCategoryAction(categoryName); + + if (isActionError(result)) { + toastError({ description: result.error }); + } else { + toastSuccess({ + description: "All emails removed from category", + }); + } + }; + const category = categoryMap[categoryName]; if (!category) { @@ -244,7 +255,7 @@ export function GroupedTable({ }} onArchiveAll={onArchiveAll} onEditCategory={onEditCategory} - labels={labels} + onRemoveAllFromCategory={onRemoveAllFromCategory} /> {isCategoryExpanded && ( void; onArchiveAll: () => void; onEditCategory: () => void; + onRemoveAllFromCategory: () => void; }) { return ( @@ -399,38 +410,15 @@ function GroupRow({ - Edit Prompt + Edit - - - Auto archive + + + Remove All From Category - - - - - Auto archive and label - - - {}} /> - - - - - - - Auto label - - - {}} /> - - - + {category.rules.length ? (
{category.rules.map((rule) => ( diff --git a/apps/web/utils/actions/categorize.ts b/apps/web/utils/actions/categorize.ts index a19170329..accd4427d 100644 --- a/apps/web/utils/actions/categorize.ts +++ b/apps/web/utils/actions/categorize.ts @@ -234,3 +234,21 @@ export const setAutoCategorizeAction = withActionInstrumentation( return { autoCategorizeSenders }; }, ); + +export const removeAllFromCategoryAction = withActionInstrumentation( + "removeAllFromCategory", + async (categoryName: string) => { + const session = await auth(); + if (!session?.user) return { error: "Not authenticated" }; + + await prisma.newsletter.updateMany({ + where: { + category: { name: categoryName }, + userId: session.user.id, + }, + data: { categoryId: null }, + }); + + revalidatePath("/smart-categories"); + }, +);