diff --git a/apps/web/app/(app)/bulk-unsubscribe/BulkUnsubscribeSection.tsx b/apps/web/app/(app)/bulk-unsubscribe/BulkUnsubscribeSection.tsx index b3d1260a9..e8129f96d 100644 --- a/apps/web/app/(app)/bulk-unsubscribe/BulkUnsubscribeSection.tsx +++ b/apps/web/app/(app)/bulk-unsubscribe/BulkUnsubscribeSection.tsx @@ -257,11 +257,14 @@ export function BulkUnsubscribeSection({ )} - setOpenedNewsletter(undefined)} - refreshInterval={refreshInterval} - /> + {openedNewsletter && ( + setOpenedNewsletter(undefined)} + refreshInterval={props.refreshInterval} + mutate={mutate} + /> + )} ); diff --git a/apps/web/app/(app)/cold-email-blocker/ColdEmailList.tsx b/apps/web/app/(app)/cold-email-blocker/ColdEmailList.tsx index fe108dca5..337fa297c 100644 --- a/apps/web/app/(app)/cold-email-blocker/ColdEmailList.tsx +++ b/apps/web/app/(app)/cold-email-blocker/ColdEmailList.tsx @@ -144,12 +144,13 @@ export function ColdEmailList() { - setOpenedRow(undefined)} - /> + {openedRow && ( + setOpenedRow(undefined)} + mutate={mutate} + /> + )} ) : ( diff --git a/apps/web/app/(app)/cold-email-blocker/ColdEmailRejected.tsx b/apps/web/app/(app)/cold-email-blocker/ColdEmailRejected.tsx index 35cc4782a..6d595b6a9 100644 --- a/apps/web/app/(app)/cold-email-blocker/ColdEmailRejected.tsx +++ b/apps/web/app/(app)/cold-email-blocker/ColdEmailRejected.tsx @@ -65,12 +65,12 @@ export function ColdEmailRejected() { - setOpenedRow(undefined)} - /> + {openedRow && ( + setOpenedRow(undefined)} + /> + )} ) : ( diff --git a/apps/web/app/(app)/compose/selectors/color-selector.tsx b/apps/web/app/(app)/compose/selectors/color-selector.tsx index 12ef2e47c..e66c4473b 100644 --- a/apps/web/app/(app)/compose/selectors/color-selector.tsx +++ b/apps/web/app/(app)/compose/selectors/color-selector.tsx @@ -132,7 +132,7 @@ export const ColorSelector = ({ open, onOpenChange }: any) => {
diff --git a/apps/web/app/(app)/compose/selectors/link-selector.tsx b/apps/web/app/(app)/compose/selectors/link-selector.tsx index eb3b4a1fe..b01bfc3ba 100644 --- a/apps/web/app/(app)/compose/selectors/link-selector.tsx +++ b/apps/web/app/(app)/compose/selectors/link-selector.tsx @@ -65,7 +65,7 @@ export const LinkSelector = ({ open, onOpenChange }: LinkSelectorProps) => { const url = getUrlFromString(input.value); url && editor.chain().focus().setLink({ href: url }).run(); }} - className="flex p-1 " + className="flex p-1" > {extra}
- setOpenedNewsletter(undefined)} - refreshInterval={refreshInterval} - /> + {openedNewsletter && ( + setOpenedNewsletter(undefined)} + refreshInterval={refreshInterval} + mutate={mutate} + /> + )} ); diff --git a/apps/web/app/(app)/stats/NewsletterModal.tsx b/apps/web/app/(app)/stats/NewsletterModal.tsx index be3d50ed4..c4cb0962a 100644 --- a/apps/web/app/(app)/stats/NewsletterModal.tsx +++ b/apps/web/app/(app)/stats/NewsletterModal.tsx @@ -1,50 +1,64 @@ -import useSWR from "swr"; -import { BarChart } from "@tremor/react"; -import type { DateRange } from "react-day-picker"; -import Link from "next/link"; -import { ExternalLinkIcon } from "lucide-react"; -import { useSession } from "next-auth/react"; -import { - Dialog, - DialogContent, - DialogHeader, - DialogTitle, -} from "@/components/ui/dialog"; +import { MoreDropdown } from "@/app/(app)/bulk-unsubscribe/common"; +import { useUnsubscribe } from "@/app/(app)/bulk-unsubscribe/hooks"; +import { Row } from "@/app/(app)/bulk-unsubscribe/types"; import { getDateRangeParams } from "@/app/(app)/stats/params"; +import type { ThreadsResponse } from "@/app/api/google/threads/controller"; import type { SenderEmailsQuery, SenderEmailsResponse, } from "@/app/api/user/stats/sender-emails/route"; -import type { ZodPeriod } from "@inboxzero/tinybird"; +import { AlertBasic } from "@/components/Alert"; import { LoadingContent } from "@/components/LoadingContent"; +import { usePremium } from "@/components/PremiumAlert"; +import { Tooltip } from "@/components/Tooltip"; 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 { 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 { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { useLabels } from "@/hooks/useLabels"; -import type { Row } from "@/app/(app)/bulk-unsubscribe/types"; +import { onAutoArchive } from "@/utils/actions/client"; +import { getGmailFilterSettingsUrl } from "@/utils/url"; +import type { ZodPeriod } from "@inboxzero/tinybird"; +import { BarChart } from "@tremor/react"; +import { ExternalLinkIcon } from "lucide-react"; +import { useSession } from "next-auth/react"; +import Link from "next/link"; import { usePostHog } from "posthog-js/react"; +import type { DateRange } from "react-day-picker"; +import useSWR from "swr"; 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 } = useUnsubscribe({ + item: newsletter, + hasUnsubscribeAccess, + mutate, + posthog, + refetchPremium, + }); + return ( @@ -55,13 +69,21 @@ export function NewsletterModal(props: { + ) : ( + Unsubscribe + )}