-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: parse global messages using zod (#301)
* refactor: parse global messages using zod * fix: use default false instead of optional * refactor: use optional chaining for function call Co-authored-by: Mikael Brevik <[email protected]> --------- Co-authored-by: Mikael Brevik <[email protected]>
- Loading branch information
1 parent
1a037c6
commit 9cebb97
Showing
2 changed files
with
44 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
import { MessageMode } from '@atb/components/message-box'; | ||
import { LocalizedString } from '@atb/translations/commons'; | ||
import { Timestamp } from 'firebase/firestore'; | ||
import { languageAndTextSchema } from '@atb/translations/types'; | ||
import { z } from 'zod'; | ||
|
||
const messageModeSchema = z.union([ | ||
z.literal('info'), | ||
z.literal('valid'), | ||
z.literal('warning'), | ||
z.literal('error'), | ||
]); | ||
|
||
export enum GlobalMessageContextEnum { | ||
plannerWebAssistant = 'planner-web-assistant', | ||
} | ||
|
||
export type GlobalMessageType = { | ||
id: string; | ||
active: boolean; | ||
title?: LocalizedString[]; | ||
body: LocalizedString[]; | ||
type: MessageMode; | ||
subtle?: boolean; | ||
context: GlobalMessageContextEnum[]; | ||
isDismissable?: boolean; | ||
startDate?: Timestamp; | ||
endDate?: Timestamp; | ||
}; | ||
export const globalMessageTypeSchema = z.object({ | ||
id: z.string(), | ||
active: z.boolean(), | ||
title: z.array(languageAndTextSchema).optional(), | ||
body: z.array(languageAndTextSchema), | ||
type: messageModeSchema, | ||
subtle: z.boolean().default(false), | ||
context: z.array(z.nativeEnum(GlobalMessageContextEnum)), | ||
isDismissable: z.boolean().default(false), | ||
startDate: z.date().optional(), | ||
endDate: z.date().optional(), | ||
}); | ||
|
||
export type GlobalMessageType = z.infer<typeof globalMessageTypeSchema>; |