Skip to content

Commit 0d1b6ea

Browse files
authored
feat: configure availability time picker interval by env variable (#12174)
1 parent 26637cd commit 0d1b6ea

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ CSP_POLICY=
207207
EDGE_CONFIG=
208208

209209
NEXT_PUBLIC_MINUTES_TO_BOOK=5 # Minutes
210+
# Control time intervals on a user's Schedule availability
211+
NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL=
210212

211213
# - ORGANIZATIONS *******************************************************************************************
212214
# Enable Organizations non-prod domain setup, works in combination with organizations feature flag

app.json

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@
8383
"NEXT_PUBLIC_TEAM_IMPERSONATION": {
8484
"description": "Set the following value to true if you wish to enable Team Impersonation",
8585
"value": "false"
86+
},
87+
"NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL": {
88+
"description": "Control time intervals on a user's Schedule availability",
89+
"value": "15"
8690
}
8791
},
8892
"scripts": {

packages/features/schedules/components/Schedule.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ interface IOption {
326326
* 23:45:00 (End of day with enough time for 15 min booking)
327327
*/
328328
/** Begin Time Increments For Select */
329-
const INCREMENT = 15;
329+
const INCREMENT = Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL) || 15;
330330
const useOptions = () => {
331331
// Get user so we can determine 12/24 hour format preferences
332332
const query = useMeQuery();

packages/lib/slots.test.ts

+43
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,46 @@ describe("Tests the slot logic", () => {
300300
expect(slots[0].time.format()).toBe("2023-07-13T08:00:00+05:30");
301301
});
302302
});
303+
304+
describe("Tests the date-range slot logic with custom env variable", () => {
305+
beforeAll(() => {
306+
vi.stubEnv("NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL", "10");
307+
});
308+
309+
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 () => {
310+
expect(Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL)).toBe(10);
311+
expect(
312+
getSlots({
313+
inviteeDate: dayjs.utc().add(1, "day"),
314+
frequency: 10,
315+
minimumBookingNotice: 0,
316+
workingHours: [
317+
{
318+
userId: 1,
319+
days: Array.from(Array(7).keys()),
320+
startTime: 10,
321+
endTime: 120,
322+
},
323+
],
324+
eventLength: 10,
325+
offsetStart: 0,
326+
organizerTimeZone: "America/Toronto",
327+
})
328+
).toHaveLength(11);
329+
});
330+
331+
it("test buildSlotsWithDateRanges using a 10 mintue interval", async () => {
332+
expect(Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL)).toBe(10);
333+
expect(
334+
getSlots({
335+
inviteeDate: dayjs.utc().add(1, "day"),
336+
frequency: 10,
337+
minimumBookingNotice: 0,
338+
eventLength: 10,
339+
offsetStart: 0,
340+
organizerTimeZone: "America/Toronto",
341+
dateRanges: [{ start: dayjs("2023-07-13T00:10:00.000Z"), end: dayjs("2023-07-13T02:00:00.000Z") }],
342+
})
343+
).toHaveLength(11);
344+
});
345+
});

packages/lib/slots.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function buildSlotsWithDateRanges({
169169
? range.start
170170
: startTimeWithMinNotice;
171171

172-
let interval = 15;
172+
let interval = Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL) || 15;
173173

174174
const intervalsWithDefinedStartTimes = [60, 30, 20, 10];
175175

packages/types/environment.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare namespace NodeJS {
1111
/** @deprecated use `NEXT_PUBLIC_WEBSITE_URL` */
1212
readonly NEXT_PUBLIC_APP_URL: string | undefined;
1313
readonly NEXTAUTH_SECRET: string | undefined;
14+
readonly NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL: string | undefined;
1415
readonly MS_GRAPH_CLIENT_ID: string | undefined;
1516
readonly MS_GRAPH_CLIENT_SECRET: string | undefined;
1617
readonly ZOOM_CLIENT_ID: string | undefined;

turbo.json

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"dependsOn": ["^build"],
2626
"outputs": [".next/**"],
2727
"env": [
28+
"NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL",
2829
"NEXT_PUBLIC_IS_E2E",
2930
"NEXT_PUBLIC_SENTRY_DSN",
3031
"NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE_MONTHLY",
@@ -70,6 +71,7 @@
7071
"DATOCMS_WEBHOOK_SECRET",
7172
"DATOCMS_PREVIEW_SECRET",
7273
"ENVIRONMENT_URL",
74+
"NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL",
7375
"NEXT_PUBLIC_IS_PREMIUM_NEW_PLAN",
7476
"NEXT_PUBLIC_STRIPE_FREE_PLAN_PRICE",
7577
"NEXT_PUBLIC_STRIPE_PREMIUM_NEW_PLAN_PRICE",

0 commit comments

Comments
 (0)