@bigbinary/neeto-molecules 5.9.12 → 5.9.13

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.
@@ -1,9 +1,10 @@
1
1
  import { createContext, useContext, memo, useMemo, useState, useEffect, useImperativeHandle, forwardRef } from 'react';
2
2
  import { useFormikContext, FieldArray, ErrorMessage, Formik, Form as Form$2 } from 'formik';
3
3
  import { findIndexBy, isNotPresent, isPresent, toLabelAndValue, isNotEmpty, noop } from '@bigbinary/neeto-cist';
4
- import { Typography, Button, DropdownMenu, Label, Checkbox, Tooltip } from '@bigbinary/neeto-atoms';
5
- import { joinHyphenCase } from '@bigbinary/neeto-commons-frontend/utils/general';
4
+ import { Button, Typography, DropdownMenu, Label, Checkbox, Tooltip } from '@bigbinary/neeto-atoms';
6
5
  import { useTranslation } from 'react-i18next';
6
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
7
+ import { joinHyphenCase } from '@bigbinary/neeto-commons-frontend/utils/general';
7
8
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
8
9
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
9
10
  import { ianaTimezoneToHumanReadable } from '@bigbinary/neeto-time-zones';
@@ -15,9 +16,8 @@ import * as yup from 'yup';
15
16
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
16
17
  import _createClass from '@babel/runtime/helpers/createClass';
17
18
  import '@babel/runtime/helpers/defineProperty';
18
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
19
- import { Select, Switch } from '@bigbinary/neeto-atoms/formik';
20
19
  import classnames from 'classnames';
20
+ import { Select, Switch } from '@bigbinary/neeto-atoms/formik';
21
21
  import _typeof from '@babel/runtime/helpers/typeof';
22
22
  import { T as Trash2 } from '../trash-2-hGkzsa87.js';
23
23
  import { P as Plus } from '../plus-Bnd2C3yl.js';
@@ -30,6 +30,50 @@ import '@babel/runtime/helpers/objectWithoutProperties';
30
30
  import '@bigbinary/neeto-commons-frontend/v2/react-utils';
31
31
  import '../ellipsis-BSu1ZIFZ.js';
32
32
 
33
+ var Actions = function Actions(_ref) {
34
+ var isCreating = _ref.isCreating,
35
+ isEditable = _ref.isEditable,
36
+ isEditing = _ref.isEditing,
37
+ setIsEditing = _ref.setIsEditing;
38
+ var _useFormikContext = useFormikContext(),
39
+ dirty = _useFormikContext.dirty,
40
+ resetForm = _useFormikContext.resetForm,
41
+ submitForm = _useFormikContext.submitForm,
42
+ isSubmitting = _useFormikContext.isSubmitting;
43
+ var _useTranslation = useTranslation(),
44
+ t = _useTranslation.t;
45
+ var handleReset = function handleReset() {
46
+ if (dirty) resetForm();else setIsEditing(false);
47
+ };
48
+ if (isEditing) {
49
+ return /*#__PURE__*/jsxs("div", {
50
+ className: "flex items-center gap-2",
51
+ children: [/*#__PURE__*/jsx(Button, {
52
+ "data-testid": "reset-button",
53
+ variant: "secondary",
54
+ label: !dirty ? t("neetoMolecules.common.actions.cancel") : t("neetoMolecules.common.actions.reset"),
55
+ onClick: handleReset
56
+ }), /*#__PURE__*/jsx(Button, {
57
+ "data-testid": "weekly-hours-save-changes-button",
58
+ disabled: !dirty && !isCreating || isSubmitting,
59
+ label: t("neetoMolecules.common.actions.saveChanges"),
60
+ loading: isSubmitting,
61
+ onClick: submitForm
62
+ })]
63
+ });
64
+ }
65
+ return isEditable ? /*#__PURE__*/jsx("div", {
66
+ children: /*#__PURE__*/jsx(Button, {
67
+ "data-testid": "weekly-schedule-header",
68
+ label: t("neetoMolecules.schedule.changeAvailability"),
69
+ variant: "default",
70
+ onClick: function onClick() {
71
+ return setIsEditing(true);
72
+ }
73
+ })
74
+ }) : null;
75
+ };
76
+
33
77
  var DAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
