From cd309e4bb969fe6ecd7bad93d916236171096024 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Tue, 25 Feb 2025 10:36:13 +0100 Subject: [PATCH 1/3] feat: add remove button to pub page --- .../c/[communitySlug]/pubs/[pubId]/page.tsx | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/app/c/[communitySlug]/pubs/[pubId]/page.tsx b/core/app/c/[communitySlug]/pubs/[pubId]/page.tsx index ef0dff19e..a0ebd0fff 100644 --- a/core/app/c/[communitySlug]/pubs/[pubId]/page.tsx +++ b/core/app/c/[communitySlug]/pubs/[pubId]/page.tsx @@ -15,6 +15,7 @@ import { MembersList } from "~/app/components//Memberships/MembersList"; import { PubsRunActionDropDownMenu } from "~/app/components/ActionUI/PubsRunActionDropDownMenu"; import { AddMemberDialog } from "~/app/components/Memberships/AddMemberDialog"; import { CreatePubButton } from "~/app/components/pubs/CreatePubButton"; +import { RemovePubButton } from "~/app/components/pubs/RemovePubButton"; import SkeletonTable from "~/app/components/skeletons/SkeletonTable"; import { db } from "~/kysely/database"; import { getPageLoginData } from "~/lib/authentication/loginData"; @@ -156,12 +157,20 @@ export default async function Page(props: {

{getPubTitle(pub)}

- +
+ + +
From b0debcc8f42a73cbf6e17a2953b4192fe3fc523a Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Tue, 25 Feb 2025 13:22:02 +0100 Subject: [PATCH 2/3] fix: make movebutton call exact bc remove has move in it --- core/playwright/pub.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/playwright/pub.spec.ts b/core/playwright/pub.spec.ts index de73cac98..a9a3fe958 100644 --- a/core/playwright/pub.spec.ts +++ b/core/playwright/pub.spec.ts @@ -62,7 +62,7 @@ test.describe("Moving a pub", () => { await pubDetailsPage.goTo(); await expect(page.getByTestId("current-stage")).toHaveText("Submitted"); // For this initial stage, there are only destinations ,no sources - await page.getByRole("button", { name: "Move" }).click(); + await page.getByRole("button", { name: "Move", exact: true }).click(); const sources = page.getByTestId("sources"); const destinations = page.getByTestId("destinations"); await expect(sources).toHaveCount(0); @@ -70,7 +70,7 @@ test.describe("Moving a pub", () => { await expect(page.getByTestId("current-stage")).toHaveText("Ask Author for Consent"); // Open the move modal again and expect to be able to move to sources and destinations - await page.getByRole("button", { name: "Move" }).click(); + await page.getByRole("button", { name: "Move", exact: true }).click(); await expect(sources.getByRole("button", { name: "Submitted" })).toHaveCount(1); await expect(destinations.getByRole("button", { name: "To Evaluate" })).toHaveCount(1); }); @@ -91,7 +91,7 @@ test.describe("Moving a pub", () => { const pubDetailsPage = new PubDetailsPage(page, COMMUNITY_SLUG, pubId); await pubDetailsPage.goTo(); await expect(page.getByTestId("current-stage")).toHaveText("Shelved"); - await expect(page.getByRole("button", { name: "Move" })).toHaveCount(0); + await expect(page.getByRole("button", { name: "Move", exact: true })).toHaveCount(0); }); }); From 3d96e36fabcbd333b6b51b7cd94061f31a7560d3 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Tue, 25 Feb 2025 17:58:50 +0100 Subject: [PATCH 3/3] fix: redirect after removal --- core/app/c/[communitySlug]/pubs/[pubId]/page.tsx | 2 +- core/app/components/pubs/RemovePubButton.tsx | 2 +- core/app/components/pubs/RemovePubForm.tsx | 11 +++-------- core/app/components/pubs/RemovePubFormClient.tsx | 15 ++++++++++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/app/c/[communitySlug]/pubs/[pubId]/page.tsx b/core/app/c/[communitySlug]/pubs/[pubId]/page.tsx index a0ebd0fff..7f96d2f4f 100644 --- a/core/app/c/[communitySlug]/pubs/[pubId]/page.tsx +++ b/core/app/c/[communitySlug]/pubs/[pubId]/page.tsx @@ -169,7 +169,7 @@ export default async function Page(props: { Update - +
diff --git a/core/app/components/pubs/RemovePubButton.tsx b/core/app/components/pubs/RemovePubButton.tsx index 041489836..0fe5186d7 100644 --- a/core/app/components/pubs/RemovePubButton.tsx +++ b/core/app/components/pubs/RemovePubButton.tsx @@ -1,7 +1,7 @@ import type { ButtonProps } from "ui/button"; import { Trash } from "ui/icon"; -import type { PubRemoveProps } from "./RemovePubForm"; +import type { PubRemoveProps } from "./RemovePubFormClient"; import { PathAwareDialog } from "../PathAwareDialog"; import { PubRemove } from "./RemovePubForm"; diff --git a/core/app/components/pubs/RemovePubForm.tsx b/core/app/components/pubs/RemovePubForm.tsx index 438a0d866..abbb794f6 100644 --- a/core/app/components/pubs/RemovePubForm.tsx +++ b/core/app/components/pubs/RemovePubForm.tsx @@ -1,14 +1,9 @@ import { Suspense } from "react"; import dynamic from "next/dynamic"; -import type { PubsId } from "db/public"; - +import type { PubRemoveProps } from "./RemovePubFormClient"; import { SkeletonCard } from "../skeletons/SkeletonCard"; -export type PubRemoveProps = { - pubId: PubsId; -}; - const PubRemoveForm = dynamic( async () => { return import("./RemovePubFormClient").then((mod) => ({ @@ -18,10 +13,10 @@ const PubRemoveForm = dynamic( { loading: () => } ); -export async function PubRemove({ pubId }: PubRemoveProps) { +export async function PubRemove({ pubId, redirectTo }: PubRemoveProps) { return ( Loading...}> - + ); } diff --git a/core/app/components/pubs/RemovePubFormClient.tsx b/core/app/components/pubs/RemovePubFormClient.tsx index 680adecd0..cf5431f20 100644 --- a/core/app/components/pubs/RemovePubFormClient.tsx +++ b/core/app/components/pubs/RemovePubFormClient.tsx @@ -13,7 +13,12 @@ import { toast } from "ui/use-toast"; import { useServerAction } from "~/lib/serverActions"; import * as actions from "./PubEditor/actions"; -export const PubRemoveForm = ({ pubId }: { pubId: PubsId }) => { +export type PubRemoveProps = { + pubId: PubsId; + redirectTo?: string; +}; + +export const PubRemoveForm = ({ pubId, redirectTo }: PubRemoveProps) => { const form = useForm({ mode: "onChange", reValidateMode: "onChange", @@ -32,8 +37,12 @@ export const PubRemoveForm = ({ pubId }: { pubId: PubsId }) => { }, [path, searchParams]); const closeForm = useCallback(() => { - router.replace(pathWithoutFormParam); - }, [pathWithoutFormParam]); + if (redirectTo) { + router.push(redirectTo); + } else { + router.replace(pathWithoutFormParam); + } + }, [pathWithoutFormParam, redirectTo, router]); const onSubmit = async () => { const result = await runRemovePub({