From bb24dfcca8d0f05a466bb3b754801257d3c487c8 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Wed, 15 Apr 2026 22:50:53 -0400 Subject: [PATCH] redirect to home and simplify delete function --- .../dashboard/settings/SettingsContent.tsx | 119 +++++++----------- .../dashboard/settings/deletePublication.ts | 41 ++---- components/Modal.tsx | 2 +- 3 files changed, 57 insertions(+), 105 deletions(-) diff --git a/app/lish/[did]/[publication]/dashboard/settings/SettingsContent.tsx b/app/lish/[did]/[publication]/dashboard/settings/SettingsContent.tsx index 4b15aa8c..f64bb893 100644 --- a/app/lish/[did]/[publication]/dashboard/settings/SettingsContent.tsx +++ b/app/lish/[did]/[publication]/dashboard/settings/SettingsContent.tsx @@ -21,7 +21,7 @@ import { InlineUpgradeToPro, UpgradeToProButton } from "../../UpgradeModal"; import { Modal } from "components/Modal"; import { Input } from "components/Input"; import { deletePublication } from "./deletePublication"; -import Link from "next/link"; +import { useRouter } from "next/navigation"; import { isOAuthSessionError, OAuthErrorMessage, @@ -286,16 +286,15 @@ let pluralize = (n: number, word: string) => `${n} ${word}${n === 1 ? "" : "s"}`; const DeletePublication = () => { - let [open, setOpen] = useState(false); let [value, setValue] = useState(""); let [deleting, setDeleting] = useState(false); - let [deleted, setDeleted] = useState(false); let record = useNormalizedPublicationRecord(); let { data: pub } = usePublicationData(); let postCount = pub?.documents?.length ?? 0; let draftCount = pub?.drafts?.length ?? 0; let subCount = pub?.publication?.publication_subscriptions?.length ?? 0; let toaster = useToaster(); + let router = useRouter(); let pubUri = pub?.publication?.uri; let onDelete = async () => { @@ -308,90 +307,68 @@ const DeletePublication = () => { type: "error", content: isOAuthSessionError(result.error) ? ( + ) : typeof result.error === "string" ? ( + result.error ) : ( - typeof result.error === "string" - ? result.error - : "Failed to delete publication" + "Failed to delete publication" ), }); return; } - setDeleting(false); - setDeleted(true); + toaster({ + type: "success", + content: `${record?.name ?? "Publication"} deleted`, + }); + router.push("/home"); }; return ( { - // Once deleted, the underlying page is stale — keep the modal open - // so the only way out is the "back to home" link. - if (deleted && !next) return; - setOpen(next); - if (!next) { - setValue(""); - } - }} trigger={Delete Publication} - title={deleted ? "Publication deleted" : "Are you sure?"} + title="Are you sure?" > - {deleted ? ( -
-
- {record?.name} and - all its posts, drafts, and associated records have been deleted. -
- - Back to home → - -
- ) : ( -
-
- This will permanently delete: -
    -
  • This publication and its settings
  • -
  • - {pluralize(postCount, "published post")} - {postCount > 0 ? " (removed from your PDS)" : ""} -
  • -
  • {pluralize(draftCount, "draft")}
  • -
  • All associated records on your PDS
  • -
- {subCount > 0 && ( -
- {pluralize(subCount, "subscriber")} will lose access. -
- )} -
- This cannot be undone. +
+
+ This will permanently delete: +
    +
  • This publication and its settings
  • +
  • + {pluralize(postCount, "published post")} + {postCount > 0 ? " (removed from your PDS)" : ""} +
  • +
  • {pluralize(draftCount, "draft")}
  • +
  • All associated records on your PDS
  • +
+ {subCount > 0 && ( +
+ {pluralize(subCount, "subscriber")} will lose access.
+ )} +
+ This cannot be undone.
-
- Enter the name of this publication to confirm -
- - setValue(e.currentTarget.value)} - /> - - {deleting ? : "Delete Publication"} -
- )} +
+ Enter the name of this publication to confirm +
+ + setValue(e.currentTarget.value)} + /> + + {deleting ? : "Delete Publication"} + +
); }; diff --git a/app/lish/[did]/[publication]/dashboard/settings/deletePublication.ts b/app/lish/[did]/[publication]/dashboard/settings/deletePublication.ts index 90547613..9a1af465 100644 --- a/app/lish/[did]/[publication]/dashboard/settings/deletePublication.ts +++ b/app/lish/[did]/[publication]/dashboard/settings/deletePublication.ts @@ -2,10 +2,7 @@ import { AtpBaseClient } from "lexicons/api"; import { getIdentityData } from "actions/getIdentityData"; -import { - restoreOAuthSession, - OAuthSessionError, -} from "src/atproto-oauth"; +import { restoreOAuthSession, OAuthSessionError } from "src/atproto-oauth"; import { AtUri } from "@atproto/syntax"; import { supabaseServerClient } from "supabase/serverClient"; import { drizzle } from "drizzle-orm/node-postgres"; @@ -43,25 +40,18 @@ export async function deletePublication( ); // Collect these BEFORE deleting the publication row — cascading deletes would remove the join rows. - let [legacyDocs, siteDocs, drafts] = await Promise.all([ + let [docs, drafts] = await Promise.all([ supabaseServerClient .from("documents_in_publications") .select("document") .eq("publication", publication_uri), - supabaseServerClient - .from("site_standard_documents_in_publications") - .select("document") - .eq("publication", publication_uri), supabaseServerClient .from("leaflets_in_publications") .select("leaflet") .eq("publication", publication_uri), ]); let documentUris = Array.from( - new Set([ - ...(legacyDocs.data ?? []).map((r) => r.document), - ...(siteDocs.data ?? []).map((r) => r.document), - ]), + new Set([...(docs.data ?? []).map((r) => r.document)]), ); let draftTokenIds = (drafts.data ?? []).map((r) => r.leaflet); @@ -119,27 +109,12 @@ export async function deletePublication( // Delete document rows before publication rows — publication cascade would leave orphaned docs. if (documentUris.length > 0) { - await Promise.all([ - supabaseServerClient - .from("documents") - .delete() - .in("uri", documentUris), - supabaseServerClient - .from("site_standard_documents") - .delete() - .in("uri", documentUris), - ]); + supabaseServerClient.from("documents").delete().in("uri", documentUris); } - await Promise.all([ - supabaseServerClient - .from("publications") - .delete() - .eq("uri", publication_uri), - supabaseServerClient - .from("site_standard_publications") - .delete() - .eq("uri", publication_uri), - ]); + await supabaseServerClient + .from("publications") + .delete() + .eq("uri", publication_uri); revalidatePath("/lish/[did]/[publication]", "layout"); return { success: true }; diff --git a/components/Modal.tsx b/components/Modal.tsx index 625150f8..ff108f8a 100644 --- a/components/Modal.tsx +++ b/components/Modal.tsx @@ -41,7 +41,7 @@ export const Modal = ({ ${className}`} > {title ? ( - +

{title}

) : ( -- 2.51.2