Compare commits

...

89 Commits

Author SHA1 Message Date
Jeroen Reumkens 825418eeb6
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-14 10:00:25 +01:00
Jeroen Reumkens 9abecc57a0 Abstracted durationtype days,hours,minutes into a reusable type, fixed type errors that were still using string. 2022-11-14 09:59:45 +01:00
Om Ray c585365807
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-13 14:14:50 -05:00
Peer Richelsen 0a15644cbe
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-12 18:27:58 +00:00
Om Ray 632d5f2592
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-11 16:02:37 -05:00
alannnc 1d1afc69c3
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-11 13:09:06 -07:00
alannnc f54dd2a502
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-11 12:45:16 -07:00
zomars 04b73d39a6 Type fixes 2022-11-11 12:10:37 -07:00
zomars 1671836b5c Syntax fix 2022-11-11 12:00:07 -07:00
Om Ray ca093f6307
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-11 13:32:19 -05:00
Om Ray 1bcbd4bd73
Delete convertMinimumBookingNoticeToMinutes.ts 2022-11-11 13:31:25 -05:00
Om Ray 93106fcbe5
Update packages/lib/convertToNewDurationType.ts
Co-authored-by: Omar López <zomars@me.com>
2022-11-11 13:29:58 -05:00
Om Ray 262a103461
Update apps/web/test/lib/getSchedule.test.ts
Co-authored-by: Omar López <zomars@me.com>
2022-11-11 13:29:42 -05:00
Om Ray 656d586b52
remove passing in as object 2022-11-11 13:29:31 -05:00
Om Ray 41910ff1b5
Update apps/web/test/lib/getSchedule.test.ts
Co-authored-by: Omar López <zomars@me.com>
2022-11-11 13:26:54 -05:00
Om Ray 1aa21b69a3
Update apps/web/components/eventtype/EventLimitsTab.tsx
Co-authored-by: Omar López <zomars@me.com>
2022-11-11 13:25:13 -05:00
Om Ray 51d2ec115c
Update packages/lib/convertToNewDurationType.ts
Co-authored-by: Omar López <zomars@me.com>
2022-11-11 13:24:59 -05:00
Om Ray 9915c4746e
Update apps/web/components/eventtype/EventLimitsTab.tsx
Co-authored-by: Omar López <zomars@me.com>
2022-11-11 13:24:18 -05:00
Om Ray 7e3aab88ba
Update packages/lib/findDurationType.ts
Co-authored-by: Omar López <zomars@me.com>
2022-11-11 13:24:01 -05:00
Om Ray a355b18db5
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-11 10:14:23 -05:00
Peer Richelsen 778c4cb332
Update apps/web/components/eventtype/EventLimitsTab.tsx
Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
2022-11-11 13:49:26 +00:00
Alex van Andel 0b127bc922
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-11 12:12:00 +00:00
Om Ray 8d259093cb
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-10 18:48:07 -05:00
Om Ray a8bda978d3
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-10 16:53:44 -05:00
123om123 6eb2a3f567 Merge https://github.com/123om123/cal.com into minimum-booking-notice-will-allow-hours-and-days 2022-11-10 11:50:16 -05:00
alannnc fd5852ebb9
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-09 17:29:16 -07:00
Om Ray a4cd2db2dd
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-09 14:47:39 -05:00
Om Ray 37a0152a2b
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-09 11:37:05 -05:00
Jeroen Reumkens 221d9e2c40 Undo adding submodule updates 2022-11-09 15:38:33 +01:00
Jeroen Reumkens 61f8f1dd41 Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-09 15:36:51 +01:00
Jeroen Reumkens 6d75920c70 Improvements for duration notice type logic 2022-11-09 15:34:03 +01:00
Om Ray 35a0c74c7b
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-08 16:00:47 -05:00
123om123 c06817c753 Replaced currentDurationType export with state passed down from parent 2022-11-08 13:33:27 -05:00
Om Ray 972724ea57
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-08 12:50:44 -05:00
Om Ray 6954afe023
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-08 12:04:54 -05:00
Om Ray 4aa789de9f
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-08 11:49:33 -05:00
Om Ray 06fe6464d9
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-08 11:33:39 -05:00
Om Ray 97c12247ca
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-07 19:21:32 -05:00
Om Ray 9a2e99ee64
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-07 17:40:55 -05:00
Om Ray 7d8b746de5
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-07 14:14:40 -05:00
Om Ray 1782399672
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-07 11:10:59 -05:00
Jeroen Reumkens 618e3cdf92
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-07 13:57:35 +01:00
Om Ray 310a82ac3f
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-06 14:20:53 -05:00
Om Ray ade30ad272
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-06 12:57:46 -05:00
Om Ray 1f12fdcf7f
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-05 21:15:06 -04:00
Om Ray d212d2d04b
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-05 11:35:34 -04:00
Om Ray 169614ba95
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-04 16:33:59 -04:00
123om123 729c3ec213 Merge https://github.com/123om123/cal.com into minimum-booking-notice-will-allow-hours-and-days 2022-11-04 16:19:47 -04:00
Om Ray c60afd0a8b
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-04 13:26:03 -04:00
123om123 1be35792c7 Revert "Revert "remove yarn lockfile""
This reverts commit c8cc4d3c0e.
2022-11-04 13:25:24 -04:00
123om123 a4bd255761 Merge branch 'minimum-booking-notice-will-allow-hours-and-days' of https://github.com/123om123/cal.com into minimum-booking-notice-will-allow-hours-and-days 2022-11-04 13:18:53 -04:00
123om123 c8cc4d3c0e Revert "remove yarn lockfile"
This reverts commit fefc24c802.
2022-11-04 13:15:09 -04:00
123om123 44e65d22fc Merge branch 'minimum-booking-notice-will-allow-hours-and-days' of https://github.com/123om123/cal.com into minimum-booking-notice-will-allow-hours-and-days 2022-11-04 13:05:36 -04:00
123om123 fefc24c802 remove yarn lockfile 2022-11-04 13:04:38 -04:00
123om123 841f170aea Merge https://github.com/123om123/cal.com into minimum-booking-notice-will-allow-hours-and-days 2022-11-04 12:57:30 -04:00
123om123 4b83854327 Removed console.logs, converted minimumBookingNoticeType to ref, removed unreliable accessing of array 2022-11-03 19:25:35 -04:00
Om Ray 80d8b76736
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-03 17:09:33 -04:00
Om Ray 0384058c90
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-03 16:01:58 -04:00
Jeroen Reumkens ab42cfd4bd
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-03 10:09:12 +01:00
123om123 16e9545dba fixed issue with minbookingnotice not updating properly in prisma 2022-11-02 16:15:38 -04:00
Peer Richelsen c5ce792a62
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-02 12:47:53 +00:00
Om Ray 535dd93836
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-01 14:27:02 -04:00
Peer Richelsen e83057fe0e
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-11-01 12:37:12 +00:00
Peer Richelsen 660060b091
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-31 23:08:25 +00:00
Peer Richelsen 03f243db21
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-31 22:07:00 +00:00
Om Ray c6a1ebfcab
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-31 15:07:52 -04:00
Hariom Balhara cdc1d915ed
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-31 20:09:23 +05:30
Om Ray bc25a1d75f
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-30 16:46:45 -04:00
123om123 ebec4ad440 minimumBookingNotice values will never be floats 2022-10-28 19:40:23 -04:00
Alan 7543045c4f Fix some comparison, mobile styles and const usages 2022-10-28 16:02:25 -06:00
123om123 ed18248df5 Merge branch 'minimum-booking-notice-will-allow-hours-and-days' of https://github.com/123om123/cal.com into minimum-booking-notice-will-allow-hours-and-days 2022-10-28 16:18:37 -04:00
123om123 af7d3eb0db added MINUTES_IN_HOUR, MINUTES_IN_DAY, and HOURS_IN_DAY as exportable consts 2022-10-28 16:18:01 -04:00
Om Ray 7591fed08b
Update packages/lib/convertMinimumBookingNoticeToMinutes.ts
Co-authored-by: alannnc <alannnc@gmail.com>
2022-10-28 16:15:48 -04:00
123om123 4946f32a1c moved minimumBookingNotice to clientside, removed migration from prisma, changed DurationField to regular InputField 2022-10-28 15:58:00 -04:00
Om Ray 1acf4b7ee4
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-28 15:34:49 -04:00
Om Ray e3e56f2113
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-28 11:53:55 -04:00
Peer Richelsen f0a83b2d8d
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-27 20:51:12 +01:00
Om Ray 2a3748f31e
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-26 17:36:29 -04:00
Om Ray 68fd207f53
Update apps/web/components/v2/eventtype/EventLimitsTab.tsx
Co-authored-by: Peer Richelsen <peer@cal.com>
2022-10-26 17:30:16 -04:00
Om Ray 444520485e
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-26 17:28:18 -04:00
Peer Richelsen c904532b81
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-26 21:18:15 +01:00
123om123 ad25e4fec0 Merge branch 'minimum-booking-notice-will-allow-hours-and-days' of https://github.com/123om123/cal.com into minimum-booking-notice-will-allow-hours-and-days 2022-10-26 12:35:59 -04:00
123om123 efe1bf9422 fix type error 2022-10-26 12:35:36 -04:00
Om Ray ffd49ef3b2
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-26 12:24:54 -04:00
Peer Richelsen 9b3af6dc10
Merge branch 'main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-26 14:58:57 +01:00
123om123 c2ad171ce0 Merge https://github.com/123om123/cal.com into minimum-booking-notice-will-allow-hours-and-days 2022-10-25 21:15:23 -04:00
123om123 fff14a2a2a Fixed error with Prisma not updating properly and input changing value to minutes autmatically 2022-10-25 21:10:21 -04:00
Om Ray 7bfdebe7b9
Merge branch 'calcom:main' into minimum-booking-notice-will-allow-hours-and-days 2022-10-24 18:49:13 -04:00
123om123 27a31d70e2 minimum booking notice allows hours and days 2022-10-24 18:47:04 -04:00
5 changed files with 155 additions and 17 deletions

