diff --git a/apps/web/app/(app)/bulk-unsubscribe/BulkUnsubscribeSection.tsx b/apps/web/app/(app)/bulk-unsubscribe/BulkUnsubscribeSection.tsx index 31d5b29c2..aced0436c 100644 --- a/apps/web/app/(app)/bulk-unsubscribe/BulkUnsubscribeSection.tsx +++ b/apps/web/app/(app)/bulk-unsubscribe/BulkUnsubscribeSection.tsx @@ -223,11 +223,14 @@ export function BulkUnsubscribeSection(props: { )} - setOpenedNewsletter(undefined)} - refreshInterval={props.refreshInterval} - /> + {openedNewsletter && ( + setOpenedNewsletter(undefined)} + refreshInterval={props.refreshInterval} + mutate={mutate} + /> + )} ); diff --git a/apps/web/app/(app)/stats/NewsletterModal.tsx b/apps/web/app/(app)/stats/NewsletterModal.tsx index 0ff1fd5bb..8e9467e65 100644 --- a/apps/web/app/(app)/stats/NewsletterModal.tsx +++ b/apps/web/app/(app)/stats/NewsletterModal.tsx @@ -21,27 +21,46 @@ import { SectionHeader } from "@/components/Typography"; import { EmailList } from "@/components/email-list/EmailList"; import type { ThreadsResponse } from "@/app/api/google/threads/controller"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import { Button } from "@/components/ui/button"; +import { Button, ButtonLoader } from "@/components/ui/button"; import { getGmailFilterSettingsUrl } from "@/utils/url"; import { Tooltip } from "@/components/Tooltip"; import { AlertBasic } from "@/components/Alert"; import { onAutoArchive } from "@/utils/actions/client"; -import { MoreDropdown } from "@/app/(app)/bulk-unsubscribe/common"; +import { + MoreDropdown, + useUnsubscribeButton, +} from "@/app/(app)/bulk-unsubscribe/common"; import { useLabels } from "@/hooks/useLabels"; import { Row } from "@/app/(app)/bulk-unsubscribe/types"; +import { usePremium } from "@/components/PremiumAlert"; +import { usePostHog } from "posthog-js/react"; export function NewsletterModal(props: { - newsletter?: Pick; + newsletter: Pick; onClose: (isOpen: boolean) => void; refreshInterval?: number; + mutate?: () => Promise; }) { const { newsletter, refreshInterval, onClose } = props; + const mutate = props.mutate || (() => Promise.resolve()); // Set a default value for mutate if it's not provided const session = useSession(); const email = session.data?.user.email; const { userLabels } = useLabels(); + const { hasUnsubscribeAccess, mutate: refetchPremium } = usePremium(); + + const posthog = usePostHog(); + + const { unsubscribeLoading, onUnsubscribe } = useUnsubscribeButton({ + item: newsletter, + hasUnsubscribeAccess, + mutate, + posthog, + refetchPremium, + }); + return ( @@ -57,8 +76,15 @@ export function NewsletterModal(props: { href={newsletter.lastUnsubscribeLink || undefined} target="_blank" rel="noreferrer" + onClick={onUnsubscribe} > - Unsubscribe + {!unsubscribeLoading && Unsubscribe} + {!!unsubscribeLoading && ( +
+ + Unsubscribing... +
+ )}