@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.cjs.js CHANGED
@@ -12,6 +12,7 @@ var ramda = require('ramda');
12
12
  var reactQuery = require('react-query');
13
13
  var i18next = require('i18next');
14
14
  var neetoIcons = require('@bigbinary/neeto-icons');
15
+ var constants = require('@bigbinary/neeto-commons-frontend/constants');
15
16
  var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
16
17
  var axios = require('axios');
17
18
  var ReactDOM = require('react-dom');
@@ -166,9 +167,9 @@ function _objectWithoutProperties$1(source, excluded) {
166
167
 
167
168
  var _excluded$d = ["size"],
168
169
  _excluded2$2 = ["size"],
169
- _excluded3$1 = ["size"],
170
- _excluded4$2 = ["size"],
171
- _excluded5 = ["size"];
170
+ _excluded3$2 = ["size"],
171
+ _excluded4$1 = ["size"],
172
+ _excluded5$1 = ["size"];
172
173
  var Star = function Star(props) {
173
174
  var _props$size = props.size,
174
175
  size = _props$size === void 0 ? 20 : _props$size,
@@ -208,7 +209,7 @@ var Heart = function Heart(props) {
208
209
  var Zap = function Zap(props) {
209
210
  var _props$size3 = props.size,
210
211
  size = _props$size3 === void 0 ? 20 : _props$size3,
211
- other = _objectWithoutProperties$1(props, _excluded3$1);
212
+ other = _objectWithoutProperties$1(props, _excluded3$2);
212
213
  return /*#__PURE__*/React__default["default"].createElement("svg", _extends$8({
213
214
  fill: "none",
214
215
  height: size,
@@ -226,7 +227,7 @@ var Zap = function Zap(props) {
226
227
  var Crown = function Crown(_ref) {
227
228
  var _ref$size = _ref.size,
228
229
  size = _ref$size === void 0 ? 20 : _ref$size,
229
- otherProps = _objectWithoutProperties$1(_ref, _excluded4$2);
230
+ otherProps = _objectWithoutProperties$1(_ref, _excluded4$1);
230
231
  return /*#__PURE__*/React__default["default"].createElement("svg", _extends$8({
231
232
  fill: "none",
232
233
  height: size,
@@ -248,7 +249,7 @@ var Crown = function Crown(_ref) {
248
249
  var Trophy = function Trophy(_ref2) {
249
250
  var _ref2$size = _ref2.size,
250
251
  size = _ref2$size === void 0 ? 20 : _ref2$size,
251
- otherProps = _objectWithoutProperties$1(_ref2, _excluded5);
252
+ otherProps = _objectWithoutProperties$1(_ref2, _excluded5$1);
252
253
  return /*#__PURE__*/React__default["default"].createElement("svg", _extends$8({
253
254
  fill: "none",
254
255
  height: size,
@@ -537,8 +538,10 @@ var getFormSubmissionsUrl = function getFormSubmissionsUrl(formId) {
537
538
  var getFormSubmissionUrl = function getFormSubmissionUrl(formId, submissionId) {
538
539
  return "".concat(getFormSubmissionsUrl(formId), "/").concat(submissionId);
539
540
  };
540
- var getForms = function getForms() {
541
- return axios__default["default"].get(getFormsUrl());
541
+ var getForms = function getForms(params) {
542
+ return axios__default["default"].get(getFormsUrl(), {
543
+ params: params
544
+ });
542
545
  };
543
546
  var createForm = function createForm(payload) {
544
547
  return axios__default["default"].post(getFormsUrl(), payload);
@@ -619,7 +622,8 @@ var neetoFormApi = {
619
622
 
620
623
  var _excluded$c = ["formId", "preview", "language"],
621
624
  _excluded2$1 = ["formId", "language"],
622
- _excluded4$1 = ["formId", "submissionId"];
625
+ _excluded3$1 = ["page", "pageSize"],
626
+ _excluded5 = ["formId", "submissionId"];
623
627
  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; }
624
628
  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; }
625
629
  var useForm = function useForm(_ref) {
@@ -705,21 +709,32 @@ var useUpdateQuestions = function useUpdateQuestions(options, language) {
705
709
  }
706
710
  }));
707
711
  };
708
- var useForms = function useForms(options) {
709
- return reactQuery.useQuery([QUERY_KEYS.FORMS], neetoFormApi.getForms, _objectSpread$j({
712
+ var useForms = function useForms() {
713
+ var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
714
+ _ref6$page = _ref6.page,
715
+ page = _ref6$page === void 0 ? constants.DEFAULT_PAGE_INDEX : _ref6$page,
716
+ _ref6$pageSize = _ref6.pageSize,
717
+ pageSize = _ref6$pageSize === void 0 ? constants.DEFAULT_PAGE_SIZE : _ref6$pageSize,
718
+ options = _objectWithoutProperties$1(_ref6, _excluded3$1);
719
+ return reactQuery.useQuery([QUERY_KEYS.FORMS, page], function () {
720
+ return neetoFormApi.getForms({
721
+ page: page,
722
+ pageSize: pageSize
723
+ });
724
+ }, _objectSpread$j({
710
725
  keepPreviousData: true
711
726
  }, options));
712
727
  };
713
728
  var useDeleteForm = function useDeleteForm(options) {
714
- return reactUtils.useMutationWithInvalidation(function (_ref6) {
715
- var id = _ref6.id;
729
+ return reactUtils.useMutationWithInvalidation(function (_ref7) {
730
+ var id = _ref7.id;
716
731
  return neetoFormApi.destroyForm(id);
717
732
  }, _objectSpread$j(_objectSpread$j({}, options), {}, {
718
- keysToInvalidate: [[QUERY_KEYS.FORMS], function (_, _ref7) {
719
- var id = _ref7.id;
720
- return [QUERY_KEYS.QUESTIONS, id];
721
- }, function (_, _ref8) {
733
+ keysToInvalidate: [[QUERY_KEYS.FORMS], function (_, _ref8) {
722
734
  var id = _ref8.id;
735
+ return [QUERY_KEYS.QUESTIONS, id];
736
+ }, function (_, _ref9) {
737
+ var id = _ref9.id;
723
738
  return [QUERY_KEYS.QUESTIONS, "preview/".concat(id)];
724
739
  }],
725
740
  onSuccess: function onSuccess() {
@@ -727,10 +742,10 @@ var useDeleteForm = function useDeleteForm(options) {
727
742
  }
728
743
  }));
729
744
  };
730
- var useSubmission = function useSubmission(_ref10) {
731
- var formId = _ref10.formId,
732
- submissionId = _ref10.submissionId,
733
- options = _objectWithoutProperties$1(_ref10, _excluded4$1);
745
+ var useSubmission = function useSubmission(_ref11) {
746
+ var formId = _ref11.formId,
747
+ submissionId = _ref11.submissionId,
748
+ options = _objectWithoutProperties$1(_ref11, _excluded5);
734
749
  return reactQuery.useQuery([QUERY_KEYS.SUBMISSION, formId, submissionId], function () {
735
750
  return neetoFormApi.getPublicSubmission(formId, submissionId);
736
751
  }, _objectSpread$j(_objectSpread$j({}, options), {}, {
@@ -739,9 +754,9 @@ var useSubmission = function useSubmission(_ref10) {
739
754
  };
740
755
  var useCreateSubmission = function useCreateSubmission(options) {
741
756
  var queryClient = reactQuery.useQueryClient();
742
- return reactQuery.useMutation(function (_ref11) {
743
- var formId = _ref11.formId,
744
- values = _ref11.values;
757
+ return reactQuery.useMutation(function (_ref12) {
758
+ var formId = _ref12.formId,
759
+ values = _ref12.values;
745
760
  return neetoFormApi.submitPublicForm(formId, values);
746
761
  }, _objectSpread$j(_objectSpread$j({}, options), {}, {
747
762
  onSuccess: function onSuccess() {
@@ -760,9 +775,9 @@ var useCreateSubmission = function useCreateSubmission(options) {
760
775
  };
761
776
  var useUpdateSubmission = function useUpdateSubmission(options) {
762
777
  var queryClient = reactQuery.useQueryClient();
763
- return reactQuery.useMutation(function (_ref12) {
764
- var formId = _ref12.formId,
765
- values = _ref12.values;
778
+ return reactQuery.useMutation(function (_ref13) {
779
+ var formId = _ref13.formId,
780
+ values = _ref13.values;
766
781
  return neetoFormApi.updatePublicSubmission(formId, values);
767
782
  }, _objectSpread$j(_objectSpread$j({}, options), {}, {
768
783
  onSuccess: function onSuccess() {
@@ -791,6 +806,7 @@ var QUESTIONS_INITIAL_VALUE = {
791
806
  title: ""
792
807
  };
793
808
  var RESERVED_FIELD_CODES = ["month", "date", "time"];
809
+ var SELECTABLE_KINDS = ["radio", "checkbox", "dropdown"];
794
810
 
795
811
  function _arrayWithHoles$3(arr) {
796
812
  if (Array.isArray(arr)) return arr;
@@ -11991,13 +12007,23 @@ var formValidationSchema = yup.object().shape({
11991
12007
  }
11992
12008
  }),
11993
12009
  kind: yup.string().required(),
11994
- fieldCode: yup.string().trim().notOneOf(RESERVED_FIELD_CODES, i18next__default["default"].t("neetoForm.error.invalidFieldCode")).when("kind", function (kind, schema) {
11995
- return QUESTIONS_WITHOUT_FIELD_CODE.includes(kind) ? schema.notRequired() : requiredLabelValidation(schema, i18next__default["default"].t("neetoForm.questions.common.questionFields.field.fieldCode"));
12010
+ fieldCode: yup.string().when("_destroy", {
12011
+ is: true,
12012
+ otherwise: function otherwise(schema) {
12013
+ return schema.trim().notOneOf(RESERVED_FIELD_CODES, i18next__default["default"].t("neetoForm.error.invalidFieldCode")).when("kind", function (kind, schema) {
12014
+ return QUESTIONS_WITHOUT_FIELD_CODE.includes(kind) ? schema.notRequired() : requiredLabelValidation(schema, i18next__default["default"].t("neetoForm.questions.common.questionFields.field.fieldCode"));
12015
+ });
12016
+ }
11996
12017
  }),
11997
- optionsAttributes: yup.array().when("kind", function (kind, schema) {
11998
- return ["radio", "checkbox", "dropdown"].includes(kind) ? schema.of(yup.object().shape({
11999
- label: requiredLabelValidation(yup.string(), i18next__default["default"].t("neetoForm.questions.common.questionFields.field.option"))
12000
- })) : schema.notRequired();
12018
+ optionsAttributes: yup.array().when("_destroy", {
12019
+ is: true,
12020
+ otherwise: function otherwise(schema) {
12021
+ return schema.when("kind", function (kind, schema) {
12022
+ return SELECTABLE_KINDS.includes(kind) ? schema.of(yup.object().shape({
12023
+ label: requiredLabelValidation(yup.string(), i18next__default["default"].t("neetoForm.questions.common.questionFields.field.option"))
12024
+ })) : schema.notRequired();
12025
+ });
12026
+ }
12001
12027
  }),
12002
12028
  highestRatingLabel: yup.string().nullable(),
12003
12029
  averageRatingLabel: yup.string().nullable(),