@bigbinary/neeto-form-frontend 1.2.51 → 1.2.53

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() {
@@ -753,6 +768,7 @@ var QUESTIONS_INITIAL_VALUE = {
753
768
  title: ""
754
769
  };
755
770
  var RESERVED_FIELD_CODES = ["month", "date", "time"];
771
+ var SELECTABLE_KINDS = ["radio", "checkbox", "dropdown"];
756
772
 
757
773
  function _arrayWithHoles$3(arr) {
758
774
  if (Array.isArray(arr)) return arr;
@@ -11953,13 +11969,23 @@ var formValidationSchema = object().shape({
11953
11969
  }
11954
11970
  }),
11955
11971
  kind: string().required(),
11956
- fieldCode: string().trim().notOneOf(RESERVED_FIELD_CODES, i18next.t("neetoForm.error.invalidFieldCode")).when("kind", function (kind, schema) {
11957
- return QUESTIONS_WITHOUT_FIELD_CODE.includes(kind) ? schema.notRequired() : requiredLabelValidation(schema, i18next.t("neetoForm.questions.common.questionFields.field.fieldCode"));
11972
+ fieldCode: string().when("_destroy", {
11973
+ is: true,
11974
+ otherwise: function otherwise(schema) {
11975
+ return schema.trim().notOneOf(RESERVED_FIELD_CODES, i18next.t("neetoForm.error.invalidFieldCode")).when("kind", function (kind, schema) {
11976
+ return QUESTIONS_WITHOUT_FIELD_CODE.includes(kind) ? schema.notRequired() : requiredLabelValidation(schema, i18next.t("neetoForm.questions.common.questionFields.field.fieldCode"));
11977
+ });
11978
+ }
11958
11979
  }),
11959
- optionsAttributes: array().when("kind", function (kind, schema) {
11960
- return ["radio", "checkbox", "dropdown"].includes(kind) ? schema.of(object().shape({
11961
- label: requiredLabelValidation(string(), i18next.t("neetoForm.questions.common.questionFields.field.option"))
11962
- })) : schema.notRequired();
11980
+ optionsAttributes: array().when("_destroy", {
11981
+ is: true,
11982
+ otherwise: function otherwise(schema) {
11983
+ return schema.when("kind", function (kind, schema) {
11984
+ return SELECTABLE_KINDS.includes(kind) ? schema.of(object().shape({
11985
+ label: requiredLabelValidation(string(), i18next.t("neetoForm.questions.common.questionFields.field.option"))
11986
+ })) : schema.notRequired();
11987
+ });
11988
+ }
11963
11989
  }),
11964
11990
  highestRatingLabel: string().nullable(),
11965
11991
  averageRatingLabel: string().nullable(),