From 6a211dd5b3f0b6e5991da71f242a8bf1c608c8a3 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Thu, 17 Mar 2022 16:48:23 +0000 Subject: [PATCH] Feature/multiple schedules post turbo (#2150) * Concluded merge * Applied stash to newly merged * Always disconnect + remove redundant success message * Added named dialog to replace new=1 * Merged with main p2 * Set eventTypeId to @unique * WIP * Undo vscode changes * Availability dropdown works * Remove console.log + set schedule to null as it is unneeded * Added schedule to availability endpoint * Reduce one refresh; hotfix state inconsistency with forced refresh for now * Add missing translations * Fixed some type errors I missed * Ditch outdated remnant from before packages/prisma * Remove Availability section for teams * Bringing back the Availability section temporarily to teams to allow configuration * Migrated getting-started to new availability system + updated translations + updated seed * Fixed type error coming from main * Titlecase 'default' by providing translation * Fixed broken 'radio' buttons. * schedule deleted translation added * Added empty state for when no schedules are configured * Added correct created message + hotfix reload hard on delete to refresh state * Removed index renames * Type fixes * Update NewScheduleButton.tsx Co-authored-by: zomars Co-authored-by: Bailey Pumfleet Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- apps/web/components/Shell.tsx | 2 +- .../availability/NewScheduleButton.tsx | 77 ++ .../{ui/form => availability}/Schedule.tsx | 2 +- apps/web/components/ui/EditableHeading.tsx | 34 + apps/web/lib/core/i18n/weekday.ts | 9 +- apps/web/pages/[user]/[type].tsx | 29 +- apps/web/pages/api/availability/[user].ts | 32 +- apps/web/pages/availability/[schedule].tsx | 154 +++ apps/web/pages/availability/index.tsx | 210 ++-- apps/web/pages/event-types/[type].tsx | 110 +- apps/web/pages/getting-started.tsx | 29 +- apps/web/pages/settings/profile.tsx | 2 - apps/web/pages/team/[slug]/[type].tsx | 14 +- apps/web/public/static/locales/en/common.json | 10 + apps/web/public/static/locales/nl/common.json | 5 +- apps/web/server/createContext.ts | 1 + apps/web/server/routers/viewer.tsx | 45 +- .../server/routers/viewer/availability.tsx | 218 ++++ apps/web/server/routers/viewer/eventTypes.tsx | 37 +- apps/web/styles/globals.css | 8 + packages/lib/availability.ts | 43 +- packages/lib/weekday.ts | 8 + .../migration.sql | 30 + packages/prisma/schema.prisma | 25 +- packages/prisma/seed.ts | 17 +- packages/ui/Alert.tsx | 10 +- packages/ui/Switch.tsx | 39 +- yarn.lock | 1080 +++-------------- 28 files changed, 1073 insertions(+), 1207 deletions(-) create mode 100644 apps/web/components/availability/NewScheduleButton.tsx rename apps/web/components/{ui/form => availability}/Schedule.tsx (98%) create mode 100644 apps/web/components/ui/EditableHeading.tsx create mode 100644 apps/web/pages/availability/[schedule].tsx create mode 100644 apps/web/server/routers/viewer/availability.tsx create mode 100644 packages/lib/weekday.ts create mode 100644 packages/prisma/migrations/20220305233635_availability_schedules/migration.sql 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 ( -
+