View File

@ -1,23 +1,29 @@
import { useAutoAnimate } from "@formkit/auto-animate/react";
import * as RadioGroup from "@radix-ui/react-radio-group";
import { EventTypeSetupInfered, FormValues } from "pages/event-types/[type]";
import { useState } from "react";
import { useFormContext, Controller, useWatch } from "react-hook-form";
import { useMemo, useRef, useState } from "react";
import { Controller, useFormContext, useWatch } from "react-hook-form";
import { classNames } from "@calcom/lib";
import convertToNewDurationType, { DurationType } from "@calcom/lib/convertToNewDurationType";
import findDurationType from "@calcom/lib/findDurationType";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { PeriodType } from "@calcom/prisma/client";
import type { BookingLimit } from "@calcom/types/Calendar";
import { Icon } from "@calcom/ui";
import { Button } from "@calcom/ui/components";
import { Label, Input, MinutesField } from "@calcom/ui/components/form";
import { Input, InputField, Label } from "@calcom/ui/components/form";
import { Select, SettingsToggle } from "@calcom/ui/v2";
import DateRangePicker from "@calcom/ui/v2/core/form/date-range-picker/DateRangePicker";
export const EventLimitsTab = (props: Pick<EventTypeSetupInfered, "eventType">) => {
export const EventLimitsTab = ({ eventType }: Pick<EventTypeSetupInfered, "eventType">) => {
const { t } = useLocale();
const formMethods = useFormContext<FormValues>();
const { eventType } = props;
const minimumBookingNoticeType = useRef<DurationType>(findDurationType(eventType.minimumBookingNotice));
const prevBookingNoticeType = useRef<DurationType>(minimumBookingNoticeType.current);
const minimumBookingNoticeInDurationTypeFormValue = formMethods.watch("minimumBookingNoticeInDurationType");
const PERIOD_TYPES = [
{
type: "ROLLING" as const,
@ -47,6 +53,57 @@ export const EventLimitsTab = (props: Pick<EventTypeSetupInfered, "eventType">)
defaultValue: periodType?.type,
});
const onMinimumNoticeDurationTypeChange = useMemo(
() => (durationType?: DurationType) => {
if (typeof durationType === "undefined") return;
// Store current selected type in ref to use in previous run for comparrison.
minimumBookingNoticeType.current = durationType;
// Uses the previous selected type and converts the value to the new type.
// Eg day was selected before, user selects hours now, so we multiple * 24 and round up.
const minimumBookingNoticeInDurationType = convertToNewDurationType(
prevBookingNoticeType.current,
durationType,
Number(minimumBookingNoticeInDurationTypeFormValue)
);
// Uses the round up value in the new type to calculate the value in minutes.
// We should NOT use minimumBookingNoticeInDurationTypeFormValue here, since that
// would break in the case that the user enters 90 minutes, changes the type to
// hours (that will show 2 hours), but the value in minutes would then remain 90,
// which is something else than the user things they save.
const minimumBookingNoticeInMinutes = convertToNewDurationType(
durationType,
"minutes",
Number(minimumBookingNoticeInDurationType)
);
// Updates both form values as well as stores the current type as previous type in ref.
formMethods.setValue("minimumBookingNotice", minimumBookingNoticeInMinutes);
formMethods.setValue("minimumBookingNoticeInDurationType", minimumBookingNoticeInDurationType);
prevBookingNoticeType.current = durationType;
},
[formMethods, minimumBookingNoticeInDurationTypeFormValue]
);
/**
* When the user inputs a new value for minimumBookingNoticeInDurationType,
* we calculate the value in minutes, and update this hidden field as well.
*/
const onMinimumNoticeChange = useMemo(
() => (duration: string) => {
const minimumBookingNoticeInMinutes = convertToNewDurationType(
minimumBookingNoticeType.current,
"minutes",
Number(duration)
);
formMethods.setValue("minimumBookingNotice", minimumBookingNoticeInMinutes);
},
[formMethods]
);
return (
<div>
<div className="flex flex-col space-y-4 lg:flex-row lg:space-y-0 lg:space-x-4">
@ -116,13 +173,54 @@ export const EventLimitsTab = (props: Pick<EventTypeSetupInfered, "eventType">)
</div>
</div>
<div className="flex flex-col space-y-4 pt-4 lg:flex-row lg:space-y-0 lg:space-x-4">
<div className="w-full">
<MinutesField
required
label={t("minimum_booking_notice")}
type="number"
placeholder="120"
{...formMethods.register("minimumBookingNotice", { valueAsNumber: true })}
<div className="flex w-full items-end">
<Controller
name="minimumBookingNotice"
control={formMethods.control}
render={() => {
const durationTypeOptions = [
{
label: t("minutes"),
value: "minutes",
},
{
label: t("hours"),
value: "hours",
},
{
label: t("days"),
value: "days",
},
];
return (
<>
<div className="w-1/2 md:w-3/4">
<InputField
required
label={t("minimum_booking_notice")}
type="number"
placeholder="120"
className="mr-2 rounded-[4px]"
{...formMethods.register("minimumBookingNoticeInDurationType", {
onChange: (event: React.ChangeEvent<HTMLInputElement>) =>
onMinimumNoticeChange(event.target.value),
})}
/>
<input type="hidden" {...formMethods.register("minimumBookingNotice")} />
</div>
<Select
isSearchable={false}
className="mb-2 ml-2 w-full capitalize md:min-w-[150px] md:max-w-[200px]"
defaultValue={durationTypeOptions.find(
(option) => option.value === minimumBookingNoticeType.current
)}
onChange={(input) => onMinimumNoticeDurationTypeChange(input?.value as DurationType)}
options={durationTypeOptions}
/>
</>
);
}}
/>
</div>
<div className="w-full">

View File

@ -12,6 +12,8 @@ import getApps, { getEventTypeAppData, getLocationOptions } from "@calcom/app-st
import { LocationObject, EventLocationType } from "@calcom/core/location";
import { parseRecurringEvent, parseBookingLimit, validateBookingLimitOrder } from "@calcom/lib";
import { CAL_URL } from "@calcom/lib/constants";
import convertToNewDurationType from "@calcom/lib/convertToNewDurationType";
import findDurationType from "@calcom/lib/findDurationType";
import getStripeAppData from "@calcom/lib/getStripeAppData";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import prisma from "@calcom/prisma";
@ -73,6 +75,7 @@ export type FormValues = {
seatsShowAttendees: boolean | null;
seatsPerTimeSlotEnabled: boolean;
minimumBookingNotice: number;
minimumBookingNoticeInDurationType: number;
beforeBufferTime: number;
afterBufferTime: number;
slotInterval: number | null;
@ -163,6 +166,11 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
},
schedulingType: eventType.schedulingType,
minimumBookingNotice: eventType.minimumBookingNotice,
minimumBookingNoticeInDurationType: convertToNewDurationType(
"minutes",
findDurationType(eventType.minimumBookingNotice),
eventType.minimumBookingNotice
),
metadata: eventType.metadata,
},
});
@ -237,9 +245,11 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
recurringEvent,
locations,
metadata,
// We don't need to send it to the backend
// 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,
...input
} = values;

