From a2457ab6196b2e0f9a5842e82d5d8b05ee511f52 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Mon, 27 Mar 2023 15:53:35 -0400 Subject: [PATCH] Fix/availability not loading (#7789) * Set default schedule if there is not one * Removing last schedule sets user.defaultScheduleId to null * Create new schedule from event type * First schedule created is the default * Go back if new schedule was created * Moved update logic out of getter * Remove flashing of empty screen * Add border prop to EmptyScreen * User requires a schedule * Change back schema --------- Co-authored-by: Peer Richelsen --- .../components/eventtype/AvailabilityTab.tsx | 47 ++++++++++++++----- apps/web/pages/availability/[schedule].tsx | 12 ++++- apps/web/pages/availability/index.tsx | 8 +++- apps/web/public/static/locales/en/common.json | 1 + .../components/NewScheduleButton.tsx | 10 +++- packages/features/shell/Shell.tsx | 2 +- packages/features/tips/UpgradeTip.tsx | 20 ++++---- .../server/routers/viewer/availability.tsx | 33 +++++++++++-- .../components/empty-screen/EmptyScreen.tsx | 8 +++- 9 files changed, 109 insertions(+), 32 deletions(-) diff --git a/apps/web/components/eventtype/AvailabilityTab.tsx b/apps/web/components/eventtype/AvailabilityTab.tsx index 52dcd3c121..cf784a76ee 100644 --- a/apps/web/components/eventtype/AvailabilityTab.tsx +++ b/apps/web/components/eventtype/AvailabilityTab.tsx @@ -4,13 +4,15 @@ import type { OptionProps, SingleValueProps } from "react-select"; import { components } from "react-select"; import dayjs from "@calcom/dayjs"; +import { NewScheduleButton } from "@calcom/features/schedules"; import classNames from "@calcom/lib/classNames"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { weekdayNames } from "@calcom/lib/weekday"; +import type { RouterOutputs } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react"; import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery"; -import { Badge, Button, Select, SettingsToggle, SkeletonText } from "@calcom/ui"; -import { FiExternalLink, FiGlobe } from "@calcom/ui/components/icon"; +import { Badge, Button, Select, SettingsToggle, SkeletonText, EmptyScreen } from "@calcom/ui"; +import { FiExternalLink, FiGlobe, FiClock } from "@calcom/ui/components/icon"; import { SelectSkeletonLoader } from "@components/availability/SkeletonLoader"; @@ -52,23 +54,24 @@ const SingleValue = ({ ...props }: SingleValueProps) => { const AvailabilitySelect = ({ className = "", + isLoading, + schedules, ...props }: { className?: string; name: string; value: number; + isLoading: boolean; + schedules: RouterOutputs["viewer"]["availability"]["list"]["schedules"] | []; onBlur: () => void; onChange: (value: AvailabilityOption | null) => void; }) => { - const { data, isLoading } = trpc.viewer.availability.list.useQuery(); const { t } = useLocale(); if (isLoading) { return ; } - const schedules = data?.schedules || []; - const options = schedules.map((schedule) => ({ value: schedule.id, label: schedule.name, @@ -107,6 +110,7 @@ const EventTypeScheduleDetails = () => { const { watch } = useFormContext(); const scheduleId = watch("schedule"); + const { isLoading, data: schedule } = trpc.viewer.availability.schedule.get.useQuery( { scheduleId: scheduleId || loggedInUser?.defaultScheduleId || undefined }, { enabled: !!scheduleId || !!loggedInUser?.defaultScheduleId } @@ -174,6 +178,19 @@ const EventTypeScheduleDetails = () => { const EventTypeSchedule = () => { const { t } = useLocale(); + const { data: schedules, isLoading } = trpc.viewer.availability.list.useQuery(); + + if (!schedules?.schedules.length && !isLoading) + return ( + } + border={false} + /> + ); + return (
@@ -183,14 +200,18 @@ const EventTypeSchedule = () => { ( - { - field.onChange(selected?.value || null); - }} - /> + <> + { + field.onChange(selected?.value || null); + }} + /> + )} />
diff --git a/apps/web/pages/availability/[schedule].tsx b/apps/web/pages/availability/[schedule].tsx index 8ba0d7f337..6f74e31b91 100644 --- a/apps/web/pages/availability/[schedule].tsx +++ b/apps/web/pages/availability/[schedule].tsx @@ -94,6 +94,7 @@ export default function Availability() { data: { schedule: scheduleId }, } = useTypedQuery(querySchema); + const { fromEventType } = router.query; const { timeFormat } = me.data || { timeFormat: null }; const { data: schedule, isLoading } = trpc.viewer.availability.schedule.get.useQuery( { scheduleId }, @@ -153,7 +154,7 @@ export default function Availability() { return ( -