cronofy-elements 1.48.2 → 1.49.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.gitkeep +0 -0
- package/dist/CronofyElements.js +2 -0
- package/{build/CronofyElements.v1.48.2.js.LICENSE.txt → dist/CronofyElements.js.LICENSE.txt} +0 -0
- package/package.json +10 -7
- package/.babelrc +0 -20
- package/.eslintrc.yaml +0 -43
- package/.prettierignore +0 -4
- package/.prettierrc +0 -7
- package/Makefile +0 -92
- package/brainstorm.md +0 -76
- package/build/CronofyElements.v1.48.2.js +0 -2
- package/build/npm/CronofyElements.js +0 -2
- package/compat.config.js +0 -25
- package/demo/agenda.ejs +0 -71
- package/demo/availability-viewer.ejs +0 -322
- package/demo/calendar-sync.ejs +0 -149
- package/demo/crossbrowser.ejs +0 -228
- package/demo/date-time-picker.ejs +0 -213
- package/demo/demo-styles.css +0 -134
- package/demo/index.ejs +0 -249
- package/demo/integration.ejs +0 -482
- package/demo/load-elements.ejs +0 -12
- package/demo/nav.ejs +0 -14
- package/demo/rules.ejs +0 -121
- package/demo/server.js +0 -425
- package/demo/slot-picker.ejs +0 -197
- package/git.README.md +0 -71
- package/notes.style.md +0 -197
- package/postcss.config.js +0 -3
- package/script/i18n-export +0 -11
- package/script/i18n-helpers/split_write.rb +0 -25
- package/script/i18n-import +0 -22
- package/script/i18n-reference-update +0 -241
- package/src/js/components/Agenda/Agenda.js +0 -243
- package/src/js/components/Agenda/AllDayEventsList.js +0 -37
- package/src/js/components/Agenda/Calendar.js +0 -100
- package/src/js/components/Agenda/CalendarHeader.js +0 -187
- package/src/js/components/Agenda/Event.js +0 -34
- package/src/js/components/Agenda/EventAllDay.js +0 -76
- package/src/js/components/Agenda/EventAttendees.js +0 -30
- package/src/js/components/Agenda/EventDetail.js +0 -111
- package/src/js/components/Agenda/EventMessages.js +0 -24
- package/src/js/components/Agenda/EventMeta.js +0 -48
- package/src/js/components/Agenda/EventTime.js +0 -34
- package/src/js/components/Agenda/EventWrapper.js +0 -271
- package/src/js/components/Agenda/Location.js +0 -29
- package/src/js/components/Agenda/Message.js +0 -22
- package/src/js/components/Agenda/TimedEventsList.js +0 -29
- package/src/js/components/AvailabilityRules/AddButton.js +0 -60
- package/src/js/components/AvailabilityRules/AvailabilityRules.js +0 -45
- package/src/js/components/AvailabilityRules/Calendar.js +0 -31
- package/src/js/components/AvailabilityRules/CalendarListItem.js +0 -53
- package/src/js/components/AvailabilityRules/CalendarProfiles.js +0 -67
- package/src/js/components/AvailabilityRules/CalendarSelector.js +0 -104
- package/src/js/components/AvailabilityRules/Calendars.js +0 -145
- package/src/js/components/AvailabilityRules/Checkmark.js +0 -51
- package/src/js/components/AvailabilityRules/DayLabels.js +0 -91
- package/src/js/components/AvailabilityRules/Footer.js +0 -109
- package/src/js/components/AvailabilityRules/Legend.js +0 -57
- package/src/js/components/AvailabilityRules/Loading.js +0 -53
- package/src/js/components/AvailabilityRules/RemoveButton.js +0 -57
- package/src/js/components/AvailabilityRules/Slot.js +0 -195
- package/src/js/components/AvailabilityRules/SlotDisplay.js +0 -27
- package/src/js/components/AvailabilityRules/Slots.js +0 -81
- package/src/js/components/AvailabilityRules/SlotsDisplay.js +0 -68
- package/src/js/components/AvailabilityRules/TimeExpander.js +0 -119
- package/src/js/components/AvailabilityRules/TimeLabels.js +0 -89
- package/src/js/components/AvailabilityRules/TimeZoneDisplay.js +0 -41
- package/src/js/components/AvailabilityRules/ToggleIcon.js +0 -41
- package/src/js/components/AvailabilityRules/Tooltip.js +0 -63
- package/src/js/components/AvailabilityRules/UnknownCalendar.js +0 -33
- package/src/js/components/AvailabilityRules/Week.js +0 -115
- package/src/js/components/AvailabilityRules/WeekGrid.js +0 -80
- package/src/js/components/AvailabilityRules/Wrapper.js +0 -423
- package/src/js/components/AvailabilityRules/contexts/drag-context.js +0 -15
- package/src/js/components/AvailabilityRules/scss/_base.buttons.scss +0 -58
- package/src/js/components/AvailabilityRules/scss/_base.theme.scss +0 -4
- package/src/js/components/AvailabilityRules/scss/_components.timezoneselector.scss +0 -74
- package/src/js/components/AvailabilityRules/scss/_generic.reset.scss +0 -13
- package/src/js/components/AvailabilityRules/scss/_settings.colours.scss +0 -12
- package/src/js/components/AvailabilityRules/scss/availabilityrules.scss +0 -5
- package/src/js/components/AvailabilityRules/utils/tz-utils.js +0 -61
- package/src/js/components/AvailabilityViewer/AvailabilityViewer.js +0 -524
- package/src/js/components/AvailabilityViewer/ColumnHeader.js +0 -35
- package/src/js/components/AvailabilityViewer/DayColumn.js +0 -36
- package/src/js/components/AvailabilityViewer/DayColumnDisplay.js +0 -33
- package/src/js/components/AvailabilityViewer/DayColumnWrapper.js +0 -29
- package/src/js/components/AvailabilityViewer/DayLabels.js +0 -41
- package/src/js/components/AvailabilityViewer/EmptyColumn.js +0 -29
- package/src/js/components/AvailabilityViewer/Footer.js +0 -36
- package/src/js/components/AvailabilityViewer/GridFreeSelect.js +0 -33
- package/src/js/components/AvailabilityViewer/HoverSlot.js +0 -35
- package/src/js/components/AvailabilityViewer/HoverTooltip.js +0 -34
- package/src/js/components/AvailabilityViewer/LabelColumn.js +0 -53
- package/src/js/components/AvailabilityViewer/LabelItem.js +0 -73
- package/src/js/components/AvailabilityViewer/Legend.js +0 -79
- package/src/js/components/AvailabilityViewer/Loading.js +0 -57
- package/src/js/components/AvailabilityViewer/MonthLabels.js +0 -43
- package/src/js/components/AvailabilityViewer/Navigation.js +0 -138
- package/src/js/components/AvailabilityViewer/Overlay.js +0 -60
- package/src/js/components/AvailabilityViewer/Preloading.js +0 -66
- package/src/js/components/AvailabilityViewer/SelectedSlot.js +0 -106
- package/src/js/components/AvailabilityViewer/SelectedSlots.js +0 -72
- package/src/js/components/AvailabilityViewer/SelectionMask.js +0 -44
- package/src/js/components/AvailabilityViewer/Slot.js +0 -237
- package/src/js/components/AvailabilityViewer/SlotFreeSelect.js +0 -115
- package/src/js/components/AvailabilityViewer/Slots.js +0 -57
- package/src/js/components/AvailabilityViewer/TimeExpander.js +0 -93
- package/src/js/components/AvailabilityViewer/TimeLines.js +0 -74
- package/src/js/components/AvailabilityViewer/TimeSelector.js +0 -243
- package/src/js/components/AvailabilityViewer/TimeSelectorTrigger.js +0 -42
- package/src/js/components/AvailabilityViewer/TimeZoneDisplay.js +0 -28
- package/src/js/components/AvailabilityViewer/ToggleIcon.js +0 -41
- package/src/js/components/AvailabilityViewer/Tooltip.js +0 -65
- package/src/js/components/AvailabilityViewer/Week.js +0 -255
- package/src/js/components/AvailabilityViewer/WeekWrapper.js +0 -132
- package/src/js/components/AvailabilityViewer/contexts/page-context.js +0 -17
- package/src/js/components/AvailabilityViewer/contexts/page-reducer.js +0 -28
- package/src/js/components/AvailabilityViewer/contexts/selection-context.js +0 -25
- package/src/js/components/AvailabilityViewer/contexts/selection-reducer.js +0 -18
- package/src/js/components/CalendarSync/Active.js +0 -57
- package/src/js/components/CalendarSync/AddToggle.js +0 -72
- package/src/js/components/CalendarSync/CalendarSync.js +0 -215
- package/src/js/components/CalendarSync/EditToggle.js +0 -71
- package/src/js/components/CalendarSync/Footer.js +0 -31
- package/src/js/components/CalendarSync/Inactive.js +0 -66
- package/src/js/components/CalendarSync/Loading.js +0 -52
- package/src/js/components/CalendarSync/Pending.js +0 -74
- package/src/js/components/CalendarSync/ProfileStatus.js +0 -33
- package/src/js/components/CalendarSync/Profiles.js +0 -109
- package/src/js/components/CalendarSync/ProviderLogo.js +0 -28
- package/src/js/components/CalendarSync/Providers.js +0 -80
- package/src/js/components/CalendarSync/RemoveLink.js +0 -96
- package/src/js/components/CalendarSync/SelectProvider.js +0 -25
- package/src/js/components/CalendarSync/contexts/status-reducer.js +0 -74
- package/src/js/components/DateTimePicker/Calendar.js +0 -127
- package/src/js/components/DateTimePicker/CalendarHeader.js +0 -80
- package/src/js/components/DateTimePicker/Confirm.js +0 -106
- package/src/js/components/DateTimePicker/DateTimePicker.js +0 -131
- package/src/js/components/DateTimePicker/DayButton.js +0 -38
- package/src/js/components/DateTimePicker/DayHeadings.js +0 -33
- package/src/js/components/DateTimePicker/Details.js +0 -33
- package/src/js/components/DateTimePicker/Error.js +0 -39
- package/src/js/components/DateTimePicker/Loading.js +0 -20
- package/src/js/components/DateTimePicker/LoadingCalendar.js +0 -21
- package/src/js/components/DateTimePicker/NoSlotsFound.js +0 -16
- package/src/js/components/DateTimePicker/SequencedSlotButton.js +0 -97
- package/src/js/components/DateTimePicker/SlotButton.js +0 -55
- package/src/js/components/DateTimePicker/SlotsList.js +0 -45
- package/src/js/components/DateTimePicker/Wrapper.js +0 -281
- package/src/js/components/DateTimePicker/contexts/status-context.js +0 -19
- package/src/js/components/DateTimePicker/contexts/status-reducer.js +0 -276
- package/src/js/components/DateTimePicker/contexts/theme-context.js +0 -33
- package/src/js/components/DateTimePicker/helpers/theming.js +0 -49
- package/src/js/components/DateTimePicker/scss/_base.buttons.scss +0 -58
- package/src/js/components/DateTimePicker/scss/_base.layout.scss +0 -28
- package/src/js/components/DateTimePicker/scss/_base.theme.scss +0 -17
- package/src/js/components/DateTimePicker/scss/_components.calendargrid.scss +0 -78
- package/src/js/components/DateTimePicker/scss/_components.calendarheader.scss +0 -71
- package/src/js/components/DateTimePicker/scss/_components.confirm.scss +0 -40
- package/src/js/components/DateTimePicker/scss/_components.details.scss +0 -20
- package/src/js/components/DateTimePicker/scss/_components.error.scss +0 -34
- package/src/js/components/DateTimePicker/scss/_components.loading.scss +0 -36
- package/src/js/components/DateTimePicker/scss/_components.slotslist.scss +0 -43
- package/src/js/components/DateTimePicker/scss/_components.timezoneselector.scss +0 -73
- package/src/js/components/DateTimePicker/scss/_generic.reset.scss +0 -18
- package/src/js/components/DateTimePicker/scss/_settings.colours.scss +0 -17
- package/src/js/components/DateTimePicker/scss/datetimepicker.scss +0 -5
- package/src/js/components/DateTimePicker/utils/calendar-keyboard.js +0 -109
- package/src/js/components/DateTimePicker/utils/calendar.js +0 -125
- package/src/js/components/DateTimePicker/utils/slots.js +0 -288
- package/src/js/components/SlotPicker/Confirm.js +0 -160
- package/src/js/components/SlotPicker/Days.js +0 -58
- package/src/js/components/SlotPicker/Slot.js +0 -72
- package/src/js/components/SlotPicker/SlotPicker.js +0 -292
- package/src/js/components/SlotPicker/Slots.js +0 -66
- package/src/js/components/SlotPicker/TimeSlots.js +0 -91
- package/src/js/components/generic/Button.js +0 -26
- package/src/js/components/generic/Container.js +0 -33
- package/src/js/components/generic/Error.js +0 -77
- package/src/js/components/generic/Loading.js +0 -51
- package/src/js/components/generic/LoadingSpinner.js +0 -30
- package/src/js/components/generic/ShadowScrollbars.js +0 -70
- package/src/js/components/generic/TimeZoneSelector.js +0 -158
- package/src/js/components/generic/TransitionSlide.js +0 -72
- package/src/js/contexts/i18n-context.js +0 -25
- package/src/js/contexts/log-context.js +0 -18
- package/src/js/contexts/tz-context.js +0 -18
- package/src/js/env.example.js +0 -8
- package/src/js/helpers/colors.js +0 -33
- package/src/js/helpers/comparators.AvailabilityViewer.js +0 -27
- package/src/js/helpers/connections.js +0 -370
- package/src/js/helpers/events.js +0 -166
- package/src/js/helpers/functional.js +0 -4
- package/src/js/helpers/generator.js +0 -107
- package/src/js/helpers/i18n.js +0 -153
- package/src/js/helpers/init.Agenda.js +0 -55
- package/src/js/helpers/init.AvailabilityRules.js +0 -195
- package/src/js/helpers/init.AvailabilityViewer.js +0 -215
- package/src/js/helpers/init.CalendarSync.js +0 -83
- package/src/js/helpers/init.DateTimePicker.js +0 -219
- package/src/js/helpers/init.SlotPicker.js +0 -89
- package/src/js/helpers/init.js +0 -308
- package/src/js/helpers/logging.js +0 -78
- package/src/js/helpers/mocks.js +0 -871
- package/src/js/helpers/slots.js +0 -340
- package/src/js/helpers/slots.rules.js +0 -220
- package/src/js/helpers/theming.js +0 -93
- package/src/js/helpers/translations.js +0 -42
- package/src/js/helpers/tz-list.js +0 -136
- package/src/js/helpers/utils.AvailabilityRules.js +0 -110
- package/src/js/helpers/utils.AvailabilityViewer.js +0 -789
- package/src/js/helpers/utils.CalendarSync.js +0 -199
- package/src/js/helpers/utils.js +0 -76
- package/src/js/hooks/useWindowSize.js +0 -20
- package/src/js/main.js +0 -133
- package/src/js/next.js +0 -37
- package/src/js/styles/_settings.utils.scss +0 -82
- package/src/js/styles/colors.js +0 -13
- package/src/js/styles/global.js +0 -49
- package/src/js/styles/utils.js +0 -81
- package/src/js/translations/de/agenda.json +0 -12
- package/src/js/translations/de/availability_rules.json +0 -18
- package/src/js/translations/de/availability_viewer.json +0 -14
- package/src/js/translations/de/calendar_sync.json +0 -14
- package/src/js/translations/de/core.json +0 -15
- package/src/js/translations/de/date_time_picker.json +0 -14
- package/src/js/translations/de/slot_picker.json +0 -9
- package/src/js/translations/de/time_zones.json +0 -135
- package/src/js/translations/en/agenda.json +0 -12
- package/src/js/translations/en/availability_rules.json +0 -18
- package/src/js/translations/en/availability_viewer.json +0 -14
- package/src/js/translations/en/calendar_sync.json +0 -14
- package/src/js/translations/en/core.json +0 -23
- package/src/js/translations/en/date_time_picker.json +0 -15
- package/src/js/translations/en/slot_picker.json +0 -9
- package/src/js/translations/en/time_zones.json +0 -17
- package/src/js/translations/es/agenda.json +0 -12
- package/src/js/translations/es/availability_rules.json +0 -18
- package/src/js/translations/es/availability_viewer.json +0 -14
- package/src/js/translations/es/calendar_sync.json +0 -14
- package/src/js/translations/es/core.json +0 -15
- package/src/js/translations/es/date_time_picker.json +0 -14
- package/src/js/translations/es/slot_picker.json +0 -9
- package/src/js/translations/es/time_zones.json +0 -203
- package/src/js/translations/fr/agenda.json +0 -12
- package/src/js/translations/fr/availability_rules.json +0 -18
- package/src/js/translations/fr/availability_viewer.json +0 -14
- package/src/js/translations/fr/calendar_sync.json +0 -14
- package/src/js/translations/fr/core.json +0 -15
- package/src/js/translations/fr/date_time_picker.json +0 -14
- package/src/js/translations/fr/slot_picker.json +0 -9
- package/src/js/translations/fr/time_zones.json +0 -161
- package/src/js/translations/fr-CA/agenda.json +0 -12
- package/src/js/translations/fr-CA/availability_rules.json +0 -18
- package/src/js/translations/fr-CA/availability_viewer.json +0 -14
- package/src/js/translations/fr-CA/calendar_sync.json +0 -14
- package/src/js/translations/fr-CA/core.json +0 -23
- package/src/js/translations/fr-CA/date_time_picker.json +0 -14
- package/src/js/translations/fr-CA/slot_picker.json +0 -9
- package/src/js/translations/fr-CA/time_zones.json +0 -163
- package/src/js/translations/it/agenda.json +0 -12
- package/src/js/translations/it/availability_rules.json +0 -18
- package/src/js/translations/it/availability_viewer.json +0 -14
- package/src/js/translations/it/calendar_sync.json +0 -14
- package/src/js/translations/it/core.json +0 -15
- package/src/js/translations/it/date_time_picker.json +0 -14
- package/src/js/translations/it/slot_picker.json +0 -9
- package/src/js/translations/it/time_zones.json +0 -126
- package/src/js/translations/ja/agenda.json +0 -12
- package/src/js/translations/ja/availability_rules.json +0 -18
- package/src/js/translations/ja/availability_viewer.json +0 -14
- package/src/js/translations/ja/calendar_sync.json +0 -14
- package/src/js/translations/ja/core.json +0 -15
- package/src/js/translations/ja/date_formats.json +0 -5
- package/src/js/translations/ja/date_time_picker.json +0 -14
- package/src/js/translations/ja/slot_picker.json +0 -9
- package/src/js/translations/ja/time_zones.json +0 -435
- package/src/js/translations/nl/agenda.json +0 -12
- package/src/js/translations/nl/availability_rules.json +0 -18
- package/src/js/translations/nl/availability_viewer.json +0 -14
- package/src/js/translations/nl/calendar_sync.json +0 -14
- package/src/js/translations/nl/core.json +0 -15
- package/src/js/translations/nl/date_time_picker.json +0 -14
- package/src/js/translations/nl/slot_picker.json +0 -9
- package/src/js/translations/nl/time_zones.json +0 -118
- package/src/js/translations/ru/agenda.json +0 -12
- package/src/js/translations/ru/availability_rules.json +0 -18
- package/src/js/translations/ru/availability_viewer.json +0 -14
- package/src/js/translations/ru/calendar_sync.json +0 -14
- package/src/js/translations/ru/core.json +0 -15
- package/src/js/translations/ru/date_time_picker.json +0 -14
- package/src/js/translations/ru/slot_picker.json +0 -9
- package/src/js/translations/ru/time_zones.json +0 -435
- package/src/js/translations/sv/agenda.json +0 -12
- package/src/js/translations/sv/availability_rules.json +0 -18
- package/src/js/translations/sv/availability_viewer.json +0 -14
- package/src/js/translations/sv/calendar_sync.json +0 -14
- package/src/js/translations/sv/core.json +0 -15
- package/src/js/translations/sv/date_time_picker.json +0 -14
- package/src/js/translations/sv/slot_picker.json +0 -9
- package/src/js/translations/sv/time_zones.json +0 -136
- package/tests/AvailabilityRules/AvailabilityRules.test.js +0 -39
- package/tests/AvailabilityRules/__snapshots__/AvailabilityRules.test.js.snap +0 -1045
- package/tests/AvailabilityViewer/Navigation.test.js +0 -130
- package/tests/AvailabilityViewer/contexts/page-reducer.test.js +0 -87
- package/tests/AvailabilityViewer/reducer.test.js +0 -73
- package/tests/CalendarSync/Active.test.js +0 -25
- package/tests/CalendarSync/AddToggle.test.js +0 -57
- package/tests/CalendarSync/EditToggle.test.js +0 -57
- package/tests/CalendarSync/Inactive.test.js +0 -26
- package/tests/CalendarSync/Pending.test.js +0 -25
- package/tests/CalendarSync/ProviderLogo.test.js +0 -95
- package/tests/CalendarSync/__snapshots__/Active.test.js.snap +0 -61
- package/tests/CalendarSync/__snapshots__/Inactive.test.js.snap +0 -78
- package/tests/CalendarSync/__snapshots__/Pending.test.js.snap +0 -90
- package/tests/CalendarSync/__snapshots__/ProviderLogo.test.js.snap +0 -267
- package/tests/CalendarSync/init.CalendarSync.test.js +0 -302
- package/tests/CalendarSync/mocks/theme.js +0 -14
- package/tests/CalendarSync/status-reducer.test.js +0 -435
- package/tests/DateTimePicker/SequencedSlotButton.test.js +0 -157
- package/tests/DateTimePicker/SlotButton.test.js +0 -118
- package/tests/DateTimePicker/contexts/status-reducer.test.js +0 -1036
- package/tests/DateTimePicker/dummy-data.js +0 -883
- package/tests/DateTimePicker/utils.test.js +0 -515
- package/tests/colors.test.js +0 -70
- package/tests/components/TimezoneSelector.test.js +0 -124
- package/tests/components/main.test.js +0 -203
- package/tests/components/rtl-utils.js +0 -32
- package/tests/connections.test.js +0 -684
- package/tests/events.test.js +0 -472
- package/tests/generator.test.js +0 -74
- package/tests/i18n.test.js +0 -255
- package/tests/init.Agenda.test.js +0 -122
- package/tests/init.AvailabilityRules.test.js +0 -279
- package/tests/init.AvailabilityViewer.test.js +0 -740
- package/tests/init.SlotPicker.test.js +0 -166
- package/tests/init.test.js +0 -231
- package/tests/logging.test.js +0 -235
- package/tests/mocks/i18n.js +0 -3
- package/tests/mocks/theme.js +0 -3
- package/tests/setupJest.js +0 -8
- package/tests/slots.rules.test.js +0 -195
- package/tests/slots.test.js +0 -278
- package/tests/utils.AvailabilityRules.test.js +0 -221
- package/tests/utils.AvailabilityViewer.test.js +0 -1800
- package/tests/utils.CalendarSync.test.js +0 -277
- package/tests/utils.test.js +0 -119
- package/webpack.config.js +0 -114
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import moment from "moment-timezone";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
parseConnectionDomains,
|
|
5
|
-
parseQuery,
|
|
6
|
-
parseTarget,
|
|
7
|
-
parseTimezone,
|
|
8
|
-
parseToken,
|
|
9
|
-
parseTranslations,
|
|
10
|
-
validateLocaleModifiers,
|
|
11
|
-
} from "./init";
|
|
12
|
-
import { logConstructor } from "./logging";
|
|
13
|
-
import { queryForDateTimePicker, sequencedQueryForDateTimePicker } from "./mocks";
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
getMonthsFromQuery,
|
|
17
|
-
parseQuery as parseWithOverlappingSlots,
|
|
18
|
-
} from "../components/DateTimePicker/utils/slots";
|
|
19
|
-
|
|
20
|
-
export const parseDateTimePickerOptions = (options = {}) => {
|
|
21
|
-
const config = typeof options.config === "undefined" ? {} : options.config;
|
|
22
|
-
const logs = typeof config.logs === "undefined" ? "warn" : config.logs;
|
|
23
|
-
const log = logConstructor(logs, "Date Time Picker", options.callback);
|
|
24
|
-
|
|
25
|
-
const startDay =
|
|
26
|
-
typeof config.week_start_day === "undefined" ? "sunday" : config.week_start_day;
|
|
27
|
-
|
|
28
|
-
const validDays = [
|
|
29
|
-
"sunday",
|
|
30
|
-
"monday",
|
|
31
|
-
"tuesday",
|
|
32
|
-
"wednesday",
|
|
33
|
-
"thursday",
|
|
34
|
-
"friday",
|
|
35
|
-
"saturday",
|
|
36
|
-
];
|
|
37
|
-
const validStartDay = validDays.includes(startDay);
|
|
38
|
-
|
|
39
|
-
if (!validStartDay) {
|
|
40
|
-
log.error(
|
|
41
|
-
`Please provide a valid \`config.week_start_day\`. \`${startDay}\` is not a supported value.`,
|
|
42
|
-
{
|
|
43
|
-
docsSlug: "availability-viewer/#config.week_start_day",
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const mode = typeof config.mode === "undefined" ? "confirm" : config.mode;
|
|
50
|
-
const validModes = ["confirm", "no_confirm"];
|
|
51
|
-
const validMode = validModes.includes(mode);
|
|
52
|
-
if (!validMode) {
|
|
53
|
-
log.error(`Please provide a valid \`config.mode\`. \`${mode}\` is not a supported value.`, {
|
|
54
|
-
docsSlug: "date-time-picker/#config.mode",
|
|
55
|
-
});
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const demoMode = typeof options.demo === "undefined" ? false : options.demo;
|
|
60
|
-
if (demoMode) {
|
|
61
|
-
log.warn("You are running in demo mode. No API requests will be made");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const token = parseToken(options, "date-time-picker", log);
|
|
65
|
-
if (!token && !demoMode) {
|
|
66
|
-
log.error(
|
|
67
|
-
"You need to include an `element_token`. If you're just testing (and don't want to use real API data) you can set the `demo` option to `true` to bypass the API connection and view dummy content."
|
|
68
|
-
);
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const target = parseTarget(options, "date-time-picker", log);
|
|
73
|
-
|
|
74
|
-
const isBookableEventsQuery = options.availability_query.bookable_events ? true : false;
|
|
75
|
-
const isSequencedAvailabilityQuery = options.availability_query.sequence ? true : false;
|
|
76
|
-
|
|
77
|
-
let query;
|
|
78
|
-
if (options.demo && !isSequencedAvailabilityQuery) {
|
|
79
|
-
query = queryForDateTimePicker;
|
|
80
|
-
} else if (options.demo && isSequencedAvailabilityQuery) {
|
|
81
|
-
query = sequencedQueryForDateTimePicker;
|
|
82
|
-
} else if (isBookableEventsQuery) {
|
|
83
|
-
query = options.availability_query;
|
|
84
|
-
query = parseWithOverlappingSlots(query);
|
|
85
|
-
} else if (isSequencedAvailabilityQuery) {
|
|
86
|
-
query = options.availability_query;
|
|
87
|
-
query = parseWithOverlappingSlots(query);
|
|
88
|
-
} else {
|
|
89
|
-
query = parseQuery({ options, elementSlug: "date-time-picker", log });
|
|
90
|
-
query = parseWithOverlappingSlots(query);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (isSequencedAvailabilityQuery) {
|
|
94
|
-
const isOneTitlePresent = query.sequence.some(obj =>
|
|
95
|
-
Object.keys(obj).includes("sequence_title")
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
if (isOneTitlePresent) {
|
|
99
|
-
const isEveryTitlePresent = query.sequence.every(obj =>
|
|
100
|
-
Object.keys(obj).includes("sequence_title")
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (!isEveryTitlePresent) {
|
|
104
|
-
log.error("There is a missing `sequence_title` from at least one sequence event.");
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (typeof config.slot_button_mode !== "undefined" && !isSequencedAvailabilityQuery) {
|
|
111
|
-
log.warn(
|
|
112
|
-
`\`config.slot_button_mode\`. can only be used with a sequenced availability query. Setting this option on a regular availability query will have no effect.`
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const slotButtonMode =
|
|
117
|
-
typeof config.slot_button_mode === "undefined" ? "summary" : config.slot_button_mode;
|
|
118
|
-
|
|
119
|
-
const validSlotButtonModes = ["summary", "detailed"];
|
|
120
|
-
const validSlotButtonMode = validSlotButtonModes.includes(slotButtonMode);
|
|
121
|
-
|
|
122
|
-
if (isSequencedAvailabilityQuery && !validSlotButtonMode) {
|
|
123
|
-
log.error(
|
|
124
|
-
`Please provide a valid \`config.slot_button_mode\`. \`${slotButtonMode}\` is not a supported value.`,
|
|
125
|
-
{
|
|
126
|
-
docsSlug: "date-time-picker/#config.slot_button_mode",
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const tzid = parseTimezone(options.tzid, "date-time-picker", log);
|
|
133
|
-
|
|
134
|
-
const tzList = typeof config.tz_list === "undefined" ? false : config.tz_list;
|
|
135
|
-
|
|
136
|
-
const domains = parseConnectionDomains(
|
|
137
|
-
options.data_center,
|
|
138
|
-
options.api_domain,
|
|
139
|
-
options.app_domain
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
const translations = parseTranslations(options.translations, "availability_rules");
|
|
143
|
-
|
|
144
|
-
const modifier =
|
|
145
|
-
typeof options.locale_modifiers !== "undefined" ? options.locale_modifiers : null;
|
|
146
|
-
const isValidLocaleModifiers = modifier ? validateLocaleModifiers(modifier) : true;
|
|
147
|
-
if (!isValidLocaleModifiers) {
|
|
148
|
-
log.warn("`locale_modifiers is invalid. Modifiers will fallback to the default.`", {
|
|
149
|
-
docsSlug: "#locale-modifiers",
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
let selectedDate = config.selected_date;
|
|
154
|
-
if (typeof selectedDate !== "undefined") {
|
|
155
|
-
const validDate = moment(selectedDate, "YYYY-MM-DD", true).isValid();
|
|
156
|
-
|
|
157
|
-
if (!validDate) {
|
|
158
|
-
log.warn(
|
|
159
|
-
`The provided date ${selectedDate} is not valid. Please ensure it's formatted like "YYYY-MM-DD". Picking the first available date as starting date.`,
|
|
160
|
-
{
|
|
161
|
-
docsSlug: "#config.start_date",
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
selectedDate = undefined;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const months = getMonthsFromQuery(query?.query_periods, tzid.tzid);
|
|
170
|
-
const selectedDateMoment = selectedDate && moment(selectedDate, "YYYY-MM-DD");
|
|
171
|
-
|
|
172
|
-
let startDateMoment = months.length
|
|
173
|
-
? moment(months[0], "YYYY-MM").startOf("month")
|
|
174
|
-
: moment().startOf("month");
|
|
175
|
-
|
|
176
|
-
if (selectedDateMoment?.isBefore(startDate)) {
|
|
177
|
-
startDateMoment = selectedDateMoment;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
let endDateMoment = months.length
|
|
181
|
-
? moment(months[months.length - 1], "YYYY-MM").endOf("month")
|
|
182
|
-
: moment().endOf("month");
|
|
183
|
-
|
|
184
|
-
if (selectedDateMoment?.isAfter(endDateMoment)) {
|
|
185
|
-
endDateMoment = selectedDateMoment;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const startDate = startDateMoment.format("YYYY-MM-DD");
|
|
189
|
-
const endDate = endDateMoment.format("YYYY-MM-DD");
|
|
190
|
-
|
|
191
|
-
delete options.availability_query;
|
|
192
|
-
delete options.element_token;
|
|
193
|
-
delete options.target_id;
|
|
194
|
-
delete options.translations;
|
|
195
|
-
delete config.week_start_day;
|
|
196
|
-
delete config.tz_list;
|
|
197
|
-
|
|
198
|
-
return {
|
|
199
|
-
...options,
|
|
200
|
-
...tzid,
|
|
201
|
-
target,
|
|
202
|
-
token,
|
|
203
|
-
domains,
|
|
204
|
-
query,
|
|
205
|
-
config: {
|
|
206
|
-
...config,
|
|
207
|
-
mode,
|
|
208
|
-
logs,
|
|
209
|
-
startDay,
|
|
210
|
-
selectedDate,
|
|
211
|
-
startDate,
|
|
212
|
-
endDate,
|
|
213
|
-
tzList,
|
|
214
|
-
slotButtonMode,
|
|
215
|
-
},
|
|
216
|
-
translations,
|
|
217
|
-
log,
|
|
218
|
-
};
|
|
219
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseConnectionDomains,
|
|
3
|
-
parseQuery,
|
|
4
|
-
parseTarget,
|
|
5
|
-
parseTimezone,
|
|
6
|
-
parseToken,
|
|
7
|
-
parseTranslations,
|
|
8
|
-
validateLocaleModifiers,
|
|
9
|
-
} from "./init";
|
|
10
|
-
import { logConstructor } from "./logging";
|
|
11
|
-
|
|
12
|
-
export const parseSlotPickerOptions = (options = {}) => {
|
|
13
|
-
const config = typeof options.config === "undefined" ? {} : options.config;
|
|
14
|
-
const logs = typeof config.logs === "undefined" ? "warn" : config.logs;
|
|
15
|
-
const log = logConstructor(logs, "Slot Picker", options.callback);
|
|
16
|
-
|
|
17
|
-
const mode = typeof config.mode === "undefined" ? "confirm" : config.mode;
|
|
18
|
-
const validModes = ["confirm", "no_confirm"];
|
|
19
|
-
const validMode = validModes.includes(mode);
|
|
20
|
-
if (!validMode) {
|
|
21
|
-
log.error(`Please provide a valid \`config.mode\`. \`${mode}\` is not a supported value.`, {
|
|
22
|
-
docsSlug: "slot-picker/#config.mode",
|
|
23
|
-
});
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const demoMode = typeof options.demo === "undefined" ? false : options.demo;
|
|
28
|
-
if (demoMode) {
|
|
29
|
-
log.warn("You are running in demo mode. No API requests will be made");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const token = parseToken(options, "slot-picker", log);
|
|
33
|
-
if (!token && !demoMode) {
|
|
34
|
-
log.error(
|
|
35
|
-
"You need to include an `element_token`. If you're just testing (and don't want to use real API data) you can set the `demo` option to `true` to bypass the API connection and view dummy content."
|
|
36
|
-
);
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const target = parseTarget(options, "slot-picker", log);
|
|
41
|
-
|
|
42
|
-
const isBookableEventsQuery = options.availability_query.bookable_events ? true : false;
|
|
43
|
-
|
|
44
|
-
let query;
|
|
45
|
-
if (isBookableEventsQuery) {
|
|
46
|
-
query = options.availability_query;
|
|
47
|
-
} else {
|
|
48
|
-
query = parseQuery({ options, elementSlug: "slot-picker", log });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const tzid = parseTimezone(options.tzid, "slot-picker", log);
|
|
52
|
-
|
|
53
|
-
const domains = parseConnectionDomains(
|
|
54
|
-
options.data_center,
|
|
55
|
-
options.api_domain,
|
|
56
|
-
options.app_domain
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const translations = parseTranslations(options.translations, "availability_rules");
|
|
60
|
-
|
|
61
|
-
const modifier =
|
|
62
|
-
typeof options.locale_modifiers !== "undefined" ? options.locale_modifiers : null;
|
|
63
|
-
|
|
64
|
-
const isValidLocaleModifiers = modifier ? validateLocaleModifiers(modifier) : true;
|
|
65
|
-
if (!isValidLocaleModifiers) {
|
|
66
|
-
log.warn(
|
|
67
|
-
"`locale_modifiers has an invalid value. Invalid modifiers will fallback to the default.`",
|
|
68
|
-
{
|
|
69
|
-
docsSlug: "#locale-modifiers",
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
delete options.availability_query;
|
|
75
|
-
delete options.element_token;
|
|
76
|
-
delete options.target_id;
|
|
77
|
-
delete options.translations;
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
...options,
|
|
81
|
-
...tzid,
|
|
82
|
-
target,
|
|
83
|
-
token,
|
|
84
|
-
domains,
|
|
85
|
-
query,
|
|
86
|
-
config: { ...config, mode, logs },
|
|
87
|
-
translations,
|
|
88
|
-
};
|
|
89
|
-
};
|
package/src/js/helpers/init.js
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
import merge from "deepmerge";
|
|
2
|
-
import { translations } from "./translations";
|
|
3
|
-
import moment from "moment-timezone";
|
|
4
|
-
import { modifierDateFormats } from "./i18n";
|
|
5
|
-
import { nestedValue } from "./utils";
|
|
6
|
-
|
|
7
|
-
export const parseConnectionDomains = (
|
|
8
|
-
dataCenter = false,
|
|
9
|
-
customApiDomain = false,
|
|
10
|
-
customAppDomain = false
|
|
11
|
-
) => {
|
|
12
|
-
let dataCenterSuffix = dataCenter && dataCenter !== "us" ? `-${dataCenter}` : "";
|
|
13
|
-
let apiDomain;
|
|
14
|
-
|
|
15
|
-
if (customApiDomain) {
|
|
16
|
-
// If the "domain" starts with a protocol, we can assume it is
|
|
17
|
-
// a full path. Otherwise assume it is *actually* a domain, so add our
|
|
18
|
-
// protocol (everyone should be using HTTPS)
|
|
19
|
-
apiDomain = customApiDomain.startsWith("http")
|
|
20
|
-
? customApiDomain
|
|
21
|
-
: `https://${customApiDomain}`;
|
|
22
|
-
} else {
|
|
23
|
-
apiDomain = `https://api${dataCenterSuffix}.cronofy.com`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let appDomain = customAppDomain || `https://app${dataCenterSuffix}.cronofy.com`;
|
|
27
|
-
return {
|
|
28
|
-
apiDomain,
|
|
29
|
-
appDomain,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const parseToken = (options, elementSlug = false, log) => {
|
|
34
|
-
const docsHash = elementSlug ? `#${elementSlug}` : "";
|
|
35
|
-
let token = false;
|
|
36
|
-
if (typeof options.token !== "undefined") {
|
|
37
|
-
log.warn(
|
|
38
|
-
"`token` option has been deprecated in v1.0.0. Please use `element_token` option instead.",
|
|
39
|
-
{ docsSlug: `upgrade-v0-to-v1/${docsHash}` }
|
|
40
|
-
);
|
|
41
|
-
token = options.token;
|
|
42
|
-
}
|
|
43
|
-
if (typeof options.element_token !== "undefined") {
|
|
44
|
-
token = options.element_token;
|
|
45
|
-
}
|
|
46
|
-
return token;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const parseTarget = (options, elementSlug, log) => {
|
|
50
|
-
const docsHash = elementSlug ? `#${elementSlug}` : "";
|
|
51
|
-
let target = false;
|
|
52
|
-
|
|
53
|
-
if (typeof options.target !== "undefined") {
|
|
54
|
-
log.warn(
|
|
55
|
-
"`target` option has been deprecated in v1.0.0. Please use `target_id` option instead.",
|
|
56
|
-
{ docsSlug: `upgrade-v0-to-v1/${docsHash}` }
|
|
57
|
-
);
|
|
58
|
-
target = options.target;
|
|
59
|
-
}
|
|
60
|
-
if (typeof options.target_id !== "undefined") {
|
|
61
|
-
target = options.target_id;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!target) {
|
|
65
|
-
log.warn(
|
|
66
|
-
`Using the default ID \`cronofy-element-${elementSlug}\` for mounting markup. You should specify a custom ID for your mounting point.`
|
|
67
|
-
);
|
|
68
|
-
target = `cronofy-element-${elementSlug}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return target;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const parseQuery = ({ options, elementSlug, log, allowEmpty = false }) => {
|
|
75
|
-
const docsHash = elementSlug ? `#${elementSlug}` : "";
|
|
76
|
-
let query = false;
|
|
77
|
-
|
|
78
|
-
if (typeof options.query !== "undefined") {
|
|
79
|
-
log.warn(
|
|
80
|
-
"`query` option has been deprecated in v1.0.0. Please use `availability_query` option instead.",
|
|
81
|
-
{ docsSlug: `upgrade-v0-to-v1/${docsHash}` }
|
|
82
|
-
);
|
|
83
|
-
query = options.query;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (typeof options.availability_query !== "undefined") {
|
|
87
|
-
query = options.availability_query;
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
typeof query.available_periods !== "undefined" &&
|
|
91
|
-
typeof query.query_periods !== "undefined"
|
|
92
|
-
) {
|
|
93
|
-
log.error(
|
|
94
|
-
"You have provided an `availability_query.query_periods` option alongside an `availability_query.available_periods` option. Please only provide `availability_query.query_periods`",
|
|
95
|
-
{ docsSlug: "availability-viewer/#availability_query" }
|
|
96
|
-
);
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (typeof query.available_periods !== "undefined") {
|
|
101
|
-
query.query_periods = query.available_periods;
|
|
102
|
-
delete query.available_periods;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (typeof query.query_periods === "undefined") {
|
|
106
|
-
log.error("You need to provide an `availability_query.query_periods` option.", {
|
|
107
|
-
docsSlug: "availability-viewer/#availability_query",
|
|
108
|
-
});
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!validateQueryPeriods(query.query_periods, log, allowEmpty)) return false;
|
|
113
|
-
|
|
114
|
-
if (typeof query.required_duration === "undefined") {
|
|
115
|
-
log.error("You need to provide an `availability_query.required_duration` option.", {
|
|
116
|
-
docsSlug: "availability-viewer/#availability_query",
|
|
117
|
-
});
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (!query) {
|
|
123
|
-
log.error("You need to provide an `availability_query` option.", {
|
|
124
|
-
docsSlug: "availability-viewer/#availability_query",
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return query;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const validateQueryPeriods = (query_periods, log, allowEmpty = false) => {
|
|
132
|
-
if (!Array.isArray(query_periods)) {
|
|
133
|
-
log.error(
|
|
134
|
-
"The provided `availability_query.query_periods` option is not an array. No results will be shown",
|
|
135
|
-
{ docsSlug: "availability-viewer/#availability_query" }
|
|
136
|
-
);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (allowEmpty && query_periods.length < 1) {
|
|
141
|
-
log.warn(
|
|
142
|
-
"The provided `availability_query.query_periods` option is empty. No results will be shown",
|
|
143
|
-
{ docsSlug: "availability-viewer/#availability_query" }
|
|
144
|
-
);
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (query_periods.length < 1) {
|
|
149
|
-
log.error(
|
|
150
|
-
"The provided `availability_query.query_periods` option is empty. No results will be shown",
|
|
151
|
-
{ docsSlug: "availability-viewer/#availability_query" }
|
|
152
|
-
);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
let errors = {};
|
|
157
|
-
query_periods.forEach((qp, index) => {
|
|
158
|
-
if (qp === null || typeof qp !== "object" || !("end" in qp) || !("start" in qp)) {
|
|
159
|
-
errors[`query_period[${index}]`] = [
|
|
160
|
-
"query period must be an object with start and end properties",
|
|
161
|
-
];
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
let out = [];
|
|
166
|
-
|
|
167
|
-
if (!moment(qp.start).isValid()) {
|
|
168
|
-
out.push("start must be a valid date string");
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (!moment(qp.end).isValid()) {
|
|
172
|
-
out.push("end must be a valid date string");
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (qp.start >= qp.end) {
|
|
176
|
-
out.push("end must be after start");
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (out.length > 0) errors[`query_period[${index}]`] = out;
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
if (Object.keys(errors).length > 0) {
|
|
183
|
-
log.error(
|
|
184
|
-
"Some of the provided `availability_query.query_periods` option have errors. No results will be shown",
|
|
185
|
-
{
|
|
186
|
-
docsSlug: "availability-viewer/#availability_query",
|
|
187
|
-
errorObject: errors,
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
return true;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export const parseTranslations = customTranslations => {
|
|
196
|
-
if (typeof customTranslations !== "undefined") {
|
|
197
|
-
return merge(translations, customTranslations);
|
|
198
|
-
}
|
|
199
|
-
return translations;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
export const parseInterval = (option = false) => {
|
|
203
|
-
// Make sure we have an interval to start with...
|
|
204
|
-
let interval = option ? option : 15;
|
|
205
|
-
// Round it to the nearest 15 mins
|
|
206
|
-
interval = Math.ceil(interval / 15) * 15;
|
|
207
|
-
// If it's 45, bump it up to 60 [^1]
|
|
208
|
-
interval = interval === 45 ? 60 : interval;
|
|
209
|
-
// If it's over 60, round down [^1]
|
|
210
|
-
interval = interval > 60 ? 60 : interval;
|
|
211
|
-
// [:1] We currently only support the following intervals: 15 | 30 | 60
|
|
212
|
-
return interval;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
export const parseTimezone = (option, elementSlug = false, log) => {
|
|
216
|
-
const docsHash = elementSlug ? `${elementSlug}/#param-tzid` : "";
|
|
217
|
-
const isValidTzid = moment.tz.zone(option);
|
|
218
|
-
|
|
219
|
-
const sniffedTimezone = !isValidTzid ? moment.tz.guess() : "";
|
|
220
|
-
|
|
221
|
-
if (typeof option !== "undefined" && !isValidTzid) {
|
|
222
|
-
log.warn(
|
|
223
|
-
`The provided TZID of ${option} is not valid. Using ${sniffedTimezone} instead. Full details of valid TZIDs can be found on the Cronofy Elements documention page: https://docs.cronofy.com/developers/ui-elements/${docsHash}`
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
tzid: !isValidTzid ? sniffedTimezone : option,
|
|
229
|
-
customtzid: typeof option !== "undefined",
|
|
230
|
-
};
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
export const parseGridTime = (time, fallback = "09:00", roundUp = false) => {
|
|
234
|
-
// If there's no time set, fallback silently.
|
|
235
|
-
if (typeof time === "undefined") return { message: false, time: fallback, offset: 0 };
|
|
236
|
-
|
|
237
|
-
// If there is a time, is it in a valid format?
|
|
238
|
-
const validTime = moment(time, "HH:mm", true).isValid();
|
|
239
|
-
if (!validTime) {
|
|
240
|
-
return {
|
|
241
|
-
message: `using default value of ${fallback}`,
|
|
242
|
-
time: fallback,
|
|
243
|
-
offset: 0,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const parts = time.split(":");
|
|
248
|
-
const rawMinutes = parseInt(parts[1], 10);
|
|
249
|
-
|
|
250
|
-
// If the time falls on an approved interval, it's valid!
|
|
251
|
-
if (rawMinutes % 15 === 0) {
|
|
252
|
-
return {
|
|
253
|
-
message: false,
|
|
254
|
-
time: time,
|
|
255
|
-
offset: rawMinutes,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const roundedMinutes = roundUp
|
|
260
|
-
? (Math.ceil(rawMinutes / 15) * 15) % 60
|
|
261
|
-
: (Math.floor(rawMinutes / 15) * 15) % 60;
|
|
262
|
-
|
|
263
|
-
const paddedMinutes = roundedMinutes.toString().padStart(2, "0");
|
|
264
|
-
|
|
265
|
-
return {
|
|
266
|
-
message: `rounded from ${time} to ${parts[0]}:${paddedMinutes}`,
|
|
267
|
-
time: `${parts[0]}:${paddedMinutes}`,
|
|
268
|
-
offset: roundedMinutes,
|
|
269
|
-
};
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
export const adjustInterval = (rawInterval, offset, log) => {
|
|
273
|
-
if (offset > 0 && rawInterval > offset) {
|
|
274
|
-
// Positive offsets will only ever be 15, 30 or 45.
|
|
275
|
-
const adjustedInterval = offset === 45 ? 15 : offset;
|
|
276
|
-
log.warn(
|
|
277
|
-
`config.interval of ${rawInterval} minutes has been shortened to ${adjustedInterval} minutes for optimal tessellation of results in the grid.`,
|
|
278
|
-
{
|
|
279
|
-
docsSlug: "availability-viewer/#config.interval",
|
|
280
|
-
}
|
|
281
|
-
);
|
|
282
|
-
return adjustedInterval;
|
|
283
|
-
}
|
|
284
|
-
return rawInterval;
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
export const validateLocaleModifiers = modifiers => {
|
|
288
|
-
const defaultLocales = Object.keys(modifierDateFormats);
|
|
289
|
-
const locales = Object.keys(modifiers);
|
|
290
|
-
|
|
291
|
-
for (const locale of locales) {
|
|
292
|
-
const test = defaultLocales.includes(locale);
|
|
293
|
-
if (!test) {
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
for (const locale of locales) {
|
|
299
|
-
const value = nestedValue([locale, "dates"], modifiers);
|
|
300
|
-
if (value) {
|
|
301
|
-
const valueA = nestedValue([locale, "dates"], modifiers);
|
|
302
|
-
const valueB = nestedValue([locale, "dates"], modifierDateFormats);
|
|
303
|
-
return valueB[valueA] ? true : false;
|
|
304
|
-
} else {
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export const errorWrap = (elementName, message, docsSlug = "") => {
|
|
2
|
-
return `UI Elements: ${elementName}\n${message}\nhttps://docs.cronofy.com/developers/ui-elements/${docsSlug}\n`;
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
export const buildLogNotification = (type, elementName, message, url = "", errorObject = false) => {
|
|
6
|
-
const notification = {
|
|
7
|
-
notification: {
|
|
8
|
-
type: type,
|
|
9
|
-
element: elementName,
|
|
10
|
-
message,
|
|
11
|
-
url: `https://docs.cronofy.com/developers/ui-elements/${url}`,
|
|
12
|
-
errors: errorObject ? errorObject : {},
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
return notification;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// `logs` options: "error" | "warn" | "info" | "none"
|
|
19
|
-
export const logConstructor = (mode = "warn", elementName = "General", callback = false) => {
|
|
20
|
-
const _log = (type = "log", ...message) => {
|
|
21
|
-
// Sometimes we just want to use a single string as a message,
|
|
22
|
-
// but occasionally we'll want to include an error object too.
|
|
23
|
-
// The "rest" (`...`) catches the string *and* any included objects.
|
|
24
|
-
|
|
25
|
-
// This is where we filter out undefined error objects (just in case)
|
|
26
|
-
const messages = message.filter(m => typeof m !== "undefined");
|
|
27
|
-
|
|
28
|
-
if (mode === "none") return;
|
|
29
|
-
if (mode === "error" && type !== "error") return;
|
|
30
|
-
if (mode === "warn" && type !== "error" && type !== "warn") return;
|
|
31
|
-
|
|
32
|
-
// Now we'll "spread" (`...` again) to log either just the message
|
|
33
|
-
// or the message and any included objects.
|
|
34
|
-
console[type](...messages);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const buildLog = type => (
|
|
38
|
-
message = "There was a problem with the UI Elements",
|
|
39
|
-
extras = {}
|
|
40
|
-
) => {
|
|
41
|
-
const messageString = errorWrap(elementName, message, extras.docsSlug);
|
|
42
|
-
if (callback) {
|
|
43
|
-
callback(
|
|
44
|
-
buildLogNotification(
|
|
45
|
-
type,
|
|
46
|
-
elementName,
|
|
47
|
-
message,
|
|
48
|
-
extras.docsSlug,
|
|
49
|
-
extras.errorObject
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
return _log(type, messageString, extras.errorObject);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
log: buildLog("log"),
|
|
58
|
-
info: buildLog("info"),
|
|
59
|
-
warn: buildLog("warn"),
|
|
60
|
-
error: buildLog("error"),
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const errorMessages = {
|
|
65
|
-
401: {
|
|
66
|
-
message: "There was a problem fetching data: check your element_token is valid.",
|
|
67
|
-
docsSlug: "authentication/#generating-a-token",
|
|
68
|
-
},
|
|
69
|
-
403: {
|
|
70
|
-
message:
|
|
71
|
-
"Incorrect permissions: check the `permissions` array when creating your element_token",
|
|
72
|
-
docsSlug: "authentication/#permissions",
|
|
73
|
-
},
|
|
74
|
-
422: {
|
|
75
|
-
message: "There was a problem with your availability query.",
|
|
76
|
-
docsSlug: "availability-viewer/#availability_query",
|
|
77
|
-
},
|
|
78
|
-
};
|