View File

@ -0,0 +1,27 @@
export const MINUTES_IN_HOUR = 60;
export const MINUTES_IN_DAY = 1440;
export const HOURS_IN_DAY = 24;
export type DurationType = "minutes" | "hours" | "days";
export default function convertToNewDurationType(
prevType: DurationType,
newType: DurationType,
prevValue: number
) {
/** Convert `prevValue` from `prevType` to `newType` */
const newDurationTypeMap = {
minutes_minutes: () => prevValue,
minutes_hours: () => prevValue * MINUTES_IN_HOUR,
minutes_days: () => prevValue * MINUTES_IN_DAY,
hours_minutes: () => prevValue / MINUTES_IN_HOUR,
hours_hours: () => prevValue,
hours_days: () => prevValue * HOURS_IN_DAY,
days_minutes: () => prevValue / MINUTES_IN_DAY,
days_hours: () => prevValue / HOURS_IN_DAY,
days_days: () => prevValue,
};
const getNewValue = newDurationTypeMap[`${prevType}_${newType}`];
const newValue = getNewValue();
return Math.ceil(newValue);
}

View File

@ -0,0 +1,7 @@
import { DurationType, MINUTES_IN_DAY, MINUTES_IN_HOUR } from "./convertToNewDurationType";
export default function findDurationType(value: number): DurationType {
if (value % MINUTES_IN_DAY === 0) return "days";
if (value % MINUTES_IN_HOUR === 0) return "hours";
return "minutes";
}

View File

@ -341,7 +341,3 @@ export function InputGroupBox(props: JSX.IntrinsicElements["div"]) {
</div>
);
}
export const MinutesField = forwardRef<HTMLInputElement, InputFieldProps>(function MinutesField(props, ref) {
return <InputField ref={ref} type="number" min={0} {...props} addOnSuffix="mins" />;
});