cronofy-elements
Advanced tools
Comparing version 1.7.15 to 1.7.17
{ | ||
"name": "cronofy-elements", | ||
"version": "1.7.15", | ||
"version": "1.7.17", | ||
"description": "Fast track scheduling with Cronofy's embeddable UI Elements", | ||
@@ -5,0 +5,0 @@ "main": "build/npm/CronofyElements.js", |
@@ -128,2 +128,3 @@ import React, { useState, useEffect } from "react"; | ||
`AvailabilityViewer`, | ||
status.tzid, | ||
options.demo | ||
@@ -130,0 +131,0 @@ ) |
@@ -44,2 +44,3 @@ import React, { useState, useEffect } from "react"; | ||
context: "slot_picker", | ||
tzid: options.tzid, | ||
callback: options.callback | ||
@@ -126,2 +127,3 @@ ? options.callback | ||
`SlotPicker`, | ||
status.tzid, | ||
options.demo | ||
@@ -128,0 +130,0 @@ ) |
@@ -150,2 +150,3 @@ import * as mocks from "./mocks"; | ||
element = "availability", | ||
tzid, | ||
mock = false | ||
@@ -163,3 +164,4 @@ ) => { | ||
params.required_duration.minutes, | ||
params.available_periods | ||
params.available_periods, | ||
tzid | ||
); | ||
@@ -166,0 +168,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import moment from "moment-timezone"; | ||
import { | ||
@@ -31,2 +32,10 @@ parseToken, | ||
if (typeof options.tzid === "undefined") { | ||
const sniffedTimezone = moment.tz.guess(); | ||
options.tzid = sniffedTimezone; | ||
options.customtzid = false; | ||
} else { | ||
options.customtzid = true; | ||
} | ||
const domains = parseConnectionDomains( | ||
@@ -33,0 +42,0 @@ options.data_center, |
@@ -595,3 +595,4 @@ import moment from "moment-timezone"; | ||
duration = 60, | ||
availablePeriods = false | ||
availablePeriods = false, | ||
tzid | ||
) => | ||
@@ -603,3 +604,4 @@ new Promise((resolve, reject) => { | ||
duration, | ||
availablePeriods | ||
availablePeriods, | ||
tzid | ||
); | ||
@@ -705,5 +707,12 @@ resolve({ | ||
duration = 60, | ||
query | ||
query, | ||
tzid | ||
) => { | ||
const createPeriodUsingQuery = (period, interval, duration, acc = []) => { | ||
const createPeriodUsingQuery = ( | ||
period, | ||
interval, | ||
duration, | ||
tzid, | ||
acc = [] | ||
) => { | ||
// // 80% chance of creating an available slot | ||
@@ -714,12 +723,12 @@ // const availableSlot = Math.random() * 100 < 80; | ||
const slotEnd = moment(period.start, "YYYY-MM-DDTHH:mm:00Z").add( | ||
duration, | ||
"minutes" | ||
); | ||
const slotEnd = moment | ||
.tz(period.start, "YYYY-MM-DDTHH:mm:00Z", tzid) | ||
.add(duration, "minutes"); | ||
const newPeriodStart = moment(period.start, "YYYY-MM-DDTHH:mm:00Z") | ||
const newPeriodStart = moment | ||
.tz(period.start, "YYYY-MM-DDTHH:mm:00Z", tzid) | ||
.add(interval, "minutes") | ||
.format("YYYY-MM-DDTHH:mm[:00Z]"); | ||
const end = moment(period.end, "YYYY-MM-DDTHH:mm:00Z"); | ||
const end = moment.tz(period.end, "YYYY-MM-DDTHH:mm:00Z", tzid); | ||
@@ -755,9 +764,10 @@ if (slotEnd.diff(end, "minutes") > 0) { | ||
duration, | ||
tzid, | ||
acc | ||
); | ||
}; | ||
const calculatedSlots = query | ||
.map(period => createPeriodUsingQuery(period, interval, duration)) | ||
.map(period => createPeriodUsingQuery(period, interval, duration, tzid)) | ||
.reduce((curr, acc) => [...acc, ...curr]); | ||
return calculatedSlots; | ||
@@ -764,0 +774,0 @@ }; |
@@ -103,15 +103,14 @@ import moment from "moment-timezone"; | ||
}; | ||
const expectedOutput = { | ||
config: { | ||
mode: "confirm" | ||
}, | ||
domains: { | ||
apiDomain: "https://api.cronofy.com", | ||
appDomain: "https://app.cronofy.com" | ||
}, | ||
query: "QUERY_OBJECT", | ||
target: "TARGET", | ||
token: "TOKEN" | ||
}; | ||
expect(parseSlotPickerOptions(input)).toEqual(expectedOutput); | ||
const result = parseSlotPickerOptions(input); | ||
expect(result.config).toEqual({ | ||
mode: "confirm" | ||
}); | ||
expect(result.domains).toEqual({ | ||
apiDomain: "https://api.cronofy.com", | ||
appDomain: "https://app.cronofy.com" | ||
}); | ||
expect(result.query).toEqual("QUERY_OBJECT"); | ||
expect(result.target).toEqual("TARGET"); | ||
expect(result.token).toEqual("TOKEN"); | ||
expect(console.error).toHaveBeenCalledTimes(0); | ||
@@ -140,8 +139,9 @@ expect(console.warn).toHaveBeenCalledTimes(0); | ||
}; | ||
expect( | ||
parseSlotPickerOptions({ | ||
demo: true, | ||
availability_query: "QUERY_OBJECT" | ||
}) | ||
).toEqual(expectedOutput); | ||
const result = parseSlotPickerOptions({ | ||
demo: true, | ||
availability_query: "QUERY_OBJECT" | ||
}); | ||
expect(result.config).toEqual(expectedOutput.config); | ||
expect(result.domains).toEqual(expectedOutput.domains); | ||
expect(result.target).toEqual(expectedOutput.target); | ||
expect(console.warn).toHaveBeenCalledTimes(2); | ||
@@ -152,14 +152,2 @@ expect(console.error).toHaveBeenCalledTimes(0); | ||
it("applies the default target if there is no target option", () => { | ||
const expectedOutput = { | ||
config: { | ||
mode: "confirm" | ||
}, | ||
domains: { | ||
apiDomain: "https://api.cronofy.com", | ||
appDomain: "https://app.cronofy.com" | ||
}, | ||
query: "QUERY_OBJECT", | ||
target: "cronofy-element-slot-picker", | ||
token: "TOKEN" | ||
}; | ||
expect( | ||
@@ -169,4 +157,4 @@ parseSlotPickerOptions({ | ||
element_token: "TOKEN" | ||
}) | ||
).toEqual(expectedOutput); | ||
}).target | ||
).toEqual("cronofy-element-slot-picker"); | ||
expect(console.warn).toHaveBeenCalledTimes(1); | ||
@@ -177,14 +165,2 @@ expect(console.error).toHaveBeenCalledTimes(0); | ||
it("applies the default domains if there is no data_center option", () => { | ||
const expectedOutput = { | ||
config: { | ||
mode: "confirm" | ||
}, | ||
domains: { | ||
apiDomain: "https://api.cronofy.com", | ||
appDomain: "https://app.cronofy.com" | ||
}, | ||
query: "QUERY_OBJECT", | ||
target: "TARGET", | ||
token: "TOKEN" | ||
}; | ||
expect( | ||
@@ -195,4 +171,7 @@ parseSlotPickerOptions({ | ||
target_id: "TARGET" | ||
}) | ||
).toEqual(expectedOutput); | ||
}).domains | ||
).toEqual({ | ||
apiDomain: "https://api.cronofy.com", | ||
appDomain: "https://app.cronofy.com" | ||
}); | ||
expect(console.warn).toHaveBeenCalledTimes(0); | ||
@@ -203,15 +182,2 @@ expect(console.error).toHaveBeenCalledTimes(0); | ||
it("creates correct domains if there is a data_center option", () => { | ||
const expectedOutput = { | ||
config: { | ||
mode: "confirm" | ||
}, | ||
data_center: "de", | ||
domains: { | ||
apiDomain: "https://api-de.cronofy.com", | ||
appDomain: "https://app-de.cronofy.com" | ||
}, | ||
query: "QUERY_OBJECT", | ||
target: "TARGET", | ||
token: "TOKEN" | ||
}; | ||
expect( | ||
@@ -223,4 +189,7 @@ parseSlotPickerOptions({ | ||
target_id: "TARGET" | ||
}) | ||
).toEqual(expectedOutput); | ||
}).domains | ||
).toEqual({ | ||
apiDomain: "https://api-de.cronofy.com", | ||
appDomain: "https://app-de.cronofy.com" | ||
}); | ||
expect(console.warn).toHaveBeenCalledTimes(0); | ||
@@ -227,0 +196,0 @@ expect(console.error).toHaveBeenCalledTimes(0); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
2446934
231
20698