From 49060b1104a7bf8edcc569766414fd81db271429 Mon Sep 17 00:00:00 2001 From: Arttu Hanska Date: Sun, 25 Aug 2024 13:12:11 +0300 Subject: [PATCH] Rename algorithm to lottery (#1033) --- client/src/locales/en.ts | 10 ++--- client/src/locales/fi.ts | 10 ++--- .../components/SignupStrategySelector.tsx | 6 +-- .../components/LotterySignupProgramItem.tsx | 8 ++-- .../components/SignupHelpText.tsx | 38 +++++++++---------- playwright/tests/lotterySignup.spec.ts | 2 +- .../features/program-item/programItemUtils.ts | 8 ++-- .../results/resultsRepository.test.ts | 3 +- .../settings/settingsController.test.ts | 2 +- shared/config/eventConfig.ts | 2 +- shared/config/eventConfigTypes.ts | 6 +-- shared/config/past-events/hitpoint2023.ts | 2 +- shared/config/past-events/ropecon2023.ts | 2 +- shared/config/past-events/ropecon2024.ts | 2 +- shared/config/past-events/solmukohta2024.ts | 2 +- shared/config/serverConfig.ts | 2 +- shared/utils/signupTimes.test.ts | 28 +++++++------- shared/utils/signupTimes.ts | 6 +-- shared/utils/tooEarlyForLotterySignup.ts | 22 +++++++++++ shared/utils/tooEearlyForAlgorithmSignup.ts | 22 ----------- 20 files changed, 92 insertions(+), 91 deletions(-) create mode 100644 shared/utils/tooEarlyForLotterySignup.ts delete mode 100644 shared/utils/tooEearlyForAlgorithmSignup.ts diff --git a/client/src/locales/en.ts b/client/src/locales/en.ts index db6dd602b..6fee7dac0 100644 --- a/client/src/locales/en.ts +++ b/client/src/locales/en.ts @@ -338,11 +338,11 @@ export const translationEN = { "Participants are selected in the order of sign-ups. Sign-up opens ", directSignupOpenNow: "Participants are selected in the order of sign-ups. Sign-up closes ", - algorithmSignupStartsLater: + lotterySignupStartsLater: "Participants are selected in a lottery. Lotter sign-up open ", - algorithmSignupOpen: + lotterySignupOpen: "Participants are selected in a lottery. Lottery sign-up closes ", - algorithmSignupEnded: "Participants were selected in a lottery.", + lotterySignupEnded: "Participants were selected in a lottery.", directSignupStarts: " Direct sign-up to remaining and cancelled spots: ", }, }, @@ -492,8 +492,8 @@ export const translationEN = { }, strategies: { direct: "Direct", - algorithm: "Algorithm", - "algorithm+direct": "Algorithm + Direct", + lottery: "Lottery", + "lottery+direct": "Lottery + Direct", }, loginProvider: { local: "Local", diff --git a/client/src/locales/fi.ts b/client/src/locales/fi.ts index 16a882f9d..48b0efebc 100644 --- a/client/src/locales/fi.ts +++ b/client/src/locales/fi.ts @@ -339,11 +339,11 @@ export const translationFI = { "Osallistujat valitaan ilmoittautumisjärjestyksessä. Ilmoittautuminen alkaa: ", directSignupOpenNow: "Osallistujat valitaan ilmoittautumisjärjestyksessä. Ilmoittautuminen sulkeutuu: ", - algorithmSignupStartsLater: + lotterySignupStartsLater: "Osallistujat valitaan arvonnalla. Arvontaan ilmoittautuminen: ", - algorithmSignupOpen: + lotterySignupOpen: "Osallistujat valitaan arvonnalla. Arvontaan ilmoittautuminen päättyy: ", - algorithmSignupEnded: "Osallistujat valittiin arvonnalla.", + lotterySignupEnded: "Osallistujat valittiin arvonnalla.", directSignupStarts: " Suora ilmoittautuminen jäljelle jääneisiin ja peruutuspaikkoihin: ", }, @@ -494,8 +494,8 @@ export const translationFI = { }, strategies: { direct: "Suora", - algorithm: "Algoritmi", - "algorithm+direct": "Algoritmi + Suora", + lottery: "Arvonta", + "lottery+direct": "Arvonta + Suora", }, loginProvider: { local: "Lokaali", diff --git a/client/src/views/admin/components/SignupStrategySelector.tsx b/client/src/views/admin/components/SignupStrategySelector.tsx index b0080e168..ee0c3ea3c 100644 --- a/client/src/views/admin/components/SignupStrategySelector.tsx +++ b/client/src/views/admin/components/SignupStrategySelector.tsx @@ -13,10 +13,10 @@ export const SignupStrategySelector = (): ReactElement => { const strategies = [ { value: SignupStrategy.DIRECT, title: t("strategies.direct") }, - { value: SignupStrategy.ALGORITHM, title: t("strategies.algorithm") }, + { value: SignupStrategy.LOTTERY, title: t("strategies.lottery") }, { - value: SignupStrategy.ALGORITHM_AND_DIRECT, - title: t("strategies.algorithm+direct"), + value: SignupStrategy.LOTTERY_AND_DIRECT, + title: t("strategies.lottery+direct"), }, ]; diff --git a/client/src/views/all-program-items/components/LotterySignupProgramItem.tsx b/client/src/views/all-program-items/components/LotterySignupProgramItem.tsx index 2d26f6a70..4503de3c3 100644 --- a/client/src/views/all-program-items/components/LotterySignupProgramItem.tsx +++ b/client/src/views/all-program-items/components/LotterySignupProgramItem.tsx @@ -17,7 +17,7 @@ import { CancelSignupForm } from "client/views/all-program-items/components/Canc import { getTimeNow } from "client/utils/getTimeNow"; import { config } from "shared/config"; import { SignupStrategy } from "shared/config/eventConfigTypes"; -import { getAlgorithmSignupStartTime } from "shared/utils/signupTimes"; +import { getLotterySignupStartTime } from "shared/utils/signupTimes"; import { getIsInGroup } from "client/views/group/groupUtils"; import { InfoText } from "client/components/InfoText"; @@ -96,12 +96,12 @@ export const LotterySignupProgramItem = ({ lotterySignups, ); - const algorithmSignupStartTime = getAlgorithmSignupStartTime(startTime); + const lotterySignupStartTime = getLotterySignupStartTime(startTime); const timeNow = getTimeNow(); const lotterySignupOpen = - timeNow.isSameOrAfter(algorithmSignupStartTime) || - config.event().manualSignupMode === SignupStrategy.ALGORITHM; + timeNow.isSameOrAfter(lotterySignupStartTime) || + config.event().manualSignupMode === SignupStrategy.LOTTERY; if (!loggedIn) { return ( diff --git a/client/src/views/all-program-items/components/SignupHelpText.tsx b/client/src/views/all-program-items/components/SignupHelpText.tsx index ae820ca29..1255a4fc1 100644 --- a/client/src/views/all-program-items/components/SignupHelpText.tsx +++ b/client/src/views/all-program-items/components/SignupHelpText.tsx @@ -6,8 +6,8 @@ import { ProgramItem, SignupType } from "shared/types/models/programItem"; import { getTimeNow } from "client/utils/getTimeNow"; import { isRevolvingDoorWorkshop } from "client/utils/isRevolvingDoorWorkshop"; import { - getAlgorithmSignupEndTime, - getAlgorithmSignupStartTime, + getLotterySignupEndTime, + getLotterySignupStartTime, getDirectSignupStartTime, } from "shared/utils/signupTimes"; import { @@ -15,7 +15,7 @@ import { getFormattedInterval, } from "client/views/all-program-items/components/allProgramItemsUtils"; import { config } from "shared/config"; -import { tooEearlyForAlgorithmSignup } from "shared/utils/tooEearlyForAlgorithmSignup"; +import { tooEarlyForLotterySignup } from "shared/utils/tooEarlyForLotterySignup"; interface Props { programItem: ProgramItem; @@ -34,18 +34,18 @@ export const SignupHelpText = ({ }: Props): ReactElement => { const { t } = useTranslation(); - const isAlgorithmSignup = + const isLotterySignup = config .event() .twoPhaseSignupProgramTypes.includes(programItem.programType) && - !tooEearlyForAlgorithmSignup(startTime); + !tooEarlyForLotterySignup(startTime); const timeNow = getTimeNow(); const programStartTime = dayjs(programItem.startTime); const directSignupStartTime = getDirectSignupStartTime(programItem); const directSignupStarted = timeNow.isSameOrAfter(directSignupStartTime); - const algorithmSignupStartTime = getAlgorithmSignupStartTime(startTime); - const algorithmSignupEndTime = getAlgorithmSignupEndTime(startTime); + const lotterySignupStartTime = getLotterySignupStartTime(startTime); + const lotterySignupEndTime = getLotterySignupEndTime(startTime); if ( programItem.signupType === SignupType.NONE || @@ -88,7 +88,7 @@ export const SignupHelpText = ({ ); } - if (!isAlgorithmSignup) { + if (!isLotterySignup) { if (!directSignupStarted) { return (

@@ -107,17 +107,17 @@ export const SignupHelpText = ({ ); } - // Algorithm sign-up - if (algorithmSignupStartTime.isSameOrAfter(timeNow)) { + // Lottery sign-up + if (lotterySignupStartTime.isSameOrAfter(timeNow)) { // Waiting for sign up to start return (

{" "} - {t("signup.help.algorithmSignupStartsLater")} + {t("signup.help.lotterySignupStartsLater")} {getFormattedInterval( - algorithmSignupStartTime, - algorithmSignupEndTime, + lotterySignupStartTime, + lotterySignupEndTime, timeNow, )} @@ -133,15 +133,15 @@ export const SignupHelpText = ({

); } else if ( - algorithmSignupEndTime.isSameOrAfter(timeNow) && + lotterySignupEndTime.isSameOrAfter(timeNow) && !directSignupStarted ) { - // Algorithm sign-up happening now + // Lottery sign-up happening now return (

{" "} - {t("signup.help.algorithmSignupOpen")} - {getFormattedTime(algorithmSignupEndTime, timeNow)}. + {t("signup.help.lotterySignupOpen")} + {getFormattedTime(lotterySignupEndTime, timeNow)}. {t("signup.help.directSignupStarts")} {getFormattedInterval( @@ -155,10 +155,10 @@ export const SignupHelpText = ({ ); } return ( - // Algorithm sign-up ended, direct sign-up starting or started + // Lottery sign-up ended, direct sign-up starting or started

{" "} - {t("signup.help.algorithmSignupEnded")} + {t("signup.help.lotterySignupEnded")} {t("signup.help.directSignupStarts")} {getFormattedInterval(directSignupStartTime, programStartTime, timeNow)} diff --git a/playwright/tests/lotterySignup.spec.ts b/playwright/tests/lotterySignup.spec.ts index e022ef351..5d1b05bb5 100644 --- a/playwright/tests/lotterySignup.spec.ts +++ b/playwright/tests/lotterySignup.spec.ts @@ -12,7 +12,7 @@ import { config } from "shared/config"; test("Add lottery signup", async ({ page, request }) => { logTestStart("Add lottery signup"); await populateDb(request); - await postSettings(request, { signupStrategy: SignupStrategy.ALGORITHM }); + await postSettings(request, { signupStrategy: SignupStrategy.LOTTERY }); await postTestSettings(request, { testTime: config.event().eventStartTime, }); diff --git a/server/src/features/program-item/programItemUtils.ts b/server/src/features/program-item/programItemUtils.ts index 365c56be8..812c92989 100644 --- a/server/src/features/program-item/programItemUtils.ts +++ b/server/src/features/program-item/programItemUtils.ts @@ -29,7 +29,7 @@ import { unwrapResult, } from "shared/utils/result"; import { MongoDbError } from "shared/types/api/errors"; -import { tooEearlyForAlgorithmSignup } from "shared/utils/tooEearlyForAlgorithmSignup"; +import { tooEarlyForLotterySignup } from "shared/utils/tooEarlyForLotterySignup"; import { UserGroup } from "shared/types/models/user"; export const removeDeletedProgramItems = async ( @@ -136,7 +136,7 @@ const getSignupStrategyForProgramItem = ( const start = dayjs(programItem.startTime); const { directSignupPhaseStart, twoPhaseSignupProgramTypes } = config.event(); - if (settings.signupStrategy !== SignupStrategy.ALGORITHM_AND_DIRECT) { + if (settings.signupStrategy !== SignupStrategy.LOTTERY_AND_DIRECT) { return settings.signupStrategy; } @@ -144,7 +144,7 @@ const getSignupStrategyForProgramItem = ( return SignupStrategy.DIRECT; } - if (tooEearlyForAlgorithmSignup(programItem.startTime)) { + if (tooEarlyForLotterySignup(programItem.startTime)) { return SignupStrategy.DIRECT; } @@ -155,7 +155,7 @@ const getSignupStrategyForProgramItem = ( return SignupStrategy.DIRECT; } - return SignupStrategy.ALGORITHM; + return SignupStrategy.LOTTERY; }; const getDirectSignupsForProgramItem = ( diff --git a/server/src/features/results/resultsRepository.test.ts b/server/src/features/results/resultsRepository.test.ts index 98acadd68..79747a7eb 100644 --- a/server/src/features/results/resultsRepository.test.ts +++ b/server/src/features/results/resultsRepository.test.ts @@ -4,6 +4,7 @@ import { faker } from "@faker-js/faker"; import { ResultsModel } from "server/features/results/resultsSchema"; import { UserAssignmentResult } from "shared/types/models/result"; import { saveResult } from "server/features/results/resultsRepository"; +import { AssignmentStrategy } from "shared/config/eventConfigTypes"; beforeEach(async () => { await mongoose.connect(globalThis.__MONGO_URI__, { @@ -18,7 +19,7 @@ afterEach(async () => { test("should insert new result into collection", async () => { const signupResultData: UserAssignmentResult[] = []; const startTime = "2019-07-26T14:00:00.000Z"; - const algorithm = "group"; + const algorithm = AssignmentStrategy.PADG; const message = "Test assign result message"; await saveResult(signupResultData, startTime, algorithm, message); diff --git a/server/src/features/settings/settingsController.test.ts b/server/src/features/settings/settingsController.test.ts index d897aa4a2..20614dd42 100644 --- a/server/src/features/settings/settingsController.test.ts +++ b/server/src/features/settings/settingsController.test.ts @@ -99,7 +99,7 @@ describe(`POST ${ApiEndpoint.SETTINGS}`, () => { hiddenProgramItems: [], appOpen: true, signupQuestions: [testSignupQuestion], - signupStrategy: SignupStrategy.ALGORITHM, + signupStrategy: SignupStrategy.LOTTERY, programUpdateLastRun: "2023-05-07T07:00:00.000Z", assignmentLastRun: "2023-05-07T07:00:00.000Z", latestServerStartTime: "2023-05-07T07:00:00.000Z", diff --git a/shared/config/eventConfig.ts b/shared/config/eventConfig.ts index ad96fef15..70a801d60 100644 --- a/shared/config/eventConfig.ts +++ b/shared/config/eventConfig.ts @@ -35,7 +35,7 @@ export const eventConfig: EventConfig = { hideParticipantListProgramTypes: [ProgramType.FLEAMARKET], - // These program items have their signup always open even if signup mode is set to algorithm + // These program items have their signup always open even if signup mode is set to lottery directSignupAlwaysOpenIds: [], // Add these to Konsti under 'other' program type diff --git a/shared/config/eventConfigTypes.ts b/shared/config/eventConfigTypes.ts index 3253d3f67..f54922376 100644 --- a/shared/config/eventConfigTypes.ts +++ b/shared/config/eventConfigTypes.ts @@ -4,8 +4,8 @@ import { SignupQuestion } from "shared/types/models/settings"; export enum SignupStrategy { DIRECT = "direct", - ALGORITHM = "algorithm", - ALGORITHM_AND_DIRECT = "algorithm+direct", + LOTTERY = "lottery", + LOTTERY_AND_DIRECT = "lottery+direct", } export enum AssignmentStrategy { @@ -49,7 +49,7 @@ export interface EventConfig { directSignupAlwaysOpenIds: string[]; requireRegistrationCode: boolean; twoPhaseSignupProgramTypes: ProgramType[]; - manualSignupMode: SignupStrategy.ALGORITHM | SignupStrategy.DIRECT | "none"; + manualSignupMode: SignupStrategy.LOTTERY | SignupStrategy.DIRECT | "none"; signupOpen: boolean; resultsVisible: boolean; addToKonstiOther: string[]; diff --git a/shared/config/past-events/hitpoint2023.ts b/shared/config/past-events/hitpoint2023.ts index 03efafc68..fc45408be 100644 --- a/shared/config/past-events/hitpoint2023.ts +++ b/shared/config/past-events/hitpoint2023.ts @@ -25,7 +25,7 @@ const eventConfig: Partial = { directSignupWindows: null, - // These program items have their signup always open even if signup mode is set to algorithm + // These program items have their signup always open even if signup mode is set to lottery directSignupAlwaysOpenIds: [], // Add these to Konsti under 'other' program type diff --git a/shared/config/past-events/ropecon2023.ts b/shared/config/past-events/ropecon2023.ts index c93f6efed..3e0e803eb 100644 --- a/shared/config/past-events/ropecon2023.ts +++ b/shared/config/past-events/ropecon2023.ts @@ -117,7 +117,7 @@ const eventConfig: Partial = { ], }, - // These program items have their signup always open even if signup mode is set to algorithm + // These program items have their signup always open even if signup mode is set to lottery directSignupAlwaysOpenIds: [], // Add these to Konsti under 'other' program type diff --git a/shared/config/past-events/ropecon2024.ts b/shared/config/past-events/ropecon2024.ts index 6380b8247..b67933221 100644 --- a/shared/config/past-events/ropecon2024.ts +++ b/shared/config/past-events/ropecon2024.ts @@ -75,7 +75,7 @@ const eventConfig: Partial = { rollingSignupStartProgramTypes: [ProgramType.WORKSHOP, ProgramType.OTHER], - // These program items have their signup always open even if signup mode is set to algorithm + // These program items have their signup always open even if signup mode is set to lottery directSignupAlwaysOpenIds: [ "pathfinder-society-4-99-blessings-of-the-forest", // Pathfinder Society #4-99 Blessings of the Forest ], diff --git a/shared/config/past-events/solmukohta2024.ts b/shared/config/past-events/solmukohta2024.ts index 39f8aaddf..7f84f5152 100644 --- a/shared/config/past-events/solmukohta2024.ts +++ b/shared/config/past-events/solmukohta2024.ts @@ -44,7 +44,7 @@ const eventConfig: Partial = { ], }, - // These program items have their signup always open even if signup mode is set to algorithm + // These program items have their signup always open even if signup mode is set to lottery directSignupAlwaysOpenIds: [], // Add these to Konsti under 'other' program type diff --git a/shared/config/serverConfig.ts b/shared/config/serverConfig.ts index 50230a415..bb9ed96b0 100644 --- a/shared/config/serverConfig.ts +++ b/shared/config/serverConfig.ts @@ -58,7 +58,7 @@ const commonConfig = { enableRemoveOverlapSignups: true, // Default DB values - defaultSignupStrategy: SignupStrategy.ALGORITHM_AND_DIRECT, + defaultSignupStrategy: SignupStrategy.LOTTERY_AND_DIRECT, defaultLoginProvider: LoginProvider.LOCAL, // Event settings diff --git a/shared/utils/signupTimes.test.ts b/shared/utils/signupTimes.test.ts index dcec0a2d4..4550068ef 100644 --- a/shared/utils/signupTimes.test.ts +++ b/shared/utils/signupTimes.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest"; import dayjs from "dayjs"; import { - getAlgorithmSignupStartTime, + getLotterySignupStartTime, getDirectSignupStartTime, } from "shared/utils/signupTimes"; import { @@ -48,72 +48,72 @@ beforeEach(() => { }); }); -describe(`Algorithm signup`, () => { +describe(`Lottery signup`, () => { test("RPG starting at 15:00 should have signup starting at 15:00", () => { const startTime = `${friday}T12:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T12:00:00.000Z`); }); test("RPG starting at 16:00 should have signup starting at 15:00", () => { const startTime = `${friday}T13:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T12:00:00.000Z`); }); test("RPG starting at 17:00 should have signup starting at 15:00", () => { const startTime = `${friday}T14:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T12:00:00.000Z`); }); test("RPG starting at 18:00 should have signup starting at 15:00", () => { const startTime = `${friday}T15:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T12:00:00.000Z`); }); test("RPG starting at 19:00 should have signup starting at 15:00", () => { const startTime = `${friday}T16:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T12:00:00.000Z`); }); test("RPG starting at 20:00 should have signup starting at 16:00", () => { const startTime = `${friday}T17:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T13:00:00.000Z`); }); test("RPG starting at 21:00 should have signup starting at 17:00", () => { const startTime = `${friday}T18:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T14:00:00.000Z`); }); }); -describe(`Early algorithm signup`, () => { +describe(`Early lottery signup`, () => { test("RPG starting at 09:00 should have signup starting at 22:00", () => { const startTime = `${saturday}T06:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T19:00:00.000Z`); }); test("RPG starting at 10:00 should have signup starting at 22:00", () => { const startTime = `${saturday}T07:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${friday}T19:00:00.000Z`); }); test("RPG starting at 11:00 should have signup starting at 07:00", () => { const startTime = `${saturday}T08:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${saturday}T04:00:00.000Z`); }); test("RPG starting at 12:00 should have signup starting at 08:00", () => { const startTime = `${saturday}T09:00:00.000Z`; - const signupStartTime = getAlgorithmSignupStartTime(startTime); + const signupStartTime = getLotterySignupStartTime(startTime); expect(signupStartTime.toISOString()).toEqual(`${saturday}T05:00:00.000Z`); }); }); diff --git a/shared/utils/signupTimes.ts b/shared/utils/signupTimes.ts index ed4a7d637..28a26d79e 100644 --- a/shared/utils/signupTimes.ts +++ b/shared/utils/signupTimes.ts @@ -3,7 +3,7 @@ import { config } from "shared/config"; import { ProgramItem } from "shared/types/models/programItem"; import { TIMEZONE } from "shared/utils/initializeDayjs"; -export const getAlgorithmSignupStartTime = (startTime: string): Dayjs => { +export const getLotterySignupStartTime = (startTime: string): Dayjs => { const { eventStartTime, preSignupStart } = config.event(); // Set timezone because hour comparison and setting hour value @@ -11,7 +11,7 @@ export const getAlgorithmSignupStartTime = (startTime: string): Dayjs => { .tz(TIMEZONE) .subtract(preSignupStart, "minutes"); - // If algorithm signup starts before event start time, use event start time + // If lottery signup starts before event start time, use event start time if (timezoneStartTime.isBefore(dayjs(eventStartTime))) { return dayjs(eventStartTime); } @@ -24,7 +24,7 @@ export const getAlgorithmSignupStartTime = (startTime: string): Dayjs => { return timezoneStartTime; }; -export const getAlgorithmSignupEndTime = (startTime: string): Dayjs => { +export const getLotterySignupEndTime = (startTime: string): Dayjs => { const { directSignupPhaseStart } = config.event(); return dayjs(startTime).subtract(directSignupPhaseStart, "minutes"); }; diff --git a/shared/utils/tooEarlyForLotterySignup.ts b/shared/utils/tooEarlyForLotterySignup.ts new file mode 100644 index 000000000..c9c995246 --- /dev/null +++ b/shared/utils/tooEarlyForLotterySignup.ts @@ -0,0 +1,22 @@ +import dayjs from "dayjs"; +import { config } from "shared/config"; + +export const tooEarlyForLotterySignup = (startTime: string): boolean => { + const { eventStartTime } = config.event(); + + // Return DIRECT for three first hours of event because there is no time for lottery signup + // For example, if event starts at 15:00 and 'preSignupStart' is 4h and 'directSignupPhaseStart' is 2h + // Start time 15:00 -> lottery 11:00-13:00 -> use direct + // Start time 16:00 -> lottery 12:00-14:00 -> use direct + // Start time 17:00 -> lottery 13:00-15:00 -> use direct + // Start time 18:00 -> lottery 14:00-16:00 -> lottery with shorter duration 15:00-16:00 (see signupTimes.ts) + // Start time 19:00 -> lottery 15:00-17:00 -> show normally + + const noLotterySignupBefore = dayjs(eventStartTime).add(3, "hours"); + + if (dayjs(startTime).isBefore(noLotterySignupBefore)) { + return true; + } + + return false; +}; diff --git a/shared/utils/tooEearlyForAlgorithmSignup.ts b/shared/utils/tooEearlyForAlgorithmSignup.ts deleted file mode 100644 index a1ccc74ce..000000000 --- a/shared/utils/tooEearlyForAlgorithmSignup.ts +++ /dev/null @@ -1,22 +0,0 @@ -import dayjs from "dayjs"; -import { config } from "shared/config"; - -export const tooEearlyForAlgorithmSignup = (startTime: string): boolean => { - const { eventStartTime } = config.event(); - - // Return DIRECT for three first hours of event because there is no time for algorithm signup - // For example, if event starts at 15:00 and 'preSignupStart' is 4h and 'directSignupPhaseStart' is 2h - // Start time 15:00 -> algorithm 11:00-13:00 -> use direct - // Start time 16:00 -> algorithm 12:00-14:00 -> use direct - // Start time 17:00 -> algorithm 13:00-15:00 -> use direct - // Start time 18:00 -> algorithm 14:00-16:00 -> algorithm with shorter duration 15:00-16:00 (see signupTimes.ts) - // Start time 19:00 -> algorithm 15:00-17:00 -> show normally - - const noAlgorithmSignupBefore = dayjs(eventStartTime).add(3, "hours"); - - if (dayjs(startTime).isBefore(noAlgorithmSignupBefore)) { - return true; - } - - return false; -};