2021-09-22 19:52:38 +00:00
|
|
|
import { ArrowRightIcon } from "@heroicons/react/outline";
|
2022-02-02 11:07:13 +00:00
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
2022-03-24 17:45:56 +00:00
|
|
|
import { Prisma } from "@prisma/client";
|
2021-09-22 19:52:38 +00:00
|
|
|
import classnames from "classnames";
|
2021-10-13 11:35:25 +00:00
|
|
|
import debounce from "lodash/debounce";
|
|
|
|
import omit from "lodash/omit";
|
2021-09-02 12:13:19 +00:00
|
|
|
import { NextPageContext } from "next";
|
2022-01-07 20:23:37 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Head from "next/head";
|
|
|
|
import { useRouter } from "next/router";
|
2022-06-10 18:38:46 +00:00
|
|
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
2021-11-10 11:16:32 +00:00
|
|
|
import { useForm } from "react-hook-form";
|
2022-01-15 16:23:42 +00:00
|
|
|
import * as z from "zod";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-03-23 22:00:30 +00:00
|
|
|
import getApps from "@calcom/app-store/utils";
|
|
|
|
import { getCalendarCredentials, getConnectedCalendars } from "@calcom/core/CalendarManager";
|
2022-06-28 20:40:58 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
2022-03-24 17:45:56 +00:00
|
|
|
import { ResponseUsernameApi } from "@calcom/ee/lib/core/checkPremiumUsername";
|
2022-03-16 23:36:43 +00:00
|
|
|
import { Alert } from "@calcom/ui/Alert";
|
|
|
|
import Button from "@calcom/ui/Button";
|
|
|
|
import { Form } from "@calcom/ui/form/fields";
|
|
|
|
|
2021-09-22 19:52:38 +00:00
|
|
|
import { getSession } from "@lib/auth";
|
2021-11-11 05:44:53 +00:00
|
|
|
import { DEFAULT_SCHEDULE } from "@lib/availability";
|
2021-10-14 14:24:21 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-09-22 19:52:38 +00:00
|
|
|
import prisma from "@lib/prisma";
|
2022-01-19 17:26:44 +00:00
|
|
|
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
|
2022-02-02 18:33:27 +00:00
|
|
|
import { trpc } from "@lib/trpc";
|
2021-10-20 15:42:40 +00:00
|
|
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
2021-11-10 11:16:32 +00:00
|
|
|
import { Schedule as ScheduleType } from "@lib/types/schedule";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-10-30 15:54:21 +00:00
|
|
|
import { ClientSuspense } from "@components/ClientSuspense";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Loader from "@components/Loader";
|
2022-03-17 16:48:23 +00:00
|
|
|
import Schedule from "@components/availability/Schedule";
|
2021-10-30 15:54:21 +00:00
|
|
|
import { CalendarListContainer } from "@components/integrations/CalendarListContainer";
|
2022-05-23 11:12:41 +00:00
|
|
|
import TimezoneSelect from "@components/ui/form/TimezoneSelect";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-09-22 07:25:33 +00:00
|
|
|
import getEventTypes from "../lib/queries/event-types/get-event-types";
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2021-11-10 11:16:32 +00:00
|
|
|
type ScheduleFormValues = {
|
|
|
|
schedule: ScheduleType;
|
|
|
|
};
|
2021-09-17 21:31:44 +00:00
|
|
|
|
2022-02-02 18:33:27 +00:00
|
|
|
let mutationComplete: ((err: Error | null) => void) | null;
|
|
|
|
|
2021-10-20 15:42:40 +00:00
|
|
|
export default function Onboarding(props: inferSSRProps<typeof getServerSideProps>) {
|
2021-10-14 14:24:21 +00:00
|
|
|
const { t } = useLocale();
|
2021-09-02 12:13:19 +00:00
|
|
|
const router = useRouter();
|
2022-01-19 17:26:44 +00:00
|
|
|
const telemetry = useTelemetry();
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-02-02 18:33:27 +00:00
|
|
|
const mutation = trpc.useMutation("viewer.updateProfile", {
|
|
|
|
onSuccess: async () => {
|
|
|
|
setSubmitting(true);
|
|
|
|
setEnteredName(nameRef.current?.value || "");
|
|
|
|
if (mutationComplete) {
|
|
|
|
mutationComplete(null);
|
|
|
|
mutationComplete = null;
|
|
|
|
}
|
|
|
|
setSubmitting(false);
|
|
|
|
},
|
|
|
|
onError: (err) => {
|
|
|
|
setError(new Error(err.message));
|
|
|
|
if (mutationComplete) {
|
|
|
|
mutationComplete(new Error(err.message));
|
|
|
|
}
|
|
|
|
setSubmitting(false);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-10-14 14:24:21 +00:00
|
|
|
const DEFAULT_EVENT_TYPES = [
|
|
|
|
{
|
|
|
|
title: t("15min_meeting"),
|
|
|
|
slug: "15min",
|
|
|
|
length: 15,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("30min_meeting"),
|
|
|
|
slug: "30min",
|
|
|
|
length: 30,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: t("secret_meeting"),
|
|
|
|
slug: "secret",
|
|
|
|
length: 15,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-09-22 07:25:33 +00:00
|
|
|
const [isSubmitting, setSubmitting] = React.useState(false);
|
2021-10-20 15:42:40 +00:00
|
|
|
const [enteredName, setEnteredName] = React.useState("");
|
2022-01-07 20:23:37 +00:00
|
|
|
const { status } = useSession();
|
|
|
|
const loading = status === "loading";
|
2021-09-02 12:13:19 +00:00
|
|
|
const [ready, setReady] = useState(false);
|
2022-01-15 16:23:42 +00:00
|
|
|
const [selectedImport, setSelectedImport] = useState("");
|
2021-10-20 15:42:40 +00:00
|
|
|
const [error, setError] = useState<Error | null>(null);
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-05-14 13:49:39 +00:00
|
|
|
const updateUser = useCallback(
|
|
|
|
async (data: Prisma.UserUpdateInput) => {
|
|
|
|
const res = await fetch(`/api/user/${props.user.id}`, {
|
|
|
|
method: "PATCH",
|
|
|
|
body: JSON.stringify({ data: { ...data } }),
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
throw new Error((await res.json()).message);
|
|
|
|
}
|
|
|
|
const responseData = await res.json();
|
|
|
|
return responseData.data;
|
|
|
|
},
|
|
|
|
[props.user.id]
|
|
|
|
);
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-06-10 18:38:46 +00:00
|
|
|
const createEventType = trpc.useMutation("viewer.eventTypes.create");
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-03-17 16:48:23 +00:00
|
|
|
const createSchedule = trpc.useMutation("viewer.availability.schedule.create", {
|
|
|
|
onError: (err) => {
|
|
|
|
throw new Error(err.message);
|
|
|
|
},
|
|
|
|
});
|
2021-09-02 12:13:19 +00:00
|
|
|
|
|
|
|
/** Name */
|
2021-10-20 15:42:40 +00:00
|
|
|
const nameRef = useRef<HTMLInputElement>(null);
|
|
|
|
const bioRef = useRef<HTMLInputElement>(null);
|
2021-09-02 12:13:19 +00:00
|
|
|
/** End Name */
|
|
|
|
/** TimeZone */
|
2021-10-30 15:54:21 +00:00
|
|
|
const [selectedTimeZone, setSelectedTimeZone] = useState(props.user.timeZone ?? dayjs.tz.guess());
|
2021-09-02 12:13:19 +00:00
|
|
|
/** End TimeZone */
|
|
|
|
|
|
|
|
/** Onboarding Steps */
|
|
|
|
const [currentStep, setCurrentStep] = useState(0);
|
|
|
|
const detectStep = () => {
|
2022-03-24 17:45:56 +00:00
|
|
|
// Always set timezone if new user
|
2021-09-02 12:13:19 +00:00
|
|
|
let step = 0;
|
|
|
|
|
2021-10-20 15:42:40 +00:00
|
|
|
const hasConfigureCalendar = props.integrations.some((integration) => integration.credential !== null);
|
2021-09-02 12:13:19 +00:00
|
|
|
if (hasConfigureCalendar) {
|
|
|
|
step = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
const hasSchedules = props.schedules && props.schedules.length > 0;
|
|
|
|
if (hasSchedules) {
|
|
|
|
step = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentStep(step);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleConfirmStep = async () => {
|
|
|
|
try {
|
2021-09-22 07:25:33 +00:00
|
|
|
setSubmitting(true);
|
2022-06-06 18:24:37 +00:00
|
|
|
const onComplete = steps[currentStep]?.onComplete;
|
|
|
|
if (onComplete) {
|
|
|
|
await onComplete();
|
2021-09-02 12:13:19 +00:00
|
|
|
}
|
|
|
|
incrementStep();
|
2021-09-22 07:25:33 +00:00
|
|
|
setSubmitting(false);
|
2021-09-02 12:13:19 +00:00
|
|
|
} catch (error) {
|
2021-09-22 07:25:33 +00:00
|
|
|
setSubmitting(false);
|
2021-10-20 15:42:40 +00:00
|
|
|
setError(error as Error);
|
2021-09-02 12:13:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-22 07:25:33 +00:00
|
|
|
const debouncedHandleConfirmStep = debounce(handleConfirmStep, 850);
|
|
|
|
|
2021-09-02 12:13:19 +00:00
|
|
|
const handleSkipStep = () => {
|
|
|
|
incrementStep();
|
|
|
|
};
|
|
|
|
|
|
|
|
const incrementStep = () => {
|
|
|
|
const nextStep = currentStep + 1;
|
|
|
|
|
|
|
|
if (nextStep >= steps.length) {
|
|
|
|
completeOnboarding();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setCurrentStep(nextStep);
|
|
|
|
};
|
|
|
|
|
|
|
|
const decrementStep = () => {
|
|
|
|
const previous = currentStep - 1;
|
|
|
|
|
|
|
|
if (previous < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setCurrentStep(previous);
|
|
|
|
};
|
|
|
|
|
|
|
|
const goToStep = (step: number) => {
|
|
|
|
setCurrentStep(step);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Complete Onboarding finalizes the onboarding flow for a new user.
|
|
|
|
*
|
|
|
|
* Here, 3 event types are pre-created for the user as well.
|
|
|
|
* Set to the availability the user enter during the onboarding.
|
|
|
|
*
|
|
|
|
* If a user skips through the Onboarding flow,
|
|
|
|
* then the default availability is applied.
|
|
|
|
*/
|
|
|
|
const completeOnboarding = async () => {
|
2021-09-22 07:25:33 +00:00
|
|
|
setSubmitting(true);
|
2021-09-02 12:13:19 +00:00
|
|
|
if (!props.eventTypes || props.eventTypes.length === 0) {
|
2021-09-22 07:25:33 +00:00
|
|
|
const eventTypes = await getEventTypes();
|
|
|
|
if (eventTypes.length === 0) {
|
2022-02-10 10:31:22 +00:00
|
|
|
await Promise.all(
|
2021-09-22 07:25:33 +00:00
|
|
|
DEFAULT_EVENT_TYPES.map(async (event) => {
|
2022-06-10 18:38:46 +00:00
|
|
|
return createEventType.mutate(event);
|
2021-09-22 07:25:33 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2021-09-02 12:13:19 +00:00
|
|
|
}
|
|
|
|
await updateUser({
|
|
|
|
completedOnboarding: true,
|
|
|
|
});
|
|
|
|
|
2021-09-22 07:25:33 +00:00
|
|
|
setSubmitting(false);
|
2021-09-02 12:13:19 +00:00
|
|
|
router.push("/event-types");
|
|
|
|
};
|
|
|
|
|
2022-01-15 16:23:42 +00:00
|
|
|
const schema = z.object({
|
|
|
|
token: z.string(),
|
|
|
|
});
|
|
|
|
|
|
|
|
const formMethods = useForm<{
|
|
|
|
token: string;
|
|
|
|
}>({ resolver: zodResolver(schema), mode: "onSubmit" });
|
|
|
|
|
2022-03-24 17:45:56 +00:00
|
|
|
const fetchUsername = async (username: string) => {
|
2022-03-26 00:39:38 +00:00
|
|
|
const response = await fetch(`${process.env.NEXT_PUBLIC_WEBSITE_URL}/api/username`, {
|
2022-03-24 17:45:56 +00:00
|
|
|
credentials: "include",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({ username: username.trim() }),
|
|
|
|
method: "POST",
|
|
|
|
mode: "cors",
|
|
|
|
});
|
|
|
|
const data = (await response.json()) as ResponseUsernameApi;
|
|
|
|
return { response, data };
|
|
|
|
};
|
|
|
|
|
|
|
|
// Should update username on user when being redirected from sign up and doing google/saml
|
|
|
|
useEffect(() => {
|
2022-04-04 20:26:14 +00:00
|
|
|
async function validateAndSave(username: string) {
|
2022-03-24 17:45:56 +00:00
|
|
|
const { data } = await fetchUsername(username);
|
|
|
|
|
|
|
|
// Only persist username if its available and not premium
|
|
|
|
// premium usernames are saved via stripe webhook
|
|
|
|
if (data.available && !data.premium) {
|
|
|
|
await updateUser({
|
|
|
|
username,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Remove it from localStorage
|
|
|
|
window.localStorage.removeItem("username");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Looking for username on localStorage
|
|
|
|
const username = window.localStorage.getItem("username");
|
|
|
|
if (username) {
|
|
|
|
validateAndSave(username);
|
|
|
|
}
|
2022-05-14 13:49:39 +00:00
|
|
|
}, [updateUser]);
|
2022-03-24 17:45:56 +00:00
|
|
|
|
2021-11-10 11:16:32 +00:00
|
|
|
const availabilityForm = useForm({ defaultValues: { schedule: DEFAULT_SCHEDULE } });
|
2021-09-02 12:13:19 +00:00
|
|
|
const steps = [
|
|
|
|
{
|
2021-10-14 14:24:21 +00:00
|
|
|
id: t("welcome"),
|
|
|
|
title: t("welcome_to_calcom"),
|
|
|
|
description: t("welcome_instructions"),
|
2021-09-02 12:13:19 +00:00
|
|
|
Component: (
|
2022-01-15 16:23:42 +00:00
|
|
|
<>
|
|
|
|
{selectedImport == "" && (
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mb-4 grid grid-cols-2 gap-x-4">
|
2022-01-15 16:23:42 +00:00
|
|
|
<Button color="secondary" onClick={() => setSelectedImport("calendly")}>
|
|
|
|
{t("import_from")} Calendly
|
|
|
|
</Button>
|
|
|
|
<Button color="secondary" onClick={() => setSelectedImport("savvycal")}>
|
|
|
|
{t("import_from")} SavvyCal
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{selectedImport && (
|
|
|
|
<div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<h2 className="font-cal text-2xl text-gray-900">
|
2022-01-15 16:23:42 +00:00
|
|
|
{t("import_from")} {selectedImport === "calendly" ? "Calendly" : "SavvyCal"}
|
|
|
|
</h2>
|
2022-01-31 10:18:12 +00:00
|
|
|
<p className="mb-2 text-sm text-gray-500">
|
|
|
|
{t("you_will_need_to_generate")}. Find out how to do this{" "}
|
|
|
|
<a href="https://docs.cal.com/import">here</a>.
|
|
|
|
</p>
|
2022-01-15 16:23:42 +00:00
|
|
|
<form
|
|
|
|
className="flex"
|
|
|
|
onSubmit={formMethods.handleSubmit(async (values) => {
|
2022-01-19 17:26:44 +00:00
|
|
|
// track the number of imports. Without personal data/payload
|
2022-06-02 16:19:01 +00:00
|
|
|
telemetry.event(telemetryEventTypes.importSubmitted, {
|
|
|
|
...collectPageParameters(),
|
|
|
|
selectedImport,
|
|
|
|
});
|
2022-01-15 16:23:42 +00:00
|
|
|
setSubmitting(true);
|
|
|
|
const response = await fetch(`/api/import/${selectedImport}`, {
|
|
|
|
method: "POST",
|
|
|
|
body: JSON.stringify({
|
|
|
|
token: values.token,
|
|
|
|
}),
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (response.status === 201) {
|
|
|
|
setSubmitting(false);
|
|
|
|
handleSkipStep();
|
|
|
|
} else {
|
|
|
|
await response.json().catch((e) => {
|
|
|
|
console.log("Error: response.json invalid: " + e);
|
|
|
|
setSubmitting(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})}>
|
|
|
|
<input
|
|
|
|
onChange={async (e) => {
|
|
|
|
formMethods.setValue("token", e.target.value);
|
|
|
|
}}
|
|
|
|
type="text"
|
|
|
|
name="token"
|
|
|
|
id="token"
|
|
|
|
placeholder={t("access_token")}
|
|
|
|
required
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
|
2022-01-15 16:23:42 +00:00
|
|
|
/>
|
2022-02-09 00:05:13 +00:00
|
|
|
<Button type="submit" className="mt-1 ml-4 h-10">
|
2022-01-15 16:23:42 +00:00
|
|
|
{t("import")}
|
|
|
|
</Button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className="relative my-4">
|
|
|
|
<div className="absolute inset-0 flex items-center" aria-hidden="true">
|
|
|
|
<div className="w-full border-t border-gray-300" />
|
|
|
|
</div>
|
|
|
|
<div className="relative flex justify-center">
|
2022-02-09 00:05:13 +00:00
|
|
|
<span className="bg-white px-2 text-sm text-gray-500">or</span>
|
2022-01-15 16:23:42 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<form className="sm:mx-auto sm:w-full">
|
|
|
|
<section className="space-y-8">
|
|
|
|
<fieldset>
|
|
|
|
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("full_name")}
|
2021-09-02 12:13:19 +00:00
|
|
|
</label>
|
2022-01-15 16:23:42 +00:00
|
|
|
<input
|
|
|
|
ref={nameRef}
|
|
|
|
type="text"
|
|
|
|
name="name"
|
|
|
|
id="name"
|
|
|
|
autoComplete="given-name"
|
|
|
|
placeholder={t("your_name")}
|
|
|
|
defaultValue={props.user.name ?? enteredName}
|
|
|
|
required
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
|
2022-01-15 16:23:42 +00:00
|
|
|
/>
|
|
|
|
</fieldset>
|
|
|
|
|
|
|
|
<fieldset>
|
|
|
|
<section className="flex justify-between">
|
|
|
|
<label htmlFor="timeZone" className="block text-sm font-medium text-gray-700">
|
|
|
|
{t("timezone")}
|
|
|
|
</label>
|
2022-05-30 09:36:23 +00:00
|
|
|
<p className="text-sm leading-tight text-gray-500 dark:text-white">
|
2022-01-15 16:23:42 +00:00
|
|
|
{t("current_time")}:
|
|
|
|
<span className="text-black">{dayjs().tz(selectedTimeZone).format("LT")}</span>
|
2022-05-30 09:36:23 +00:00
|
|
|
</p>
|
2022-01-15 16:23:42 +00:00
|
|
|
</section>
|
|
|
|
<TimezoneSelect
|
|
|
|
id="timeZone"
|
|
|
|
value={selectedTimeZone}
|
|
|
|
onChange={({ value }) => setSelectedTimeZone(value)}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm"
|
2022-01-15 16:23:42 +00:00
|
|
|
/>
|
|
|
|
</fieldset>
|
|
|
|
</section>
|
|
|
|
</form>
|
|
|
|
</>
|
2021-09-02 12:13:19 +00:00
|
|
|
),
|
|
|
|
hideConfirm: false,
|
2021-10-14 14:24:21 +00:00
|
|
|
confirmText: t("continue"),
|
2021-09-02 12:13:19 +00:00
|
|
|
showCancel: true,
|
2021-10-14 14:24:21 +00:00
|
|
|
cancelText: t("set_up_later"),
|
2021-09-02 12:13:19 +00:00
|
|
|
onComplete: async () => {
|
2022-02-02 18:33:27 +00:00
|
|
|
mutationComplete = null;
|
|
|
|
setError(null);
|
|
|
|
const mutationAsync = new Promise((resolve, reject) => {
|
|
|
|
mutationComplete = (err) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve(null);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-03-24 17:45:56 +00:00
|
|
|
const userUpdateData = {
|
2022-02-02 18:33:27 +00:00
|
|
|
name: nameRef.current?.value,
|
|
|
|
timeZone: selectedTimeZone,
|
2022-03-24 17:45:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mutation.mutate(userUpdateData);
|
2022-02-02 18:33:27 +00:00
|
|
|
|
|
|
|
if (mutationComplete) {
|
|
|
|
await mutationAsync;
|
2021-09-02 12:13:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "connect-calendar",
|
2021-10-14 14:24:21 +00:00
|
|
|
title: t("connect_your_calendar"),
|
|
|
|
description: t("connect_your_calendar_instructions"),
|
2021-09-02 12:13:19 +00:00
|
|
|
Component: (
|
2021-10-30 15:54:21 +00:00
|
|
|
<ClientSuspense fallback={<Loader />}>
|
2022-06-12 15:19:35 +00:00
|
|
|
<CalendarListContainer heading={false} fromOnboarding={true} />
|
2021-10-30 15:54:21 +00:00
|
|
|
</ClientSuspense>
|
2021-09-02 12:13:19 +00:00
|
|
|
),
|
|
|
|
hideConfirm: true,
|
2021-10-14 14:24:21 +00:00
|
|
|
confirmText: t("continue"),
|
2021-09-02 12:13:19 +00:00
|
|
|
showCancel: true,
|
2021-10-14 14:24:21 +00:00
|
|
|
cancelText: t("continue_without_calendar"),
|
2021-09-02 12:13:19 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "set-availability",
|
2021-10-14 14:24:21 +00:00
|
|
|
title: t("set_availability"),
|
|
|
|
description: t("set_availability_instructions"),
|
2021-09-02 12:13:19 +00:00
|
|
|
Component: (
|
2021-11-11 05:44:53 +00:00
|
|
|
<Form<ScheduleFormValues>
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mx-auto max-w-lg bg-white text-black dark:bg-opacity-5 dark:text-white"
|
2021-11-10 11:16:32 +00:00
|
|
|
form={availabilityForm}
|
|
|
|
handleSubmit={async (values) => {
|
|
|
|
try {
|
|
|
|
setSubmitting(true);
|
2022-03-17 16:48:23 +00:00
|
|
|
await createSchedule.mutate({
|
|
|
|
name: t("default_schedule_name"),
|
|
|
|
...values,
|
|
|
|
});
|
2021-11-10 11:16:32 +00:00
|
|
|
debouncedHandleConfirmStep();
|
|
|
|
setSubmitting(false);
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof Error) {
|
|
|
|
setError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}>
|
|
|
|
<section>
|
|
|
|
<Schedule name="schedule" />
|
2022-02-09 00:05:13 +00:00
|
|
|
<footer className="flex flex-col space-y-6 py-6 sm:mx-auto sm:w-full">
|
2021-11-10 11:16:32 +00:00
|
|
|
<Button className="justify-center" EndIcon={ArrowRightIcon} type="submit">
|
|
|
|
{t("continue")}
|
|
|
|
</Button>
|
|
|
|
</footer>
|
2021-09-02 12:13:19 +00:00
|
|
|
</section>
|
2021-11-10 11:16:32 +00:00
|
|
|
</Form>
|
2021-09-02 12:13:19 +00:00
|
|
|
),
|
|
|
|
hideConfirm: true,
|
|
|
|
showCancel: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "profile",
|
2021-10-14 14:24:21 +00:00
|
|
|
title: t("nearly_there"),
|
|
|
|
description: t("nearly_there_instructions"),
|
2021-09-02 12:13:19 +00:00
|
|
|
Component: (
|
2021-10-09 13:34:13 +00:00
|
|
|
<form className="sm:mx-auto sm:w-full" id="ONBOARDING_STEP_4">
|
2021-09-02 12:13:19 +00:00
|
|
|
<section className="space-y-4">
|
|
|
|
<fieldset>
|
|
|
|
<label htmlFor="name" className="block text-sm font-medium text-gray-700">
|
2021-10-14 14:24:21 +00:00
|
|
|
{t("full_name")}
|
2021-09-02 12:13:19 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
ref={nameRef}
|
|
|
|
type="text"
|
|
|
|
name="name"
|
|
|
|
id="name"
|
|
|
|
autoComplete="given-name"
|
2021-10-14 14:24:21 +00:00
|
|
|
placeholder={t("your_name")}
|
2021-09-02 12:13:19 +00:00
|
|
|
defaultValue={props.user.name || enteredName}
|
|
|
|
required
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
|
2021-09-02 12:13:19 +00:00
|
|
|
/>
|
|
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
|
|
<label htmlFor="bio" className="block text-sm font-medium text-gray-700">
|
2021-10-14 14:24:21 +00:00
|
|
|
{t("about")}
|
2021-09-02 12:13:19 +00:00
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
ref={bioRef}
|
|
|
|
type="text"
|
|
|
|
name="bio"
|
|
|
|
id="bio"
|
|
|
|
required
|
2022-02-09 00:05:13 +00:00
|
|
|
className="mt-1 block w-full rounded-sm border border-gray-300 px-3 py-2 shadow-sm focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
|
2021-10-20 15:42:40 +00:00
|
|
|
defaultValue={props.user.bio || undefined}
|
2021-09-02 12:13:19 +00:00
|
|
|
/>
|
2022-05-30 09:36:23 +00:00
|
|
|
<p className="mt-2 text-sm leading-tight text-gray-500 dark:text-white">
|
2021-10-14 14:24:21 +00:00
|
|
|
{t("few_sentences_about_yourself")}
|
2022-05-30 09:36:23 +00:00
|
|
|
</p>
|
2021-09-02 12:13:19 +00:00
|
|
|
</fieldset>
|
|
|
|
</section>
|
|
|
|
</form>
|
|
|
|
),
|
|
|
|
hideConfirm: false,
|
2021-10-14 14:24:21 +00:00
|
|
|
confirmText: t("finish"),
|
2021-09-02 12:13:19 +00:00
|
|
|
showCancel: true,
|
2021-10-14 14:24:21 +00:00
|
|
|
cancelText: t("set_up_later"),
|
2021-09-02 12:13:19 +00:00
|
|
|
onComplete: async () => {
|
|
|
|
try {
|
2021-09-22 07:25:33 +00:00
|
|
|
setSubmitting(true);
|
2021-09-02 12:13:19 +00:00
|
|
|
await updateUser({
|
2021-10-20 15:42:40 +00:00
|
|
|
bio: bioRef.current?.value,
|
2021-09-02 12:13:19 +00:00
|
|
|
});
|
2021-09-22 07:25:33 +00:00
|
|
|
setSubmitting(false);
|
2021-09-02 12:13:19 +00:00
|
|
|
} catch (error) {
|
2021-10-20 15:42:40 +00:00
|
|
|
setError(error as Error);
|
2021-09-22 07:25:33 +00:00
|
|
|
setSubmitting(false);
|
2021-09-02 12:13:19 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
/** End Onboarding Steps */
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
detectStep();
|
|
|
|
setReady(true);
|
2021-11-10 11:16:32 +00:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2021-09-02 12:13:19 +00:00
|
|
|
}, []);
|
|
|
|
|
2022-01-07 20:23:37 +00:00
|
|
|
if (loading || !ready) {
|
2021-09-02 12:13:19 +00:00
|
|
|
return <div className="loader"></div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-02-09 22:32:31 +00:00
|
|
|
<div className="bg-brand min-h-screen" data-testid="onboarding">
|
2021-09-02 12:13:19 +00:00
|
|
|
<Head>
|
2021-10-14 14:24:21 +00:00
|
|
|
<title>Cal.com - {t("getting_started")}</title>
|
2021-09-02 12:13:19 +00:00
|
|
|
<link rel="icon" href="/favicon.ico" />
|
|
|
|
</Head>
|
|
|
|
|
2021-09-22 07:25:33 +00:00
|
|
|
{isSubmitting && (
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="fixed z-10 flex h-full w-full flex-col content-center items-center justify-center bg-white bg-opacity-25">
|
2021-09-22 07:25:33 +00:00
|
|
|
<Loader />
|
|
|
|
</div>
|
|
|
|
)}
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mx-auto px-4 py-24">
|
2021-09-22 07:25:33 +00:00
|
|
|
<article className="relative">
|
2021-10-20 15:42:40 +00:00
|
|
|
<section className="space-y-4 sm:mx-auto sm:w-full sm:max-w-lg">
|
2021-09-24 15:03:28 +00:00
|
|
|
<header>
|
2022-05-30 09:36:23 +00:00
|
|
|
<p className="font-cal mb-2 text-3xl tracking-wider text-white">{steps[currentStep].title}</p>
|
|
|
|
<p className="text-sm font-normal text-white">{steps[currentStep].description}</p>
|
2021-09-02 12:13:19 +00:00
|
|
|
</header>
|
2022-02-09 00:05:13 +00:00
|
|
|
<section className="space-y-2 pt-4">
|
2022-05-30 09:36:23 +00:00
|
|
|
<p className="text-xs font-medium text-gray-500 dark:text-white">
|
2021-09-02 12:13:19 +00:00
|
|
|
Step {currentStep + 1} of {steps.length}
|
2022-05-30 09:36:23 +00:00
|
|
|
</p>
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-02-02 18:33:27 +00:00
|
|
|
{error && <Alert severity="error" message={error?.message} />}
|
2021-09-02 15:17:24 +00:00
|
|
|
|
2022-02-02 11:07:13 +00:00
|
|
|
<section className="flex w-full space-x-2 rtl:space-x-reverse">
|
2021-09-02 12:13:19 +00:00
|
|
|
{steps.map((s, index) => {
|
|
|
|
return index <= currentStep ? (
|
|
|
|
<div
|
|
|
|
key={`step-${index}`}
|
|
|
|
onClick={() => goToStep(index)}
|
|
|
|
className={classnames(
|
2022-02-09 00:05:13 +00:00
|
|
|
"h-1 w-1/4 bg-white",
|
2021-09-02 12:13:19 +00:00
|
|
|
index < currentStep ? "cursor-pointer" : ""
|
|
|
|
)}></div>
|
|
|
|
) : (
|
2022-02-09 00:05:13 +00:00
|
|
|
<div key={`step-${index}`} className="h-1 w-1/4 bg-white bg-opacity-25"></div>
|
2021-09-02 12:13:19 +00:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</section>
|
|
|
|
</section>
|
|
|
|
</section>
|
2022-02-09 00:05:13 +00:00
|
|
|
<section className="mx-auto mt-10 max-w-xl rounded-sm bg-white p-10">
|
2021-09-02 12:13:19 +00:00
|
|
|
{steps[currentStep].Component}
|
|
|
|
|
|
|
|
{!steps[currentStep].hideConfirm && (
|
2022-02-09 00:05:13 +00:00
|
|
|
<footer className="mt-8 flex flex-col space-y-6 sm:mx-auto sm:w-full">
|
2021-09-22 07:25:33 +00:00
|
|
|
<Button
|
|
|
|
className="justify-center"
|
|
|
|
disabled={isSubmitting}
|
|
|
|
onClick={debouncedHandleConfirmStep}
|
2022-03-24 17:45:56 +00:00
|
|
|
EndIcon={ArrowRightIcon}
|
|
|
|
data-testid={`continue-button-${currentStep}`}>
|
2021-09-06 09:14:01 +00:00
|
|
|
{steps[currentStep].confirmText}
|
|
|
|
</Button>
|
2021-09-02 12:13:19 +00:00
|
|
|
</footer>
|
|
|
|
)}
|
|
|
|
</section>
|
2022-02-09 00:05:13 +00:00
|
|
|
<section className="mx-auto max-w-xl py-8">
|
2021-10-20 15:42:40 +00:00
|
|
|
<div className="flex flex-row-reverse justify-between">
|
2021-11-10 11:16:32 +00:00
|
|
|
<button
|
|
|
|
disabled={isSubmitting}
|
|
|
|
onClick={handleSkipStep}
|
|
|
|
className="text-sm leading-tight text-gray-500 dark:text-white">
|
|
|
|
{t("next_step")}
|
2021-09-02 12:13:19 +00:00
|
|
|
</button>
|
2021-09-06 09:14:01 +00:00
|
|
|
{currentStep !== 0 && (
|
2021-11-10 11:16:32 +00:00
|
|
|
<button
|
|
|
|
disabled={isSubmitting}
|
|
|
|
onClick={decrementStep}
|
|
|
|
className="text-sm leading-tight text-gray-500 dark:text-white">
|
|
|
|
{t("prev_step")}
|
2021-09-06 09:14:01 +00:00
|
|
|
</button>
|
|
|
|
)}
|
2021-09-02 12:13:19 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</article>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getServerSideProps(context: NextPageContext) {
|
|
|
|
const session = await getSession(context);
|
|
|
|
|
2021-09-03 07:45:57 +00:00
|
|
|
if (!session?.user?.id) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
permanent: false,
|
|
|
|
destination: "/auth/login",
|
2021-09-08 11:03:43 +00:00
|
|
|
},
|
2021-09-03 07:45:57 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
const user = await prisma.user.findFirst({
|
|
|
|
where: {
|
|
|
|
id: session.user.id,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
startTime: true,
|
|
|
|
endTime: true,
|
|
|
|
username: true,
|
|
|
|
name: true,
|
|
|
|
email: true,
|
|
|
|
bio: true,
|
|
|
|
avatar: true,
|
|
|
|
timeZone: true,
|
2022-02-18 17:32:12 +00:00
|
|
|
identityProvider: true,
|
2021-09-03 07:45:57 +00:00
|
|
|
completedOnboarding: true,
|
2021-10-20 15:42:40 +00:00
|
|
|
selectedCalendars: {
|
|
|
|
select: {
|
|
|
|
externalId: true,
|
|
|
|
integration: true,
|
|
|
|
},
|
|
|
|
},
|
2021-09-03 07:45:57 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
if (!user) {
|
|
|
|
throw new Error(`Signed in as ${session.user.id} but cannot be found in db`);
|
|
|
|
}
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2021-09-03 07:45:57 +00:00
|
|
|
if (user.completedOnboarding) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
permanent: false,
|
|
|
|
destination: "/event-types",
|
2021-09-02 12:13:19 +00:00
|
|
|
},
|
2021-09-03 07:45:57 +00:00
|
|
|
};
|
|
|
|
}
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-02-10 17:42:06 +00:00
|
|
|
const credentials = await prisma.credential.findMany({
|
2021-09-03 07:45:57 +00:00
|
|
|
where: {
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
type: true,
|
|
|
|
key: true,
|
2022-03-23 22:00:30 +00:00
|
|
|
userId: true,
|
2022-05-02 20:39:35 +00:00
|
|
|
appId: true,
|
2021-09-03 07:45:57 +00:00
|
|
|
},
|
|
|
|
});
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-03-23 22:00:30 +00:00
|
|
|
const integrations = getApps(credentials)
|
2021-10-20 15:42:40 +00:00
|
|
|
.filter((item) => item.type.endsWith("_calendar"))
|
|
|
|
.map((item) => omit(item, "key"));
|
|
|
|
|
|
|
|
// get user's credentials + their connected integrations
|
|
|
|
const calendarCredentials = getCalendarCredentials(credentials, user.id);
|
|
|
|
// get all the connected integrations' calendars (from third party)
|
2022-02-10 17:42:06 +00:00
|
|
|
const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-02-10 17:42:06 +00:00
|
|
|
const eventTypes = await prisma.eventType.findMany({
|
2021-09-03 07:45:57 +00:00
|
|
|
where: {
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
title: true,
|
|
|
|
slug: true,
|
|
|
|
description: true,
|
|
|
|
length: true,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
});
|
2021-09-02 12:13:19 +00:00
|
|
|
|
2022-02-10 17:42:06 +00:00
|
|
|
const schedules = await prisma.schedule.findMany({
|
2021-09-03 07:45:57 +00:00
|
|
|
where: {
|
|
|
|
userId: user.id,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
},
|
|
|
|
});
|
2021-09-02 12:13:19 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
2021-09-26 21:49:16 +00:00
|
|
|
session,
|
2021-09-02 12:13:19 +00:00
|
|
|
user,
|
|
|
|
integrations,
|
2021-10-20 15:42:40 +00:00
|
|
|
connectedCalendars,
|
2021-09-02 12:13:19 +00:00
|
|
|
eventTypes,
|
|
|
|
schedules,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|