From 0d1b6ea5b200173bca63b97f7744106ab7c433b1 Mon Sep 17 00:00:00 2001 From: Ash Davis <11312962+Shpadoinkle@users.noreply.github.com> Date: Fri, 10 Nov 2023 00:50:42 +1000 Subject: [PATCH] feat: configure availability time picker interval by env variable (#12174) --- .env.example | 2 + app.json | 4 ++ .../schedules/components/Schedule.tsx | 2 +- packages/lib/slots.test.ts | 43 +++++++++++++++++++ packages/lib/slots.ts | 2 +- packages/types/environment.d.ts | 1 + turbo.json | 2 + 7 files changed, 54 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 97bdb2e398..1cc4f37308 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 4078d8be61..ff45e67a92 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 49aa75d474..4edc981131 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 b6bff8d30f..6a0b9ddd1a 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 f3f4b290cb..e28019a8df 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 84bc50b691..006be0478d 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 4463f6faf0..7f1282d0c4 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",