refactor: event type settings (#11539)

Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-09-28 12:59:06 +01:00
1 parent ab17cb216f
commit ef45cbfb3f
15 files changed
+861 -686

No files matched your search

+148 -112
View File
@@ -34,7 +34,7 @@ import {
TextField, TextField,
Tooltip, Tooltip,
} from "@calcom/ui"; } from "@calcom/ui";
import { Copy, Edit } from "@calcom/ui/components/icon"; import { Copy, Edit, Info } from "@calcom/ui/components/icon";
import { IS_VISUAL_REGRESSION_TESTING } from "@calcom/web/constants"; import { IS_VISUAL_REGRESSION_TESTING } from "@calcom/web/constants";
import RequiresConfirmationController from "./RequiresConfirmationController"; import RequiresConfirmationController from "./RequiresConfirmationController";
@@ -124,79 +124,81 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
const setEventName = (value: string) => formMethods.setValue("eventName", value); const setEventName = (value: string) => formMethods.setValue("eventName", value);
return ( return (
<div className="flex flex-col space-y-8"> <div className="flex flex-col space-y-4">
{/** {/**
* Only display calendar selector if user has connected calendars AND if it's not * Only display calendar selector if user has connected calendars AND if it's not
* a team event. Since we don't have logic to handle each attendee calendar (for now). * a team event. Since we don't have logic to handle each attendee calendar (for now).
* This will fallback to each user selected destination calendar. * This will fallback to each user selected destination calendar.
*/} */}
{!!connectedCalendarsQuery.data?.connectedCalendars.length && !team && ( <div className="border-subtle space-y-6 rounded-md border p-6">
<div className="flex flex-col"> {!!connectedCalendarsQuery.data?.connectedCalendars.length && !team && (
<div className="flex justify-between"> <div className="flex flex-col">
<Label>{t("add_to_calendar")}</Label> <div className="flex justify-between">
<Link <Label className="font-medium">{t("add_to_calendar")}</Label>
href="/apps/categories/calendar" <Link
target="_blank" href="/apps/categories/calendar"
className="hover:text-emphasis text-default text-sm"> target="_blank"
{t("add_another_calendar")} className="hover:text-emphasis text-default text-sm">
</Link> {t("add_another_calendar")}
</Link>
</div>
<div className="-mt-1 w-full">
<Controller
control={formMethods.control}
name="destinationCalendar"
defaultValue={eventType.destinationCalendar || undefined}
render={({ field: { onChange, value } }) => (
<DestinationCalendarSelector
destinationCalendar={eventType.destinationCalendar}
value={value ? value.externalId : undefined}
onChange={onChange}
hidePlaceholder
/>
)}
/>
</div>
<p className="text-subtle text-sm">{t("select_which_cal")}</p>
</div> </div>
<div className="-mt-1 w-full"> )}
<Controller <div className="w-full">
control={formMethods.control} <TextField
name="destinationCalendar" label={t("event_name_in_calendar")}
defaultValue={eventType.destinationCalendar || undefined} type="text"
render={({ field: { onChange, value } }) => ( {...shouldLockDisableProps("eventName")}
<DestinationCalendarSelector placeholder={eventNamePlaceholder}
destinationCalendar={eventType.destinationCalendar} defaultValue={eventType.eventName || ""}
value={value ? value.externalId : undefined} {...formMethods.register("eventName")}
onChange={onChange} addOnSuffix={
hidePlaceholder <Button
/> color="minimal"
)} size="sm"
/> aria-label="edit custom name"
</div> className="hover:stroke-3 hover:text-emphasis min-w-fit !py-0 px-0 hover:bg-transparent"
<p className="text-default text-sm">{t("select_which_cal")}</p> onClick={() => setShowEventNameTip((old) => !old)}>
<Edit className="h-4 w-4" />
</Button>
}
/>
</div> </div>
)} </div>
<div className="w-full">
<TextField <BookerLayoutSelector fallbackToUserSettings isDark={selectedThemeIsDark} />
label={t("event_name_in_calendar")}
type="text" <div className="border-subtle space-y-6 rounded-md border p-6">
{...shouldLockDisableProps("eventName")} <FormBuilder
placeholder={eventNamePlaceholder} title={t("booking_questions_title")}
defaultValue={eventType.eventName || ""} description={t("booking_questions_description")}
{...formMethods.register("eventName")} addFieldLabel={t("add_a_booking_question")}
addOnSuffix={ formProp="bookingFields"
<Button {...shouldLockDisableProps("bookingFields")}
color="minimal" dataStore={{
size="sm" options: {
aria-label="edit custom name" locations: getLocationsOptionsForSelect(eventType?.locations ?? [], t),
className="hover:stroke-3 hover:text-emphasis min-w-fit !py-0 px-0 hover:bg-transparent" },
onClick={() => setShowEventNameTip((old) => !old)}> }}
<Edit className="h-4 w-4" />
</Button>
}
/> />
</div> </div>
<hr className="border-subtle [&:has(+div:empty)]:hidden" />
<div>
<BookerLayoutSelector fallbackToUserSettings isDark={selectedThemeIsDark} />
</div>
<hr className="border-subtle" />
<FormBuilder
title={t("booking_questions_title")}
description={t("booking_questions_description")}
addFieldLabel={t("add_a_booking_question")}
formProp="bookingFields"
{...shouldLockDisableProps("bookingFields")}
dataStore={{
options: {
locations: getLocationsOptionsForSelect(eventType?.locations ?? [], t),
},
}}
/>
<hr className="border-subtle" />
<RequiresConfirmationController <RequiresConfirmationController
eventType={eventType} eventType={eventType}
seatsEnabled={seatsEnabled} seatsEnabled={seatsEnabled}
@@ -204,13 +206,15 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
requiresConfirmation={requiresConfirmation} requiresConfirmation={requiresConfirmation}
onRequiresConfirmation={setRequiresConfirmation} onRequiresConfirmation={setRequiresConfirmation}
/> />
<hr className="border-subtle" />
<Controller <Controller
name="requiresBookerEmailVerification" name="requiresBookerEmailVerification"
control={formMethods.control} control={formMethods.control}
defaultValue={eventType.requiresBookerEmailVerification} defaultValue={eventType.requiresBookerEmailVerification}
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName="border-subtle rounded-md border py-6 px-4 sm:px-6"
title={t("requires_booker_email_verification")} title={t("requires_booker_email_verification")}
{...shouldLockDisableProps("requiresBookerEmailVerification")} {...shouldLockDisableProps("requiresBookerEmailVerification")}
description={t("description_requires_booker_email_verification")} description={t("description_requires_booker_email_verification")}
@@ -219,13 +223,15 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
/> />
)} )}
/> />
<hr className="border-subtle" />
<Controller <Controller
name="hideCalendarNotes" name="hideCalendarNotes"
control={formMethods.control} control={formMethods.control}
defaultValue={eventType.hideCalendarNotes} defaultValue={eventType.hideCalendarNotes}
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName="border-subtle rounded-md border py-6 px-4 sm:px-6"
title={t("disable_notes")} title={t("disable_notes")}
{...shouldLockDisableProps("hideCalendarNotes")} {...shouldLockDisableProps("hideCalendarNotes")}
description={t("disable_notes_description")} description={t("disable_notes_description")}
@@ -234,13 +240,19 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
/> />
)} )}
/> />
<hr className="border-subtle" />
<Controller <Controller
name="successRedirectUrl" name="successRedirectUrl"
control={formMethods.control} control={formMethods.control}
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<> <>
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName={classNames(
"border-subtle rounded-md border py-6 px-4 sm:px-6",
redirectUrlVisible && "rounded-b-none"
)}
childrenClassName="lg:ml-0"
title={t("redirect_success_booking")} title={t("redirect_success_booking")}
{...successRedirectUrlLocked} {...successRedirectUrlLocked}
description={t("redirect_url_description")} description={t("redirect_url_description")}
@@ -249,8 +261,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
setRedirectUrlVisible(e); setRedirectUrlVisible(e);
onChange(e ? value : ""); onChange(e ? value : "");
}}> }}>
{/* Textfield has some margin by default we remove that so we can keep consistent alignment */} <div className="border-subtle rounded-b-md border border-t-0 p-6">
<div className="lg:-mb-2 lg:-ml-2">
<TextField <TextField
className="w-full" className="w-full"
label={t("redirect_success_booking")} label={t("redirect_success_booking")}
@@ -274,10 +285,24 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
</> </>
)} )}
/> />
<hr className="border-subtle" />
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName={classNames(
"border-subtle rounded-md border py-6 px-4 sm:px-6",
hashedLinkVisible && "rounded-b-none"
)}
childrenClassName="lg:ml-0"
data-testid="hashedLinkCheck" data-testid="hashedLinkCheck"
title={t("private_link")} title={t("private_link")}
Badge={
<a
target="_blank"
rel="noreferrer"
href="https://cal.com/docs/core-features/event-types/single-use-private-links">
<Info className="mb-2 ml-1.5 h-4 w-4 cursor-pointer" />
</a>
}
{...shouldLockDisableProps("hashedLinkCheck")} {...shouldLockDisableProps("hashedLinkCheck")}
description={t("private_link_description", { appName: APP_NAME })} description={t("private_link_description", { appName: APP_NAME })}
checked={hashedLinkVisible} checked={hashedLinkVisible}
@@ -285,8 +310,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
formMethods.setValue("hashedLink", e ? hashedUrl : undefined); formMethods.setValue("hashedLink", e ? hashedUrl : undefined);
setHashedLinkVisible(e); setHashedLinkVisible(e);
}}> }}>
{/* Textfield has some margin by default we remove that so we can keep consitant aligment */} <div className="border-subtle rounded-b-md border border-t-0 p-6">
<div className="lg:-ml-2">
{!IS_VISUAL_REGRESSION_TESTING && ( {!IS_VISUAL_REGRESSION_TESTING && (
<TextField <TextField
disabled disabled
@@ -321,7 +345,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
)} )}
</div> </div>
</SettingsToggle> </SettingsToggle>
<hr className="border-subtle" />
<Controller <Controller
name="seatsPerTimeSlotEnabled" name="seatsPerTimeSlotEnabled"
control={formMethods.control} control={formMethods.control}
@@ -329,6 +353,12 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<> <>
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName={classNames(
"border-subtle rounded-md border py-6 px-4 sm:px-6",
value && "rounded-b-none"
)}
childrenClassName="lg:ml-0"
data-testid="offer-seats-toggle" data-testid="offer-seats-toggle"
title={t("offer_seats")} title={t("offer_seats")}
{...seatsLocked} {...seatsLocked}
@@ -349,45 +379,49 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
} }
onChange(e); onChange(e);
}}> }}>
<Controller <div className="border-subtle rounded-b-md border border-t-0 p-6">
name="seatsPerTimeSlot" <Controller
control={formMethods.control} name="seatsPerTimeSlot"
defaultValue={eventType.seatsPerTimeSlot} control={formMethods.control}
render={({ field: { value, onChange } }) => ( defaultValue={eventType.seatsPerTimeSlot}
<div className="lg:-ml-2"> render={({ field: { value, onChange } }) => (
<TextField <div className="lg:-ml-2">
required <TextField
name="seatsPerTimeSlot" required
labelSrOnly name="seatsPerTimeSlot"
label={t("number_of_seats")} labelSrOnly
type="number" label={t("number_of_seats")}
disabled={seatsLocked.disabled} type="number"
defaultValue={value || 2}
min={1}
addOnSuffix={<>{t("seats")}</>}
onChange={(e) => {
onChange(Math.abs(Number(e.target.value)));
}}
/>
<div className="mt-2">
<CheckboxField
description={t("show_attendees")}
disabled={seatsLocked.disabled} disabled={seatsLocked.disabled}
onChange={(e) => formMethods.setValue("seatsShowAttendees", e.target.checked)} defaultValue={value || 2}
defaultChecked={!!eventType.seatsShowAttendees} min={1}
addOnSuffix={<>{t("seats")}</>}
onChange={(e) => {
onChange(Math.abs(Number(e.target.value)));
}}
/> />
<div className="mt-2">
<CheckboxField
description={t("show_attendees")}
disabled={seatsLocked.disabled}
onChange={(e) => formMethods.setValue("seatsShowAttendees", e.target.checked)}
defaultChecked={!!eventType.seatsShowAttendees}
/>
</div>
<div className="mt-2">
<CheckboxField
description={t("show_available_seats_count")}
disabled={seatsLocked.disabled}
onChange={(e) =>
formMethods.setValue("seatsShowAvailabilityCount", e.target.checked)
}
defaultChecked={!!eventType.seatsShowAvailabilityCount}
/>
</div>
</div> </div>
<div className="mt-2"> )}
<CheckboxField />
description={t("show_available_seats_count")} </div>
disabled={seatsLocked.disabled}
onChange={(e) => formMethods.setValue("seatsShowAvailabilityCount", e.target.checked)}
defaultChecked={!!eventType.seatsShowAvailabilityCount}
/>
</div>
</div>
)}
/>
</SettingsToggle> </SettingsToggle>
{noShowFeeEnabled && <Alert severity="warning" title={t("seats_and_no_show_fee_error")} />} {noShowFeeEnabled && <Alert severity="warning" title={t("seats_and_no_show_fee_error")} />}
</> </>
@@ -395,13 +429,14 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
/> />
{allowDisablingAttendeeConfirmationEmails(workflows) && ( {allowDisablingAttendeeConfirmationEmails(workflows) && (
<> <>
<hr className="border-subtle" />
<Controller <Controller
name="metadata.disableStandardEmails.confirmation.attendee" name="metadata.disableStandardEmails.confirmation.attendee"
control={formMethods.control} control={formMethods.control}
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<> <>
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName="border-subtle rounded-md border py-6 px-4 sm:px-6"
title={t("disable_attendees_confirmation_emails")} title={t("disable_attendees_confirmation_emails")}
description={t("disable_attendees_confirmation_emails_description")} description={t("disable_attendees_confirmation_emails_description")}
checked={value || false} checked={value || false}
@@ -417,7 +452,6 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
)} )}
{allowDisablingHostConfirmationEmails(workflows) && ( {allowDisablingHostConfirmationEmails(workflows) && (
<> <>
<hr className="border-subtle" />
<Controller <Controller
name="metadata.disableStandardEmails.confirmation.host" name="metadata.disableStandardEmails.confirmation.host"
control={formMethods.control} control={formMethods.control}
@@ -425,6 +459,8 @@ export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps,
render={({ field: { value, onChange } }) => ( render={({ field: { value, onChange } }) => (
<> <>
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName="border-subtle rounded-md border py-6 px-4 sm:px-6"
title={t("disable_host_confirmation_emails")} title={t("disable_host_confirmation_emails")}
description={t("disable_host_confirmation_emails_description")} description={t("disable_host_confirmation_emails_description")}
checked={value || false} checked={value || false}
@@ -158,7 +158,7 @@ export const EventAppsTab = ({ eventType }: { eventType: EventType }) => {
</div> </div>
</div> </div>
{!shouldLockDisableProps("apps").disabled && ( {!shouldLockDisableProps("apps").disabled && (
<div className="bg-muted rounded-md p-8"> <div className="bg-muted mt-6 rounded-md p-8">
{!isLoading && notInstalledApps?.length ? ( {!isLoading && notInstalledApps?.length ? (
<> <>
<h2 className="text-emphasis mb-2 text-xl font-semibold leading-5 tracking-[0.01em]"> <h2 className="text-emphasis mb-2 text-xl font-semibold leading-5 tracking-[0.01em]">
@@ -166,7 +166,7 @@ export const EventAppsTab = ({ eventType }: { eventType: EventType }) => {
</h2> </h2>
<p className="text-default mb-6 text-sm font-normal"> <p className="text-default mb-6 text-sm font-normal">
<Trans i18nKey="available_apps_desc"> <Trans i18nKey="available_apps_desc">
You have no apps installed. View popular apps below and explore more in our &nbsp; View popular apps below and explore more in our &nbsp;
<Link className="cursor-pointer underline" href="/apps"> <Link className="cursor-pointer underline" href="/apps">
App Store App Store
</Link> </Link>
@@ -98,42 +98,43 @@ const EventTypeScheduleDetails = memo(
schedule?.schedule.filter((item) => item.days.includes((dayNum + 1) % 7)) || []; schedule?.schedule.filter((item) => item.days.includes((dayNum + 1) % 7)) || [];
return ( return (
<div className="border-default space-y-4 rounded border px-6 pb-4"> <div>
<ol className="table border-collapse text-sm"> <div className="border-subtle space-y-4 border-x p-6">
{weekdayNames(i18n.language, 1, "long").map((day, index) => { <ol className="table border-collapse text-sm">
const isAvailable = !!filterDays(index).length; {weekdayNames(i18n.language, 1, "long").map((day, index) => {
return ( const isAvailable = !!filterDays(index).length;
<li key={day} className="my-6 flex border-transparent last:mb-2"> return (
<span <li key={day} className="my-6 flex border-transparent last:mb-2">
className={classNames( <span
"w-20 font-medium sm:w-32 ", className={classNames(
!isAvailable ? "text-subtle line-through" : "text-default" "w-20 font-medium sm:w-32 ",
)}> !isAvailable ? "text-subtle line-through" : "text-default"
{day} )}>
</span> {day}
{isLoading ? ( </span>
<SkeletonText className="block h-5 w-60" /> {isLoading ? (
) : isAvailable ? ( <SkeletonText className="block h-5 w-60" />
<div className="space-y-3 text-right"> ) : isAvailable ? (
{filterDays(index).map((dayRange, i) => ( <div className="space-y-3 text-right">
<div key={i} className="text-default flex items-center leading-4"> {filterDays(index).map((dayRange, i) => (
<span className="w-16 sm:w-28 sm:text-left"> <div key={i} className="text-default flex items-center leading-4">
{format(dayRange.startTime, timeFormat === 12)} <span className="w-16 sm:w-28 sm:text-left">
</span> {format(dayRange.startTime, timeFormat === 12)}
<span className="ms-4">-</span> </span>
<div className="ml-6 sm:w-28">{format(dayRange.endTime, timeFormat === 12)}</div> <span className="ms-4">-</span>
</div> <div className="ml-6 sm:w-28">{format(dayRange.endTime, timeFormat === 12)}</div>
))} </div>
</div> ))}
) : ( </div>
<span className="text-subtle ml-6 sm:ml-0">{t("unavailable")}</span> ) : (
)} <span className="text-subtle ml-6 sm:ml-0">{t("unavailable")}</span>
</li> )}
); </li>
})} );
</ol> })}
<hr className="border-subtle" /> </ol>
<div className="flex flex-col justify-center gap-2 sm:flex-row sm:justify-between"> </div>
<div className="bg-muted border-subtle flex flex-col justify-center gap-2 rounded-b-md border p-6 sm:flex-row sm:justify-between">
<span className="text-default flex items-center justify-center text-sm sm:justify-start"> <span className="text-default flex items-center justify-center text-sm sm:justify-start">
<Globe className="h-3.5 w-3.5 ltr:mr-2 rtl:ml-2" /> <Globe className="h-3.5 w-3.5 ltr:mr-2 rtl:ml-2" />
{schedule?.timeZone || <SkeletonText className="block h-5 w-32" />} {schedule?.timeZone || <SkeletonText className="block h-5 w-32" />}
@@ -234,8 +235,8 @@ const EventTypeSchedule = ({ eventType }: { eventType: EventTypeSetup }) => {
}, [availabilityValue, setValue]); }, [availabilityValue, setValue]);
return ( return (
<div className="space-y-4"> <div>
<div> <div className="border-subtle rounded-t-md border p-6">
<label htmlFor="availability" className="text-default mb-2 block text-sm font-medium leading-none"> <label htmlFor="availability" className="text-default mb-2 block text-sm font-medium leading-none">
{t("availability")} {t("availability")}
{shouldLockIndicator("availability")} {shouldLockIndicator("availability")}
+203 -158
View File
@@ -17,7 +17,7 @@ import { ascendingLimitKeys, intervalLimitKeyToUnit } from "@calcom/lib/interval
import type { PeriodType } from "@calcom/prisma/enums"; import type { PeriodType } from "@calcom/prisma/enums";
import type { IntervalLimit } from "@calcom/types/Calendar"; import type { IntervalLimit } from "@calcom/types/Calendar";
import { Button, DateRangePicker, InputField, Label, Select, SettingsToggle, TextField } from "@calcom/ui"; import { Button, DateRangePicker, InputField, Label, Select, SettingsToggle, TextField } from "@calcom/ui";
import { Plus, Trash } from "@calcom/ui/components/icon"; import { Plus, Trash2 } from "@calcom/ui/components/icon";
const MinimumBookingNoticeInput = React.forwardRef< const MinimumBookingNoticeInput = React.forwardRef<
HTMLInputElement, HTMLInputElement,
@@ -83,14 +83,14 @@ const MinimumBookingNoticeInput = React.forwardRef<
type="number" type="number"
placeholder="0" placeholder="0"
min={0} min={0}
className="mb-0 h-[38px] rounded-[4px] ltr:mr-2 rtl:ml-2" className="mb-0 h-9 rounded-[4px] ltr:mr-2 rtl:ml-2"
/> />
<input type="hidden" ref={ref} {...passThroughProps} /> <input type="hidden" ref={ref} {...passThroughProps} />
</div> </div>
<Select <Select
isSearchable={false} isSearchable={false}
isDisabled={passThroughProps.disabled} isDisabled={passThroughProps.disabled}
className="mb-0 ml-2 h-[38px] w-full capitalize md:min-w-[150px] md:max-w-[200px]" className="mb-0 ml-2 h-9 w-full capitalize md:min-w-[150px] md:max-w-[200px]"
defaultValue={durationTypeOptions.find( defaultValue={durationTypeOptions.find(
(option) => option.value === minimumBookingNoticeDisplayValues.type (option) => option.value === minimumBookingNoticeDisplayValues.type
)} )}
@@ -170,8 +170,8 @@ export const EventLimitsTab = ({ eventType }: Pick<EventTypeSetupProps, "eventTy
const offsetAdjustedTime = new Date(offsetOriginalTime.getTime() + offsetStartValue * 60 * 1000); const offsetAdjustedTime = new Date(offsetOriginalTime.getTime() + offsetStartValue * 60 * 1000);
return ( return (
<div className="space-y-8"> <div>
<div className="space-y-4 lg:space-y-8"> <div className="border-subtle space-y-6 rounded-md border p-6">
<div className="flex flex-col space-y-4 lg:flex-row lg:space-x-4 lg:space-y-0"> <div className="flex flex-col space-y-4 lg:flex-row lg:space-x-4 lg:space-y-0">
<div className="w-full"> <div className="w-full">
<Label htmlFor="beforeBufferTime"> <Label htmlFor="beforeBufferTime">
@@ -295,159 +295,195 @@ export const EventLimitsTab = ({ eventType }: Pick<EventTypeSetupProps, "eventTy
</div> </div>
</div> </div>
</div> </div>
<hr className="border-subtle" />
<Controller <Controller
name="bookingLimits" name="bookingLimits"
control={formMethods.control} control={formMethods.control}
render={({ field: { value } }) => ( render={({ field: { value } }) => {
<SettingsToggle const isChecked = Object.keys(value ?? {}).length > 0;
title={t("limit_booking_frequency")} return (
{...bookingLimitsLocked} <SettingsToggle
description={t("limit_booking_frequency_description")} toggleSwitchAtTheEnd={true}
checked={Object.keys(value ?? {}).length > 0} title={t("limit_booking_frequency")}
onCheckedChange={(active) => { {...bookingLimitsLocked}
if (active) { description={t("limit_booking_frequency_description")}
formMethods.setValue("bookingLimits", { checked={isChecked}
PER_DAY: 1, onCheckedChange={(active) => {
}); if (active) {
} else { formMethods.setValue("bookingLimits", {
formMethods.setValue("bookingLimits", {}); PER_DAY: 1,
} });
}}> } else {
<IntervalLimitsManager formMethods.setValue("bookingLimits", {});
disabled={bookingLimitsLocked.disabled} }
propertyName="bookingLimits" }}
defaultLimit={1} switchContainerClassName={classNames(
step={1} "border-subtle mt-6 rounded-md border py-6 px-4 sm:px-6",
/> isChecked && "rounded-b-none"
</SettingsToggle> )}
)} childrenClassName="lg:ml-0">
<div className="border-subtle rounded-b-md border border-t-0 p-6">
<IntervalLimitsManager
disabled={bookingLimitsLocked.disabled}
propertyName="bookingLimits"
defaultLimit={1}
step={1}
/>
</div>
</SettingsToggle>
);
}}
/> />
<hr className="border-subtle" />
<Controller <Controller
name="durationLimits" name="durationLimits"
control={formMethods.control} control={formMethods.control}
render={({ field: { value } }) => ( render={({ field: { value } }) => {
<SettingsToggle const isChecked = Object.keys(value ?? {}).length > 0;
title={t("limit_total_booking_duration")} return (
description={t("limit_total_booking_duration_description")} <SettingsToggle
{...durationLimitsLocked} toggleSwitchAtTheEnd={true}
checked={Object.keys(value ?? {}).length > 0} switchContainerClassName={classNames(
onCheckedChange={(active) => { "border-subtle mt-6 rounded-md border py-6 px-4 sm:px-6",
if (active) { isChecked && "rounded-b-none"
formMethods.setValue("durationLimits", { )}
PER_DAY: 60, childrenClassName="lg:ml-0"
}); title={t("limit_total_booking_duration")}
} else { description={t("limit_total_booking_duration_description")}
formMethods.setValue("durationLimits", {}); {...durationLimitsLocked}
} checked={isChecked}
}}> onCheckedChange={(active) => {
<IntervalLimitsManager if (active) {
propertyName="durationLimits" formMethods.setValue("durationLimits", {
defaultLimit={60} PER_DAY: 60,
disabled={durationLimitsLocked.disabled} });
step={15} } else {
textFieldSuffix={t("minutes")} formMethods.setValue("durationLimits", {});
/> }
</SettingsToggle> }}>
)} <div className="border-subtle rounded-b-md border border-t-0 p-6">
<IntervalLimitsManager
propertyName="durationLimits"
defaultLimit={60}
disabled={durationLimitsLocked.disabled}
step={15}
textFieldSuffix={t("minutes")}
/>
</div>
</SettingsToggle>
);
}}
/> />
<hr className="border-subtle" />
<Controller <Controller
name="periodType" name="periodType"
control={formMethods.control} control={formMethods.control}
render={({ field: { value } }) => ( render={({ field: { value } }) => {
<SettingsToggle const isChecked = value && value !== "UNLIMITED";
title={t("limit_future_bookings")}
description={t("limit_future_bookings_description")} return (
{...periodTypeLocked} <SettingsToggle
checked={value && value !== "UNLIMITED"} toggleSwitchAtTheEnd={true}
onCheckedChange={(bool) => formMethods.setValue("periodType", bool ? "ROLLING" : "UNLIMITED")}> switchContainerClassName={classNames(
<RadioGroup.Root "border-subtle mt-6 rounded-md border py-6 px-4 sm:px-6",
defaultValue={watchPeriodType} isChecked && "rounded-b-none"
value={watchPeriodType} )}
onValueChange={(val) => formMethods.setValue("periodType", val as PeriodType)}> childrenClassName="lg:ml-0"
{PERIOD_TYPES.filter((opt) => title={t("limit_future_bookings")}
periodTypeLocked.disabled ? watchPeriodType === opt.type : true description={t("limit_future_bookings_description")}
).map((period) => { {...periodTypeLocked}
if (period.type === "UNLIMITED") return null; checked={isChecked}
return ( onCheckedChange={(bool) => formMethods.setValue("periodType", bool ? "ROLLING" : "UNLIMITED")}>
<div <div className="border-subtle rounded-b-md border border-t-0 p-6">
className={classNames( <RadioGroup.Root
"text-default mb-2 flex flex-wrap items-center text-sm", defaultValue={watchPeriodType}
watchPeriodType === "UNLIMITED" && "pointer-events-none opacity-30" value={watchPeriodType}
)} onValueChange={(val) => formMethods.setValue("periodType", val as PeriodType)}>
key={period.type}> {PERIOD_TYPES.filter((opt) =>
{!periodTypeLocked.disabled && ( periodTypeLocked.disabled ? watchPeriodType === opt.type : true
<RadioGroup.Item ).map((period) => {
id={period.type} if (period.type === "UNLIMITED") return null;
value={period.type} return (
className="min-w-4 bg-default border-default flex h-4 w-4 cursor-pointer items-center rounded-full border focus:border-2 focus:outline-none ltr:mr-2 rtl:ml-2"> <div
<RadioGroup.Indicator className="after:bg-inverted relative flex h-4 w-4 items-center justify-center after:block after:h-2 after:w-2 after:rounded-full" /> className={classNames(
</RadioGroup.Item> "text-default mb-2 flex flex-wrap items-center text-sm",
)} watchPeriodType === "UNLIMITED" && "pointer-events-none opacity-30"
{period.prefix ? <span>{period.prefix}&nbsp;</span> : null} )}
{period.type === "ROLLING" && ( key={period.type}>
<div className="flex items-center"> {!periodTypeLocked.disabled && (
<TextField <RadioGroup.Item
labelSrOnly id={period.type}
type="number" value={period.type}
className="border-default my-0 block w-16 text-sm [appearance:textfield] ltr:mr-2 rtl:ml-2" className="min-w-4 bg-default border-default flex h-4 w-4 cursor-pointer items-center rounded-full border focus:border-2 focus:outline-none ltr:mr-2 rtl:ml-2">
placeholder="30" <RadioGroup.Indicator className="after:bg-inverted relative flex h-4 w-4 items-center justify-center after:block after:h-2 after:w-2 after:rounded-full" />
disabled={periodTypeLocked.disabled} </RadioGroup.Item>
{...formMethods.register("periodDays", { valueAsNumber: true })} )}
defaultValue={eventType.periodDays || 30} {period.prefix ? <span>{period.prefix}&nbsp;</span> : null}
/> {period.type === "ROLLING" && (
<Select <div className="flex items-center">
options={optionsPeriod} <TextField
isSearchable={false} labelSrOnly
isDisabled={periodTypeLocked.disabled} type="number"
onChange={(opt) => { className="border-default my-0 block w-16 text-sm [appearance:textfield] ltr:mr-2 rtl:ml-2"
formMethods.setValue( placeholder="30"
"periodCountCalendarDays",
opt?.value.toString() as "0" | "1"
);
}}
defaultValue={
optionsPeriod.find(
(opt) => opt.value === (eventType.periodCountCalendarDays ? 1 : 0)
) ?? optionsPeriod[0]
}
/>
</div>
)}
{period.type === "RANGE" && (
<div className="me-2 ms-2 inline-flex space-x-2 rtl:space-x-reverse">
<Controller
name="periodDates"
control={formMethods.control}
defaultValue={periodDates}
render={() => (
<DateRangePicker
startDate={formMethods.getValues("periodDates").startDate}
endDate={formMethods.getValues("periodDates").endDate}
disabled={periodTypeLocked.disabled} disabled={periodTypeLocked.disabled}
onDatesChange={({ startDate, endDate }) => { {...formMethods.register("periodDays", { valueAsNumber: true })}
formMethods.setValue("periodDates", { defaultValue={eventType.periodDays || 30}
startDate,
endDate,
});
}}
/> />
)} <Select
/> options={optionsPeriod}
isSearchable={false}
isDisabled={periodTypeLocked.disabled}
onChange={(opt) => {
formMethods.setValue(
"periodCountCalendarDays",
opt?.value.toString() as "0" | "1"
);
}}
defaultValue={
optionsPeriod.find(
(opt) => opt.value === (eventType.periodCountCalendarDays ? 1 : 0)
) ?? optionsPeriod[0]
}
/>
</div>
)}
{period.type === "RANGE" && (
<div className="me-2 ms-2 inline-flex space-x-2 rtl:space-x-reverse">
<Controller
name="periodDates"
control={formMethods.control}
defaultValue={periodDates}
render={() => (
<DateRangePicker
startDate={formMethods.getValues("periodDates").startDate}
endDate={formMethods.getValues("periodDates").endDate}
disabled={periodTypeLocked.disabled}
onDatesChange={({ startDate, endDate }) => {
formMethods.setValue("periodDates", {
startDate,
endDate,
});
}}
/>
)}
/>
</div>
)}
{period.suffix ? <span className="me-2 ms-2">&nbsp;{period.suffix}</span> : null}
</div> </div>
)} );
{period.suffix ? <span className="me-2 ms-2">&nbsp;{period.suffix}</span> : null} })}
</div> </RadioGroup.Root>
); </div>
})} </SettingsToggle>
</RadioGroup.Root> );
</SettingsToggle> }}
)}
/> />
<hr className="border-subtle" />
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName={classNames(
"border-subtle mt-6 rounded-md border py-6 px-4 sm:px-6",
offsetToggle && "rounded-b-none"
)}
childrenClassName="lg:ml-0"
title={t("offset_toggle")} title={t("offset_toggle")}
description={t("offset_toggle_description")} description={t("offset_toggle_description")}
{...offsetStartLockedProps} {...offsetStartLockedProps}
@@ -458,18 +494,20 @@ export const EventLimitsTab = ({ eventType }: Pick<EventTypeSetupProps, "eventTy
formMethods.setValue("offsetStart", 0); formMethods.setValue("offsetStart", 0);
} }
}}> }}>
<TextField <div className="border-subtle rounded-b-md border border-t-0 p-6">
required <TextField
type="number" required
{...offsetStartLockedProps} type="number"
label={t("offset_start")} {...offsetStartLockedProps}
{...formMethods.register("offsetStart")} label={t("offset_start")}
addOnSuffix={<>{t("minutes")}</>} {...formMethods.register("offsetStart")}
hint={t("offset_start_description", { addOnSuffix={<>{t("minutes")}</>}
originalTime: offsetOriginalTime.toLocaleTimeString(i18n.language, { timeStyle: "short" }), hint={t("offset_start_description", {
adjustedTime: offsetAdjustedTime.toLocaleTimeString(i18n.language, { timeStyle: "short" }), originalTime: offsetOriginalTime.toLocaleTimeString(i18n.language, { timeStyle: "short" }),
})} adjustedTime: offsetAdjustedTime.toLocaleTimeString(i18n.language, { timeStyle: "short" }),
/> })}
/>
</div>
</SettingsToggle> </SettingsToggle>
</div> </div>
); );
@@ -509,19 +547,19 @@ const IntervalLimitItem = ({
onIntervalSelect, onIntervalSelect,
}: IntervalLimitItemProps) => { }: IntervalLimitItemProps) => {
return ( return (
<div className="mb-2 flex items-center space-x-2 text-sm rtl:space-x-reverse" key={limitKey}> <div className="mb-4 flex max-h-9 items-center space-x-2 text-sm rtl:space-x-reverse" key={limitKey}>
<TextField <TextField
required required
type="number" type="number"
containerClassName={textFieldSuffix ? "w-44 -mb-1" : "w-16 mb-0"} containerClassName={textFieldSuffix ? "w-44 -mb-1" : "w-16 mb-0"}
className="mb-0 !h-auto" className="mb-0"
placeholder={`${value}`} placeholder={`${value}`}
disabled={disabled} disabled={disabled}
min={step} min={step}
step={step} step={step}
defaultValue={value} defaultValue={value}
addOnSuffix={textFieldSuffix} addOnSuffix={textFieldSuffix}
onChange={(e) => onLimitChange(limitKey, parseInt(e.target.value))} onChange={(e) => onLimitChange(limitKey, parseInt(e.target.value || "0", 10))}
/> />
<Select <Select
options={selectOptions} options={selectOptions}
@@ -529,9 +567,16 @@ const IntervalLimitItem = ({
isDisabled={disabled} isDisabled={disabled}
defaultValue={INTERVAL_LIMIT_OPTIONS.find((option) => option.value === limitKey)} defaultValue={INTERVAL_LIMIT_OPTIONS.find((option) => option.value === limitKey)}
onChange={onIntervalSelect} onChange={onIntervalSelect}
className="w-36"
/> />
{hasDeleteButton && !disabled && ( {hasDeleteButton && !disabled && (
<Button variant="icon" StartIcon={Trash} color="destructive" onClick={() => onDelete(limitKey)} /> <Button
variant="icon"
StartIcon={Trash2}
color="destructive"
className="border-none"
onClick={() => onDelete(limitKey)}
/>
)} )}
</div> </div>
); );
+171 -164
View File
@@ -387,178 +387,185 @@ export const EventSetupTab = (
return ( return (
<div> <div>
<div className="space-y-8"> <div className="space-y-4">
<TextField <div className="border-subtle space-y-6 rounded-md border p-6">
required
label={t("title")}
{...shouldLockDisableProps("title")}
defaultValue={eventType.title}
{...formMethods.register("title")}
/>
<div>
<Label>
{t("description")}
{shouldLockIndicator("description")}
</Label>
<DescriptionEditor
description={eventType?.description}
editable={!descriptionLockedProps.disabled}
/>
</div>
<TextField
required
label={t("URL")}
{...shouldLockDisableProps("slug")}
defaultValue={eventType.slug}
addOnLeading={
<>
{urlPrefix}/
{!isManagedEventType
? team
? (orgBranding ? "" : "team/") + team.slug
: eventType.users[0].username
: t("username_placeholder")}
/
</>
}
{...formMethods.register("slug", {
setValueAs: (v) => slugify(v),
})}
/>
{multipleDuration ? (
<div className="space-y-4">
<div>
<Skeleton as={Label} loadingClassName="w-16">
{t("available_durations")}
</Skeleton>
<Select
isMulti
defaultValue={selectedMultipleDuration}
name="metadata.multipleDuration"
isSearchable={false}
className="h-auto !min-h-[36px] text-sm"
options={multipleDurationOptions}
value={selectedMultipleDuration}
onChange={(options) => {
let newOptions = [...options];
newOptions = newOptions.sort((a, b) => {
return a?.value - b?.value;
});
const values = newOptions.map((opt) => opt.value);
setMultipleDuration(values);
setSelectedMultipleDuration(newOptions);
if (!newOptions.find((opt) => opt.value === defaultDuration?.value)) {
if (newOptions.length > 0) {
setDefaultDuration(newOptions[0]);
formMethods.setValue("length", newOptions[0].value);
} else {
setDefaultDuration(null);
}
}
if (newOptions.length === 1 && defaultDuration === null) {
setDefaultDuration(newOptions[0]);
formMethods.setValue("length", newOptions[0].value);
}
formMethods.setValue("metadata.multipleDuration", values);
}}
/>
</div>
<div>
<Skeleton as={Label} loadingClassName="w-16">
{t("default_duration")}
{shouldLockIndicator("length")}
</Skeleton>
<Select
value={defaultDuration}
isSearchable={false}
name="length"
className="text-sm"
isDisabled={lengthLockedProps.disabled}
noOptionsMessage={() => t("default_duration_no_options")}
options={selectedMultipleDuration}
onChange={(option) => {
setDefaultDuration(
selectedMultipleDuration.find((opt) => opt.value === option?.value) ?? null
);
if (option) formMethods.setValue("length", option.value);
}}
/>
</div>
</div>
) : (
<TextField <TextField
required required
type="number" label={t("title")}
{...lengthLockedProps} {...shouldLockDisableProps("title")}
label={t("duration")} defaultValue={eventType.title}
defaultValue={eventType.length ?? 15} {...formMethods.register("title")}
{...formMethods.register("length")}
addOnSuffix={<>{t("minutes")}</>}
min={1}
/> />
)} <div>
{!lengthLockedProps.disabled && ( <Label>
<div className="!mt-4 [&_label]:my-1 [&_label]:font-normal"> {t("description")}
<SettingsToggle {shouldLockIndicator("description")}
title={t("allow_booker_to_select_duration")} </Label>
checked={multipleDuration !== undefined} <DescriptionEditor
disabled={seatsEnabled} description={eventType?.description}
tooltip={seatsEnabled ? t("seat_options_doesnt_multiple_durations") : undefined} editable={!descriptionLockedProps.disabled}
onCheckedChange={() => {
if (multipleDuration !== undefined) {
setMultipleDuration(undefined);
formMethods.setValue("metadata.multipleDuration", undefined);
formMethods.setValue("length", eventType.length);
} else {
setMultipleDuration([]);
formMethods.setValue("metadata.multipleDuration", []);
formMethods.setValue("length", 0);
}
}}
/> />
</div> </div>
)} <TextField
<div> required
<Skeleton as={Label} loadingClassName="w-16"> label={t("URL")}
{t("location")} {...shouldLockDisableProps("slug")}
{shouldLockIndicator("locations")} defaultValue={eventType.slug}
</Skeleton> addOnLeading={
<>
<Controller {urlPrefix}/
name="locations" {!isManagedEventType
control={formMethods.control} ? team
defaultValue={eventType.locations || []} ? (orgBranding ? "" : "team/") + team.slug
render={() => <Locations />} : eventType.users[0].username
: t("username_placeholder")}
/
</>
}
{...formMethods.register("slug", {
setValueAs: (v) => slugify(v),
})}
/> />
</div> </div>
</div> <div className="border-subtle rounded-md border p-6">
{multipleDuration ? (
<div className="space-y-6">
<div>
<Skeleton as={Label} loadingClassName="w-16">
{t("available_durations")}
</Skeleton>
<Select
isMulti
defaultValue={selectedMultipleDuration}
name="metadata.multipleDuration"
isSearchable={false}
className="h-auto !min-h-[36px] text-sm"
options={multipleDurationOptions}
value={selectedMultipleDuration}
onChange={(options) => {
let newOptions = [...options];
newOptions = newOptions.sort((a, b) => {
return a?.value - b?.value;
});
const values = newOptions.map((opt) => opt.value);
setMultipleDuration(values);
setSelectedMultipleDuration(newOptions);
if (!newOptions.find((opt) => opt.value === defaultDuration?.value)) {
if (newOptions.length > 0) {
setDefaultDuration(newOptions[0]);
formMethods.setValue("length", newOptions[0].value);
} else {
setDefaultDuration(null);
}
}
if (newOptions.length === 1 && defaultDuration === null) {
setDefaultDuration(newOptions[0]);
formMethods.setValue("length", newOptions[0].value);
}
formMethods.setValue("metadata.multipleDuration", values);
}}
/>
</div>
<div>
<Skeleton as={Label} loadingClassName="w-16">
{t("default_duration")}
{shouldLockIndicator("length")}
</Skeleton>
<Select
value={defaultDuration}
isSearchable={false}
name="length"
className="text-sm"
isDisabled={lengthLockedProps.disabled}
noOptionsMessage={() => t("default_duration_no_options")}
options={selectedMultipleDuration}
onChange={(option) => {
setDefaultDuration(
selectedMultipleDuration.find((opt) => opt.value === option?.value) ?? null
);
if (option) formMethods.setValue("length", option.value);
}}
/>
</div>
</div>
) : (
<TextField
required
type="number"
{...lengthLockedProps}
label={t("duration")}
defaultValue={eventType.length ?? 15}
{...formMethods.register("length")}
addOnSuffix={<>{t("minutes")}</>}
min={1}
/>
)}
{!lengthLockedProps.disabled && (
<div className="!mt-4 [&_label]:my-1 [&_label]:font-normal">
<SettingsToggle
title={t("allow_booker_to_select_duration")}
checked={multipleDuration !== undefined}
disabled={seatsEnabled}
tooltip={seatsEnabled ? t("seat_options_doesnt_multiple_durations") : undefined}
onCheckedChange={() => {
if (multipleDuration !== undefined) {
setMultipleDuration(undefined);
formMethods.setValue("metadata.multipleDuration", undefined);
formMethods.setValue("length", eventType.length);
} else {
setMultipleDuration([]);
formMethods.setValue("metadata.multipleDuration", []);
formMethods.setValue("length", 0);
}
}}
/>
</div>
)}
</div>
{/* We portal this modal so we can submit the form inside. Otherwise we get issues submitting two forms at once */} <div className="border-subtle rounded-md border p-6">
<EditLocationDialog <div>
isOpenDialog={showLocationModal} <Skeleton as={Label} loadingClassName="w-16">
setShowLocationModal={setShowLocationModal} {t("location")}
saveLocation={saveLocation} {shouldLockIndicator("locations")}
defaultValues={formMethods.getValues("locations")} </Skeleton>
selection={
selectedLocation <Controller
? selectedLocation.address name="locations"
? { control={formMethods.control}
value: selectedLocation.value, defaultValue={eventType.locations || []}
label: t(selectedLocation.label), render={() => <Locations />}
icon: selectedLocation.icon, />
address: selectedLocation.address, </div>
} </div>
: {
value: selectedLocation.value, {/* We portal this modal so we can submit the form inside. Otherwise we get issues submitting two forms at once */}
label: t(selectedLocation.label), <EditLocationDialog
icon: selectedLocation.icon, isOpenDialog={showLocationModal}
} setShowLocationModal={setShowLocationModal}
: undefined saveLocation={saveLocation}
} defaultValues={formMethods.getValues("locations")}
setSelectedLocation={setSelectedLocation} selection={
setEditingLocationType={setEditingLocationType} selectedLocation
teamId={eventType.team?.id} ? selectedLocation.address
/> ? {
value: selectedLocation.value,
label: t(selectedLocation.label),
icon: selectedLocation.icon,
address: selectedLocation.address,
}
: {
value: selectedLocation.value,
label: t(selectedLocation.label),
icon: selectedLocation.icon,
}
: undefined
}
setSelectedLocation={setSelectedLocation}
setEditingLocationType={setEditingLocationType}
teamId={eventType.team?.id}
/>
</div>
</div> </div>
); );
}; };
@@ -1,5 +1,7 @@
import type { Webhook } from "@prisma/client"; import type { Webhook } from "@prisma/client";
import { Webhook as TbWebhook } from "lucide-react"; import { Webhook as TbWebhook } from "lucide-react";
import { Trans } from "next-i18next";
import Link from "next/link";
import type { EventTypeSetupProps } from "pages/event-types/[type]"; import type { EventTypeSetupProps } from "pages/event-types/[type]";
import { useState } from "react"; import { useState } from "react";
@@ -8,6 +10,7 @@ import { WebhookForm } from "@calcom/features/webhooks/components";
import type { WebhookFormSubmitData } from "@calcom/features/webhooks/components/WebhookForm"; import type { WebhookFormSubmitData } from "@calcom/features/webhooks/components/WebhookForm";
import WebhookListItem from "@calcom/features/webhooks/components/WebhookListItem"; import WebhookListItem from "@calcom/features/webhooks/components/WebhookListItem";
import { subscriberUrlReserved } from "@calcom/features/webhooks/lib/subscriberUrlReserved"; import { subscriberUrlReserved } from "@calcom/features/webhooks/lib/subscriberUrlReserved";
import { APP_NAME } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react";
import { Alert, Button, Dialog, DialogContent, EmptyScreen, showToast } from "@calcom/ui"; import { Alert, Button, Dialog, DialogContent, EmptyScreen, showToast } from "@calcom/ui";
@@ -115,23 +118,40 @@ export const EventWebhooksTab = ({ eventType }: Pick<EventTypeSetupProps, "event
)} )}
{webhooks.length ? ( {webhooks.length ? (
<> <>
<div className="mb-2 rounded-md border"> <div className="border-subtle mb-2 rounded-md border p-8">
{webhooks.map((webhook, index) => { <div className="text-default text-sm font-semibold">{t("webhooks")}</div>
return ( <p className="text-subtle max-w-[280px] break-words text-sm sm:max-w-[500px]">
<WebhookListItem {t("add_webhook_description", { appName: APP_NAME })}
key={webhook.id} </p>
webhook={webhook}
lastItem={webhooks.length === index + 1} <div className="border-subtle mt-8 rounded-md border">
canEditWebhook={!webhookLockedStatus.disabled} {webhooks.map((webhook, index) => {
onEditWebhook={() => { return (
setEditModalOpen(true); <WebhookListItem
setWebhookToEdit(webhook); key={webhook.id}
}} webhook={webhook}
/> lastItem={webhooks.length === index + 1}
); canEditWebhook={!webhookLockedStatus.disabled}
})} onEditWebhook={() => {
setEditModalOpen(true);
setWebhookToEdit(webhook);
}}
/>
);
})}
</div>
<p className="text-default mt-8 text-sm font-normal">
<Trans i18nKey="edit_or_manage_webhooks">
If you wish to edit or manage your web hooks, please head over to &nbsp;
<Link
className="cursor-pointer font-semibold underline"
href="/settings/developer/webhooks">
webhooks settings
</Link>
</Trans>
</p>
</div> </div>
<NewWebhookButton />
</> </>
) : ( ) : (
<EmptyScreen <EmptyScreen
@@ -3,6 +3,7 @@ import { useState } from "react";
import { useFormContext } from "react-hook-form"; import { useFormContext } from "react-hook-form";
import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager"; import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager";
import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Frequency } from "@calcom/prisma/zod-utils"; import { Frequency } from "@calcom/prisma/zod-utils";
import type { RecurringEvent } from "@calcom/types/Calendar"; import type { RecurringEvent } from "@calcom/types/Calendar";
@@ -47,6 +48,12 @@ export default function RecurringEventController({
) : ( ) : (
<> <>
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName={classNames(
"border-subtle rounded-md border py-6 px-4 sm:px-6",
recurringEventState !== null && "rounded-b-none"
)}
childrenClassName="lg:ml-0"
title={t("recurring_event")} title={t("recurring_event")}
{...recurringLocked} {...recurringLocked}
description={t("recurring_event_description")} description={t("recurring_event_description")}
@@ -66,68 +73,70 @@ export default function RecurringEventController({
setRecurringEventState(newVal); setRecurringEventState(newVal);
} }
}}> }}>
{recurringEventState && ( <div className="border-subtle rounded-b-md border border-t-0 p-6">
<div data-testid="recurring-event-collapsible" className="text-sm"> {recurringEventState && (
<div className="flex items-center"> <div data-testid="recurring-event-collapsible" className="text-sm">
<p className="text-emphasis ltr:mr-2 rtl:ml-2">{t("repeats_every")}</p> <div className="flex items-center">
<TextField <p className="text-emphasis ltr:mr-2 rtl:ml-2">{t("repeats_every")}</p>
disabled={recurringLocked.disabled} <TextField
type="number" disabled={recurringLocked.disabled}
min="1" type="number"
max="20" min="1"
className="mb-0" max="20"
defaultValue={recurringEventState.interval} className="mb-0"
onChange={(event) => { defaultValue={recurringEventState.interval}
const newVal = { onChange={(event) => {
...recurringEventState, const newVal = {
interval: parseInt(event?.target.value), ...recurringEventState,
}; interval: parseInt(event?.target.value),
formMethods.setValue("recurringEvent", newVal); };
setRecurringEventState(newVal); formMethods.setValue("recurringEvent", newVal);
}} setRecurringEventState(newVal);
/> }}
<Select />
options={recurringEventFreqOptions} <Select
value={recurringEventFreqOptions[recurringEventState.freq]} options={recurringEventFreqOptions}
isSearchable={false} value={recurringEventFreqOptions[recurringEventState.freq]}
className="w-18 ml-2 block min-w-0 rounded-md text-sm" isSearchable={false}
isDisabled={recurringLocked.disabled} className="w-18 ml-2 block min-w-0 rounded-md text-sm"
onChange={(event) => { isDisabled={recurringLocked.disabled}
const newVal = { onChange={(event) => {
...recurringEventState, const newVal = {
freq: parseInt(event?.value || `${Frequency.WEEKLY}`), ...recurringEventState,
}; freq: parseInt(event?.value || `${Frequency.WEEKLY}`),
formMethods.setValue("recurringEvent", newVal); };
setRecurringEventState(newVal); formMethods.setValue("recurringEvent", newVal);
}} setRecurringEventState(newVal);
/> }}
/>
</div>
<div className="mt-4 flex items-center">
<p className="text-emphasis ltr:mr-2 rtl:ml-2">{t("for_a_maximum_of")}</p>
<TextField
disabled={recurringLocked.disabled}
type="number"
min="1"
max="20"
defaultValue={recurringEventState.count}
className="mb-0"
onChange={(event) => {
const newVal = {
...recurringEventState,
count: parseInt(event?.target.value),
};
formMethods.setValue("recurringEvent", newVal);
setRecurringEventState(newVal);
}}
/>
<p className="text-emphasis ltr:ml-2 rtl:mr-2">
{t("events", {
count: recurringEventState.count,
})}
</p>
</div>
</div> </div>
<div className="mt-4 flex items-center"> )}
<p className="text-emphasis ltr:mr-2 rtl:ml-2">{t("for_a_maximum_of")}</p> </div>
<TextField
disabled={recurringLocked.disabled}
type="number"
min="1"
max="20"
defaultValue={recurringEventState.count}
className="mb-0"
onChange={(event) => {
const newVal = {
...recurringEventState,
count: parseInt(event?.target.value),
};
formMethods.setValue("recurringEvent", newVal);
setRecurringEventState(newVal);
}}
/>
<p className="text-emphasis ltr:ml-2 rtl:mr-2">
{t("events", {
count: recurringEventState.count,
})}
</p>
</div>
</div>
)}
</SettingsToggle> </SettingsToggle>
</> </>
)} )}
@@ -67,6 +67,12 @@ export default function RequiresConfirmationController({
control={formMethods.control} control={formMethods.control}
render={() => ( render={() => (
<SettingsToggle <SettingsToggle
toggleSwitchAtTheEnd={true}
switchContainerClassName={classNames(
"border-subtle rounded-md border py-6 px-4 sm:px-6",
requiresConfirmation && "rounded-b-none"
)}
childrenClassName="lg:ml-0"
title={t("requires_confirmation")} title={t("requires_confirmation")}
disabled={seatsEnabled || requiresConfirmationLockedProps.disabled} disabled={seatsEnabled || requiresConfirmationLockedProps.disabled}
tooltip={seatsEnabled ? t("seat_options_doesnt_support_confirmation") : undefined} tooltip={seatsEnabled ? t("seat_options_doesnt_support_confirmation") : undefined}
@@ -77,107 +83,111 @@ export default function RequiresConfirmationController({
formMethods.setValue("requiresConfirmation", val); formMethods.setValue("requiresConfirmation", val);
onRequiresConfirmation(val); onRequiresConfirmation(val);
}}> }}>
<RadioGroup.Root <div className="border-subtle rounded-b-md border border-t-0 p-6">
defaultValue={ <RadioGroup.Root
requiresConfirmation defaultValue={
? requiresConfirmationSetup === undefined requiresConfirmation
? "always" ? requiresConfirmationSetup === undefined
: "notice" ? "always"
: undefined : "notice"
} : undefined
onValueChange={(val) => {
if (val === "always") {
formMethods.setValue("requiresConfirmation", true);
onRequiresConfirmation(true);
formMethods.setValue("metadata.requiresConfirmationThreshold", undefined);
setRequiresConfirmationSetup(undefined);
} else if (val === "notice") {
formMethods.setValue("requiresConfirmation", true);
onRequiresConfirmation(true);
formMethods.setValue(
"metadata.requiresConfirmationThreshold",
requiresConfirmationSetup || defaultRequiresConfirmationSetup
);
} }
}}> onValueChange={(val) => {
<div className="flex flex-col flex-wrap justify-start gap-y-2"> if (val === "always") {
{(requiresConfirmationSetup === undefined || !requiresConfirmationLockedProps.disabled) && ( formMethods.setValue("requiresConfirmation", true);
<RadioField onRequiresConfirmation(true);
label={t("always_requires_confirmation")} formMethods.setValue("metadata.requiresConfirmationThreshold", undefined);
disabled={requiresConfirmationLockedProps.disabled} setRequiresConfirmationSetup(undefined);
id="always" } else if (val === "notice") {
value="always" formMethods.setValue("requiresConfirmation", true);
/> onRequiresConfirmation(true);
)} formMethods.setValue(
{(requiresConfirmationSetup !== undefined || !requiresConfirmationLockedProps.disabled) && ( "metadata.requiresConfirmationThreshold",
<RadioField requiresConfirmationSetup || defaultRequiresConfirmationSetup
disabled={requiresConfirmationLockedProps.disabled} );
className="items-center" }
label={ }}>
<> <div className="flex flex-col flex-wrap justify-start gap-y-2">
<Trans {(requiresConfirmationSetup === undefined ||
i18nKey="when_booked_with_less_than_notice" !requiresConfirmationLockedProps.disabled) && (
defaults="When booked with less than <time></time> notice" <RadioField
components={{ label={t("always_requires_confirmation")}
time: ( disabled={requiresConfirmationLockedProps.disabled}
<div className="mx-2 inline-flex"> id="always"
<Input value="always"
type="number" />
min={1} )}
disabled={requiresConfirmationLockedProps.disabled} {(requiresConfirmationSetup !== undefined ||
onChange={(evt) => { !requiresConfirmationLockedProps.disabled) && (
const val = Number(evt.target?.value); <RadioField
setRequiresConfirmationSetup({ disabled={requiresConfirmationLockedProps.disabled}
unit: className="items-center"
requiresConfirmationSetup?.unit ?? label={
defaultRequiresConfirmationSetup.unit, <>
time: val, <Trans
}); i18nKey="when_booked_with_less_than_notice"
formMethods.setValue( defaults="When booked with less than <time></time> notice"
"metadata.requiresConfirmationThreshold.time", components={{
val time: (
); <div className="mx-2 inline-flex">
}} <Input
className="border-default !m-0 block w-16 rounded-md text-sm [appearance:textfield]" type="number"
defaultValue={metadata?.requiresConfirmationThreshold?.time || 30} min={1}
/> disabled={requiresConfirmationLockedProps.disabled}
<label onChange={(evt) => {
className={classNames( const val = Number(evt.target?.value);
requiresConfirmationLockedProps.disabled && "cursor-not-allowed"
)}>
<Select
inputId="notice"
options={options}
isSearchable={false}
isDisabled={requiresConfirmationLockedProps.disabled}
className="ml-2"
onChange={(opt) => {
setRequiresConfirmationSetup({ setRequiresConfirmationSetup({
time: unit:
requiresConfirmationSetup?.time ?? requiresConfirmationSetup?.unit ??
defaultRequiresConfirmationSetup.time, defaultRequiresConfirmationSetup.unit,
unit: opt?.value as UnitTypeLongPlural, time: val,
}); });
formMethods.setValue( formMethods.setValue(
"metadata.requiresConfirmationThreshold.unit", "metadata.requiresConfirmationThreshold.time",
opt?.value as UnitTypeLongPlural val
); );
}} }}
defaultValue={defaultValue} className="border-default !m-0 block w-16 rounded-r-none border-r-0 text-sm [appearance:textfield]"
defaultValue={metadata?.requiresConfirmationThreshold?.time || 30}
/> />
</label> <label
</div> className={classNames(
), requiresConfirmationLockedProps.disabled && "cursor-not-allowed"
}} )}>
/> <Select
</> inputId="notice"
} options={options}
id="notice" isSearchable={false}
value="notice" isDisabled={requiresConfirmationLockedProps.disabled}
/> innerClassNames={{ control: "rounded-l-none bg-subtle" }}
)} onChange={(opt) => {
</div> setRequiresConfirmationSetup({
</RadioGroup.Root> time:
requiresConfirmationSetup?.time ??
defaultRequiresConfirmationSetup.time,
unit: opt?.value as UnitTypeLongPlural,
});
formMethods.setValue(
"metadata.requiresConfirmationThreshold.unit",
opt?.value as UnitTypeLongPlural
);
}}
defaultValue={defaultValue}
/>
</label>
</div>
),
}}
/>
</>
}
id="notice"
value="notice"
/>
)}
</div>
</RadioGroup.Root>
</div>
</SettingsToggle> </SettingsToggle>
)} )}
/> />
+2 -1
View File
@@ -449,7 +449,8 @@ const EventTypePage = (props: EventTypeSetupProps) => {
availability={availability} availability={availability}
isUpdateMutationLoading={updateMutation.isLoading} isUpdateMutationLoading={updateMutation.isLoading}
formMethods={formMethods} formMethods={formMethods}
disableBorder={tabName === "apps" || tabName === "workflows" || tabName === "webhooks"} // disableBorder={tabName === "apps" || tabName === "workflows" || tabName === "webhooks"}
disableBorder={true}
currentUserMembership={currentUserMembership} currentUserMembership={currentUserMembership}
isUserOrganizationAdmin={props.isUserOrganizationAdmin}> isUserOrganizationAdmin={props.isUserOrganizationAdmin}>
<Form <Form
@@ -255,7 +255,7 @@
"yours": "Your account", "yours": "Your account",
"available_apps": "Available Apps", "available_apps": "Available Apps",
"available_apps_lower_case": "Available apps", "available_apps_lower_case": "Available apps",
"available_apps_desc": "You have no apps installed. View popular apps below and explore more in our <1>App Store</1>", "available_apps_desc": "View popular apps below and explore more in our <1>App Store</1>",
"fixed_host_helper": "Add anyone who needs to attend the event. <1>Learn more</1>", "fixed_host_helper": "Add anyone who needs to attend the event. <1>Learn more</1>",
"round_robin_helper":"People in the group take turns and only one person will show up for the event.", "round_robin_helper":"People in the group take turns and only one person will show up for the event.",
"check_email_reset_password": "Check your email. We sent you a link to reset your password.", "check_email_reset_password": "Check your email. We sent you a link to reset your password.",
@@ -6,7 +6,7 @@ import { components } from "react-select";
import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { DestinationCalendar } from "@calcom/prisma/client"; import type { DestinationCalendar } from "@calcom/prisma/client";
import { trpc } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react";
import { Select } from "@calcom/ui"; import { Select, Badge } from "@calcom/ui";
import { Check } from "@calcom/ui/components/icon"; import { Check } from "@calcom/ui/components/icon";
interface Props { interface Props {
@@ -133,9 +133,9 @@ const DestinationCalendarSelector = ({
`${t("create_events_on")}` `${t("create_events_on")}`
) : ( ) : (
<span className="text-default min-w-0 overflow-hidden truncate whitespace-nowrap"> <span className="text-default min-w-0 overflow-hidden truncate whitespace-nowrap">
{t("default_calendar_selected")}{" "} <Badge variant="blue">Default</Badge>{" "}
{queryDestinationCalendar.name && {queryDestinationCalendar.name &&
`| ${queryDestinationCalendar.name} (${queryDestinationCalendar?.integrationTitle} - ${queryDestinationCalendar.primaryEmail})`} `${queryDestinationCalendar.name} (${queryDestinationCalendar?.integrationTitle} - ${queryDestinationCalendar.primaryEmail})`}
</span> </span>
) )
} }
@@ -112,7 +112,7 @@ export const FormBuilder = function FormBuilder({
{LockedIcon} {LockedIcon}
</div> </div>
<p className="text-subtle max-w-[280px] break-words py-1 text-sm sm:max-w-[500px]">{description}</p> <p className="text-subtle max-w-[280px] break-words py-1 text-sm sm:max-w-[500px]">{description}</p>
<ul className="border-default divide-subtle mt-2 divide-y rounded-md border"> <ul className="border-subtle divide-subtle mt-2 divide-y rounded-md border">
{fields.map((field, index) => { {fields.map((field, index) => {
const options = field.options const options = field.options
? field.options ? field.options
@@ -155,7 +155,7 @@ export const FormBuilder = function FormBuilder({
{index >= 1 && ( {index >= 1 && (
<button <button
type="button" type="button"
className="bg-default text-muted hover:text-emphasis disabled:hover:text-muted border-default hover:border-emphasis invisible absolute -left-[12px] -ml-4 -mt-4 mb-4 hidden h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:shadow disabled:hover:border-inherit disabled:hover:shadow-none group-hover:visible group-hover:scale-100 sm:ml-0 sm:flex" className="bg-default text-muted hover:text-emphasis disabled:hover:text-muted border-subtle hover:border-emphasis invisible absolute -left-[12px] -ml-4 -mt-4 mb-4 hidden h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:shadow disabled:hover:border-inherit disabled:hover:shadow-none group-hover:visible group-hover:scale-100 sm:ml-0 sm:flex"
onClick={() => swap(index, index - 1)}> onClick={() => swap(index, index - 1)}>
<ArrowUp className="h-5 w-5" /> <ArrowUp className="h-5 w-5" />
</button> </button>
@@ -163,7 +163,7 @@ export const FormBuilder = function FormBuilder({
{index < fields.length - 1 && ( {index < fields.length - 1 && (
<button <button
type="button" type="button"
className="bg-default text-muted hover:border-emphasis border-default hover:text-emphasis disabled:hover:text-muted invisible absolute -left-[12px] -ml-4 mt-8 hidden h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:shadow disabled:hover:border-inherit disabled:hover:shadow-none group-hover:visible group-hover:scale-100 sm:ml-0 sm:flex" className="bg-default text-muted hover:border-emphasis border-subtle hover:text-emphasis disabled:hover:text-muted invisible absolute -left-[12px] -ml-4 mt-8 hidden h-6 w-6 scale-0 items-center justify-center rounded-md border p-1 transition-all hover:shadow disabled:hover:border-inherit disabled:hover:shadow-none group-hover:visible group-hover:scale-100 sm:ml-0 sm:flex"
onClick={() => swap(index, index + 1)}> onClick={() => swap(index, index + 1)}>
<ArrowDown className="h-5 w-5" /> <ArrowDown className="h-5 w-5" />
</button> </button>
@@ -628,7 +628,7 @@ function VariantFields({
<ul <ul
className={classNames( className={classNames(
!isSimpleVariant ? "border-default divide-subtle mt-2 divide-y rounded-md border" : "" !isSimpleVariant ? "border-subtle divide-subtle mt-2 divide-y rounded-md border" : ""
)}> )}>
{variantFields.map((f, index) => { {variantFields.map((f, index) => {
const rhfVariantFieldPrefix = `variantsConfig.variants.${variantName}.fields.${index}` as const; const rhfVariantFieldPrefix = `variantsConfig.variants.${variantName}.fields.${index}` as const;
@@ -15,7 +15,7 @@ import {
Switch, Switch,
Tooltip, Tooltip,
} from "@calcom/ui"; } from "@calcom/ui";
import { AlertCircle, Edit, MoreHorizontal, Trash } from "@calcom/ui/components/icon"; import { Edit, MoreHorizontal, Trash, Zap } from "@calcom/ui/components/icon";
type WebhookProps = { type WebhookProps = {
id: string; id: string;
@@ -87,7 +87,7 @@ export default function WebhookListItem(props: {
key={trigger} key={trigger}
className="mt-2.5 basis-1/5 ltr:mr-2 rtl:ml-2" className="mt-2.5 basis-1/5 ltr:mr-2 rtl:ml-2"
variant="gray" variant="gray"
startIcon={AlertCircle}> startIcon={Zap}>
{t(`${trigger.toLowerCase()}`)} {t(`${trigger.toLowerCase()}`)}
</Badge> </Badge>
))} ))}
+22 -11
View File
@@ -24,8 +24,19 @@ export const Select = <
menuPlacement, menuPlacement,
variant = "default", variant = "default",
...props ...props
}: SelectProps<Option, IsMulti, Group>) => { }: SelectProps<Option, IsMulti, Group> & {
const { classNames, ...restProps } = props; innerClassNames?: {
input?: string;
option?: string;
control?: string;
singleValue?: string;
valueContainer?: string;
multiValue?: string;
menu?: string;
menuList?: string;
};
}) => {
const { classNames, innerClassNames, ...restProps } = props;
const reactSelectProps = React.useMemo(() => { const reactSelectProps = React.useMemo(() => {
return getReactSelectProps<Option, IsMulti, Group>({ return getReactSelectProps<Option, IsMulti, Group>({
components: components || {}, components: components || {},
@@ -39,14 +50,14 @@ export const Select = <
<ReactSelect <ReactSelect
{...reactSelectProps} {...reactSelectProps}
classNames={{ classNames={{
input: () => cx("text-emphasis", props.classNames?.input), input: () => cx("text-emphasis", innerClassNames?.input),
option: (state) => option: (state) =>
cx( cx(
"bg-default flex cursor-pointer justify-between py-2.5 px-3 rounded-none text-default ", "bg-default flex cursor-pointer justify-between py-2.5 px-3 rounded-none text-default ",
state.isFocused && "bg-subtle", state.isFocused && "bg-subtle",
state.isDisabled && "bg-muted", state.isDisabled && "bg-muted",
state.isSelected && "bg-emphasis text-default", state.isSelected && "bg-emphasis text-default",
props.classNames?.option innerClassNames?.option
), ),
placeholder: (state) => cx("text-muted", state.isFocused && variant !== "checkbox" && "hidden"), placeholder: (state) => cx("text-muted", state.isFocused && variant !== "checkbox" && "hidden"),
dropdownIndicator: () => "text-default", dropdownIndicator: () => "text-default",
@@ -59,25 +70,25 @@ export const Select = <
: state.hasValue : state.hasValue
? "p-1 h-fit" ? "p-1 h-fit"
: "px-3 py-2 h-fit" : "px-3 py-2 h-fit"
: "py-2 px-3 h-fit", : "py-2 px-3",
props.isDisabled && "bg-subtle", props.isDisabled && "bg-subtle",
props.classNames?.control innerClassNames?.control
), ),
singleValue: () => cx("text-emphasis placeholder:text-muted", props.classNames?.singleValue), singleValue: () => cx("text-emphasis placeholder:text-muted", innerClassNames?.singleValue),
valueContainer: () => valueContainer: () =>
cx("text-emphasis placeholder:text-muted flex gap-1", props.classNames?.valueContainer), cx("text-emphasis placeholder:text-muted flex gap-1", innerClassNames?.valueContainer),
multiValue: () => multiValue: () =>
cx( cx(
"bg-subtle text-default rounded-md py-1.5 px-2 flex items-center text-sm leading-none", "bg-subtle text-default rounded-md py-1.5 px-2 flex items-center text-sm leading-none",
props.classNames?.multiValue innerClassNames?.multiValue
), ),
menu: () => menu: () =>
cx( cx(
"rounded-md bg-default text-sm leading-4 text-default mt-1 border border-subtle", "rounded-md bg-default text-sm leading-4 text-default mt-1 border border-subtle",
props.classNames?.menu innerClassNames?.menu
), ),
groupHeading: () => "leading-none text-xs uppercase text-default pl-2.5 pt-4 pb-2", groupHeading: () => "leading-none text-xs uppercase text-default pl-2.5 pt-4 pb-2",
menuList: () => cx("scroll-bar scrollbar-track-w-20 rounded-md", props.classNames?.menuList), menuList: () => cx("scroll-bar scrollbar-track-w-20 rounded-md", innerClassNames?.menuList),
indicatorsContainer: (state) => indicatorsContainer: (state) =>
cx( cx(
state.selectProps.menuIsOpen state.selectProps.menuIsOpen
@@ -1,6 +1,8 @@
import { useAutoAnimate } from "@formkit/auto-animate/react"; import { useAutoAnimate } from "@formkit/auto-animate/react";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import { classNames } from "@calcom/lib";
import { Label } from ".."; import { Label } from "..";
import Switch from "./Switch"; import Switch from "./Switch";
@@ -11,9 +13,13 @@ type Props = {
checked: boolean; checked: boolean;
disabled?: boolean; disabled?: boolean;
LockedIcon?: React.ReactNode; LockedIcon?: React.ReactNode;
Badge?: React.ReactNode;
onCheckedChange?: (checked: boolean) => void; onCheckedChange?: (checked: boolean) => void;
"data-testid"?: string; "data-testid"?: string;
tooltip?: string; tooltip?: string;
toggleSwitchAtTheEnd?: boolean;
childrenClassName?: string;
switchContainerClassName?: string;
}; };
function SettingsToggle({ function SettingsToggle({
@@ -21,10 +27,14 @@ function SettingsToggle({
onCheckedChange, onCheckedChange,
description, description,
LockedIcon, LockedIcon,
Badge,
title, title,
children, children,
disabled, disabled,
tooltip, tooltip,
toggleSwitchAtTheEnd = false,
childrenClassName,
switchContainerClassName,
...rest ...rest
}: Props) { }: Props) {
const [animateRef] = useAutoAnimate<HTMLDivElement>(); const [animateRef] = useAutoAnimate<HTMLDivElement>();
@@ -33,27 +43,52 @@ function SettingsToggle({
<> <>
<div className="flex w-full flex-col space-y-4 lg:flex-row lg:space-x-4 lg:space-y-0"> <div className="flex w-full flex-col space-y-4 lg:flex-row lg:space-x-4 lg:space-y-0">
<fieldset className="block w-full flex-col sm:flex"> <fieldset className="block w-full flex-col sm:flex">
<div className="flex space-x-3"> {toggleSwitchAtTheEnd ? (
<Switch <div className={classNames("flex justify-between space-x-3", switchContainerClassName)}>
data-testid={rest["data-testid"]} <div>
fitToHeight={true} <div className="flex items-center">
checked={checked} <Label className="text-emphasis text-base font-semibold leading-none">
onCheckedChange={onCheckedChange} {title}
disabled={disabled} {LockedIcon}
tooltip={tooltip} </Label>
/> {Badge}
</div>
<div> {description && <p className="text-default -mt-1.5 text-sm leading-normal">{description}</p>}
<Label className="text-emphasis text-sm font-semibold leading-none"> </div>
{title} <div className="my-auto h-full">
{LockedIcon} <Switch
</Label> data-testid={rest["data-testid"]}
{description && <p className="text-default -mt-1.5 text-sm leading-normal">{description}</p>} fitToHeight={true}
checked={checked}
onCheckedChange={onCheckedChange}
disabled={disabled}
tooltip={tooltip}
/>
</div>
</div> </div>
</div> ) : (
<div className="flex space-x-3">
<Switch
data-testid={rest["data-testid"]}
fitToHeight={true}
checked={checked}
onCheckedChange={onCheckedChange}
disabled={disabled}
tooltip={tooltip}
/>
<div>
<Label className="text-emphasis text-sm font-semibold leading-none">
{title}
{LockedIcon}
</Label>
{description && <p className="text-default -mt-1.5 text-sm leading-normal">{description}</p>}
</div>
</div>
)}
{children && ( {children && (
<div className="lg:ml-14" ref={animateRef}> <div className={classNames("lg:ml-14", childrenClassName)} ref={animateRef}>
{checked && <div className="mt-4">{children}</div>} {checked && <div className={classNames(!toggleSwitchAtTheEnd && "mt-4")}>{children}</div>}
</div> </div>
)} )}
</fieldset> </fieldset>