@bigbinary/neeto-molecules 3.9.10 → 3.9.12
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/Schedule.js +199 -182
- package/dist/Schedule.js.map +1 -1
- package/dist/cjs/Schedule.js +196 -179
- package/dist/cjs/Schedule.js.map +1 -1
- package/package.json +3 -1
- package/types/AuditLogs.d.ts +5 -3
- package/types/Breadcrumbs.d.ts +5 -3
- package/types/BrowserSupport.d.ts +5 -3
- package/types/Builder.d.ts +5 -7
- package/types/CalendarView.d.ts +8 -6
- package/types/Codeblock.d.ts +7 -5
- package/types/Columns.d.ts +8 -6
- package/types/ConfigurePageSidebar.d.ts +5 -3
- package/types/ConfirmationModal.d.ts +5 -3
- package/types/Container.d.ts +5 -3
- package/types/CopyToClipboardButton.d.ts +6 -4
- package/types/Currency.d.ts +7 -5
- package/types/CustomDomain.d.ts +6 -4
- package/types/CustomDomainDashboard.d.ts +6 -4
- package/types/DateFormat.d.ts +5 -9
- package/types/DateRangeFilter.d.ts +7 -5
- package/types/DeleteArchiveModal.d.ts +5 -3
- package/types/DeviceIncompatibilityMessage.d.ts +5 -3
- package/types/DocumentEditor.d.ts +6 -4
- package/types/DownloadMobileAppCallout.d.ts +5 -3
- package/types/DynamicVariables.d.ts +6 -4
- package/types/EmailForm.d.ts +7 -5
- package/types/EmailFormProvider.d.ts +3 -2
- package/types/EmailPreview.d.ts +5 -3
- package/types/EmojiPicker.d.ts +6 -4
- package/types/EmojiReactions.d.ts +5 -3
- package/types/ErrorPage.d.ts +6 -4
- package/types/FileUpload.d.ts +8 -6
- package/types/FloatingActionMenu.d.ts +6 -4
- package/types/GoogleFontPicker.d.ts +27 -20
- package/types/Header.d.ts +9 -6
- package/types/HelpPopover.d.ts +7 -5
- package/types/IconPicker.d.ts +5 -3
- package/types/ImageWithFallback.d.ts +5 -3
- package/types/InlineInput.d.ts +9 -7
- package/types/Insights.d.ts +5 -4
- package/types/IntegrationCard.d.ts +7 -5
- package/types/IpRestriction.d.ts +5 -3
- package/types/KeyboardShortcuts.d.ts +6 -4
- package/types/LoginPage.d.ts +5 -3
- package/types/MadeWith.d.ts +5 -3
- package/types/MenuBar.d.ts +7 -5
- package/types/Metadata.d.ts +5 -3
- package/types/MobilePreviewHeader.d.ts +5 -3
- package/types/MoreDropdown.d.ts +6 -4
- package/types/NavigationHeader.d.ts +7 -6
- package/types/NeetoWidget.d.ts +5 -3
- package/types/Onboarding.d.ts +5 -3
- package/types/OptionFields.d.ts +4 -2
- package/types/PageLoader.d.ts +5 -3
- package/types/PhoneNumber.d.ts +15 -13
- package/types/ProductEmbed.d.ts +5 -3
- package/types/PublishBlock.d.ts +6 -4
- package/types/Rename.d.ts +6 -4
- package/types/ResponsiveDevicePicker.d.ts +5 -3
- package/types/Schedule.d.ts +5 -3
- package/types/Scrollable.d.ts +6 -4
- package/types/Search.d.ts +6 -4
- package/types/SendToFields.d.ts +6 -4
- package/types/SessionEnvironment.d.ts +8 -5
- package/types/Settings.d.ts +5 -4
- package/types/ShareRecordingPane.d.ts +4 -2
- package/types/ShareViaEmail.d.ts +5 -3
- package/types/ShareViaLink.d.ts +5 -4
- package/types/Sidebar.d.ts +7 -5
- package/types/StatusDropdown.d.ts +5 -3
- package/types/StickyRibbonsContainer.d.ts +5 -3
- package/types/SubHeader.d.ts +7 -5
- package/types/SuffixedInput.d.ts +5 -3
- package/types/TableWrapper.d.ts +5 -3
- package/types/Taxonomy.d.ts +6 -4
- package/types/TimeFormat.d.ts +5 -9
- package/types/TimezoneMismatchModal.d.ts +5 -3
- package/types/ToggleFeatureCard.d.ts +7 -5
package/dist/Schedule.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { createContext, useContext, useState, useEffect, useImperativeHandle,
|
|
2
|
-
import { FieldArray, ErrorMessage,
|
|
3
|
-
import { findIndexBy, isPresent, toLabelAndValue,
|
|
4
|
-
import { uniq, pluck, difference, append, without, identity, pick, assoc } from 'ramda';
|
|
1
|
+
import { createContext, useContext, memo, useMemo, useState, useEffect, useImperativeHandle, forwardRef } from 'react';
|
|
2
|
+
import { useFormikContext, FieldArray, ErrorMessage, Formik, Form as Form$2 } from 'formik';
|
|
3
|
+
import { findIndexBy, isNotPresent, isPresent, toLabelAndValue, noop } from '@bigbinary/neeto-cist';
|
|
5
4
|
import { joinHyphenCase } from '@bigbinary/neeto-commons-frontend/utils/general';
|
|
6
5
|
import Typography from '@bigbinary/neetoui/Typography';
|
|
7
6
|
import { useTranslation } from 'react-i18next';
|
|
@@ -11,6 +10,7 @@ import { ianaTimezoneToHumanReadable } from '@bigbinary/neeto-time-zones';
|
|
|
11
10
|
import i18next from 'i18next';
|
|
12
11
|
import { dayjs } from '@bigbinary/neeto-commons-frontend/utils';
|
|
13
12
|
import { timeFormat } from '@bigbinary/neeto-commons-frontend/utils/datetime';
|
|
13
|
+
import { fromPairs, map, prop, pick, assoc, uniq, pluck, difference, append, without, identity } from 'ramda';
|
|
14
14
|
import * as yup from 'yup';
|
|
15
15
|
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
16
16
|
import _createClass from '@babel/runtime/helpers/createClass';
|
|
@@ -176,22 +176,25 @@ var sortDays = function sortDays(chosenIndex) {
|
|
|
176
176
|
if (chosenIndex < 0 || chosenIndex >= 7) return DAYS;
|
|
177
177
|
return [].concat(_toConsumableArray(DAYS.slice(chosenIndex)), _toConsumableArray(DAYS.slice(0, chosenIndex)));
|
|
178
178
|
};
|
|
179
|
+
var wdayValidation = yup.object().shape({
|
|
180
|
+
periods: yup.array().of(yup.object().shape({
|
|
181
|
+
startTime: yup.string().required(i18next.t("neetoMolecules.schedule.errors.period.startTime")),
|
|
182
|
+
endTime: yup.string().required(i18next.t("neetoMolecules.schedule.errors.period.endTime")).test("ensureToTimeNotBehindFromTime", i18next.t("neetoMolecules.schedule.errors.period.isBehind"), function (value) {
|
|
183
|
+
var startTime = this.parent.startTime;
|
|
184
|
+
if (isFromAndToSame(value, startTime)) return true;
|
|
185
|
+
return isTimeBehind(startTime, value);
|
|
186
|
+
})
|
|
187
|
+
}).test("ensureTimeNotSame", i18next.t("neetoMolecules.schedule.errors.period.sameTime"), function (value) {
|
|
188
|
+
var startTime = value.startTime,
|
|
189
|
+
endTime = value.endTime;
|
|
190
|
+
return !isFromAndToSame(startTime, endTime);
|
|
191
|
+
})).ensureSlotsCantOverlap()
|
|
192
|
+
});
|
|
179
193
|
var getScheduleValidationSchema = function getScheduleValidationSchema() {
|
|
180
194
|
return yup.object().shape({
|
|
181
|
-
wdays: yup.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
endTime: yup.string().required(i18next.t("neetoMolecules.schedule.errors.period.endTime")).test("ensureToTimeNotBehindFromTime", i18next.t("neetoMolecules.schedule.errors.period.isBehind"), function (value) {
|
|
185
|
-
var startTime = this.parent.startTime;
|
|
186
|
-
if (isFromAndToSame(value, startTime)) return true;
|
|
187
|
-
return isTimeBehind(startTime, value);
|
|
188
|
-
})
|
|
189
|
-
}).test("ensureTimeNotSame", i18next.t("neetoMolecules.schedule.errors.period.sameTime"), function (value) {
|
|
190
|
-
var startTime = value.startTime,
|
|
191
|
-
endTime = value.endTime;
|
|
192
|
-
return !isFromAndToSame(startTime, endTime);
|
|
193
|
-
})).ensureSlotsCantOverlap()
|
|
194
|
-
}))
|
|
195
|
+
wdays: yup.object().shape(fromPairs(map(function (day) {
|
|
196
|
+
return [day, wdayValidation];
|
|
197
|
+
}, DAYS)))
|
|
195
198
|
});
|
|
196
199
|
};
|
|
197
200
|
var getUserTimeZone = function getUserTimeZone() {
|
|
@@ -281,6 +284,62 @@ var findIndicesOfOverlappingRangesInPeriods = function findIndicesOfOverlappingR
|
|
|
281
284
|
secondIndex: secondIndex
|
|
282
285
|
};
|
|
283
286
|
};
|
|
287
|
+
var handleCopy = function handleCopy(_ref3) {
|
|
288
|
+
var _values$wdays$day$per;
|
|
289
|
+
var values = _ref3.values,
|
|
290
|
+
day = _ref3.day,
|
|
291
|
+
setFieldValue = _ref3.setFieldValue,
|
|
292
|
+
wdaysToCopy = _ref3.wdaysToCopy;
|
|
293
|
+
var newPeriods = (_values$wdays$day$per = values.wdays[day].periods) === null || _values$wdays$day$per === void 0 ? void 0 : _values$wdays$day$per.map(pick(["startTime", "endTime"]));
|
|
294
|
+
if (isNotPresent(newPeriods)) return;
|
|
295
|
+
wdaysToCopy.forEach(function (wday) {
|
|
296
|
+
return setFieldValue("wdays.".concat(wday), {
|
|
297
|
+
available: true,
|
|
298
|
+
periods: newPeriods.map(assoc("wday", wday))
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
var buildFormValuesArray = function buildFormValuesArray(_ref4) {
|
|
303
|
+
var firstDay = _ref4.firstDay,
|
|
304
|
+
periods = _ref4.periods;
|
|
305
|
+
return sortDays(firstDay).map(function (wday) {
|
|
306
|
+
var _periods$wday;
|
|
307
|
+
return {
|
|
308
|
+
periods: sortPeriodsByKey({
|
|
309
|
+
periods: periods[wday],
|
|
310
|
+
key: "startTime",
|
|
311
|
+
order: "asc"
|
|
312
|
+
}),
|
|
313
|
+
available: !!((_periods$wday = periods[wday]) !== null && _periods$wday !== void 0 && _periods$wday.length),
|
|
314
|
+
wday: wday
|
|
315
|
+
};
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
var buildFormValuesObject = function buildFormValuesObject(_ref5) {
|
|
319
|
+
var periods = _ref5.periods;
|
|
320
|
+
var formValues = {};
|
|
321
|
+
DAYS.forEach(function (wday) {
|
|
322
|
+
var _periods$wday2;
|
|
323
|
+
formValues[wday] = {
|
|
324
|
+
periods: sortPeriodsByKey({
|
|
325
|
+
periods: periods[wday],
|
|
326
|
+
key: "startTime",
|
|
327
|
+
order: "asc"
|
|
328
|
+
}),
|
|
329
|
+
available: !!((_periods$wday2 = periods[wday]) !== null && _periods$wday2 !== void 0 && _periods$wday2.length),
|
|
330
|
+
wday: wday
|
|
331
|
+
};
|
|
332
|
+
});
|
|
333
|
+
return formValues;
|
|
334
|
+
};
|
|
335
|
+
var processFormValues = function processFormValues(values, firstDay) {
|
|
336
|
+
return {
|
|
337
|
+
wdays: buildFormValuesArray({
|
|
338
|
+
firstDay: firstDay,
|
|
339
|
+
periods: map(prop("periods"), values.wdays)
|
|
340
|
+
})
|
|
341
|
+
};
|
|
342
|
+
};
|
|
284
343
|
|
|
285
344
|
var DisplayAvailability = function DisplayAvailability(_ref) {
|
|
286
345
|
var periods = _ref.periods;
|
|
@@ -344,20 +403,17 @@ var DisplayAvailability = function DisplayAvailability(_ref) {
|
|
|
344
403
|
|
|
345
404
|
var buildSlotIntervals = function buildSlotIntervals(_ref) {
|
|
346
405
|
var interval = _ref.interval,
|
|
347
|
-
bookedSlots = _ref.bookedSlots
|
|
348
|
-
slotType = _ref.slotType,
|
|
349
|
-
_ref$selectedValue = _ref.selectedValue,
|
|
350
|
-
selectedValue = _ref$selectedValue === void 0 ? null : _ref$selectedValue;
|
|
351
|
-
var selectedOption = {
|
|
352
|
-
label: selectedValue,
|
|
353
|
-
value: selectedValue
|
|
354
|
-
};
|
|
406
|
+
bookedSlots = _ref.bookedSlots;
|
|
355
407
|
var allIntervalsForADay = dayjsExtended.timeIntervalsForDay(interval);
|
|
356
408
|
allIntervalsForADay.push(END_OF_DAY);
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
409
|
+
return function (slotType) {
|
|
410
|
+
var selectedValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
411
|
+
var uniqBookedSlots = uniq(pluck(slotType, bookedSlots));
|
|
412
|
+
var slotsAvailableForBooking = difference(allIntervalsForADay, uniqBookedSlots);
|
|
413
|
+
var slots = slotsAvailableForBooking.map(toLabelAndValue);
|
|
414
|
+
if (!selectedValue) return slots;
|
|
415
|
+
return sortSlots([toLabelAndValue(selectedValue)].concat(_toConsumableArray(slots)));
|
|
416
|
+
};
|
|
361
417
|
};
|
|
362
418
|
var sortSlots = function sortSlots(slots) {
|
|
363
419
|
return slots.sort(function (a, b) {
|
|
@@ -400,36 +456,43 @@ var addDefaultPeriod = function addDefaultPeriod(wday) {
|
|
|
400
456
|
};
|
|
401
457
|
|
|
402
458
|
var ScheduleRow = function ScheduleRow(_ref) {
|
|
403
|
-
var
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
459
|
+
var day = _ref.day;
|
|
460
|
+
var _useFormikContext = useFormikContext(),
|
|
461
|
+
values = _useFormikContext.values,
|
|
462
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
463
|
+
var bookedSlots = values.wdays[day].periods;
|
|
464
|
+
var _useContext = useContext(ScheduleContext),
|
|
465
|
+
allowAddPeriod = _useContext.allowAddPeriod,
|
|
466
|
+
slotInterval = _useContext.slotInterval;
|
|
407
467
|
var _useTranslation = useTranslation(),
|
|
408
468
|
t = _useTranslation.t;
|
|
469
|
+
var sortSlotsInterval = useMemo(function () {
|
|
470
|
+
return buildSlotIntervals({
|
|
471
|
+
interval: slotInterval,
|
|
472
|
+
bookedSlots: bookedSlots
|
|
473
|
+
});
|
|
474
|
+
}, [slotInterval, bookedSlots]);
|
|
409
475
|
var handleAddRow = function handleAddRow(arrayHelpers) {
|
|
410
|
-
if (isNotPresent(values.wdays[
|
|
476
|
+
if (isNotPresent(values.wdays[day].periods)) {
|
|
411
477
|
arrayHelpers.push(addDefaultPeriod(day));
|
|
412
478
|
} else {
|
|
413
|
-
arrayHelpers.push(generateNewPeriod(values.wdays[
|
|
479
|
+
arrayHelpers.push(generateNewPeriod(values.wdays[day].periods, day));
|
|
414
480
|
}
|
|
415
|
-
setFieldValue("wdays
|
|
481
|
+
setFieldValue("wdays.".concat(day, ".available"), true);
|
|
416
482
|
};
|
|
417
483
|
var handleDeleteRow = function handleDeleteRow(arrayHelpers, index) {
|
|
418
|
-
var isLastRowDeleted = values.wdays[
|
|
484
|
+
var isLastRowDeleted = values.wdays[day].periods.length === 1;
|
|
419
485
|
arrayHelpers.remove(index);
|
|
420
|
-
setFieldValue("wdays
|
|
486
|
+
setFieldValue("wdays.".concat(day, ".available"), !isLastRowDeleted);
|
|
421
487
|
};
|
|
422
|
-
var _useContext = useContext(ScheduleContext),
|
|
423
|
-
allowAddPeriod = _useContext.allowAddPeriod,
|
|
424
|
-
slotInterval = _useContext.slotInterval;
|
|
425
488
|
return /*#__PURE__*/jsx(FieldArray, {
|
|
426
|
-
name: "wdays
|
|
489
|
+
name: "wdays.".concat(day, ".periods"),
|
|
427
490
|
render: function render(arrayHelpers) {
|
|
428
|
-
var _values$wdays$
|
|
491
|
+
var _values$wdays$day, _values$wdays$day$per;
|
|
429
492
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
430
|
-
children: [isPresent((_values$wdays$
|
|
493
|
+
children: [isPresent((_values$wdays$day = values.wdays[day]) === null || _values$wdays$day === void 0 ? void 0 : _values$wdays$day.periods) && /*#__PURE__*/jsx("div", {
|
|
431
494
|
className: "w-full space-y-2",
|
|
432
|
-
children: (_values$wdays$
|
|
495
|
+
children: (_values$wdays$day$per = values.wdays[day].periods) === null || _values$wdays$day$per === void 0 ? void 0 : _values$wdays$day$per.map(function (period, index) {
|
|
433
496
|
return /*#__PURE__*/jsxs("div", {
|
|
434
497
|
className: "flex w-full flex-col sm:mx-auto sm:w-80",
|
|
435
498
|
children: [/*#__PURE__*/jsxs("div", {
|
|
@@ -441,18 +504,13 @@ var ScheduleRow = function ScheduleRow(_ref) {
|
|
|
441
504
|
className: "w-full",
|
|
442
505
|
components: REMOVE_SELECT_DOWN_ARROW,
|
|
443
506
|
filterOption: customFilter,
|
|
444
|
-
name: "wdays
|
|
507
|
+
name: "wdays.".concat(day, ".periods[").concat(index, "].startTime"),
|
|
445
508
|
placeholder: t("neetoMolecules.schedule.startTime"),
|
|
446
509
|
styles: BLUR_TEXT_WHEN_SELECT_MENU_IS_OPEN,
|
|
447
|
-
options:
|
|
448
|
-
interval: slotInterval,
|
|
449
|
-
bookedSlots: values.wdays[wdayIndex].periods,
|
|
450
|
-
slotType: "startTime",
|
|
451
|
-
selectedValue: period === null || period === void 0 ? void 0 : period.startTime
|
|
452
|
-
}),
|
|
510
|
+
options: sortSlotsInterval("startTime", period === null || period === void 0 ? void 0 : period.startTime),
|
|
453
511
|
value: slotsSelectComponentDefaultValue(period === null || period === void 0 ? void 0 : period.startTime),
|
|
454
512
|
onChange: function onChange(e) {
|
|
455
|
-
return setFieldValue("wdays
|
|
513
|
+
return setFieldValue("wdays.".concat(day, ".periods[").concat(index, "].startTime"), (e === null || e === void 0 ? void 0 : e.value) || "");
|
|
456
514
|
}
|
|
457
515
|
}), /*#__PURE__*/jsx(Select, {
|
|
458
516
|
isClearable: true,
|
|
@@ -460,18 +518,13 @@ var ScheduleRow = function ScheduleRow(_ref) {
|
|
|
460
518
|
className: "w-full",
|
|
461
519
|
components: REMOVE_SELECT_DOWN_ARROW,
|
|
462
520
|
filterOption: customFilter,
|
|
463
|
-
name: "wdays
|
|
521
|
+
name: "wdays.".concat(day, ".periods[").concat(index, "].endTime"),
|
|
522
|
+
options: sortSlotsInterval("endTime", period === null || period === void 0 ? void 0 : period.endTime),
|
|
464
523
|
placeholder: t("neetoMolecules.schedule.endTime"),
|
|
465
524
|
styles: BLUR_TEXT_WHEN_SELECT_MENU_IS_OPEN,
|
|
466
525
|
value: slotsSelectComponentDefaultValue(period === null || period === void 0 ? void 0 : period.endTime),
|
|
467
|
-
options: buildSlotIntervals({
|
|
468
|
-
interval: slotInterval,
|
|
469
|
-
bookedSlots: values.wdays[wdayIndex].periods,
|
|
470
|
-
slotType: "endTime",
|
|
471
|
-
selectedValue: period === null || period === void 0 ? void 0 : period.endTime
|
|
472
|
-
}),
|
|
473
526
|
onChange: function onChange(e) {
|
|
474
|
-
return setFieldValue("wdays
|
|
527
|
+
return setFieldValue("wdays.".concat(day, ".periods[").concat(index, "].endTime"), (e === null || e === void 0 ? void 0 : e.value) || "");
|
|
475
528
|
}
|
|
476
529
|
}), /*#__PURE__*/jsx(Button, {
|
|
477
530
|
className: "flex-shrink-0 self-start",
|
|
@@ -484,7 +537,7 @@ var ScheduleRow = function ScheduleRow(_ref) {
|
|
|
484
537
|
}
|
|
485
538
|
})]
|
|
486
539
|
}), /*#__PURE__*/jsx(ErrorMessage, {
|
|
487
|
-
name: "wdays
|
|
540
|
+
name: "wdays.".concat(day, ".periods[").concat(index, "]"),
|
|
488
541
|
children: function children(message) {
|
|
489
542
|
return _typeof(message) !== "object" && /*#__PURE__*/jsx("span", {
|
|
490
543
|
className: "neeto-ui-text-error-500 mt-1 w-11/12 px-2 text-xs",
|
|
@@ -492,9 +545,9 @@ var ScheduleRow = function ScheduleRow(_ref) {
|
|
|
492
545
|
});
|
|
493
546
|
}
|
|
494
547
|
})]
|
|
495
|
-
}, "wdays
|
|
548
|
+
}, "wdays.".concat(day, ".periods[").concat(index, "]"));
|
|
496
549
|
})
|
|
497
|
-
}), values.wdays[
|
|
550
|
+
}), values.wdays[day].available && allowAddPeriod && /*#__PURE__*/jsx(Button, {
|
|
498
551
|
className: "absolute right-14 top-3 ml-auto flex-shrink-0 sm:static",
|
|
499
552
|
"data-cy": "add-new-period-button",
|
|
500
553
|
"data-testid": "add-new-period-button",
|
|
@@ -514,14 +567,11 @@ var ScheduleRow = function ScheduleRow(_ref) {
|
|
|
514
567
|
}
|
|
515
568
|
});
|
|
516
569
|
};
|
|
570
|
+
var ScheduleRow$1 = /*#__PURE__*/memo(ScheduleRow);
|
|
517
571
|
|
|
518
572
|
var Form = function Form(_ref) {
|
|
519
|
-
var _values$wdays$
|
|
520
|
-
var day = _ref.day
|
|
521
|
-
handleCopy = _ref.handleCopy,
|
|
522
|
-
values = _ref.values,
|
|
523
|
-
setFieldValue = _ref.setFieldValue,
|
|
524
|
-
index = _ref.index;
|
|
573
|
+
var _values$wdays$day;
|
|
574
|
+
var day = _ref.day;
|
|
525
575
|
var _useState = useState([]),
|
|
526
576
|
_useState2 = _slicedToArray(_useState, 2),
|
|
527
577
|
deletedPeriods = _useState2[0],
|
|
@@ -530,39 +580,42 @@ var Form = function Form(_ref) {
|
|
|
530
580
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
531
581
|
wdaysToCopy = _useState4[0],
|
|
532
582
|
setWdaysToCopy = _useState4[1];
|
|
583
|
+
var _useFormikContext = useFormikContext(),
|
|
584
|
+
values = _useFormikContext.values,
|
|
585
|
+
setFieldValue = _useFormikContext.setFieldValue;
|
|
533
586
|
var _useTranslation = useTranslation(),
|
|
534
587
|
t = _useTranslation.t;
|
|
535
588
|
var _useContext = useContext(ScheduleContext),
|
|
536
589
|
firstDay = _useContext.firstDay;
|
|
537
|
-
var restoreDeletedPeriods = function restoreDeletedPeriods(
|
|
538
|
-
setFieldValue("wdays
|
|
590
|
+
var restoreDeletedPeriods = function restoreDeletedPeriods() {
|
|
591
|
+
setFieldValue("wdays.".concat(day, ".periods"), deletedPeriods);
|
|
539
592
|
};
|
|
540
|
-
var uncheckCheckbox = function uncheckCheckbox(
|
|
541
|
-
var _values$wdays$
|
|
542
|
-
setFieldValue("wdays
|
|
543
|
-
setFieldValue("wdays
|
|
544
|
-
if ((_values$wdays$
|
|
545
|
-
setDeletedPeriods(values.wdays[
|
|
593
|
+
var uncheckCheckbox = function uncheckCheckbox() {
|
|
594
|
+
var _values$wdays$day$per;
|
|
595
|
+
setFieldValue("wdays.".concat(day, ".available"), false);
|
|
596
|
+
setFieldValue("wdays.".concat(day, ".periods"), []);
|
|
597
|
+
if ((_values$wdays$day$per = values.wdays[day].periods[0]) !== null && _values$wdays$day$per !== void 0 && _values$wdays$day$per.id) {
|
|
598
|
+
setDeletedPeriods(values.wdays[day].periods.filter(function (item) {
|
|
546
599
|
return item.startTime && item.endTime;
|
|
547
600
|
}).map(identity));
|
|
548
601
|
}
|
|
549
602
|
};
|
|
550
|
-
var checkCheckbox = function checkCheckbox(
|
|
603
|
+
var checkCheckbox = function checkCheckbox() {
|
|
551
604
|
var _deletedPeriods$;
|
|
552
|
-
setFieldValue("wdays
|
|
605
|
+
setFieldValue("wdays.".concat(day, ".available"), true);
|
|
553
606
|
if ((_deletedPeriods$ = deletedPeriods[0]) !== null && _deletedPeriods$ !== void 0 && _deletedPeriods$.startTime) {
|
|
554
|
-
restoreDeletedPeriods(
|
|
555
|
-
} else if (isNotPresent(values.wdays[
|
|
556
|
-
setFieldValue("wdays
|
|
607
|
+
restoreDeletedPeriods();
|
|
608
|
+
} else if (isNotPresent(values.wdays[day].periods)) {
|
|
609
|
+
setFieldValue("wdays.".concat(day, ".periods"), [addDefaultPeriod(day)]);
|
|
557
610
|
} else {
|
|
558
|
-
setFieldValue("wdays
|
|
611
|
+
setFieldValue("wdays.".concat(day, ".periods"), [""]);
|
|
559
612
|
}
|
|
560
613
|
};
|
|
561
|
-
var handleCheckbox = function handleCheckbox(
|
|
562
|
-
if (values.wdays[
|
|
563
|
-
uncheckCheckbox(
|
|
614
|
+
var handleCheckbox = function handleCheckbox() {
|
|
615
|
+
if (values.wdays[day].available) {
|
|
616
|
+
uncheckCheckbox();
|
|
564
617
|
} else {
|
|
565
|
-
checkCheckbox(
|
|
618
|
+
checkCheckbox();
|
|
566
619
|
}
|
|
567
620
|
};
|
|
568
621
|
var handleCopyChange = function handleCopyChange(e, day) {
|
|
@@ -576,34 +629,29 @@ var Form = function Form(_ref) {
|
|
|
576
629
|
"data-cy": "working-day-container",
|
|
577
630
|
children: [/*#__PURE__*/jsxs("div", {
|
|
578
631
|
className: classnames("flex w-36 flex-shrink-0 items-center justify-start sm:mt-1", {
|
|
579
|
-
"mb-3 sm:mb-0": isPresent((_values$wdays$
|
|
632
|
+
"mb-3 sm:mb-0": isPresent((_values$wdays$day = values.wdays[day]) === null || _values$wdays$day === void 0 ? void 0 : _values$wdays$day.periods)
|
|
580
633
|
}),
|
|
581
634
|
children: [/*#__PURE__*/jsx(Switch, {
|
|
582
|
-
"aria-label": "wdays
|
|
583
|
-
checked: values.wdays[
|
|
635
|
+
"aria-label": "wdays.".concat(day, ".available"),
|
|
636
|
+
checked: values.wdays[day].available,
|
|
584
637
|
className: "flex-grow-0",
|
|
585
638
|
"data-cy": joinHyphenCase(day, "weekly-hours-checkbox"),
|
|
586
639
|
id: "day",
|
|
587
|
-
name: "wdays
|
|
588
|
-
onChange:
|
|
589
|
-
return handleCheckbox(setFieldValue, values);
|
|
590
|
-
}
|
|
640
|
+
name: "wdays.".concat(day, ".available"),
|
|
641
|
+
onChange: handleCheckbox
|
|
591
642
|
}), /*#__PURE__*/jsx(Typography, {
|
|
592
643
|
component: "span",
|
|
593
644
|
"data-cy": joinHyphenCase(day, "day-text"),
|
|
594
645
|
style: "body2",
|
|
595
|
-
weight: values.wdays[
|
|
646
|
+
weight: values.wdays[day].available ? "semibold" : "normal",
|
|
596
647
|
className: classnames("ml-2 capitalize", {
|
|
597
|
-
"neeto-ui-text-gray-600": !values.wdays[
|
|
648
|
+
"neeto-ui-text-gray-600": !values.wdays[day].available
|
|
598
649
|
}),
|
|
599
650
|
children: t("neetoMolecules.schedule.days.".concat(day))
|
|
600
651
|
})]
|
|
601
|
-
}), /*#__PURE__*/jsx(ScheduleRow, {
|
|
602
|
-
day: day
|
|
603
|
-
|
|
604
|
-
values: values,
|
|
605
|
-
wdayIndex: index
|
|
606
|
-
}), values.wdays[index].available && /*#__PURE__*/jsxs(Dropdown, {
|
|
652
|
+
}), /*#__PURE__*/jsx(ScheduleRow$1, {
|
|
653
|
+
day: day
|
|
654
|
+
}), values.wdays[day].available && /*#__PURE__*/jsxs(Dropdown, {
|
|
607
655
|
closeOnSelect: true,
|
|
608
656
|
buttonStyle: "secondary",
|
|
609
657
|
icon: Copy,
|
|
@@ -658,7 +706,7 @@ var Form = function Form(_ref) {
|
|
|
658
706
|
onClick: function onClick() {
|
|
659
707
|
handleCopy({
|
|
660
708
|
values: values,
|
|
661
|
-
|
|
709
|
+
day: day,
|
|
662
710
|
setFieldValue: setFieldValue,
|
|
663
711
|
wdaysToCopy: wdaysToCopy
|
|
664
712
|
});
|
|
@@ -670,19 +718,20 @@ var Form = function Form(_ref) {
|
|
|
670
718
|
})
|
|
671
719
|
});
|
|
672
720
|
};
|
|
721
|
+
var Form$1 = /*#__PURE__*/memo(Form);
|
|
673
722
|
|
|
674
723
|
var Fields = function Fields(_ref) {
|
|
675
|
-
var
|
|
676
|
-
handleValuesChanged = _ref.handleValuesChanged,
|
|
724
|
+
var handleValuesChanged = _ref.handleValuesChanged,
|
|
677
725
|
scheduleRef = _ref.scheduleRef;
|
|
726
|
+
var _useContext = useContext(ScheduleContext),
|
|
727
|
+
firstDay = _useContext.firstDay;
|
|
678
728
|
var _useFormikContext = useFormikContext(),
|
|
679
729
|
values = _useFormikContext.values,
|
|
680
|
-
setFieldValue = _useFormikContext.setFieldValue,
|
|
681
730
|
resetForm = _useFormikContext.resetForm,
|
|
682
731
|
errors = _useFormikContext.errors,
|
|
683
732
|
dirty = _useFormikContext.dirty;
|
|
684
733
|
useEffect(function () {
|
|
685
|
-
handleValuesChanged(values, dirty);
|
|
734
|
+
handleValuesChanged(processFormValues(values, firstDay), dirty);
|
|
686
735
|
}, [values]);
|
|
687
736
|
useImperativeHandle(scheduleRef, function () {
|
|
688
737
|
return {
|
|
@@ -690,25 +739,10 @@ var Fields = function Fields(_ref) {
|
|
|
690
739
|
errors: errors
|
|
691
740
|
};
|
|
692
741
|
});
|
|
693
|
-
return
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
className: "space-y-4",
|
|
698
|
-
children: values.wdays.map(function (item, index) {
|
|
699
|
-
return /*#__PURE__*/createElement(Form, {
|
|
700
|
-
handleCopy: handleCopy,
|
|
701
|
-
index: index,
|
|
702
|
-
setFieldValue: setFieldValue,
|
|
703
|
-
values: values,
|
|
704
|
-
day: DAYS.find(function (day) {
|
|
705
|
-
return day === item.wday;
|
|
706
|
-
}),
|
|
707
|
-
key: item.wday
|
|
708
|
-
});
|
|
709
|
-
})
|
|
710
|
-
});
|
|
711
|
-
}
|
|
742
|
+
return sortDays(firstDay).map(function (wday) {
|
|
743
|
+
return /*#__PURE__*/jsx(Form$1, {
|
|
744
|
+
day: wday
|
|
745
|
+
}, wday);
|
|
712
746
|
});
|
|
713
747
|
};
|
|
714
748
|
|
|
@@ -829,69 +863,52 @@ var Schedule = /*#__PURE__*/forwardRef(function (_ref, scheduleRef) {
|
|
|
829
863
|
showTimeZone = _ref$showTimeZone === void 0 ? true : _ref$showTimeZone,
|
|
830
864
|
_ref$slotInterval = _ref.slotInterval,
|
|
831
865
|
slotInterval = _ref$slotInterval === void 0 ? DEFAULT_SLOT_INTERVAL : _ref$slotInterval;
|
|
832
|
-
var
|
|
833
|
-
var _values$wdays$index$p;
|
|
834
|
-
var values = _ref2.values,
|
|
835
|
-
index = _ref2.index,
|
|
836
|
-
setFieldValue = _ref2.setFieldValue,
|
|
837
|
-
wdaysToCopy = _ref2.wdaysToCopy;
|
|
838
|
-
var newPeriods = (_values$wdays$index$p = values.wdays[index].periods) === null || _values$wdays$index$p === void 0 ? void 0 : _values$wdays$index$p.map(pick(["startTime", "endTime"]));
|
|
839
|
-
wdaysToCopy.forEach(function (wday) {
|
|
840
|
-
var dayIndex = sortDays(firstDay).indexOf(wday);
|
|
841
|
-
setFieldValue("wdays[".concat(dayIndex, "].available"), isPresent(values.wdays[index].periods));
|
|
842
|
-
setFieldValue("wdays[".concat(dayIndex, "].periods"), newPeriods.map(function (period) {
|
|
843
|
-
return assoc("wday", wday, period);
|
|
844
|
-
}));
|
|
845
|
-
});
|
|
846
|
-
};
|
|
866
|
+
var validationSchema = useMemo(getScheduleValidationSchema, []);
|
|
847
867
|
var getInitialFormValues = function getInitialFormValues() {
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
return {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
wday: wday
|
|
858
|
-
};
|
|
868
|
+
var isSubmitHandler = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
869
|
+
if (isSubmitHandler) {
|
|
870
|
+
return buildFormValuesArray({
|
|
871
|
+
firstDay: firstDay,
|
|
872
|
+
periods: periods
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
return buildFormValuesObject({
|
|
876
|
+
periods: periods
|
|
859
877
|
});
|
|
860
878
|
};
|
|
861
|
-
return /*#__PURE__*/jsx(
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
879
|
+
return /*#__PURE__*/jsx(ScheduleContext.Provider, {
|
|
880
|
+
value: {
|
|
881
|
+
allowAddPeriod: allowAddPeriod,
|
|
882
|
+
firstDay: firstDay,
|
|
883
|
+
slotInterval: slotInterval
|
|
884
|
+
},
|
|
885
|
+
children: /*#__PURE__*/jsx("div", {
|
|
886
|
+
className: "neeto-molecules-schedule neeto-ui-border-gray-200 flex-shrink-0",
|
|
887
|
+
children: /*#__PURE__*/jsx(Formik, {
|
|
888
|
+
validationSchema: validationSchema,
|
|
889
|
+
enableReinitialize: true,
|
|
890
|
+
initialValues: {
|
|
891
|
+
wdays: getInitialFormValues()
|
|
892
|
+
},
|
|
893
|
+
onSubmit: function onSubmit(values) {
|
|
894
|
+
handleSubmit(processFormValues(values, firstDay), getInitialFormValues(true));
|
|
895
|
+
},
|
|
896
|
+
children: /*#__PURE__*/jsxs(Fragment, {
|
|
897
|
+
children: [showHeader && /*#__PURE__*/jsx(Header, {
|
|
898
|
+
isCreating: isCreating,
|
|
899
|
+
isEditable: isEditable,
|
|
900
|
+
isEditing: isEditing,
|
|
901
|
+
setIsEditing: setIsEditing,
|
|
902
|
+
showTimeZone: showTimeZone
|
|
903
|
+
}), isEditing || !showHeader ? /*#__PURE__*/jsx(Form$2, {
|
|
886
904
|
children: /*#__PURE__*/jsx(Fields, {
|
|
887
|
-
handleCopy: handleCopy,
|
|
888
905
|
handleValuesChanged: handleValuesChanged,
|
|
889
906
|
scheduleRef: scheduleRef
|
|
890
907
|
})
|
|
891
908
|
}) : /*#__PURE__*/jsx(DisplayAvailability, {
|
|
892
909
|
periods: periods
|
|
893
|
-
})
|
|
894
|
-
})
|
|
910
|
+
})]
|
|
911
|
+
})
|
|
895
912
|
})
|
|
896
913
|
})
|
|
897
914
|
});
|