@bigbinary/neeto-form-frontend 1.3.0 → 1.3.3

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/index.js CHANGED
@@ -4,8 +4,8 @@ import { useFormikContext, useField, FieldArray, Form as Form$1, Formik, Field,
4
4
  import { noop as noop$4, findBy, slugify, toLabelAndValue, filterBy, isNotEmpty, truncate, humanize, removeBy, isPresent as isPresent$1, isNotPresent, findById, notEqualsDeep } from '@bigbinary/neeto-cist';
5
5
  import { showThumbsUpToastr, withEventTargetValue, getQueryParams, dateFormat } from '@bigbinary/neeto-commons-frontend/utils';
6
6
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
7
- import { Tooltip, Dropdown as Dropdown$2, Alert, Typography, Button as Button$1, Label, Checkbox as Checkbox$1, Toastr, MultiEmailInput, DatePicker, Input as Input$2, Radio as Radio$1, Select as Select$1, Textarea as Textarea$1, Spinner as Spinner$2 } from '@bigbinary/neetoui';
8
- import { assoc, mergeLeft, prop, isEmpty, path, range, values, compose as compose$1, trim, useWith, split, either, isNil, equals, difference, reject, pluck, keys, pick, omit, isNotNil, insert, not, pipe as pipe$1, toLower, map, includes, identity, clamp as clamp$2, filter as filter$1 } from 'ramda';
7
+ import Toastr from '@bigbinary/neetoui/Toastr';
8
+ import { assoc, mergeLeft, compose as compose$1, isEmpty, trim, useWith, path, split, either, isNil, values, equals, modify, prop, range, difference, without, reject, pluck, keys, pick, omit, includes, __, isNotNil, insert, not, pipe as pipe$1, toLower, map, identity, clamp as clamp$2, filter as filter$1 } from 'ramda';
9
9
  import { useQuery, useQueryClient, useMutation } from 'react-query';
10
10
  import i18next, { t as t$4 } from 'i18next';
11
11
  import { Input, Email as Email$2, Phone as Phone$2, Globe, Up, Down, MenuHorizontal, Delete, Plus, NeetoInvisible, Checkbox as Checkbox$2, Radio, Dropdown as Dropdown$3, Rating as Rating$4, Smiley, Calendar, Upload, Check, Close, FileGeneric } from '@bigbinary/neeto-icons';
@@ -13,21 +13,40 @@ import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-
13
13
  import { useMutationWithInvalidation, withImmutableActions, withT, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
14
14
  import axios from 'axios';
15
15
  import ReactDOM, { unstable_batchedUpdates, flushSync as flushSync$1 } from 'react-dom';
16
- import { Input as Input$1, Textarea, Checkbox, Select, ActionBlock } from '@bigbinary/neetoui/formik';
16
+ import Alert from '@bigbinary/neetoui/Alert';
17
+ import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
17
18
  import { useTranslation, Trans } from 'react-i18next';
18
19
  import { create as create$1 } from 'zustand';
20
+ import Typography from '@bigbinary/neetoui/Typography';
21
+ import Dropdown$2 from '@bigbinary/neetoui/Dropdown';
22
+ import Tooltip from '@bigbinary/neetoui/Tooltip';
19
23
  import classnames from 'classnames';
24
+ import Button$1 from '@bigbinary/neetoui/Button';
25
+ import Input$1 from '@bigbinary/neetoui/formik/Input';
26
+ import Textarea from '@bigbinary/neetoui/formik/Textarea';
27
+ import Checkbox from '@bigbinary/neetoui/formik/Checkbox';
28
+ import Label from '@bigbinary/neetoui/Label';
29
+ import Checkbox$1 from '@bigbinary/neetoui/Checkbox';
30
+ import Select from '@bigbinary/neetoui/formik/Select';
20
31
  import { Editor as Editor$1, isEditorEmpty, EditorContent } from '@bigbinary/neeto-editor';
32
+ import { shallow } from 'zustand/shallow';
21
33
  import * as yup from 'yup';
22
34
  import { object, array, string } from 'yup';
23
35
  import useHotkeys from '@bigbinary/neeto-hotkeys';
36
+ import Spinner$2 from '@bigbinary/neetoui/Spinner';
24
37
  import dayjs from 'dayjs';
38
+ import NeetoUIMultiEmailInput from '@bigbinary/neetoui/MultiEmailInput';
25
39
  import { validation, PhoneNumberInput, PhoneNumber as PhoneNumber$1 } from '@bigbinary/neeto-molecules/PhoneNumber';
26
40
  import localeData from 'dayjs/plugin/localeData';
27
41
  import utc from 'dayjs/plugin/utc';
28
42
  import weekday from 'dayjs/plugin/weekday';
29
43
  import weekOfYear from 'dayjs/plugin/weekOfYear';
44
+ import DatePicker from '@bigbinary/neetoui/DatePicker';
30
45
  import path$1 from 'path';
46
+ import Input$2 from '@bigbinary/neetoui/Input';
47
+ import Select$1 from '@bigbinary/neetoui/Select';
48
+ import Radio$1 from '@bigbinary/neetoui/Radio';
49
+ import Textarea$1 from '@bigbinary/neetoui/Textarea';
31
50
  import { renderToString } from 'react-dom/server';
32
51
 
33
52
  function _extends$8() {
@@ -769,6 +788,7 @@ var QUESTIONS_INITIAL_VALUE = {
769
788
  };
770
789
  var RESERVED_FIELD_CODES = ["month", "date", "time"];
771
790
  var SELECTABLE_KINDS = ["radio", "checkbox", "dropdown"];
791
+ var RICH_TEXT_QUESTIONS = ["paragraph", "termsandcondition"];
772
792
 
773
793
  function _arrayWithHoles$3(arr) {
774
794
  if (Array.isArray(arr)) return arr;
@@ -9804,6 +9824,28 @@ var formHelpers = {
9804
9824
  pushToList: pushToList
9805
9825
  };
9806
9826
 
9827
+ var isBlank = compose$1(isEmpty, trim);
9828
+ var parseServerError = function parseServerError(error) {
9829
+ var _error$notice;
9830
+ return (_error$notice = error.notice) !== null && _error$notice !== void 0 ? _error$notice : t$4("neetoForm.common.somethingWentWrong");
9831
+ };
9832
+ var isEmptyValues = function isEmptyValues(obj) {
9833
+ return either(isNil, isEmpty)(obj) ? true : values(obj).every(function (value) {
9834
+ if (isEmpty(value)) {
9835
+ return true;
9836
+ } else if (Array.isArray(value)) {
9837
+ return equals([false, false, false], value);
9838
+ }
9839
+ return !value;
9840
+ });
9841
+ };
9842
+
9843
+ // eslint-disable-next-line react-hooks/rules-of-hooks
9844
+ var dotPath = useWith(path, [split(".")]);
9845
+ var isFunction$1 = function isFunction(obj) {
9846
+ return typeof obj === "function";
9847
+ };
9848
+
9807
9849
  /** @type {import("neetocommons/react-utils").ZustandStoreHook} */
9808
9850
  var useBuildFormStore = create$1(withImmutableActions(function (set) {
9809
9851
  return {
@@ -9818,10 +9860,11 @@ var useBuildFormStore = create$1(withImmutableActions(function (set) {
9818
9860
  selectedLanguage: i18next.resolvedLanguage,
9819
9861
  formId: null,
9820
9862
  enabled: false,
9821
- title: ""
9863
+ title: "",
9864
+ richTextFieldsToReset: []
9822
9865
  },
9823
- setFormData: function setFormData(payload) {
9824
- return set(assoc("formState", payload));
9866
+ setFormData: function setFormData(arg) {
9867
+ return set(modify("formState", isFunction$1(arg) ? arg : mergeLeft(arg)));
9825
9868
  }
9826
9869
  };
9827
9870
  }));
@@ -10455,25 +10498,6 @@ var Email$1 = withT(function (_ref) {
10455
10498
  }));
10456
10499
  });
10457
10500
 
10458
- var isBlank = compose$1(isEmpty, trim);
10459
- var parseServerError = function parseServerError(error) {
10460
- var _error$notice;
10461
- return (_error$notice = error.notice) !== null && _error$notice !== void 0 ? _error$notice : t$4("neetoForm.common.somethingWentWrong");
10462
- };
10463
- var isEmptyValues = function isEmptyValues(obj) {
10464
- return either(isNil, isEmpty)(obj) ? true : values(obj).every(function (value) {
10465
- if (isEmpty(value)) {
10466
- return true;
10467
- } else if (Array.isArray(value)) {
10468
- return equals([false, false, false], value);
10469
- }
10470
- return !value;
10471
- });
10472
- };
10473
-
10474
- // eslint-disable-next-line react-hooks/rules-of-hooks
10475
- var dotPath = useWith(path, [split(".")]);
10476
-
10477
10501
  var FileGroup = function FileGroup(_ref) {
10478
10502
  var name = _ref.name,
10479
10503
  label = _ref.label,
@@ -11048,18 +11072,42 @@ var StarRating$3 = function StarRating(_ref) {
11048
11072
  }));
11049
11073
  };
11050
11074
 
11051
- var useUpdateEditorContent = function useUpdateEditorContent(editorRef, fieldName, value) {
11075
+ var useUpdateEditorContent = function useUpdateEditorContent(_ref) {
11076
+ var editorRef = _ref.editorRef,
11077
+ fieldName = _ref.fieldName,
11078
+ value = _ref.value,
11079
+ initialValue = _ref.initialValue,
11080
+ fieldCode = _ref.fieldCode;
11052
11081
  var initialStateRef = useRef({
11053
11082
  language: "",
11054
11083
  value: null
11055
11084
  });
11056
- var _useBuildFormState = useBuildFormState(),
11057
- formId = _useBuildFormState.formId,
11058
- language = _useBuildFormState.selectedLanguage;
11085
+ var _useBuildFormStore = useBuildFormStore(function (store) {
11086
+ return {
11087
+ setFormData: store["setFormData"]
11088
+ };
11089
+ }, shallow),
11090
+ setFormData = _useBuildFormStore.setFormData;
11091
+ var _useBuildFormStore2 = useBuildFormStore(function (store) {
11092
+ var _store$formState, _store$formState2;
11093
+ return {
11094
+ formId: (_store$formState = store["formState"]) === null || _store$formState === void 0 ? void 0 : _store$formState["formId"],
11095
+ selectedLanguage: (_store$formState2 = store["formState"]) === null || _store$formState2 === void 0 ? void 0 : _store$formState2["selectedLanguage"]
11096
+ };
11097
+ }, shallow),
11098
+ formId = _useBuildFormStore2.formId,
11099
+ language = _useBuildFormStore2.selectedLanguage;
11100
+ var shouldReset = useBuildFormStore(function (store) {
11101
+ return store.formState.richTextFieldsToReset.includes(fieldCode);
11102
+ });
11059
11103
  var setEditorContent = function setEditorContent(content) {
11060
11104
  var _editorRef$current$ed;
11061
11105
  return (_editorRef$current$ed = editorRef.current.editor) === null || _editorRef$current$ed === void 0 || (_editorRef$current$ed = _editorRef$current$ed.commands) === null || _editorRef$current$ed === void 0 ? void 0 : _editorRef$current$ed.setContent(content);
11062
11106
  };
11107
+ if (shouldReset) {
11108
+ setEditorContent(initialValue);
11109
+ setFormData(modify("richTextFieldsToReset", without([fieldCode])));
11110
+ }
11063
11111
  useEffect(function () {
11064
11112
  if (initialStateRef.current["language"] !== language) {
11065
11113
  initialStateRef.current["language"] = language;
@@ -11086,11 +11134,13 @@ var useUpdateEditorContent = function useUpdateEditorContent(editorRef, fieldNam
11086
11134
 
11087
11135
  var Terms$1 = function Terms(_ref) {
11088
11136
  var name = _ref.name,
11137
+ item = _ref.item,
11089
11138
  isLabelDisabled = _ref.isLabelDisabled;
11090
11139
  var editorRef = useRef({
11091
11140
  editor: {}
11092
11141
  });
11093
11142
  var fieldName = "".concat(name, ".label");
11143
+ var fieldCode = item.fieldCode;
11094
11144
  var _useField = useField({
11095
11145
  name: fieldName,
11096
11146
  validate: validateEditorContent(editorRef)
@@ -11100,10 +11150,17 @@ var Terms$1 = function Terms(_ref) {
11100
11150
  _useField2$ = _useField2[1],
11101
11151
  touched = _useField2$.touched,
11102
11152
  error = _useField2$.error,
11153
+ initialValue = _useField2$.initialValue,
11103
11154
  _useField2$2 = _useField2[2],
11104
11155
  setTouched = _useField2$2.setTouched,
11105
11156
  setValue = _useField2$2.setValue;
11106
- useUpdateEditorContent(editorRef, fieldName, value);
11157
+ useUpdateEditorContent({
11158
+ editorRef: editorRef,
11159
+ fieldName: fieldName,
11160
+ value: value,
11161
+ initialValue: initialValue,
11162
+ fieldCode: fieldCode
11163
+ });
11107
11164
  return /*#__PURE__*/React__default.createElement("div", {
11108
11165
  className: "w-full cursor-auto"
11109
11166
  }, /*#__PURE__*/React__default.createElement(Editor$1, {
@@ -11145,11 +11202,13 @@ var Fields = {
11145
11202
 
11146
11203
  var Editor = function Editor(_ref) {
11147
11204
  var name = _ref.name,
11205
+ item = _ref.item,
11148
11206
  isLabelDisabled = _ref.isLabelDisabled;
11149
11207
  var editorRef = useRef({
11150
11208
  editor: {}
11151
11209
  });
11152
11210
  var fieldName = "".concat(name, ".label");
11211
+ var fieldCode = item.fieldCode;
11153
11212
  var _useField = useField({
11154
11213
  name: fieldName,
11155
11214
  validate: validateEditorContent(editorRef)
@@ -11159,10 +11218,17 @@ var Editor = function Editor(_ref) {
11159
11218
  _useField2$ = _useField2[1],
11160
11219
  touched = _useField2$.touched,
11161
11220
  error = _useField2$.error,
11221
+ initialValue = _useField2$.initialValue,
11162
11222
  _useField2$2 = _useField2[2],
11163
11223
  setTouched = _useField2$2.setTouched,
11164
11224
  setValue = _useField2$2.setValue;
11165
- useUpdateEditorContent(editorRef, fieldName, value);
11225
+ useUpdateEditorContent({
11226
+ editorRef: editorRef,
11227
+ fieldName: fieldName,
11228
+ value: value,
11229
+ initialValue: initialValue,
11230
+ fieldCode: fieldCode
11231
+ });
11166
11232
  return /*#__PURE__*/React__default.createElement("div", {
11167
11233
  className: "w-full cursor-auto"
11168
11234
  }, /*#__PURE__*/React__default.createElement(Editor$1, {
@@ -11887,6 +11953,15 @@ var Form = function Form(_ref) {
11887
11953
  if (isNotEmpty(questionLabel)) return truncate(questionLabel, 40);
11888
11954
  return humanize(questionKind);
11889
11955
  };
11956
+ var richTextQuestions = filterBy({
11957
+ kind: includes(__, RICH_TEXT_QUESTIONS)
11958
+ }, questions);
11959
+ var resetFormData = function resetFormData() {
11960
+ resetForm();
11961
+ setFormData({
11962
+ richTextFieldsToReset: pluck("fieldCode", richTextQuestions)
11963
+ });
11964
+ };
11890
11965
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Alert, {
11891
11966
  isOpen: isNotNil(deleteQuestionIndex),
11892
11967
  submitButtonLabel: t("neetoForm.common.delete"),
@@ -11976,13 +12051,11 @@ var Form = function Form(_ref) {
11976
12051
  }))), showActionBlock && /*#__PURE__*/React__default.createElement("div", {
11977
12052
  className: "neeto-ui-border-gray-300 flex-shrink-0 border-t py-4"
11978
12053
  }, /*#__PURE__*/React__default.createElement(ActionBlock, {
11979
- className: "space-x-2",
12054
+ submitButtonProps: submitButtonProps,
11980
12055
  cancelButtonProps: _objectSpread$h({
11981
- label: t("neetoForm.common.reset")
11982
- }, cancelButtonProps),
11983
- submitButtonProps: _objectSpread$h({
11984
- disabled: isSubmitting || !dirty
11985
- }, submitButtonProps)
12056
+ label: t("neetoForm.common.reset"),
12057
+ onClick: resetFormData
12058
+ }, cancelButtonProps)
11986
12059
  }))));
11987
12060
  };
11988
12061
 
@@ -16049,7 +16122,7 @@ var MultipleEmailInput = function MultipleEmailInput(_ref) {
16049
16122
  className: "neeto-form-engine-input__wrapper"
16050
16123
  }, /*#__PURE__*/React__default.createElement("div", {
16051
16124
  className: "neeto-ui-w-full"
16052
- }, isInputVisible ? /*#__PURE__*/React__default.createElement(MultiEmailInput, {
16125
+ }, isInputVisible ? /*#__PURE__*/React__default.createElement(NeetoUIMultiEmailInput, {
16053
16126
  isRequired: isRequired,
16054
16127
  label: label,
16055
16128
  error: meta.touched ? meta.error : "",
@@ -27015,7 +27088,7 @@ var TermsField = function TermsField(_ref) {
27015
27088
  kind = question.kind,
27016
27089
  isRequired = question.isRequired,
27017
27090
  nodeId = question.nodeId;
27018
- var label = fieldWithFallback(question, "label");
27091
+ var label = fieldWithFallback(question, "label", true);
27019
27092
  return /*#__PURE__*/React__default.createElement(Field, {
27020
27093
  name: name || nodeId,
27021
27094
  validate: validateFieldValue({
@@ -27101,14 +27174,16 @@ var _QUESTION_TO_COMPONEN;
27101
27174
  var QUESTION_TO_COMPONENT_MAP = (_QUESTION_TO_COMPONEN = {}, _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.TEXT.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.NAME.value, NameField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.EMAIL.value, EmailField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.INTEGER.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.DECIMAL.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.PHONE.value, PhoneNumberField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.QUESTION.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.TEXTAREA.value, TextField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.CHECKBOX.value, OptionsField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.RADIO.value, OptionsField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.DROPDOWN.value, OptionsField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.RATING.value, RatingField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.PARAGRAPH.value, function (_ref) {
27102
27175
  var question = _ref.question;
27103
27176
  return /*#__PURE__*/React__default.createElement(EditorContent, {
27104
- content: isEmpty(question.label) ? question.labelFallback : question.label
27177
+ content: fieldWithFallback(question, "label", true)
27105
27178
  });
27106
27179
  }), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.TERMS.value, TermsField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.DATE.value, DateField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.STAR_RATING.value, StarRatingField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.ADDITIONAL_GUESTS.value, MultipleEmailInput), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.RICH_TEXT.value, RichTextEditor), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.CONDITION.value, ConditionField), _defineProperty$6(_QUESTION_TO_COMPONEN, QUESTION_KIND.FILE_UPLOAD.value, FileUploadField), _QUESTION_TO_COMPONEN);
27107
27180
 
27108
27181
  var fieldWithFallback = function fieldWithFallback(question, fieldName) {
27182
+ var hasRichContent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
27109
27183
  var fallback = question["".concat(fieldName, "Fallback")];
27110
27184
  var field = question[fieldName];
27111
- return isEmpty(field) && isNotNil(fallback) ? fallback : field;
27185
+ var isFieldEmpty = hasRichContent ? isEditorEmpty(field) : isEmpty(field);
27186
+ return isFieldEmpty && isNotNil(fallback) ? fallback : field;
27112
27187
  };
27113
27188
  var getFieldComponent = function getFieldComponent(_ref) {
27114
27189
  var kind = _ref.kind;
@@ -30089,6 +30164,10 @@ var linkifyDecorator = function linkifyDecorator(decoratedHref, decoratedText, k
30089
30164
  target: "_blank"
30090
30165
  }, decoratedText);
30091
30166
  };
30167
+ var filterResponses = removeBy({
30168
+ kind: QUESTION_KIND.ADDITIONAL_GUESTS.value,
30169
+ value: isNotPresent
30170
+ });
30092
30171
 
30093
30172
  var FileUpload = function FileUpload(_ref) {
30094
30173
  var files = _ref.files;
@@ -30152,6 +30231,7 @@ var Submission = function Submission(_ref2) {
30152
30231
  } : _useSubmission$data,
30153
30232
  isLoading = _useSubmission.isLoading;
30154
30233
  var responses = submission.responses;
30234
+ var filteredResponses = filterResponses(responses);
30155
30235
  var renderSubmittedValue = function renderSubmittedValue(kind, value) {
30156
30236
  switch (kind) {
30157
30237
  case QUESTION_KIND.RICH_TEXT.value:
@@ -30188,7 +30268,7 @@ var Submission = function Submission(_ref2) {
30188
30268
  }
30189
30269
  return /*#__PURE__*/React__default.createElement("div", {
30190
30270
  className: classnames("mx-auto flex h-full w-full flex-col items-start", _defineProperty$6({}, className, className))
30191
- }, responses.map(function (_ref3) {
30271
+ }, filteredResponses.map(function (_ref3) {
30192
30272
  var kind = _ref3.kind,
30193
30273
  label = _ref3.label,
30194
30274
  value = _ref3.value;