Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove setup-availability step in onboarding flow #17799

Draft
wants to merge 2 commits into
base: feat/reduce-onboarding-steps-2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

48 changes: 30 additions & 18 deletions apps/web/modules/getting-started/[[...step]]/onboarding-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { signOut } from "next-auth/react";
import type { TFunction } from "next-i18next";
import Head from "next/head";
import { usePathname, useRouter } from "next/navigation";
import { Suspense } from "react";
import { Suspense, useEffect } from "react";
import { z } from "zod";

import { classNames } from "@calcom/lib";
import { DEFAULT_SCHEDULE } from "@calcom/lib/availability";
import { APP_NAME } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
import { IdentityProvider } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc";
import type { TRPCClientErrorLike } from "@calcom/trpc/react";
import type { AppRouter } from "@calcom/trpc/server/routers/_app";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import { Button, StepCard, Steps } from "@calcom/ui";
import { Icon } from "@calcom/ui";
Expand All @@ -21,12 +24,11 @@ import type { getServerSideProps } from "@lib/getting-started/[[...step]]/getSer

import { ConnectedCalendars } from "@components/getting-started/steps-views/ConnectCalendars";
import { ConnectedVideoStep } from "@components/getting-started/steps-views/ConnectedVideoStep";
import { SetupAvailability } from "@components/getting-started/steps-views/SetupAvailability";
import UserProfile from "@components/getting-started/steps-views/UserProfile";
import { UserSettings } from "@components/getting-started/steps-views/UserSettings";

const INITIAL_STEP = "user-settings";
const BASE_STEPS = ["user-settings", "setup-availability", "user-profile"] as const;
const BASE_STEPS = ["user-settings", "user-profile"] as const;
const EXTRA_STEPS = ["connected-calendar", "connected-video"] as const;
type StepType = (typeof BASE_STEPS)[number] | (typeof EXTRA_STEPS)[number];

Expand All @@ -40,13 +42,6 @@ const getStepsAndHeadersForUser = (identityProvider: IdentityProvider, t: TFunct
title: t("welcome_to_cal_header", { appName: APP_NAME }),
subtitle: [t("we_just_need_basic_info"), t("edit_form_later_subtitle")],
},
{
title: t("set_availability"),
subtitle: [
t("set_availability_getting_started_subtitle_1"),
t("set_availability_getting_started_subtitle_2"),
],
},
{
title: t("nearly_there"),
subtitle: [t("nearly_there_instructions")],
Expand Down Expand Up @@ -85,9 +80,7 @@ const getStepsAndHeadersForUser = (identityProvider: IdentityProvider, t: TFunct

const stepRouteSchema = z.object({
step: z
.array(
z.enum(["user-settings", "setup-availability", "user-profile", "connected-calendar", "connected-video"])
)
.array(z.enum(["user-settings", "user-profile", "connected-calendar", "connected-video"]))
.default([INITIAL_STEP]),
from: z.string().optional(),
});
Expand All @@ -96,10 +89,18 @@ export type PageProps = inferSSRProps<typeof getServerSideProps>;
const OnboardingPage = (props: PageProps) => {
const pathname = usePathname();
const params = useParamsWithFallback();

const router = useRouter();
const [user] = trpc.viewer.me.useSuspenseQuery();
const { t } = useLocale();
const [user] = trpc.viewer.me.useSuspenseQuery();
const scheduleMutationOptions = {
onError: (error: TRPCClientErrorLike<AppRouter>) => {
throw new Error(error.message);
},
onSuccess: () => {
goToNextStep();
},
};
const createSchedule = trpc.viewer.availability.schedule.create.useMutation(scheduleMutationOptions);

const result = stepRouteSchema.safeParse({
...params,
Expand Down Expand Up @@ -136,6 +137,20 @@ const OnboardingPage = (props: PageProps) => {
router.push(`/getting-started/${stepTransform(newStep)}`);
};

useEffect(() => {
if (user.completedOnboarding) {
return;
}
const createDefaultSchedule = async () => {
await createSchedule.mutateAsync({
name: t("default_schedule_name"),
...DEFAULT_SCHEDULE,
});
};

createDefaultSchedule();
}, []);

return (
<div
className={classNames(
Expand Down Expand Up @@ -177,9 +192,6 @@ const OnboardingPage = (props: PageProps) => {

{currentStep === "connected-video" && <ConnectedVideoStep nextStep={goToNextStep} />}

{currentStep === "setup-availability" && (
<SetupAvailability nextStep={goToNextStep} defaultScheduleId={user.defaultScheduleId} />
)}
{currentStep === "user-profile" && <UserProfile />}
</Suspense>
</StepCard>
Expand Down
15 changes: 3 additions & 12 deletions apps/web/playwright/onboarding.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test.describe("Onboarding", () => {
await page.locator("button[type=submit]").click();

if (identityProvider === IdentityProvider.GOOGLE) {
await expect(page).toHaveURL(/.*setup-availability/);
await expect(page).toHaveURL(/.*user-profile/);
} else {
await expect(page).toHaveURL(/.*connected-calendar/);
}
Expand All @@ -66,20 +66,11 @@ test.describe("Onboarding", () => {
// tests skip button, we don't want to test entire flow.
await page.locator("button[data-testid=skip-step]").click();

await expect(page).toHaveURL(/.*setup-availability/);
await expect(page).toHaveURL(/.*user-profile/);
});
}

await test.step("step 4 - Setup Availability", async () => {
const isDisabled = await page.locator("button[data-testid=save-availability]").isDisabled();
await expect(isDisabled).toBe(false);
// same here, skip this step.
await page.locator("button[data-testid=save-availability]").click();

await expect(page).toHaveURL(/.*user-profile/);
});

await test.step("step 5- User Profile", async () => {
await test.step("step 4 - User Profile", async () => {
await page.locator("button[type=submit]").click();

// should redirect to /event-types after onboarding
Expand Down
Loading