Skip to content

Scheduling infrastructure for absolutely everyone.

feat: configure availability time picker interval by env variable (#12174)

Ash Davis0d1b6ea5b200
diff --git a/.env.example b/.env.example
index 97bdb2e3980..1cc4f37308d 100644
--- a/.env.example
+++ b/.env.example
@@ -207,6 +207,8 @@ CSP_POLICY=
EDGE_CONFIG=
NEXT_PUBLIC_MINUTES_TO_BOOK=5 # Minutes
+# Control time intervals on a user's Schedule availability
+NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL=
# - ORGANIZATIONS *******************************************************************************************
# Enable Organizations non-prod domain setup, works in combination with organizations feature flag
diff --git a/app.json b/app.json
index 4078d8be61d..ff45e67a923 100644
--- a/app.json
+++ b/app.json
@@ -83,6 +83,10 @@
"NEXT_PUBLIC_TEAM_IMPERSONATION": {
"description": "Set the following value to true if you wish to enable Team Impersonation",
"value": "false"
+ },
+ "NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL": {
+ "description": "Control time intervals on a user's Schedule availability",
+ "value": "15"
}
},
"scripts": {
diff --git a/packages/features/schedules/components/Schedule.tsx b/packages/features/schedules/components/Schedule.tsx
index 49aa75d4747..4edc981131d 100644
--- a/packages/features/schedules/components/Schedule.tsx
+++ b/packages/features/schedules/components/Schedule.tsx
@@ -326,7 +326,7 @@ interface IOption {
* 23:45:00 (End of day with enough time for 15 min booking)
*/
/** Begin Time Increments For Select */
-const INCREMENT = 15;
+const INCREMENT = Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL) || 15;
const useOptions = () => {
// Get user so we can determine 12/24 hour format preferences
const query = useMeQuery();
diff --git a/packages/lib/slots.test.ts b/packages/lib/slots.test.ts
index b6bff8d30f9..6a0b9ddd1a5 100644
--- a/packages/lib/slots.test.ts
+++ b/packages/lib/slots.test.ts
@@ -300,3 +300,46 @@ describe("Tests the slot logic", () => {
expect(slots[0].time.format()).toBe("2023-07-13T08:00:00+05:30");
});
});
+
+describe("Tests the date-range slot logic with custom env variable", () => {
+ beforeAll(() => {
+ vi.stubEnv("NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL", "10");
+ });
+
+ it("can fit 11 10 minute slots within a 2 hour window using a 10 mintue availabilty option with a starting time of 10 past the hour", async () => {
+ expect(Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL)).toBe(10);
+ expect(
+ getSlots({
+ inviteeDate: dayjs.utc().add(1, "day"),
+ frequency: 10,
+ minimumBookingNotice: 0,
+ workingHours: [
+ {
+ userId: 1,
+ days: Array.from(Array(7).keys()),
+ startTime: 10,
+ endTime: 120,
+ },
+ ],
+ eventLength: 10,
+ offsetStart: 0,
+ organizerTimeZone: "America/Toronto",
+ })
+ ).toHaveLength(11);
+ });
+
+ it("test buildSlotsWithDateRanges using a 10 mintue interval", async () => {
+ expect(Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL)).toBe(10);
+ expect(
+ getSlots({
+ inviteeDate: dayjs.utc().add(1, "day"),
+ frequency: 10,
+ minimumBookingNotice: 0,
+ eventLength: 10,
+ offsetStart: 0,
+ organizerTimeZone: "America/Toronto",
+ dateRanges: [{ start: dayjs("2023-07-13T00:10:00.000Z"), end: dayjs("2023-07-13T02:00:00.000Z") }],
+ })
+ ).toHaveLength(11);
+ });
+});
diff --git a/packages/lib/slots.ts b/packages/lib/slots.ts
index f3f4b290cb2..e28019a8df4 100644
--- a/packages/lib/slots.ts
+++ b/packages/lib/slots.ts
@@ -169,7 +169,7 @@ function buildSlotsWithDateRanges({
? range.start
: startTimeWithMinNotice;
- let interval = 15;
+ let interval = Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL) || 15;
const intervalsWithDefinedStartTimes = [60, 30, 20, 10];
diff --git a/packages/types/environment.d.ts b/packages/types/environment.d.ts
index 84bc50b691f..006be0478d8 100644
--- a/packages/types/environment.d.ts
+++ b/packages/types/environment.d.ts
@@ -11,6 +11,7 @@ declare namespace NodeJS {
/** @deprecated use `NEXT_PUBLIC_WEBSITE_URL` */
readonly NEXT_PUBLIC_APP_URL: string | undefined;
readonly NEXTAUTH_SECRET: string | undefined;
+ readonly NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL: string | undefined;
readonly MS_GRAPH_CLIENT_ID: string | undefined;
readonly MS_GRAPH_CLIENT_SECRET: string | undefined;
readonly ZOOM_CLIENT_ID: string | undefined;
diff --git a/turbo.json b/turbo.json
index 4463f6faf05..7f1282d0c4b 100644
--- a/turbo.json
+++ b/turbo.json
@@ -25,6 +25,7 @@
"dependsOn": ["^build"],
"outputs": [".next/**"],
"env": [
+ "NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL",
"NEXT_PUBLIC_IS_E2E",
"NEXT_PUBLIC_SENTRY_DSN",
"NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE_MONTHLY",
@@ -70,6 +71,7 @@
"DATOCMS_WEBHOOK_SECRET",
"DATOCMS_PREVIEW_SECRET",
"ENVIRONMENT_URL",
+ "NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL",
"NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN",
"NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE",
"NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE",