feat: Restrict same email to create more than 'n' active bookings at… (#21745)
* feat - Restrict same email to create more than 'n' active bookings at a time * updated checkbookerbookinglimit function * type fix * minor change * import fix * minor fixes * back to null on disable * back * type check * managed edge cases * chore: name changes * name changes * fix * minor change * changed name * use default value for maxactivebookingsperbooker, and some minor changes * disabling bookerbooking limit for recurring event * disabling bookerbooking limit for recurring event * type fix * ui fix and backend eventtype update check * removed unused code * minor changes * update validation * chore * Do not check booking limits if rescheduling * minor fix * Refactor eventType update errors * Typo fix --------- Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
1 parent
ddf5717992
commit
630065ca89
16 files changed
+143
-2
No files matched your search
@@ -449,6 +449,7 @@ export const EventAdvancedTab = ({
|
||||
formMethods.getValues("metadata")?.apps?.stripe?.paymentOption === "HOLD";
|
||||
|
||||
const isRecurringEvent = !!formMethods.getValues("recurringEvent");
|
||||
|
||||
const isRoundRobinEventType =
|
||||
eventType.schedulingType && eventType.schedulingType === SchedulingType.ROUND_ROBIN;
|
||||
|
||||
|
||||
@@ -374,6 +374,8 @@ export const EventLimitsTab = ({ eventType, customClassNames }: EventLimitsTabPr
|
||||
const { t, i18n } = useLocale();
|
||||
const formMethods = useFormContext<FormValues>();
|
||||
|
||||
const isRecurringEvent = !!formMethods.getValues("recurringEvent");
|
||||
|
||||
const { shouldLockIndicator, shouldLockDisableProps } = useLockedFieldsManager({
|
||||
eventType,
|
||||
translate: t,
|
||||
@@ -387,6 +389,9 @@ export const EventLimitsTab = ({ eventType, customClassNames }: EventLimitsTabPr
|
||||
const offsetStartLockedProps = shouldLockDisableProps("offsetStart");
|
||||
|
||||
const [offsetToggle, setOffsetToggle] = useState(formMethods.getValues("offsetStart") > 0);
|
||||
const [maxActiveBookingsPerBookerToggle, setMaxActiveBookingsPerBookerToggle] = useState(
|
||||
(formMethods.getValues("maxActiveBookingsPerBooker") ?? 0) > 0
|
||||
);
|
||||
|
||||
// Preview how the offset will affect start times
|
||||
const watchOffsetStartValue = formMethods.watch("offsetStart");
|
||||
@@ -680,6 +685,52 @@ export const EventLimitsTab = ({ eventType, customClassNames }: EventLimitsTabPr
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Controller
|
||||
name="maxActiveBookingsPerBooker"
|
||||
render={({ field: { onChange, value } }) => {
|
||||
const isChecked = maxActiveBookingsPerBookerToggle;
|
||||
return (
|
||||
<SettingsToggle
|
||||
labelClassName={classNames("text-sm")}
|
||||
disabled={isRecurringEvent}
|
||||
tooltip={isRecurringEvent ? t("recurring_event_doesnt_support_booker_booking_limit") : ""}
|
||||
toggleSwitchAtTheEnd={true}
|
||||
switchContainerClassName={classNames(
|
||||
"border-subtle mt-6 rounded-lg border py-6 px-4 sm:px-6",
|
||||
isChecked && "rounded-b-none"
|
||||
)}
|
||||
childrenClassName={classNames("lg:ml-0")}
|
||||
title={t("booker_booking_limit")}
|
||||
description={t("booker_booking_limit_description")}
|
||||
checked={isChecked}
|
||||
onCheckedChange={(active) => {
|
||||
if (active) {
|
||||
onChange(1);
|
||||
} else {
|
||||
onChange(null);
|
||||
}
|
||||
setMaxActiveBookingsPerBookerToggle((state) => !state);
|
||||
}}>
|
||||
<div className="border-subtle rounded-b-lg border border-t-0 p-6">
|
||||
<TextField
|
||||
required
|
||||
type="number"
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
onChange(parseInt(e.target.value, 10));
|
||||
}}
|
||||
placeholder="1"
|
||||
min={1}
|
||||
step={1}
|
||||
containerClassName={classNames("max-w-80")}
|
||||
addOnSuffix="bookings"
|
||||
data-testid="booker-booking-limit-input"
|
||||
/>
|
||||
</div>
|
||||
</SettingsToggle>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Controller
|
||||
name="periodType"
|
||||
render={({ field: { onChange, value } }) => {
|
||||
|
||||
@@ -50,6 +50,7 @@ export default function RecurringEventController({
|
||||
formMethods.getValues("recurringEvent")
|
||||
);
|
||||
const isSeatsOffered = !!formMethods.getValues("seatsPerTimeSlot");
|
||||
const hasBookingLimitPerBooker = !!formMethods.getValues("maxActiveBookingsPerBooker");
|
||||
/* Just yearly-0, monthly-1 and weekly-2 */
|
||||
const recurringEventFreqOptions = Object.entries(Frequency)
|
||||
.filter(([key, value]) => isNaN(Number(key)) && Number(value) < 3)
|
||||
@@ -93,8 +94,14 @@ export default function RecurringEventController({
|
||||
description={t("recurring_event_description")}
|
||||
checked={!!recurringEventState}
|
||||
data-testid="recurring-event-check"
|
||||
disabled={!recurringEventState && isSeatsOffered}
|
||||
tooltip={isSeatsOffered ? t("seats_doesnt_support_recurring") : undefined}
|
||||
disabled={(!recurringEventState && isSeatsOffered) || hasBookingLimitPerBooker}
|
||||
tooltip={
|
||||
isSeatsOffered
|
||||
? t("seats_doesnt_support_recurring")
|
||||
: hasBookingLimitPerBooker
|
||||
? t("booking_limit_per_booker_doesnt_support_recurring")
|
||||
: undefined
|
||||
}
|
||||
onCheckedChange={(e) => {
|
||||
if (!e) {
|
||||
formMethods.setValue("recurringEvent", null, { shouldDirty: true });
|
||||
|
||||
@@ -123,6 +123,7 @@ export type FormValues = {
|
||||
scheduleName: string;
|
||||
minimumBookingNotice: number;
|
||||
minimumBookingNoticeInDurationType: number;
|
||||
maxActiveBookingsPerBooker: number | null;
|
||||
beforeEventBuffer: number;
|
||||
afterEventBuffer: number;
|
||||
slotInterval: number | null;
|
||||
|
||||
Reference in new issue
Block a user