refactor: enhance onboarding logic and update default redirect path
This commit is contained in:
47
frontend/src/lib/onboarding.test.ts
Normal file
47
frontend/src/lib/onboarding.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { isOnboardingComplete } from "@/lib/onboarding";
|
||||
|
||||
describe("isOnboardingComplete", () => {
|
||||
it("returns false when profile is missing", () => {
|
||||
expect(isOnboardingComplete(null)).toBe(false);
|
||||
expect(isOnboardingComplete(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when timezone is missing", () => {
|
||||
expect(
|
||||
isOnboardingComplete({
|
||||
preferred_name: "Asha",
|
||||
timezone: "",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when both name fields are missing", () => {
|
||||
expect(
|
||||
isOnboardingComplete({
|
||||
name: " ",
|
||||
preferred_name: " ",
|
||||
timezone: "America/New_York",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts preferred_name + timezone", () => {
|
||||
expect(
|
||||
isOnboardingComplete({
|
||||
preferred_name: "Asha",
|
||||
timezone: "America/New_York",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts fallback name + timezone", () => {
|
||||
expect(
|
||||
isOnboardingComplete({
|
||||
name: "Asha",
|
||||
timezone: "America/New_York",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
13
frontend/src/lib/onboarding.ts
Normal file
13
frontend/src/lib/onboarding.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
type OnboardingProfileLike = {
|
||||
name?: string | null;
|
||||
preferred_name?: string | null;
|
||||
timezone?: string | null;
|
||||
};
|
||||
|
||||
export function isOnboardingComplete(
|
||||
profile: OnboardingProfileLike | null | undefined,
|
||||
): boolean {
|
||||
if (!profile) return false;
|
||||
const resolvedName = profile.preferred_name?.trim() || profile.name?.trim();
|
||||
return Boolean(resolvedName) && Boolean(profile.timezone?.trim());
|
||||
}
|
||||
Reference in New Issue
Block a user