13c2dc24dc
* [WIP] New design and components for onboarding page * saving work in progress * new fonts * [WIP] new onboarding page, initial page, components * WIP calendar connect * WIP availability new design * WIP onboarding page * WIP onboarding, working new availability form * WIP AvailabilitySchedule componente v2 * WIP availability with defaultSchedule * User profile view * Relocate new onboarding/getting-started page components * Steps test for onboarding v2 * Remove logs and unused code * remove any as types * Adding translations * Fixes translation text and css for step 4 * Deprecation note for old-getting-started * Added defaul events and refetch user query when finishing getting-started * Fix button text translation * Undo schedule v1 changes * Fix calendar switches state * Add cookie to save return-to when connecting calendar * Change useTranslation for useLocale instead * Change test to work with data-testid instead of hardcoded plain text due to translation * Fix skeleton containers for calendars * Style fixes * fix styles to match v2 * Fix styles and props types to match v2 design * Bugfix/router and console errors (#4206) * The loading={boolean} parameter is required, so this must be <Button /> * Fixes duplicate key error * Use zod and router.query.step directly to power state machine * use ul>li & divide for borders * Update apps/web/components/getting-started/steps-views/ConnectCalendars.tsx Co-authored-by: alannnc <alannnc@gmail.com> * Linting * Deprecation notices and type fixes * Update CreateEventsOnCalendarSelect.tsx * Type fixes Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: zomars <zomars@me.com>
86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
import { useRouter } from "next/router";
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { HttpError } from "@calcom/lib/http-error";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { Dialog, DialogClose, DialogContent, DialogTrigger } from "@calcom/ui/Dialog";
|
|
import { Icon } from "@calcom/ui/Icon";
|
|
import { Form } from "@calcom/ui/form/fields";
|
|
import Button from "@calcom/ui/v2/core/Button";
|
|
import showToast from "@calcom/ui/v2/core/notifications";
|
|
|
|
export function NewScheduleButton({ name = "new-schedule" }: { name?: string }) {
|
|
const router = useRouter();
|
|
const { t } = useLocale();
|
|
|
|
const form = useForm<{
|
|
name: string;
|
|
}>();
|
|
const { register } = form;
|
|
|
|
const createMutation = trpc.useMutation("viewer.availability.schedule.create", {
|
|
onSuccess: async ({ schedule }) => {
|
|
await router.push("/availability/" + schedule.id);
|
|
showToast(t("schedule_created_successfully", { scheduleName: schedule.name }), "success");
|
|
},
|
|
onError: (err) => {
|
|
if (err instanceof HttpError) {
|
|
const message = `${err.statusCode}: ${err.message}`;
|
|
showToast(message, "error");
|
|
}
|
|
|
|
if (err.data?.code === "UNAUTHORIZED") {
|
|
const message = `${err.data.code}: You are not able to create this event`;
|
|
showToast(message, "error");
|
|
}
|
|
},
|
|
});
|
|
|
|
return (
|
|
<Dialog name={name} clearQueryParamsOnClose={["copy-schedule-id"]}>
|
|
<DialogTrigger asChild>
|
|
<Button data-testid={name} StartIcon={Icon.FiPlus}>
|
|
{t("new")}
|
|
</Button>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<div className="mb-8">
|
|
<h3 className="text-lg font-bold leading-6 text-gray-900" id="modal-title">
|
|
{t("add_new_schedule")}
|
|
</h3>
|
|
</div>
|
|
<Form
|
|
form={form}
|
|
handleSubmit={(values) => {
|
|
createMutation.mutate(values);
|
|
}}>
|
|
<div className="mt-3 space-y-2">
|
|
<label htmlFor="label" className="block text-sm font-medium text-gray-700">
|
|
{t("name")}
|
|
</label>
|
|
<div className="mt-1">
|
|
<input
|
|
type="text"
|
|
id="name"
|
|
required
|
|
className="block w-full rounded-sm border-gray-300 text-sm"
|
|
placeholder={t("default_schedule_name")}
|
|
{...register("name")}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div className="mt-8 flex flex-row-reverse gap-x-2">
|
|
<Button type="submit" loading={createMutation.isLoading}>
|
|
{t("continue")}
|
|
</Button>
|
|
<DialogClose asChild>
|
|
<Button color="secondary">{t("cancel")}</Button>
|
|
</DialogClose>
|
|
</div>
|
|
</Form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|