Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

onboarding_steps: Validate parameters with Zod.

Anders Kaseorg4ddc8f406d35
diff --git a/web/src/onboarding_steps.ts b/web/src/onboarding_steps.ts
index 2727c08e958..9ca8ced2b5e 100644
--- a/web/src/onboarding_steps.ts
+++ b/web/src/onboarding_steps.ts
@@ -1,19 +1,8 @@
-import {z} from "zod";
+import type {z} from "zod";
import * as blueslip from "./blueslip";
import * as channel from "./channel";
-
-const one_time_notice_schema = z.object({
- name: z.string(),
- type: z.literal("one_time_notice"),
-});
-
-/* We may introduce onboarding step of types other than 'one time notice'
-in future. Earlier, we had 'hotspot' and 'one time notice' as the two
-types. We can simply do:
-const onboarding_step_schema = z.union([one_time_notice_schema, other_type_schema]);
-to avoid major refactoring when new type is introduced in the future. */
-const onboarding_step_schema = one_time_notice_schema;
+import type {StateData, onboarding_step_schema} from "./state_data";
export type OnboardingStep = z.output<typeof onboarding_step_schema>;
@@ -45,6 +34,6 @@ export function update_onboarding_steps_to_display(onboarding_steps: OnboardingS
}
}
-export function initialize(params: {onboarding_steps: OnboardingStep[]}): void {
+export function initialize(params: StateData["onboarding_steps"]): void {
update_onboarding_steps_to_display(params.onboarding_steps);
}
diff --git a/web/src/state_data.ts b/web/src/state_data.ts
index 5f249274ba0..3b59211c5a5 100644
--- a/web/src/state_data.ts
+++ b/web/src/state_data.ts
@@ -174,6 +174,18 @@ export const presence_schema = z.object({
idle_timestamp: z.number().optional(),
});
+const one_time_notice_schema = z.object({
+ name: z.string(),
+ type: z.literal("one_time_notice"),
+});
+
+/* We may introduce onboarding step of types other than 'one time notice'
+in future. Earlier, we had 'hotspot' and 'one time notice' as the two
+types. We can simply do:
+const onboarding_step_schema = z.union([one_time_notice_schema, other_type_schema]);
+to avoid major refactoring when new type is introduced in the future. */
+export const onboarding_step_schema = one_time_notice_schema;
+
// Sync this with zerver.lib.events.do_events_register.
const current_user_schema = z.object({
avatar_source: z.string(),
@@ -484,7 +496,7 @@ export const state_data_schema = z
.and(z.object({max_message_id: z.number()}).transform((local_message) => ({local_message})))
.and(
z
- .object({onboarding_steps: NOT_TYPED_YET})
+ .object({onboarding_steps: z.array(onboarding_step_schema)})
.transform((onboarding_steps) => ({onboarding_steps})),
)
.and(current_user_schema.transform((current_user) => ({current_user})))