@bigbinary/neeto-form-frontend 1.2.50 → 1.2.52

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
@@ -9,6 +9,7 @@ import { assoc, mergeLeft, prop, isEmpty, path, values, compose as compose$1, tr
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';
12
+ import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-frontend/constants';
12
13
  import { useMutationWithInvalidation, withImmutableActions, withT, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
13
14
  import axios from 'axios';
14
15
  import ReactDOM, { unstable_batchedUpdates, flushSync as flushSync$1 } from 'react-dom';
@@ -128,9 +129,9 @@ function _objectWithoutProperties$1(source, excluded) {
128
129
 
129
130
  var _excluded$d = ["size"],
130
131
  _excluded2$2 = ["size"],
131
- _excluded3$1 = ["size"],
132
- _excluded4$2 = ["size"],
133
- _excluded5 = ["size"];
132
+ _excluded3$2 = ["size"],
133
+ _excluded4$1 = ["size"],
134
+ _excluded5$1 = ["size"];
134
135
  var Star = function Star(props) {
135
136
  var _props$size = props.size,
136
137
  size = _props$size === void 0 ? 20 : _props$size,
@@ -170,7 +171,7 @@ var Heart = function Heart(props) {
170
171
  var Zap = function Zap(props) {
171
172
  var _props$size3 = props.size,
172
173
  size = _props$size3 === void 0 ? 20 : _props$size3,
173
- other = _objectWithoutProperties$1(props, _excluded3$1);
174
+ other = _objectWithoutProperties$1(props, _excluded3$2);
174
175
  return /*#__PURE__*/React__default.createElement("svg", _extends$8({
175
176
  fill: "none",
176
177
  height: size,
@@ -188,7 +189,7 @@ var Zap = function Zap(props) {
188
189
  var Crown = function Crown(_ref) {
189
190
  var _ref$size = _ref.size,
190
191
  size = _ref$size === void 0 ? 20 : _ref$size,
191
- otherProps = _objectWithoutProperties$1(_ref, _excluded4$2);
192
+ otherProps = _objectWithoutProperties$1(_ref, _excluded4$1);
192
193
  return /*#__PURE__*/React__default.createElement("svg", _extends$8({
193
194
  fill: "none",
194
195
  height: size,
@@ -210,7 +211,7 @@ var Crown = function Crown(_ref) {
210
211
  var Trophy = function Trophy(_ref2) {
211
212
  var _ref2$size = _ref2.size,
212
213
  size = _ref2$size === void 0 ? 20 : _ref2$size,
213
- otherProps = _objectWithoutProperties$1(_ref2, _excluded5);
214
+ otherProps = _objectWithoutProperties$1(_ref2, _excluded5$1);
214
215
  return /*#__PURE__*/React__default.createElement("svg", _extends$8({
215
216
  fill: "none",
216
217
  height: size,
@@ -499,8 +500,10 @@ var getFormSubmissionsUrl = function getFormSubmissionsUrl(formId) {
499
500
  var getFormSubmissionUrl = function getFormSubmissionUrl(formId, submissionId) {
500
501
  return "".concat(getFormSubmissionsUrl(formId), "/").concat(submissionId);
501
502
  };
502
- var getForms = function getForms() {
503
- return axios.get(getFormsUrl());
503
+ var getForms = function getForms(params) {
504
+ return axios.get(getFormsUrl(), {
505
+ params: params
506
+ });
504
507
  };
505
508
  var createForm = function createForm(payload) {
506
509
  return axios.post(getFormsUrl(), payload);
@@ -581,7 +584,8 @@ var neetoFormApi = {
581
584
 
582
585
  var _excluded$c = ["formId", "preview", "language"],
583
586
  _excluded2$1 = ["formId", "language"],
584
- _excluded4$1 = ["formId", "submissionId"];
587
+ _excluded3$1 = ["page", "pageSize"],
588
+ _excluded5 = ["formId", "submissionId"];
585
589
  function ownKeys$k(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
586
590
  function _objectSpread$j(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$k(Object(t), !0).forEach(function (r) { _defineProperty$6(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$k(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
587
591
  var useForm = function useForm(_ref) {
@@ -667,21 +671,32 @@ var useUpdateQuestions = function useUpdateQuestions(options, language) {
667
671
  }
668
672
  }));
669
673
  };
670
- var useForms = function useForms(options) {
671
- return useQuery([QUERY_KEYS.FORMS], neetoFormApi.getForms, _objectSpread$j({
674
+ var useForms = function useForms() {
675
+ var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
676
+ _ref6$page = _ref6.page,
677
+ page = _ref6$page === void 0 ? DEFAULT_PAGE_INDEX : _ref6$page,
678
+ _ref6$pageSize = _ref6.pageSize,
679
+ pageSize = _ref6$pageSize === void 0 ? DEFAULT_PAGE_SIZE : _ref6$pageSize,
680
+ options = _objectWithoutProperties$1(_ref6, _excluded3$1);
681
+ return useQuery([QUERY_KEYS.FORMS, page], function () {
682
+ return neetoFormApi.getForms({
683
+ page: page,
684
+ pageSize: pageSize
685
+ });
686
+ }, _objectSpread$j({
672
687
  keepPreviousData: true
673
688
  }, options));
674
689
  };
675
690
  var useDeleteForm = function useDeleteForm(options) {
676
- return useMutationWithInvalidation(function (_ref6) {
677
- var id = _ref6.id;
691
+ return useMutationWithInvalidation(function (_ref7) {
692
+ var id = _ref7.id;
678
693
  return neetoFormApi.destroyForm(id);
679
694
  }, _objectSpread$j(_objectSpread$j({}, options), {}, {
680
- keysToInvalidate: [[QUERY_KEYS.FORMS], function (_, _ref7) {
681
- var id = _ref7.id;
682
- return [QUERY_KEYS.QUESTIONS, id];
683
- }, function (_, _ref8) {
695
+ keysToInvalidate: [[QUERY_KEYS.FORMS], function (_, _ref8) {
684
696
  var id = _ref8.id;
697
+ return [QUERY_KEYS.QUESTIONS, id];
698
+ }, function (_, _ref9) {
699
+ var id = _ref9.id;
685
700
  return [QUERY_KEYS.QUESTIONS, "preview/".concat(id)];
686
701
  }],
687
702
  onSuccess: function onSuccess() {
@@ -689,10 +704,10 @@ var useDeleteForm = function useDeleteForm(options) {
689
704
  }
690
705
  }));
691
706
  };
692
- var useSubmission = function useSubmission(_ref10) {
693
- var formId = _ref10.formId,
694
- submissionId = _ref10.submissionId,
695
- options = _objectWithoutProperties$1(_ref10, _excluded4$1);
707
+ var useSubmission = function useSubmission(_ref11) {
708
+ var formId = _ref11.formId,
709
+ submissionId = _ref11.submissionId,
710
+ options = _objectWithoutProperties$1(_ref11, _excluded5);
696
711
  return useQuery([QUERY_KEYS.SUBMISSION, formId, submissionId], function () {
697
712
  return neetoFormApi.getPublicSubmission(formId, submissionId);
698
713
  }, _objectSpread$j(_objectSpread$j({}, options), {}, {
@@ -701,9 +716,9 @@ var useSubmission = function useSubmission(_ref10) {
701
716
  };
702
717
  var useCreateSubmission = function useCreateSubmission(options) {
703
718
  var queryClient = useQueryClient();
704
- return useMutation(function (_ref11) {
705
- var formId = _ref11.formId,
706
- values = _ref11.values;
719
+ return useMutation(function (_ref12) {
720
+ var formId = _ref12.formId,
721
+ values = _ref12.values;
707
722
  return neetoFormApi.submitPublicForm(formId, values);
708
723
  }, _objectSpread$j(_objectSpread$j({}, options), {}, {
709
724
  onSuccess: function onSuccess() {
@@ -722,9 +737,9 @@ var useCreateSubmission = function useCreateSubmission(options) {
722
737
  };
723
738
  var useUpdateSubmission = function useUpdateSubmission(options) {
724
739
  var queryClient = useQueryClient();
725
- return useMutation(function (_ref12) {
726
- var formId = _ref12.formId,
727
- values = _ref12.values;
740
+ return useMutation(function (_ref13) {
741
+ var formId = _ref13.formId,
742
+ values = _ref13.values;
728
743
  return neetoFormApi.updatePublicSubmission(formId, values);
729
744
  }, _objectSpread$j(_objectSpread$j({}, options), {}, {
730
745
  onSuccess: function onSuccess() {
@@ -10989,20 +11004,38 @@ var StarRating$3 = function StarRating(_ref) {
10989
11004
  }));
10990
11005
  };
10991
11006
 
10992
- var useUpdateEditorContent = function useUpdateEditorContent(editorRef, fieldName) {
11007
+ var useUpdateEditorContent = function useUpdateEditorContent(editorRef, fieldName, value) {
11008
+ var initialStateRef = useRef({
11009
+ language: "",
11010
+ value: null
11011
+ });
10993
11012
  var _useBuildFormState = useBuildFormState(),
10994
11013
  formId = _useBuildFormState.formId,
10995
11014
  language = _useBuildFormState.selectedLanguage;
11015
+ var setEditorContent = function setEditorContent(content) {
11016
+ var _editorRef$current$ed;
11017
+ 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);
11018
+ };
11019
+ useEffect(function () {
11020
+ if (initialStateRef.current["language"] !== language) {
11021
+ initialStateRef.current["language"] = language;
11022
+ initialStateRef.current["value"] = null;
11023
+ return;
11024
+ }
11025
+ if (initialStateRef.current["value"] === null && value !== null) {
11026
+ setEditorContent(value);
11027
+ initialStateRef.current["value"] = value;
11028
+ }
11029
+ }, [language, value]);
10996
11030
  useFetchQuestions({
10997
11031
  formId: formId,
10998
11032
  language: language,
10999
11033
  onSuccess: function onSuccess(data) {
11000
- var _editorRef$current$ed;
11001
11034
  var pathArray = fieldName.split(".").map(function (part) {
11002
11035
  var parsedPart = parseInt(part);
11003
11036
  return isNaN(parsedPart) ? part : parsedPart;
11004
11037
  });
11005
- (_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 || _editorRef$current$ed.setContent(path(pathArray, data));
11038
+ setEditorContent(path(pathArray, data));
11006
11039
  }
11007
11040
  });
11008
11041
  };
@@ -11014,7 +11047,6 @@ var Terms$1 = function Terms(_ref) {
11014
11047
  editor: {}
11015
11048
  });
11016
11049
  var fieldName = "".concat(name, ".label");
11017
- useUpdateEditorContent(editorRef, fieldName);
11018
11050
  var _useField = useField({
11019
11051
  name: fieldName,
11020
11052
  validate: validateEditorContent(editorRef)
@@ -11023,6 +11055,7 @@ var Terms$1 = function Terms(_ref) {
11023
11055
  value = _useField2[0].value,
11024
11056
  error = _useField2[1].error,
11025
11057
  setValue = _useField2[2].setValue;
11058
+ useUpdateEditorContent(editorRef, fieldName, value);
11026
11059
  return /*#__PURE__*/React__default.createElement("div", {
11027
11060
  className: "w-full cursor-auto"
11028
11061
  }, /*#__PURE__*/React__default.createElement(Editor$1, {
@@ -11061,7 +11094,6 @@ var Editor = function Editor(_ref) {
11061
11094
  editor: {}
11062
11095
  });
11063
11096
  var fieldName = "".concat(name, ".label");
11064
- useUpdateEditorContent(editorRef, fieldName);
11065
11097
  var _useField = useField({
11066
11098
  name: fieldName,
11067
11099
  validate: validateEditorContent(editorRef)
@@ -11074,6 +11106,7 @@ var Editor = function Editor(_ref) {
11074
11106
  _useField2$2 = _useField2[2],
11075
11107
  setTouched = _useField2$2.setTouched,
11076
11108
  setValue = _useField2$2.setValue;
11109
+ useUpdateEditorContent(editorRef, fieldName, value);
11077
11110
  return /*#__PURE__*/React__default.createElement("div", {
11078
11111
  className: "w-full cursor-auto"
11079
11112
  }, /*#__PURE__*/React__default.createElement(Editor$1, {
@@ -26665,24 +26698,24 @@ var RichTextEditor = function RichTextEditor(_ref) {
26665
26698
  nodeId = question.nodeId;
26666
26699
  var label = fieldWithFallback(question, "label");
26667
26700
  var debouncedPlaceholder = useDebounce(fieldWithFallback(question, "placeholder"), 300);
26701
+ var propsToCompare = preview ? ["debouncedPlaceholder", "error"] : ["debouncedPlaceholder"];
26668
26702
  return /*#__PURE__*/React__default.createElement("div", {
26669
26703
  className: "neeto-form-engine-input__wrapper"
26670
26704
  }, /*#__PURE__*/React__default.createElement("div", {
26671
26705
  className: "neeto-form-engine-input__label-wrapper"
26672
26706
  }, label && /*#__PURE__*/React__default.createElement("label", {
26673
26707
  className: "neeto-form-engine-label"
26674
- }, getLabel(label, isRequired))), /*#__PURE__*/React__default.createElement(FastField, _extends$8({
26708
+ }, getLabel(label, isRequired))), /*#__PURE__*/React__default.createElement(FastField, {
26675
26709
  debouncedPlaceholder: debouncedPlaceholder,
26676
26710
  error: errors[name],
26677
26711
  name: name || nodeId,
26712
+ shouldUpdate: isPropsUnequal(propsToCompare),
26678
26713
  validate: validateFieldValue({
26679
26714
  kind: kind,
26680
26715
  label: label,
26681
26716
  isRequired: isRequired
26682
26717
  })
26683
- }, preview && {
26684
- shouldUpdate: isPropsUnequal(["debouncedPlaceholder", "error"])
26685
- }), function (_ref2) {
26718
+ }, function (_ref2) {
26686
26719
  var field = _ref2.field,
26687
26720
  form = _ref2.form,
26688
26721
  meta = _ref2.meta;