From 770c35039dc1861c8ad553ebf0926d58d857609b Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Fri, 9 Sep 2022 15:47:17 +0100 Subject: [PATCH] Feature/add availability tab (#4314) * Add Availability Tab * Some i18n fixups * Update apps/web/components/v2/eventtype/AvailabilityTab.tsx Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> * Update apps/web/components/v2/eventtype/AvailabilityTab.tsx Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> * Update apps/web/components/v2/eventtype/AvailabilityTab.tsx Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> * Update apps/web/components/v2/eventtype/AvailabilityTab.tsx Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> * Fixed lint * Oops * Use classnames for SkeletonText instead of width,height * Ditches QueryCell Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: Peer Richelsen Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../v2/eventtype/AvailabilityTab.tsx | 144 ++++++++++++++++++ .../web/pages/v2/event-types/[type]/index.tsx | 28 +--- apps/web/public/static/locales/en/common.json | 1 + 3 files changed, 153 insertions(+), 20 deletions(-) create mode 100644 apps/web/components/v2/eventtype/AvailabilityTab.tsx diff --git a/apps/web/components/v2/eventtype/AvailabilityTab.tsx b/apps/web/components/v2/eventtype/AvailabilityTab.tsx new file mode 100644 index 0000000000..2e4bedb3a6 --- /dev/null +++ b/apps/web/components/v2/eventtype/AvailabilityTab.tsx @@ -0,0 +1,144 @@ +import { FormValues } from "pages/v2/event-types/[type]"; +import { Controller, useFormContext } from "react-hook-form"; + +import dayjs from "@calcom/dayjs"; +import classNames from "@calcom/lib/classNames"; +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import { weekdayNames } from "@calcom/lib/weekday"; +import { trpc } from "@calcom/trpc/react"; +import { Icon } from "@calcom/ui"; +import Button from "@calcom/ui/v2/core/Button"; +import Select from "@calcom/ui/v2/core/form/Select"; +import { SkeletonText } from "@calcom/ui/v2/core/skeleton"; + +import { AvailabilitySelectSkeletonLoader } from "@components/availability/SkeletonLoader"; + +type AvailabilityOption = { + label: string; + value: number; +}; + +const AvailabilitySelect = ({ + className = "", + ...props +}: { + className?: string; + name: string; + value: number; + onBlur: () => void; + onChange: (value: AvailabilityOption | null) => void; +}) => { + const { data, isLoading } = trpc.useQuery(["viewer.availability.list"]); + if (isLoading) { + return ; + } + + const schedules = data?.schedules || []; + + const options = schedules.map((schedule) => ({ + value: schedule.id, + label: schedule.name, + })); + + const value = options.find((option) => + props.value + ? option.value === props.value + : option.value === schedules.find((schedule) => schedule.isDefault)?.id + ); + + return ( +