2024-06-03 09:11:07 +02:00
|
|
|
import {z} from "zod";
|
|
|
|
|
2023-12-01 11:52:41 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
|
|
|
import * as channel from "./channel";
|
2024-06-03 09:11:07 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
export type OnboardingStep = z.output<typeof onboarding_step_schema>;
|
2023-12-02 13:34:05 +01:00
|
|
|
|
2024-02-24 20:09:41 +01:00
|
|
|
export const ONE_TIME_NOTICES_TO_DISPLAY = new Set<string>();
|
2023-12-01 11:52:41 +01:00
|
|
|
|
2024-02-24 20:09:41 +01:00
|
|
|
export function post_onboarding_step_as_read(onboarding_step_name: string): void {
|
|
|
|
void channel.post({
|
2023-12-01 11:52:41 +01:00
|
|
|
url: "/json/users/me/onboarding_steps",
|
|
|
|
data: {onboarding_step: onboarding_step_name},
|
|
|
|
error(err) {
|
|
|
|
if (err.readyState !== 0) {
|
|
|
|
blueslip.error("Failed to fetch onboarding steps", {
|
|
|
|
readyState: err.readyState,
|
|
|
|
status: err.status,
|
|
|
|
body: err.responseText,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-12-02 11:30:35 +01:00
|
|
|
|
2024-06-03 09:27:36 +02:00
|
|
|
export function update_onboarding_steps_to_display(onboarding_steps: OnboardingStep[]): void {
|
2023-12-02 13:34:05 +01:00
|
|
|
ONE_TIME_NOTICES_TO_DISPLAY.clear();
|
|
|
|
|
|
|
|
for (const onboarding_step of onboarding_steps) {
|
|
|
|
if (onboarding_step.type === "one_time_notice") {
|
|
|
|
ONE_TIME_NOTICES_TO_DISPLAY.add(onboarding_step.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-03 09:11:07 +02:00
|
|
|
export function initialize(params: {onboarding_steps: OnboardingStep[]}): void {
|
|
|
|
update_onboarding_steps_to_display(params.onboarding_steps);
|
2023-12-02 13:34:05 +01:00
|
|
|
}
|