diff --git a/apps/web/components/Shell.tsx b/apps/web/components/Shell.tsx index 47e7e023..548f57c7 100644 --- a/apps/web/components/Shell.tsx +++ b/apps/web/components/Shell.tsx @@ -307,7 +307,7 @@ export default function Shell(props: { )} -
+
{props.HeadingLeftIcon &&
{props.HeadingLeftIcon}
}

{props.heading}

diff --git a/apps/web/components/availability/NewScheduleButton.tsx b/apps/web/components/availability/NewScheduleButton.tsx new file mode 100644 index 00000000..a9259f9c --- /dev/null +++ b/apps/web/components/availability/NewScheduleButton.tsx @@ -0,0 +1,77 @@ +import { PlusIcon } from "@heroicons/react/solid"; +import { useRouter } from "next/router"; +import { useForm } from "react-hook-form"; + +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import showToast from "@calcom/lib/notification"; +import { Button } from "@calcom/ui"; +import { Dialog, DialogClose, DialogContent, DialogTrigger } from "@calcom/ui/Dialog"; +import { Form, TextField } from "@calcom/ui/form/fields"; + +import { HttpError } from "@lib/core/http/error"; +import { trpc } from "@lib/trpc"; + +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 ( + + + + + +
+ +
+

{t("new_event_type_to_book_description")}

+
+
+
{ + createMutation.mutate(values); + }}> +
+ +
+
+ + + + +
+
+
+
+ ); +} diff --git a/apps/web/components/ui/form/Schedule.tsx b/apps/web/components/availability/Schedule.tsx similarity index 98% rename from apps/web/components/ui/form/Schedule.tsx rename to apps/web/components/availability/Schedule.tsx index f194c724..7c13a8ca 100644 --- a/apps/web/components/ui/form/Schedule.tsx +++ b/apps/web/components/availability/Schedule.tsx @@ -147,7 +147,7 @@ const ScheduleBlock = ({ name, day, weekday }: ScheduleBlockProps) => { }; return ( -
+