Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | 651x 1538x 1538x 1538x 1538x 1538x 1538x 1538x 1538x 1538x | import { TZDate } from "@date-fns/tz";
import { getMinutes } from "date-fns";
import { config } from "shared/config";
import { ProgramItem, SignupType } from "shared/types/models/programItem";
import { isLotterySignupProgramItem } from "shared/utils/isLotterySignupProgramItem";
import { TIMEZONE } from "shared/utils/timezone";
interface ProgramItemValidity {
isValidMinAttendanceValue: boolean;
isValidMaxAttendanceValue: boolean;
minAttendanceBiggerThanMax: boolean;
signupTypeMissing: boolean;
lotteryItemNotStartingOnEvenHour: boolean;
allValuesValid: boolean;
}
// Check if a program item is missing required info, like attendance limits.
// Invalid program items cannot be signed up to.
export const getProgramItemValidity = (
programItem: ProgramItem,
): ProgramItemValidity => {
const { noKonstiSignupIds, startTimesByParentIds } = config.event();
const usesKonstiSignup =
programItem.signupType === SignupType.KONSTI &&
!noKonstiSignupIds.includes(programItem.programItemId);
const isValidMinAttendanceValue = programItem.minAttendance > 0;
const isValidMaxAttendanceValue =
!usesKonstiSignup || programItem.maxAttendance > 0;
const minAttendanceBiggerThanMax =
programItem.minAttendance > programItem.maxAttendance &&
programItem.maxAttendance > 0;
const signupTypeMissing = programItem.signupType === SignupType.MISSING;
// Lottery batches sign-ups by start time, so lottery items must start at an
// even hour. Items with a configured parent start time are exempt: the whole
// batch is run as one lottery at that admin-configured time.
//
// Read in the event timezone, not the viewer's: an even Helsinki hour is 30 or
// 45 minutes past in a zone with a half-hour offset, which would mark every
// lottery item invalid and hide its sign-up controls for those attendees.
const lotteryItemNotStartingOnEvenHour =
usesKonstiSignup &&
isLotterySignupProgramItem(programItem) &&
!startTimesByParentIds.has(programItem.parentId) &&
getMinutes(new TZDate(programItem.startTime, TIMEZONE)) !== 0;
const allValuesValid =
isValidMinAttendanceValue &&
isValidMaxAttendanceValue &&
!minAttendanceBiggerThanMax &&
!signupTypeMissing &&
!lotteryItemNotStartingOnEvenHour;
return {
isValidMinAttendanceValue,
isValidMaxAttendanceValue,
minAttendanceBiggerThanMax,
signupTypeMissing,
lotteryItemNotStartingOnEvenHour,
allValuesValid,
};
};
|