From 2fc85f36184aed6c7c30d1f214f369e8ba454af0 Mon Sep 17 00:00:00 2001 From: Emily Jablonski <65367387+emilyjablonski@users.noreply.github.com> Date: Thu, 18 Jul 2024 13:43:22 -0600 Subject: [PATCH] feat: retract modal (#4207) --- .../__tests__/pages/listings/lottery.test.tsx | 54 ++++++++++- .../locale_overrides/general.json | 3 + .../src/pages/listings/[id]/lottery.tsx | 97 ++++++++++++++++--- 3 files changed, 136 insertions(+), 18 deletions(-) diff --git a/sites/partners/__tests__/pages/listings/lottery.test.tsx b/sites/partners/__tests__/pages/listings/lottery.test.tsx index 6126643c6d..effc0c63a2 100644 --- a/sites/partners/__tests__/pages/listings/lottery.test.tsx +++ b/sites/partners/__tests__/pages/listings/lottery.test.tsx @@ -204,7 +204,9 @@ describe("lottery", () => { ) const { getByText, findByText } = render( - + ) const header = await findByText("Partners Portal") @@ -239,7 +241,9 @@ describe("lottery", () => { ) const { getByText, findByText } = render( - + ) const header = await findByText("Partners Portal") @@ -271,7 +275,9 @@ describe("lottery", () => { ) const { getByText, findByText } = render( - + ) const header = await findByText("Partners Portal") @@ -286,6 +292,48 @@ describe("lottery", () => { ).toBeInTheDocument() }) + it("should show retract modal if user clicks on retract", async () => { + mockNextRouter({ id: "Uvbk5qurpB2WI9V6WnNdH" }) + document.cookie = "access-token-available=True" + server.use( + rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => { + return res( + ctx.json({ + id: "user1", + userRoles: { isAdmin: true }, + }) + ) + }), + rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => { + return res(ctx.json("")) + }), + rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => { + return res(ctx.json({ totalCount: 0 })) + }) + ) + + const { getByText, findByText } = render( + + ) + + const header = await findByText("Partners Portal") + expect(header).toBeInTheDocument() + + fireEvent.click(getByText("Retract lottery")) + expect(await findByText("Are you sure?")).toBeInTheDocument() + expect( + getByText( + "Retracting the lottery will revoke Partner users’ access to the lottery data, including their ability to publish results to applicants." + ) + ).toBeInTheDocument() + }) + it("should show confirm modal if user clicks on run lottery with no unresolved duplicates", async () => { mockNextRouter({ id: "Uvbk5qurpB2WI9V6WnNdH" }) document.cookie = "access-token-available=True" diff --git a/sites/partners/page_content/locale_overrides/general.json b/sites/partners/page_content/locale_overrides/general.json index 878867309e..f87f29413a 100644 --- a/sites/partners/page_content/locale_overrides/general.json +++ b/sites/partners/page_content/locale_overrides/general.json @@ -245,6 +245,9 @@ "listings.lottery.reRunHistory": "Re-running a lottery will also be tracked in the history log.", "listings.lottery.reRunCannotBeUndone": "This action cannot be undone.", "listings.lottery.reRunUnderstand": "I understand, re-run lottery", + "listings.lottery.retract": "Retract lottery", + "listings.lottery.retractContent": "Retracting the lottery will revoke Partner users’ access to the lottery data, including their ability to publish results to applicants.", + "listings.lottery.retractContentRemoval": "If a lottery has already been published, it will also remove any lottery results from applicant accounts and the listing status will be marked as 'Lottery retracted'.", "listings.lottery.runLottery": "Run lottery", "listings.lottery.runLotteryContent": "Make sure to add all paper applications before running the lottery.", "listings.lottery.runLotteryDuplicates": "Run lottery without resolving duplicates", diff --git a/sites/partners/src/pages/listings/[id]/lottery.tsx b/sites/partners/src/pages/listings/[id]/lottery.tsx index 4fce5fe65f..1ef4f44efc 100644 --- a/sites/partners/src/pages/listings/[id]/lottery.tsx +++ b/sites/partners/src/pages/listings/[id]/lottery.tsx @@ -37,6 +37,7 @@ const Lottery = (props: { listing: Listing }) => { const [releaseModal, setReleaseModal] = useState(false) const [exportModal, setExportModal] = useState(false) const [publishModal, setPublishModal] = useState(false) + const [retractModal, setRetractModal] = useState(false) const [loading, setLoading] = useState(false) const { listingsService, profile } = useContext(AuthContext) @@ -170,23 +171,39 @@ const Lottery = (props: { listing: Listing }) => { } const getActions = () => { - if (listing.lotteryLastRunAt && profile?.userRoles?.isAdmin) { + if (profile?.userRoles?.isAdmin) { return (
- - + <> + {listing.lotteryStatus === LotteryStatusEnum.ran && ( + <> + + + + )} + {(listing.lotteryStatus === LotteryStatusEnum.releasedToPartners || + listing.lotteryStatus === LotteryStatusEnum.publishedToPublic) && ( + + )} +
) } @@ -428,6 +445,56 @@ const Lottery = (props: { listing: Listing }) => { + setRetractModal(false)} + > + {t("t.areYouSure")} + +

+ {t("listings.lottery.retractContent")}{" "} + + {t("listings.lottery.retractContentRemoval")} + +

+

{t("applications.addConfirmModalAddApplicationPostLotteryAreYouSure")}

+
+ + + + +