From c1f346c9356caf7481f61f2cbf81465c72148d60 Mon Sep 17 00:00:00 2001 From: Abhisht Singh <39940817+abhisht51@users.noreply.github.com> Date: Wed, 19 Apr 2023 04:59:02 +0530 Subject: [PATCH] Cal 1099 availability section defined hour mismatch (#7416) * CAL-1099 Add prop for availability in formMethods * fix: show correct availabilty name Signed-off-by: Udit Takkar * CAL - 1099 / fix 12 hr time format bug * fix: remove useEffect and fix vertical tab item ui Signed-off-by: Udit Takkar * Fixes merge conflicts * Update index.tsx * More conflict fixes * Update packages/ui/components/navigation/tabs/VerticalTabs.tsx * Type fixes --------- Signed-off-by: Udit Takkar Co-authored-by: Udit Takkar Co-authored-by: zomars --- .../eventtype/EventAvailabilityTab.tsx | 186 ++++++++---------- .../eventtype/EventTypeSingleLayout.tsx | 12 +- apps/web/pages/event-types/[type]/index.tsx | 78 ++++++-- .../navigation/tabs/VerticalTabItem.tsx | 13 +- .../navigation/tabs/VerticalTabs.tsx | 19 +- 5 files changed, 184 insertions(+), 124 deletions(-) diff --git a/apps/web/components/eventtype/EventAvailabilityTab.tsx b/apps/web/components/eventtype/EventAvailabilityTab.tsx index 68240b3b82..ac425eafc8 100644 --- a/apps/web/components/eventtype/EventAvailabilityTab.tsx +++ b/apps/web/components/eventtype/EventAvailabilityTab.tsx @@ -1,21 +1,23 @@ import { SchedulingType } from "@prisma/client"; -import type { FormValues, EventTypeSetup } from "pages/event-types/[type]"; +import type { EventTypeSetup, FormValues } from "pages/event-types/[type]"; +import { useState } from "react"; import { Controller, useFormContext } from "react-hook-form"; import type { OptionProps, SingleValueProps } from "react-select"; import { components } from "react-select"; import dayjs from "@calcom/dayjs"; import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager"; -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 { trpc } from "@calcom/trpc/react"; import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery"; -import { Badge, Button, Select, SettingsToggle, SkeletonText, EmptyScreen } from "@calcom/ui"; -import { ExternalLink, Globe, Clock } from "@calcom/ui/components/icon"; +import { Badge, Button, Select, SettingsToggle, SkeletonText } from "@calcom/ui"; +import { ExternalLink, Globe } from "@calcom/ui/components/icon"; -type AvailabilityOption = { +import { SelectSkeletonLoader } from "@components/availability/SkeletonLoader"; + +export type AvailabilityOption = { label: string; value: number; isDefault: boolean; @@ -62,40 +64,12 @@ const SingleValue = ({ ...props }: SingleValueProps) => { ); }; -const AvailabilitySelect = ({ - className = "", - options, - value, - ...props -}: { - className?: string; - name: string; - value: AvailabilityOption | undefined; - options: AvailabilityOption[]; - isDisabled?: boolean; - onBlur: () => void; - onChange: (value: AvailabilityOption | null) => void; -}) => { - const { t } = useLocale(); - return ( - { + field.onChange(selected?.value || null); + if (selected?.value) formMethods.setValue("availability", selected); + }} + className="block w-full min-w-0 flex-1 rounded-sm text-sm" + value={availabilityValue} + components={{ Option, SingleValue }} + isMulti={false} + /> + ); + }} + /> + )} - {value?.value !== 0 ? ( + {availabilityValue?.value !== 0 ? ( ) : ( diff --git a/apps/web/components/eventtype/EventTypeSingleLayout.tsx b/apps/web/components/eventtype/EventTypeSingleLayout.tsx index 1eb973182c..78bf2ae373 100644 --- a/apps/web/components/eventtype/EventTypeSingleLayout.tsx +++ b/apps/web/components/eventtype/EventTypeSingleLayout.tsx @@ -51,6 +51,7 @@ import { } from "@calcom/ui/components/icon"; import { EmbedButton, EmbedDialog } from "@components/Embed"; +import type { AvailabilityOption } from "@components/eventtype/EventAvailabilityTab"; type Props = { children: React.ReactNode; @@ -63,6 +64,7 @@ type Props = { enabledWorkflowsNumber: number; formMethods: UseFormReturn; isUpdateMutationLoading?: boolean; + availability?: AvailabilityOption; }; function getNavigation(props: { @@ -71,8 +73,10 @@ function getNavigation(props: { enabledAppsNumber: number; enabledWorkflowsNumber: number; installedAppsNumber: number; + availability: AvailabilityOption | undefined; }) { - const { eventType, t, enabledAppsNumber, installedAppsNumber, enabledWorkflowsNumber } = props; + const { eventType, t, enabledAppsNumber, installedAppsNumber, enabledWorkflowsNumber, availability } = + props; const duration = eventType.metadata?.multipleDuration?.map((duration) => ` ${duration}`) || eventType.length; @@ -128,6 +132,7 @@ function EventTypeSingleLayout({ enabledWorkflowsNumber, isUpdateMutationLoading, formMethods, + availability, }: Props) { const utils = trpc.useContext(); const { t } = useLocale(); @@ -171,6 +176,7 @@ function EventTypeSingleLayout({ enabledAppsNumber, installedAppsNumber, enabledWorkflowsNumber, + availability, }); navigation.splice(1, 0, { name: "availability", @@ -214,7 +220,7 @@ function EventTypeSingleLayout({ }); } return navigation; - }, [t, eventType, installedAppsNumber, enabledAppsNumber, enabledWorkflowsNumber, team]); + }, [t, eventType, installedAppsNumber, enabledAppsNumber, enabledWorkflowsNumber, team, availability]); const permalink = `${CAL_URL}/${team ? `team/${team.slug}` : eventType.users[0].username}/${ eventType.slug @@ -374,6 +380,8 @@ function EventTypeSingleLayout({ tabs={EventTypeTabs} sticky linkProps={{ shallow: true }} + itemClassname="items-start" + iconClassName="md:mt-px" />
diff --git a/apps/web/pages/event-types/[type]/index.tsx b/apps/web/pages/event-types/[type]/index.tsx index 136b53ab77..c40404e61d 100644 --- a/apps/web/pages/event-types/[type]/index.tsx +++ b/apps/web/pages/event-types/[type]/index.tsx @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/no-empty-function */ import { useAutoAnimate } from "@formkit/auto-animate/react"; import { zodResolver } from "@hookform/resolvers/zod"; -import type { PeriodType } from "@prisma/client"; -import type { SchedulingType } from "@prisma/client"; +import type { PeriodType, SchedulingType } from "@prisma/client"; import type { GetServerSidePropsContext } from "next"; import { Trans } from "next-i18next"; import { useEffect, useState } from "react"; @@ -18,10 +17,10 @@ import { CAL_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery"; import { HttpError } from "@calcom/lib/http-error"; -import { useTelemetry, telemetryEventTypes } from "@calcom/lib/telemetry"; +import { telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry"; import type { Prisma } from "@calcom/prisma/client"; -import { eventTypeBookingFields } from "@calcom/prisma/zod-utils"; import type { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; +import { eventTypeBookingFields } from "@calcom/prisma/zod-utils"; import type { RouterOutputs } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react"; import type { IntervalLimit, RecurringEvent } from "@calcom/types/Calendar"; @@ -34,6 +33,7 @@ import PageWrapper from "@components/PageWrapper"; // These can't really be moved into calcom/ui due to the fact they use infered getserverside props typings import { EventAdvancedTab } from "@components/eventtype/EventAdvancedTab"; import { EventAppsTab } from "@components/eventtype/EventAppsTab"; +import type { AvailabilityOption } from "@components/eventtype/EventAvailabilityTab"; import { EventAvailabilityTab } from "@components/eventtype/EventAvailabilityTab"; import { EventLimitsTab } from "@components/eventtype/EventLimitsTab"; import { EventRecurringTab } from "@components/eventtype/EventRecurringTab"; @@ -94,6 +94,7 @@ export type FormValues = { children: ChildrenEventType[]; hosts: { userId: number; isFixed: boolean }[]; bookingFields: z.infer; + availability?: AvailabilityOption; }; export type CustomInputParsed = typeof customInputSchema._output; @@ -262,6 +263,7 @@ const EventTypePage = (props: EventTypeSetupProps) => { }, [defaultValues]); const appsMetadata = formMethods.getValues("metadata")?.apps; + const availability = formMethods.watch("availability"); const numberOfInstalledApps = eventTypeApps?.filter((app) => app.isInstalled).length || 0; let numberOfActiveApps = 0; @@ -378,6 +380,7 @@ const EventTypePage = (props: EventTypeSetupProps) => { enabledWorkflowsNumber={eventType.workflows.length} eventType={eventType} team={team} + availability={availability} isUpdateMutationLoading={updateMutation.isLoading} formMethods={formMethods} disableBorder={tabName === "apps" || tabName === "workflows" || tabName === "webhooks"} @@ -385,13 +388,66 @@ const EventTypePage = (props: EventTypeSetupProps) => {
{ - if (!values.children.length) return handleSubmit(values); - const existingSlugEventTypes = values.children.filter((ch) => - ch.owner.eventTypeSlugs.includes(slug) - ); - if (!existingSlugEventTypes.length) return handleSubmit(values); - setSlugExistsChildrenDialogOpen(existingSlugEventTypes); + handleSubmit={async (values) => { + const { + periodDates, + periodCountCalendarDays, + beforeBufferTime, + afterBufferTime, + seatsPerTimeSlot, + seatsShowAttendees, + bookingLimits, + durationLimits, + recurringEvent, + locations, + metadata, + customInputs, + // We don't need to send send these values to the backend + // eslint-disable-next-line @typescript-eslint/no-unused-vars + seatsPerTimeSlotEnabled, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + minimumBookingNoticeInDurationType, + availability, + ...input + } = values; + + if (bookingLimits) { + const isValid = validateIntervalLimitOrder(bookingLimits); + if (!isValid) throw new Error(t("event_setup_booking_limits_error")); + } + + if (durationLimits) { + const isValid = validateIntervalLimitOrder(durationLimits); + if (!isValid) throw new Error(t("event_setup_duration_limits_error")); + } + + if (metadata?.multipleDuration !== undefined) { + if (metadata?.multipleDuration.length < 1) { + throw new Error(t("event_setup_multiple_duration_error")); + } else { + if (!input.length && !metadata?.multipleDuration?.includes(input.length)) { + throw new Error(t("event_setup_multiple_duration_default_error")); + } + } + } + + updateMutation.mutate({ + ...input, + locations, + recurringEvent, + periodStartDate: periodDates.startDate, + periodEndDate: periodDates.endDate, + periodCountCalendarDays: periodCountCalendarDays === "1", + id: eventType.id, + beforeEventBuffer: beforeBufferTime, + afterEventBuffer: afterBufferTime, + bookingLimits, + durationLimits, + seatsPerTimeSlot, + seatsShowAttendees, + metadata, + customInputs, + }); }}>
{tabMap[tabName]}
diff --git a/packages/ui/components/navigation/tabs/VerticalTabItem.tsx b/packages/ui/components/navigation/tabs/VerticalTabItem.tsx index 0b6e566d3e..f3a98a9c75 100644 --- a/packages/ui/components/navigation/tabs/VerticalTabItem.tsx +++ b/packages/ui/components/navigation/tabs/VerticalTabItem.tsx @@ -25,9 +25,10 @@ export type VerticalTabItemProps = { isExternalLink?: boolean; linkProps?: Omit, "href">; avatar?: string; + iconClassName?: string; }; -const VerticalTabItem = function ({ +const VerticalTabItem = ({ name, href, info, @@ -35,11 +36,10 @@ const VerticalTabItem = function ({ disableChevron, linkProps, ...props -}: VerticalTabItemProps) { +}: VerticalTabItemProps) => { const { t } = useLocale(); const { asPath } = useRouter(); const isCurrent = asPath.startsWith(href); - return ( {!props.hidden && ( @@ -60,7 +60,12 @@ const VerticalTabItem = function ({ data-testid={`vertical-tab-${name}`} aria-current={isCurrent ? "page" : undefined}> {props.icon && ( - + )}
diff --git a/packages/ui/components/navigation/tabs/VerticalTabs.tsx b/packages/ui/components/navigation/tabs/VerticalTabs.tsx index bec1c6e720..8d6d4d66a7 100644 --- a/packages/ui/components/navigation/tabs/VerticalTabs.tsx +++ b/packages/ui/components/navigation/tabs/VerticalTabs.tsx @@ -12,9 +12,18 @@ export interface NavTabProps { sticky?: boolean; linkProps?: VerticalTabItemProps["linkProps"]; itemClassname?: string; + iconClassName?: string; } -const NavTabs = function ({ tabs, className = "", sticky, linkProps, itemClassname, ...props }: NavTabProps) { +const NavTabs = function ({ + tabs, + className = "", + sticky, + linkProps, + itemClassname, + iconClassName, + ...props +}: NavTabProps) { return ( );