diff --git a/actions/publications/membershipSettings.ts b/actions/publications/membershipSettings.ts index ce4e692c..717ed591 100644 --- a/actions/publications/membershipSettings.ts +++ b/actions/publications/membershipSettings.ts @@ -2,6 +2,7 @@ import { getAuthIdentity } from "src/auth"; import { supabaseServerClient } from "supabase/serverClient"; +import { revalidatePublicationSettingsPaths } from "src/utils/revalidatePublication"; import { getStripe } from "stripe/client"; import { Ok, Err, type Result } from "src/result"; @@ -57,6 +58,7 @@ export async function enableMemberships( console.error("[membershipSettings] enable upsert failed:", error); return Err("database_error"); } + await revalidatePublicationSettingsPaths(publicationUri); return Ok(null); } @@ -264,6 +266,7 @@ export async function upsertMembershipTier( console.error("[membershipSettings] price archive failed:", e), ); } + await revalidatePublicationSettingsPaths(publicationUri); return Ok({ id: rowId }); } @@ -318,5 +321,6 @@ export async function deleteMembershipTier( console.error("[membershipSettings] tier delete failed:", error); return Err("database_error"); } + await revalidatePublicationSettingsPaths(publicationUri); return Ok(null); } diff --git a/actions/publications/newsletterSettings.tsx b/actions/publications/newsletterSettings.tsx index 033ce0b8..2643104e 100644 --- a/actions/publications/newsletterSettings.tsx +++ b/actions/publications/newsletterSettings.tsx @@ -2,6 +2,7 @@ import { getAuthIdentity } from "src/auth"; import { supabaseServerClient } from "supabase/serverClient"; +import { revalidatePublicationSettingsPaths } from "src/utils/revalidatePublication"; import { LeafletConfirmEmail } from "emails/leafletConfirmEmail"; import { Ok, Err, type Result } from "src/result"; import { @@ -58,6 +59,7 @@ export async function enableNewsletter( console.error("[newsletterSettings] enable upsert failed:", error); return Err("database_error"); } + await revalidatePublicationSettingsPaths(publicationUri); return Ok(null); } @@ -78,6 +80,7 @@ export async function disableNewsletter( console.error("[newsletterSettings] disable update failed:", error); return Err("database_error"); } + await revalidatePublicationSettingsPaths(publicationUri); return Ok(null); } diff --git a/src/utils/revalidatePublication.ts b/src/utils/revalidatePublication.ts index 03ee2f15..91be9fed 100644 --- a/src/utils/revalidatePublication.ts +++ b/src/utils/revalidatePublication.ts @@ -135,6 +135,22 @@ export async function revalidateDocumentPaths( revalidatePath(`/p/${docUri.host}/${docUri.rkey}`); } +// For settings stored outside the publication record (newsletter, membership +// tiers): cached publication and post pages render them (subscribe UI, the +// members-only gate's tier list), so their mutations must drop the same +// paths. The record isn't at hand in those actions, so resolve the name here +// for the legacy name-form URLs. +export async function revalidatePublicationSettingsPaths(pubUri: string) { + const { data } = await supabaseServerClient + .from("publications") + .select("record") + .eq("uri", pubUri) + .single(); + await revalidateAllPublicationPaths(pubUri, [ + normalizePublicationRecord(data?.record)?.name, + ]); +} + // For changes that touch every page of a publication (theme, name, base // path): enumerate the publication's published pages and post URLs and drop // them all. `names` should carry both the old and new name on a rename so