From 6248a9ae365094d2eea32a5ac76e5e3c744d4481 Mon Sep 17 00:00:00 2001 From: Jared White Date: Thu, 9 Jan 2025 20:30:10 -0800 Subject: [PATCH] fix: don't show lottery dates when open waitlist is selected (#4522) * fix: don't show lottery dates when open waitlist is selected * feat: make selection logic more clear * fix: improved events filtering logic * fix: lottery opt in should be null if not lottery type --- .../sections/RankingsAndResults.tsx | 6 +++++- .../listings/AdditionalMetadataFormatter.ts | 6 ------ .../src/lib/listings/BooleansFormatter.ts | 18 ++++++++++++++---- .../src/lib/listings/EventsFormatter.ts | 5 +++-- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/sites/partners/src/components/listings/PaperListingForm/sections/RankingsAndResults.tsx b/sites/partners/src/components/listings/PaperListingForm/sections/RankingsAndResults.tsx index 005404ee91..5a50e5c524 100644 --- a/sites/partners/src/components/listings/PaperListingForm/sections/RankingsAndResults.tsx +++ b/sites/partners/src/components/listings/PaperListingForm/sections/RankingsAndResults.tsx @@ -51,6 +51,10 @@ const RankingsAndResults = ({ listing, isAdmin }: RankingsAndResultsProps) => { name: "listingAvailabilityQuestion", }) + // Ensure the lottery fields only show when it's "available units" listing + const showLotteryFields = + availabilityQuestion !== "openWaitlist" && reviewOrder === "reviewOrderLottery" + const yesNoRadioOptions = [ { label: t("t.yes"), @@ -95,7 +99,7 @@ const RankingsAndResults = ({ listing, isAdmin }: RankingsAndResultsProps) => { )} - {reviewOrder === "reviewOrderLottery" && ( + {showLotteryFields && ( <> {process.env.showLottery && ( <> diff --git a/sites/partners/src/lib/listings/AdditionalMetadataFormatter.ts b/sites/partners/src/lib/listings/AdditionalMetadataFormatter.ts index 716bbc812d..66f562525b 100644 --- a/sites/partners/src/lib/listings/AdditionalMetadataFormatter.ts +++ b/sites/partners/src/lib/listings/AdditionalMetadataFormatter.ts @@ -72,12 +72,6 @@ export default class AdditionalMetadataFormatter extends Formatter { ? ReviewOrderTypeEnum.lottery : ReviewOrderTypeEnum.firstComeFirstServe - if (this.data.reviewOrderType !== ReviewOrderTypeEnum.lottery) { - this.data.lotteryOptIn = null - } else { - if (this.data.lotteryOptIn === null) delete this.data.lotteryOptIn - } - if (this.data.listingAvailabilityQuestion === "openWaitlist") { this.data.reviewOrderType = ReviewOrderTypeEnum.waitlist } diff --git a/sites/partners/src/lib/listings/BooleansFormatter.ts b/sites/partners/src/lib/listings/BooleansFormatter.ts index 5c87128746..9e98fa1d6e 100644 --- a/sites/partners/src/lib/listings/BooleansFormatter.ts +++ b/sites/partners/src/lib/listings/BooleansFormatter.ts @@ -69,10 +69,20 @@ export default class BooleansFormatter extends Formatter { when: this.data.referralOpportunityChoice === YesNoEnum.yes, falseCase: () => (this.data.referralOpportunityChoice === YesNoEnum.no ? false : null), }) - this.processBoolean("lotteryOptIn", { - when: this.data.lotteryOptInQuestion === YesNoEnum.yes, - falseCase: () => (this.data.lotteryOptInQuestion === YesNoEnum.no ? false : null), - }) + + if ( + this.data.reviewOrderQuestion !== "reviewOrderLottery" || + this.data.listingAvailabilityQuestion === "openWaitlist" + ) { + this.data.lotteryOptIn = null + } else { + this.processBoolean("lotteryOptIn", { + when: this.data.lotteryOptInQuestion === YesNoEnum.yes, + falseCase: () => (this.data.lotteryOptInQuestion === YesNoEnum.no ? false : null), + }) + if (this.data.lotteryOptIn === null) delete this.data.lotteryOptIn + } + this.processBoolean("includeCommunityDisclaimer", { when: this.data.includeCommunityDisclaimerQuestion === YesNoEnum.yes, falseCase: () => diff --git a/sites/partners/src/lib/listings/EventsFormatter.ts b/sites/partners/src/lib/listings/EventsFormatter.ts index a0ee4bbcf5..237b271b9f 100644 --- a/sites/partners/src/lib/listings/EventsFormatter.ts +++ b/sites/partners/src/lib/listings/EventsFormatter.ts @@ -17,11 +17,12 @@ export default class EventsFormatter extends Formatter { ) ) if ( + this.data.listingAvailabilityQuestion !== "openWaitlist" && + this.data.reviewOrderQuestion === "reviewOrderLottery" && this.data.lotteryDate && this.data.lotteryDate.day && this.data.lotteryDate.month && - this.data.lotteryDate.year && - this.data.reviewOrderQuestion === "reviewOrderLottery" + this.data.lotteryDate.year ) { events.push({ type: ListingEventsTypeEnum.publicLottery,