Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed too strict zod-schema for global messages #484

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/modules/global-messages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const messageModeSchema = z.union([
z.literal('error'),
]);

/**
* Defines **valid** and **relevant** values for the context field
*
* There are other possible values for this enum, but only the relevant values
* for the planner-web are listed here. Others are filtered out in the
* globalMessageTypeSchema.context below.
*/
export enum GlobalMessageContextEnum {
plannerWeb = 'planner-web',
plannerWebDepartures = 'planner-web-departures',
Expand All @@ -23,7 +30,15 @@ export const globalMessageTypeSchema = z.object({
body: z.array(languageAndTextSchema),
type: messageModeSchema,
subtle: z.boolean().default(false),
context: z.array(z.nativeEnum(GlobalMessageContextEnum)),
context: z
.array(z.string())
.transform((arr) =>
arr.filter((val): val is GlobalMessageContextEnum =>
Object.values(GlobalMessageContextEnum).includes(
val as GlobalMessageContextEnum,
),
),
),
isDismissable: z.boolean().default(false),
startDate: z.date().optional(),
endDate: z.date().optional(),
Expand Down
Loading