Skip to content

Commit

Permalink
feat: retract modal (#4207)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyjablonski authored Jul 18, 2024
1 parent c75fc3d commit 2fc85f3
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 18 deletions.
54 changes: 51 additions & 3 deletions sites/partners/__tests__/pages/listings/lottery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ describe("lottery", () => {
)

const { getByText, findByText } = render(
<Lottery listing={{ ...listing, lotteryLastRunAt: new Date() }} />
<Lottery
listing={{ ...listing, lotteryLastRunAt: new Date(), lotteryStatus: LotteryStatusEnum.ran }}
/>
)

const header = await findByText("Partners Portal")
Expand Down Expand Up @@ -239,7 +241,9 @@ describe("lottery", () => {
)

const { getByText, findByText } = render(
<Lottery listing={{ ...listing, lotteryLastRunAt: new Date() }} />
<Lottery
listing={{ ...listing, lotteryLastRunAt: new Date(), lotteryStatus: LotteryStatusEnum.ran }}
/>
)

const header = await findByText("Partners Portal")
Expand Down Expand Up @@ -271,7 +275,9 @@ describe("lottery", () => {
)

const { getByText, findByText } = render(
<Lottery listing={{ ...listing, lotteryLastRunAt: new Date() }} />
<Lottery
listing={{ ...listing, lotteryLastRunAt: new Date(), lotteryStatus: LotteryStatusEnum.ran }}
/>
)

const header = await findByText("Partners Portal")
Expand All @@ -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(
<Lottery
listing={{
...listing,
lotteryLastRunAt: new Date(),
lotteryStatus: LotteryStatusEnum.releasedToPartners,
}}
/>
)

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"
Expand Down
3 changes: 3 additions & 0 deletions sites/partners/page_content/locale_overrides/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
97 changes: 82 additions & 15 deletions sites/partners/src/pages/listings/[id]/lottery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -170,23 +171,39 @@ const Lottery = (props: { listing: Listing }) => {
}

const getActions = () => {
if (listing.lotteryLastRunAt && profile?.userRoles?.isAdmin) {
if (profile?.userRoles?.isAdmin) {
return (
<div className={styles["actions-container"]}>
<Button
className={styles["action"]}
onClick={() => setReRunModal(true)}
variant={"primary-outlined"}
>
{t("listings.lottery.reRun")}
</Button>
<Button
className={styles["action"]}
onClick={() => setReleaseModal(true)}
variant={"primary-outlined"}
>
{t("listings.lottery.release")}
</Button>
<>
{listing.lotteryStatus === LotteryStatusEnum.ran && (
<>
<Button
className={styles["action"]}
onClick={() => setReRunModal(true)}
variant={"primary-outlined"}
>
{t("listings.lottery.reRun")}
</Button>
<Button
className={styles["action"]}
onClick={() => setReleaseModal(true)}
variant={"primary-outlined"}
>
{t("listings.lottery.release")}
</Button>
</>
)}
{(listing.lotteryStatus === LotteryStatusEnum.releasedToPartners ||
listing.lotteryStatus === LotteryStatusEnum.publishedToPublic) && (
<Button
className={styles["action"]}
onClick={() => setRetractModal(true)}
variant={"alert-outlined"}
>
{t("listings.lottery.retract")}
</Button>
)}
</>
</div>
)
}
Expand Down Expand Up @@ -428,6 +445,56 @@ const Lottery = (props: { listing: Listing }) => {
</Button>
</Dialog.Footer>
</Dialog>
<Dialog
isOpen={!!retractModal}
ariaLabelledBy="retract-lottery-modal-header"
ariaDescribedBy="retract-lottery-modal-content"
onClose={() => setRetractModal(false)}
>
<Dialog.Header id="retract-lottery-modal-header">{t("t.areYouSure")}</Dialog.Header>
<Dialog.Content id="retract-lottery-modal-content">
<p>
{t("listings.lottery.retractContent")}{" "}
<span className={"font-semibold"}>
{t("listings.lottery.retractContentRemoval")}
</span>
</p>
<p>{t("applications.addConfirmModalAddApplicationPostLotteryAreYouSure")}</p>
</Dialog.Content>
<Dialog.Footer>
<Button
variant="alert"
onClick={async () => {
setLoading(true)
try {
await listingsService.lotteryStatus({
body: {
listingId: listing.id,
lotteryStatus: LotteryStatusEnum.ran,
},
})
location.reload()
} catch (err) {
console.log(err)
setLoading(false)
}
}}
loadingMessage={loading ? t("t.loading") : null}
size="sm"
>
{t("listings.lottery.retract")}
</Button>
<Button
variant="primary-outlined"
onClick={() => {
setRetractModal(false)
}}
size="sm"
>
{t("t.cancel")}
</Button>
</Dialog.Footer>
</Dialog>
<Dialog
isOpen={!!exportModal}
ariaLabelledBy="export-lottery-modal-header"
Expand Down

0 comments on commit 2fc85f3

Please sign in to comment.