cronofy-elements
Advanced tools
Comparing version 1.13.3 to 1.14.0
{ | ||
"name": "cronofy-elements", | ||
"version": "1.13.3", | ||
"version": "1.14.0", | ||
"description": "Fast track scheduling with Cronofy's embeddable UI Elements", | ||
@@ -5,0 +5,0 @@ "main": "build/npm/CronofyElements.js", |
@@ -23,3 +23,7 @@ import React, { useState, useEffect } from "react"; | ||
const [log, setLog] = useState( | ||
logConstructor(options.config.logs, "Agenda View") | ||
logConstructor( | ||
options.config.logs, | ||
"Agenda View", | ||
options.callback ? options.callback : false | ||
) | ||
); | ||
@@ -26,0 +30,0 @@ |
@@ -40,3 +40,7 @@ import React, { useState, useEffect } from "react"; | ||
const [log, setLog] = useState( | ||
logConstructor(options.config.logs, "Availability Rules") | ||
logConstructor( | ||
options.config.logs, | ||
"Availability Rules", | ||
options.callback ? options.callback : false | ||
) | ||
); | ||
@@ -43,0 +47,0 @@ const [account, setAccount] = useState(parseAccountOptions(options)); |
@@ -39,3 +39,7 @@ import React, { useState, useEffect } from "react"; | ||
const [log, setLog] = useState( | ||
logConstructor(options.config.logs, "Availability Viewer") | ||
logConstructor( | ||
options.config.logs, | ||
"Availability Viewer", | ||
options.callback ? options.callback : false | ||
) | ||
); | ||
@@ -80,3 +84,3 @@ | ||
preloading: false, | ||
selectionConfirm: options.callback | ||
notificationCallback: options.callback | ||
? options.callback | ||
@@ -170,2 +174,12 @@ : () => log.warn("No `callback` option has been provided"), | ||
if (response.length < 1) { | ||
const notification = { | ||
notification: { | ||
type: "no_slots_found", | ||
query: croppedQuery | ||
} | ||
}; | ||
status.notificationCallback(notification); | ||
} | ||
const slotsWithKeys = addKeysToSlots(response); | ||
@@ -172,0 +186,0 @@ |
@@ -44,3 +44,3 @@ import React, { useContext } from "react"; | ||
}; | ||
status.selectionConfirm(callbackContent); | ||
status.notificationCallback(callbackContent); | ||
}; | ||
@@ -87,3 +87,3 @@ | ||
? removeFromSelectionList() | ||
: status.selectionConfirm({ | ||
: status.notificationCallback({ | ||
notification: { | ||
@@ -90,0 +90,0 @@ type: "slot_selected", |
@@ -146,3 +146,3 @@ import React, { useState, useContext, useEffect } from "react"; | ||
status.selectionConfirm({ | ||
status.notificationCallback({ | ||
notification: { | ||
@@ -174,3 +174,3 @@ type: "slot_selected", | ||
}; | ||
status.selectionConfirm(callbackContent); | ||
status.notificationCallback(callbackContent); | ||
} | ||
@@ -177,0 +177,0 @@ } |
@@ -31,3 +31,7 @@ import React, { useState, useEffect } from "react"; | ||
const [log, setLog] = useState( | ||
logConstructor(options.config.logs, "Calendar Sync") | ||
logConstructor( | ||
options.config.logs, | ||
"Calendar Sync", | ||
options.callback ? options.callback : false | ||
) | ||
); | ||
@@ -34,0 +38,0 @@ |
@@ -12,3 +12,3 @@ import { | ||
const logs = typeof config.logs === "undefined" ? "warn" : config.logs; | ||
const log = logConstructor(logs, "Agenda View"); | ||
const log = logConstructor(logs, "Agenda View", options.callback); | ||
@@ -15,0 +15,0 @@ const demoMode = typeof options.demo === "undefined" ? false : options.demo; |
@@ -14,3 +14,7 @@ import moment from "moment-timezone"; | ||
const logs = typeof config.logs === "undefined" ? "warn" : config.logs; | ||
const log = logConstructor(logs, "Availability Rules"); | ||
const log = logConstructor( | ||
logs, | ||
"Availability Rules", | ||
options.callback ? options.callback : false | ||
); | ||
const startDay = | ||
@@ -17,0 +21,0 @@ typeof config.week_start_day === "undefined" |
@@ -14,3 +14,7 @@ import moment from "moment-timezone"; | ||
const logs = typeof config.logs === "undefined" ? "warn" : config.logs; | ||
const log = logConstructor(logs, "Availability Viewer"); | ||
const log = logConstructor( | ||
logs, | ||
"Availability Viewer", | ||
options.callback ? options.callback : false | ||
); | ||
@@ -17,0 +21,0 @@ options.error = false; |
@@ -12,3 +12,7 @@ import { | ||
const logs = typeof config.logs === "undefined" ? "warn" : config.logs; | ||
const log = logConstructor(logs, "Calendar Sync"); | ||
const log = logConstructor( | ||
logs, | ||
"Calendar Sync", | ||
options.callback ? options.callback : false | ||
); | ||
@@ -15,0 +19,0 @@ options.error = false; |
@@ -5,3 +5,9 @@ export const errorWrap = (elementName, message, docsSlug = "") => { | ||
const buildLogNotification = (type, elementName, message, url = "") => { | ||
export const buildLogNotification = ( | ||
type, | ||
elementName, | ||
message, | ||
url = "", | ||
errorObject = false | ||
) => { | ||
const notification = { | ||
@@ -12,3 +18,4 @@ notification: { | ||
message, | ||
url: `https://docs.cronofy.com/developers/ui-elements/${url}` | ||
url: `https://docs.cronofy.com/developers/ui-elements/${url}`, | ||
errors: errorObject ? errorObject : {} | ||
} | ||
@@ -53,3 +60,4 @@ }; | ||
message, | ||
extras.docsSlug | ||
extras.docsSlug, | ||
extras.errorObject | ||
) | ||
@@ -56,0 +64,0 @@ ); |
@@ -1,2 +0,5 @@ | ||
import { logConstructor } from "../src/js/helpers/logging"; | ||
import { | ||
buildLogNotification, | ||
logConstructor | ||
} from "../src/js/helpers/logging"; | ||
@@ -150,2 +153,104 @@ // The parsers rely on console warning and errors to | ||
}); | ||
it("calls provided callback", () => { | ||
const callback = jest.fn(); | ||
const expectedNotification = { | ||
notification: { | ||
element: "ELEMENT_NAME", | ||
errors: {}, | ||
message: "TEST MESSAGE", | ||
type: "error", | ||
url: "https://docs.cronofy.com/developers/ui-elements/" | ||
} | ||
}; | ||
logConstructor("error", "ELEMENT_NAME", callback); | ||
const log = logConstructor("error", "ELEMENT_NAME", callback); | ||
log.error("TEST MESSAGE"); | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
expect(callback).toHaveBeenCalledWith(expectedNotification); | ||
}); | ||
it("calls provided callback with extra options", () => { | ||
const callback = jest.fn(); | ||
const expectedNotification = { | ||
notification: { | ||
element: "ELEMENT_NAME", | ||
errors: "ERRORS_OBJECT", | ||
message: "TEST MESSAGE", | ||
type: "error", | ||
url: "https://docs.cronofy.com/developers/ui-elements/TEST" | ||
} | ||
}; | ||
logConstructor("error", "ELEMENT_NAME", callback); | ||
const log = logConstructor("error", "ELEMENT_NAME", callback); | ||
log.error("TEST MESSAGE", { | ||
docsSlug: "TEST", | ||
errorObject: "ERRORS_OBJECT", | ||
unwanted: "THING" | ||
}); | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
expect(callback).toHaveBeenCalledWith(expectedNotification); | ||
}); | ||
it("correctly builds log notification", () => { | ||
const notification = buildLogNotification("TYPE", "ELEMENT", "MESSAGE"); | ||
expect(typeof notification.notification).toBe("object"); | ||
expect(notification.notification.message).toEqual("MESSAGE"); | ||
expect(notification.notification.type).toEqual("TYPE"); | ||
expect(notification.notification.element).toEqual("ELEMENT"); | ||
expect(notification.notification.errors).toEqual({}); | ||
}); | ||
it("correctly builds log notification with a URL slug", () => { | ||
const notificationWithUrlSlug = buildLogNotification( | ||
"TYPE", | ||
"ELEMENT", | ||
"MESSAGE", | ||
"SLUG" | ||
); | ||
expect(typeof notificationWithUrlSlug.notification).toBe("object"); | ||
expect(notificationWithUrlSlug.notification.message).toEqual("MESSAGE"); | ||
expect(notificationWithUrlSlug.notification.type).toEqual("TYPE"); | ||
expect(notificationWithUrlSlug.notification.element).toEqual("ELEMENT"); | ||
expect(notificationWithUrlSlug.notification.url).toEqual( | ||
"https://docs.cronofy.com/developers/ui-elements/SLUG" | ||
); | ||
}); | ||
it("correctly builds log notification with an errors object", () => { | ||
const notificationWithUrlSlug = buildLogNotification( | ||
"TYPE", | ||
"ELEMENT", | ||
"MESSAGE", | ||
"SLUG", | ||
{ | ||
error_1: "ERROR_1", | ||
error_2: "ERROR_2" | ||
} | ||
); | ||
expect(typeof notificationWithUrlSlug.notification).toBe("object"); | ||
expect(notificationWithUrlSlug.notification.message).toEqual("MESSAGE"); | ||
expect(notificationWithUrlSlug.notification.type).toEqual("TYPE"); | ||
expect(notificationWithUrlSlug.notification.element).toEqual("ELEMENT"); | ||
expect(notificationWithUrlSlug.notification.url).toEqual( | ||
"https://docs.cronofy.com/developers/ui-elements/SLUG" | ||
); | ||
expect(typeof notificationWithUrlSlug.notification.errors).toBe( | ||
"object" | ||
); | ||
expect( | ||
Object.keys(notificationWithUrlSlug.notification.errors).length | ||
).toEqual(2); | ||
expect(notificationWithUrlSlug.notification.errors.error_1).toEqual( | ||
"ERROR_1" | ||
); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2480119
21946