34
78
  var DEFAULT_SLOT_INTERVAL = 30;
35
79
  var HOUR_FORMATS = {
@@ -704,7 +748,7 @@ var Form = function Form(_ref) {
704
748
  "data-testid": joinHyphenCase(day, "weekly-hours-checkbox"),
705
749
  id: "day",
706
750
  name: "wdays.".concat(day, ".available"),
707
- size: "lg",
751
+ size: "default",
708
752
  onCheckedChange: handleCheckbox
709
753
  }), /*#__PURE__*/jsx(Typography, {
710
754
  as: "span",
@@ -808,17 +852,7 @@ var Fields = function Fields(_ref) {
808
852
  };
809
853
 
810
854
  var Header = function Header(_ref) {
811
- var isCreating = _ref.isCreating,
812
- isEditable = _ref.isEditable,
813
- isEditing = _ref.isEditing,
814
- setIsEditing = _ref.setIsEditing,
815
- _ref$showTimeZone = _ref.showTimeZone,
816
- showTimeZone = _ref$showTimeZone === void 0 ? true : _ref$showTimeZone;
817
- var _useFormikContext = useFormikContext(),
818
- dirty = _useFormikContext.dirty,
819
- resetForm = _useFormikContext.resetForm,
820
- submitForm = _useFormikContext.submitForm,
821
- isSubmitting = _useFormikContext.isSubmitting;
855
+ var isEditable = _ref.isEditable;
822
856
  var _useTranslation = useTranslation(),
823
857
  t = _useTranslation.t;
824
858
  var _useState = useState(getTimeZoneAndTime()),
@@ -829,9 +863,6 @@ var Header = function Header(_ref) {
829
863
  _Profile$usePaneState2 = _slicedToArray(_Profile$usePaneState, 2);
830
864
  _Profile$usePaneState2[0];
831
865
  var setIsProfilePaneOpen = _Profile$usePaneState2[1];
832
- var handleReset = function handleReset() {
833
- if (dirty) resetForm();else setIsEditing(false);
834
- };
835
866
  useEffect(function () {
836
867
  var time = setInterval(function () {
837
868
  setTimeZoneAndTime(getTimeZoneAndTime());
@@ -841,58 +872,32 @@ var Header = function Header(_ref) {
841
872
  };
842
873
  }, []);
843
874
  return /*#__PURE__*/jsxs("div", {
844
- className: "mb-6 flex flex-wrap justify-between gap-2",
845
- children: [showTimeZone && /*#__PURE__*/jsxs("div", {
846
- className: "flex items-center gap-3",
847
- "data-testid": "schedule-timezone-header",
848
- children: [/*#__PURE__*/jsx(Tooltip, {
849
- content: t("neetoMolecules.schedule.timezoneTooltip"),
850
- position: "bottom",
851
- touch: ["hold", 500],
852
- children: /*#__PURE__*/jsx(Typography, {
853
- as: "h4",
854
- "data-testid": "timezone-text",
855
- variant: "h6",
856
- weight: "medium",
857
- children: timeZoneAndTime
858
- })
859
- }), isEditable && /*#__PURE__*/jsx(MoreDropdown, {
860
- dropdownButtonProps: {
861
- "data-testid": "nui-more-dropdown"
862
- },
863
- menuItems: [{
864
- onClick: function onClick() {
865
- return setIsProfilePaneOpen(true);
866
- },
867
- label: t("neetoMolecules.common.actions.changeTimezone"),
868
- target: "_blank",
869
- key: "change-timezone-option",
870
- "data-testid": "change-timezone-option"
871
- }]
872
- })]
873
- }), isEditing ? /*#__PURE__*/jsxs("div", {
874
- className: "flex items-center gap-2",
875
- children: [/*#__PURE__*/jsx(Button, {
876
- "data-testid": "reset-button",
877
- variant: "secondary",
878
- label: !dirty ? t("neetoMolecules.common.actions.cancel") : t("neetoMolecules.common.actions.reset"),
879
- onClick: handleReset
880
- }), /*#__PURE__*/jsx(Button, {
881
- "data-testid": "weekly-hours-save-changes-button",
882
- disabled: !dirty && !isCreating || isSubmitting,
883
- label: t("neetoMolecules.common.actions.saveChanges"),
884
- loading: isSubmitting,
885
- onClick: submitForm
886
- })]
887
- }) : isEditable && /*#__PURE__*/jsx("div", {
888
- children: /*#__PURE__*/jsx(Button, {
889
- "data-testid": "weekly-schedule-header",
890
- label: t("neetoMolecules.schedule.changeAvailability"),
891
- variant: "default",
892
- onClick: function onClick() {
893
- return setIsEditing(true);
894
- }
875
+ className: "mb-6 flex items-center gap-3",
876
+ "data-testid": "schedule-timezone-header",
877
+ children: [/*#__PURE__*/jsx(Tooltip, {
878
+ content: t("neetoMolecules.schedule.timezoneTooltip"),
879
+ position: "bottom",
880
+ touch: ["hold", 500],
881
+ children: /*#__PURE__*/jsx(Typography, {
882
+ as: "h4",
883
+ "data-testid": "timezone-text",
884
+ variant: "h6",
885
+ weight: "medium",
886
+ children: timeZoneAndTime
895
887
  })
888
+ }), isEditable && /*#__PURE__*/jsx(MoreDropdown, {
889
+ dropdownButtonProps: {
890
+ "data-testid": "nui-more-dropdown"
891
+ },
892
+ menuItems: [{
893
+ onClick: function onClick() {
894
+ return setIsProfilePaneOpen(true);
895
+ },
896
+ label: t("neetoMolecules.common.actions.changeTimezone"),
897
+ target: "_blank",
898
+ key: "change-timezone-option",
899
+ "data-testid": "change-timezone-option"
900
+ }]
896
901
  })]
897
902
  });
898
903
  };
@@ -957,12 +962,8 @@ var Schedule = /*#__PURE__*/forwardRef(function (_ref, scheduleRef) {
957
962
  handleSubmit(processFormValues(values, firstDay), getInitialFormValues(true));
958
963
  },
959
964
  children: /*#__PURE__*/jsxs(Fragment, {
960
- children: [showHeader && /*#__PURE__*/jsx(Header, {
961
- isCreating: isCreating,
962
- isEditable: isEditable,
963
- isEditing: isEditing,
964
- setIsEditing: setIsEditing,
965
- showTimeZone: showTimeZone
965
+ children: [showHeader && showTimeZone && /*#__PURE__*/jsx(Header, {
966
+ isEditable: isEditable
966
967
  }), isEditing || !showHeader ? /*#__PURE__*/jsx(Form$2, {
967
968
  children: /*#__PURE__*/jsx(Fields, {
968
969
  handleValuesChanged: handleValuesChanged,
@@ -970,6 +971,14 @@ var Schedule = /*#__PURE__*/forwardRef(function (_ref, scheduleRef) {
970
971
  })
971
972
  }) : /*#__PURE__*/jsx(DisplayAvailability, {
972
973
  periods: periods
974
+ }), showHeader && (isEditing || isEditable) && /*#__PURE__*/jsx("div", {
975
+ className: "neeto-molecules-schedule__actions border-border bg-card sticky bottom-0 z-10 mt-10 flex justify-end gap-2 border-t py-6",
976
+ children: /*#__PURE__*/jsx(Actions, {
977
+ isCreating: isCreating,
978
+ isEditable: isEditable,
979
+ isEditing: isEditing,
980
+ setIsEditing: setIsEditing
981
+ })
973
982
  })]
974
983
  })
975
984
  })