38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import type { FirstStepsChecklistVM } from "./first-steps-checklist.vm.js";
|
|
import type { VMState } from "../index.js";
|
|
|
|
export type WelcomeSetupData = {
|
|
readonly firstName: string | null;
|
|
readonly workspaceName: string;
|
|
readonly dashboardHref: string;
|
|
readonly checklist: NonNullable<FirstStepsChecklistVM["data"]>;
|
|
readonly nextItem: NonNullable<FirstStepsChecklistVM["data"]>["items"][number] | null;
|
|
};
|
|
|
|
export type WelcomeSetupVM = VMState<WelcomeSetupData>;
|
|
|
|
export function toWelcomeSetupVM(input: {
|
|
readonly firstName: string | null;
|
|
readonly workspaceName: string;
|
|
readonly dashboardHref: string;
|
|
readonly checklist: FirstStepsChecklistVM;
|
|
}): WelcomeSetupVM {
|
|
if (input.checklist.status === "error") {
|
|
return { status: "error", error: input.checklist.error };
|
|
}
|
|
if (input.checklist.status !== "ready" || !input.checklist.data) {
|
|
return input.checklist.status === "loading" || input.checklist.status === "idle" ? { status: input.checklist.status } : { status: "empty" };
|
|
}
|
|
|
|
return {
|
|
status: "ready",
|
|
data: {
|
|
firstName: input.firstName?.trim() || null,
|
|
workspaceName: input.workspaceName,
|
|
dashboardHref: input.dashboardHref,
|
|
checklist: input.checklist.data,
|
|
nextItem: input.checklist.data.items.find((item) => !item.completed) ?? null,
|
|
},
|
|
};
|
|
}
|