@bigbinary/neeto-form-frontend 1.2.42 → 1.2.43

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
@@ -1,11 +1,11 @@
1
1
  import * as React$2 from 'react';
2
2
  import React__default, { useState, useRef, useEffect, useContext, useLayoutEffect as useLayoutEffect$1, forwardRef, useImperativeHandle, Fragment, useReducer, useCallback as useCallback$1, useMemo as useMemo$1, createContext, createElement } from 'react';
3
- import { useField, useFormikContext, FieldArray, Form as Form$1, Formik, Field, FastField } from 'formik';
4
- import { noop as noop$4, slugify, filterBy, findBy, removeBy, isPresent as isPresent$1, isNotPresent, isNotEmpty, findById, notEqualsDeep } from '@bigbinary/neeto-cist';
3
+ import { useFormikContext, useField, FieldArray, Form as Form$1, Formik, Field, FastField } from 'formik';
4
+ import { noop as noop$4, slugify, filterBy, findBy, isNotEmpty, truncate, humanize, removeBy, isPresent as isPresent$1, isNotPresent, findById, notEqualsDeep } from '@bigbinary/neeto-cist';
5
5
  import { withEventTargetValue, showThumbsUpToastr, getQueryParams, dateFormat } from '@bigbinary/neeto-commons-frontend/utils';
6
6
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
7
7
  import { Tooltip, Dropdown as Dropdown$2, Alert, Typography, Button as Button$1, Label, Checkbox as Checkbox$1, Toastr, MultiEmailInput, DatePicker, Radio as Radio$1, Select, Textarea as Textarea$1, Input as Input$2, Spinner as Spinner$2 } from '@bigbinary/neetoui';
8
- import { assoc, prop, isEmpty, path, values, compose as compose$1, trim, useWith, split, either, isNil, equals, difference, reject, pluck, keys, pick, omit, insert, not, pipe as pipe$1, toLower, map, includes, identity, isNotNil, times, clamp as clamp$2, filter as filter$1 } from 'ramda';
8
+ import { assoc, mergeLeft, prop, isEmpty, path, values, compose as compose$1, trim, useWith, split, either, isNil, equals, difference, reject, pluck, keys, pick, omit, insert, isNotNil, not, pipe as pipe$1, toLower, map, includes, identity, times, 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';
@@ -605,20 +605,14 @@ var useUpdateForm = function useUpdateForm(options) {
605
605
  }, _objectSpread$g(_objectSpread$g({}, options), {}, {
606
606
  onSuccess: function onSuccess(data, _ref3) {
607
607
  var id = _ref3.id;
608
- queryClient.setQueryData([QUERY_KEYS.QUESTIONS, id, language], function (form) {
609
- return _objectSpread$g(_objectSpread$g({}, form), {}, {
610
- title: data.title
611
- });
612
- });
613
- queryClient.setQueryData([QUERY_KEYS.QUESTIONS, "preview/".concat(id), language], function (form) {
614
- return _objectSpread$g(_objectSpread$g({}, form), {}, {
615
- title: data.title,
616
- questions: data.questions
617
- });
618
- });
608
+ queryClient.setQueryData([QUERY_KEYS.QUESTIONS, id, language], assoc("title", data.title));
609
+ queryClient.setQueryData([QUERY_KEYS.QUESTIONS, "preview/".concat(id), language], mergeLeft({
610
+ questions: data.questions,
611
+ title: data.title
612
+ }));
619
613
  queryClient.invalidateQueries([QUERY_KEYS.FORMS]);
620
- queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, id, language]);
621
- queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, "preview/".concat(id), language]);
614
+ queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, id]);
615
+ queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, "preview/".concat(id)]);
622
616
  options.onSuccess && options.onSuccess(data);
623
617
  }
624
618
  }));
@@ -636,6 +630,8 @@ var useUpdateQuestions = function useUpdateQuestions(options, language) {
636
630
  }
637
631
  var data = args[0],
638
632
  id = args[1].id;
633
+ queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, id]);
634
+ queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, "preview/".concat(id)]);
639
635
  queryClient.setQueryData([QUERY_KEYS.QUESTIONS, id, language], assoc("questions", data.questions));
640
636
  queryClient.setQueryData([QUERY_KEYS.QUESTIONS, "preview/".concat(id), language], assoc("questions", data.questions));
641
637
  options.onSuccess && options.onSuccess.apply(options, args);
@@ -714,102 +710,12 @@ var useUpdateSubmission = function useUpdateSubmission(options) {
714
710
  }));
715
711
  };
716
712
 
717
- ({
718
- questions: [{
719
- id: "bb101126-4183-4ddf-adff-7563a2be0b19",
720
- kind: "paragraph",
721
- displayOrder: 1,
722
- displayKind: "Description Field",
723
- label: t$4("neetoForm.common.fillTheFormToChat"),
724
- placeholder: "",
725
- isRequired: false,
726
- options: [],
727
- nodeId: "bb101126-4183-4ddf-adff-7563a2be0b19"
728
- }, {
729
- id: "a8e0178e-44df-465e-8acb-ef5d1c08d541",
730
- kind: "email",
731
- displayOrder: 2,
732
- displayKind: "Email Input Field",
733
- label: t$4("neetoForm.common.email"),
734
- placeholder: "",
735
- isRequired: true,
736
- options: [],
737
- nodeId: "a8e0178e-44df-465e-8acb-ef5d1c08d541"
738
- }, {
739
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62d8f6",
740
- label: t$4("neetoForm.common.selectOne"),
741
- isRequired: false,
742
- options: [{
743
- label: "ABC",
744
- id: "ABC"
745
- }, {
746
- label: "EFG",
747
- id: "EFG"
748
- }, {
749
- label: "QWE",
750
- id: "QWE"
751
- }],
752
- kind: "checkbox",
753
- nodeId: "f32ad8aa-039a-4b70-b3af-b97ed6fc67a6"
754
- }, {
755
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62wew",
756
- label: t$4("neetoForm.common.rate"),
757
- isRequired: true,
758
- highestRatingLabel: "",
759
- averageRatingLabel: "",
760
- lowestRatingLabel: "",
761
- kind: "rating",
762
- nodeId: "236a8cb3-b86d-4c30-9c18-f0d69788f6bc"
763
- }, {
764
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62d8as",
765
- label: t$4("neetoForm.common.phone"),
766
- kind: "phone",
767
- nodeId: "5dd3be53-ec99-48e2-bf21-298b6108cb00"
768
- }, {
769
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62d8f32",
770
- label: t$4("neetoForm.common.select"),
771
- isRequired: false,
772
- options: [{
773
- label: "A",
774
- id: "A"
775
- }, {
776
- label: "B",
777
- id: "B"
778
- }, {
779
- label: "C",
780
- id: "C"
781
- }],
782
- kind: "dropdown",
783
- nodeId: "e65f27ea-a9b9-45b1-a8de-efb27a5b3e72"
784
- }, {
785
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62d8f8",
786
- label: "Nice",
787
- kind: "paragraph",
788
- nodeId: "15507c92-4bb5-4428-bc2b-0a7b078a144a"
789
- }, {
790
- id: "a7d3e47d-f7a2-4bf9-aaea-d301addw2d8f9",
791
- label: t$4("neetoForm.common.singleChoice"),
792
- isRequired: false,
793
- options: [{
794
- label: "A",
795
- id: "A"
796
- }, {
797
- label: "B",
798
- id: "B"
799
- }, {
800
- label: "C",
801
- id: "C"
802
- }],
803
- kind: "radio",
804
- nodeId: "37683bae-da1b-4890-ade9-0664006dc57d"
805
- }]
806
- });
807
- var QUESTIONS_WITHOUT_FIELD_CODE = ["paragraph", "termsandcondition", "condition", "file_upload"];
808
- var RESERVED_FIELD_CODES = ["month", "date", "time"];
809
713
  var DEFAULT_AVAILABLE_LANGUAGES = [{
810
714
  code: "en",
811
715
  name: "English"
812
716
  }];
717
+ var QUESTIONS_WITHOUT_FIELD_CODE = ["paragraph", "termsandcondition", "condition", "file_upload"];
718
+ var RESERVED_FIELD_CODES = ["month", "date", "time"];
813
719
 
814
720
  function _arrayWithHoles$3(arr) {
815
721
  if (Array.isArray(arr)) return arr;
@@ -9867,8 +9773,7 @@ var useBuildFormState = function useBuildFormState() {
9867
9773
  };
9868
9774
 
9869
9775
  var ChangeLanguageDropdown = function ChangeLanguageDropdown(_ref) {
9870
- var dirty = _ref.dirty,
9871
- initialLanguage = _ref.initialLanguage,
9776
+ var initialLanguage = _ref.initialLanguage,
9872
9777
  languages = _ref.languages,
9873
9778
  onChange = _ref.onChange;
9874
9779
  var _useState = useState(false),
@@ -9881,6 +9786,8 @@ var ChangeLanguageDropdown = function ChangeLanguageDropdown(_ref) {
9881
9786
  setSelectedLanguage = _useState4[1];
9882
9787
  var _useTranslation = useTranslation(),
9883
9788
  t = _useTranslation.t;
9789
+ var _useFormikContext = useFormikContext(),
9790
+ dirty = _useFormikContext.dirty;
9884
9791
  var languageChangeHandler = function languageChangeHandler(code) {
9885
9792
  if (!dirty) {
9886
9793
  onChange(code);
@@ -9925,7 +9832,6 @@ var Overview = function Overview(_ref) {
9925
9832
  description = _ref.description,
9926
9833
  availableLanguages = _ref.availableLanguages,
9927
9834
  selectedLanguage = _ref.selectedLanguage,
9928
- dirty = _ref.dirty,
9929
9835
  onLanguageChange = _ref.onLanguageChange;
9930
9836
  return /*#__PURE__*/React__default.createElement("div", {
9931
9837
  className: "mb-4 flex-shrink-0"
@@ -9937,7 +9843,6 @@ var Overview = function Overview(_ref) {
9937
9843
  style: "h4",
9938
9844
  weight: "semibold"
9939
9845
  }, title), availableLanguages.length > 1 && /*#__PURE__*/React__default.createElement(ChangeLanguageDropdown, {
9940
- dirty: dirty,
9941
9846
  initialLanguage: selectedLanguage,
9942
9847
  languages: availableLanguages,
9943
9848
  onChange: onLanguageChange
@@ -11617,12 +11522,6 @@ var getAvailableQuestionKinds = function getAvailableQuestionKinds(_ref5) {
11617
11522
  });
11618
11523
  }, allQuestionKinds);
11619
11524
  };
11620
- var sliceLabel = function sliceLabel(label) {
11621
- if (label && label.length > 23) {
11622
- return "".concat(label.slice(0, 20), "...");
11623
- }
11624
- return label;
11625
- };
11626
11525
 
11627
11526
  var _path$2, _path2, _path3, _path4, _path5, _path6, _path7;
11628
11527
  function _extends$2() { _extends$2 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$2.apply(this, arguments); }
@@ -11705,7 +11604,6 @@ var _excluded$6 = ["questionKinds", "showAddQuestionDivider", "onValueChange", "
11705
11604
  function ownKeys$d(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; }
11706
11605
  function _objectSpread$d(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$d(Object(t), !0).forEach(function (r) { _defineProperty$6(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$d(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11707
11606
  var Form = function Form(_ref) {
11708
- var _INDEPENDENT_LABELS_M, _questions$deleteQues, _questions$deleteQues2;
11709
11607
  var questionKinds = _ref.questionKinds,
11710
11608
  showAddQuestionDivider = _ref.showAddQuestionDivider,
11711
11609
  onValueChange = _ref.onValueChange,
@@ -11817,14 +11715,23 @@ var Form = function Form(_ref) {
11817
11715
  resetForm();
11818
11716
  onLanguageChange(code);
11819
11717
  };
11718
+ var deleteAlertMessageLabel = function deleteAlertMessageLabel() {
11719
+ var questionKind = questions[deleteQuestionIndex].kind;
11720
+ var independentLabel = INDEPENDENT_LABELS_MAP[questionKind];
11721
+ if (isNotNil(independentLabel)) return independentLabel;
11722
+ var questionLabel = questions[deleteQuestionIndex].label;
11723
+ if (isNotEmpty(questionLabel)) return truncate(questionLabel, 40);
11724
+ return humanize(questionKind);
11725
+ };
11820
11726
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Alert, {
11821
11727
  isOpen: deleteQuestionIndex !== null,
11822
11728
  submitButtonLabel: t("neetoForm.common.delete"),
11823
11729
  title: t("neetoForm.questions.deleteAlert.title"),
11824
- message: /*#__PURE__*/React__default.createElement(Trans, {
11730
+ message: deleteQuestionIndex && /*#__PURE__*/React__default.createElement(Trans, {
11825
11731
  i18nKey: "neetoForm.questions.deleteAlert.message",
11826
11732
  values: {
11827
- label: (_INDEPENDENT_LABELS_M = INDEPENDENT_LABELS_MAP[(_questions$deleteQues = questions[deleteQuestionIndex]) === null || _questions$deleteQues === void 0 ? void 0 : _questions$deleteQues.kind]) !== null && _INDEPENDENT_LABELS_M !== void 0 ? _INDEPENDENT_LABELS_M : sliceLabel((_questions$deleteQues2 = questions[deleteQuestionIndex]) === null || _questions$deleteQues2 === void 0 ? void 0 : _questions$deleteQues2.label)
11733
+ count: availableLanguages.length,
11734
+ label: deleteAlertMessageLabel()
11828
11735
  }
11829
11736
  }),
11830
11737
  onClose: function onClose() {
@@ -11843,7 +11750,6 @@ var Form = function Form(_ref) {
11843
11750
  noValidate: true
11844
11751
  }), formTitle && /*#__PURE__*/React__default.createElement(Overview, {
11845
11752
  availableLanguages: availableLanguages,
11846
- dirty: dirty,
11847
11753
  selectedLanguage: selectedLanguage,
11848
11754
  description: formDescription,
11849
11755
  title: formTitle,
@@ -11937,29 +11843,34 @@ var getActiveQuestionKindDetails = function getActiveQuestionKindDetails(_ref) {
11937
11843
  };
11938
11844
 
11939
11845
  /* eslint-disable @bigbinary/neeto/file-name-and-export-name-standards */
11940
- var requiredLabel = function requiredLabel() {
11941
- var errorMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : i18next.t("neetoForm.common.fieldReq", {
11942
- field: i18next.t("neetoForm.questions.common.questionFields.field.label")
11943
- });
11944
- return string().required(errorMessage);
11846
+ var requiredLabelValidation = function requiredLabelValidation(schema, field) {
11847
+ return schema.required(i18next.t("neetoForm.common.fieldReq", {
11848
+ field: field
11849
+ }));
11945
11850
  };
11946
11851
  var formValidationSchema = object().shape({
11947
11852
  questions: array().of(object().shape({
11948
- label: requiredLabel().when("kind", {
11949
- is: "paragraph",
11950
- then: requiredLabel(i18next.t("neetoForm.common.paragraphCantBeEmpty"))
11853
+ label: string().when("_destroy", {
11854
+ is: true,
11855
+ otherwise: function otherwise(schema) {
11856
+ return schema.when("kind", {
11857
+ is: "paragraph",
11858
+ then: function then(schema) {
11859
+ return schema.required(i18next.t("neetoForm.common.paragraphCantBeEmpty"));
11860
+ },
11861
+ otherwise: function otherwise(schema) {
11862
+ return requiredLabelValidation(schema, i18next.t("neetoForm.questions.common.questionFields.field.label"));
11863
+ }
11864
+ });
11865
+ }
11951
11866
  }),
11952
11867
  kind: string().required(),
11953
11868
  fieldCode: string().trim().notOneOf(RESERVED_FIELD_CODES, i18next.t("neetoForm.error.invalidFieldCode")).when("kind", function (kind, schema) {
11954
- return QUESTIONS_WITHOUT_FIELD_CODE.includes(kind) ? schema.notRequired() : schema.required(i18next.t("neetoForm.common.fieldReq", {
11955
- field: i18next.t("neetoForm.questions.common.questionFields.field.fieldCode")
11956
- }));
11869
+ return QUESTIONS_WITHOUT_FIELD_CODE.includes(kind) ? schema.notRequired() : requiredLabelValidation(schema, i18next.t("neetoForm.questions.common.questionFields.field.fieldCode"));
11957
11870
  }),
11958
11871
  optionsAttributes: array().when("kind", function (kind, schema) {
11959
11872
  return ["radio", "checkbox", "dropdown"].includes(kind) ? schema.of(object().shape({
11960
- label: requiredLabel(i18next.t("neetoForm.common.fieldReq", {
11961
- field: i18next.t("neetoForm.questions.common.questionFields.field.option")
11962
- }))
11873
+ label: requiredLabelValidation(string(), i18next.t("neetoForm.questions.common.questionFields.field.option"))
11963
11874
  })) : schema.notRequired();
11964
11875
  }),
11965
11876
  highestRatingLabel: string().nullable(),
@@ -12048,23 +11959,22 @@ var BuildForm = function BuildForm(_ref) {
12048
11959
  } : _useForm$data,
12049
11960
  questions = _useForm$data2.questions,
12050
11961
  isQuestionsLoading = _useForm$data2.isQuestionsLoading,
12051
- isLoading = _useForm.isLoading;
11962
+ isLoading = _useForm.isLoading,
11963
+ refetch = _useForm.refetch;
12052
11964
  if (isLoading || showLoader && isQuestionsLoading) {
12053
11965
  return /*#__PURE__*/React__default.createElement("div", {
12054
11966
  className: "flex h-full w-full items-center justify-center py-6"
12055
11967
  }, /*#__PURE__*/React__default.createElement(PageLoader, null));
12056
11968
  }
12057
- var handleSubmit = function handleSubmit(payload, _ref2) {
12058
- var resetForm = _ref2.resetForm;
11969
+ var handleSubmit = function handleSubmit(payload) {
12059
11970
  updateQuestions({
12060
11971
  id: id,
12061
11972
  values: _objectSpread$c({
12062
- neetoFormQuestion: _objectSpread$c(_objectSpread$c({}, payload), {}, {
12063
- language: selectedLanguage
12064
- })
11973
+ language: selectedLanguage,
11974
+ neetoFormQuestion: payload
12065
11975
  }, buildRequestArgs)
12066
11976
  }, {
12067
- onSuccess: resetForm
11977
+ onSuccess: refetch
12068
11978
  });
12069
11979
  };
12070
11980
  var onValueChange = function onValueChange(questions) {
@@ -12077,8 +11987,8 @@ var BuildForm = function BuildForm(_ref) {
12077
11987
  var isDeletable = isQuestionDeletable !== null && isQuestionDeletable !== void 0 ? isQuestionDeletable : function (question) {
12078
11988
  return !nonRemovableFields.includes(question.kind);
12079
11989
  };
12080
- var isRequiredField = isFieldRequired !== null && isFieldRequired !== void 0 ? isFieldRequired : function (_ref3) {
12081
- var kind = _ref3.kind;
11990
+ var isRequiredField = isFieldRequired !== null && isFieldRequired !== void 0 ? isFieldRequired : function (_ref2) {
11991
+ var kind = _ref2.kind;
12082
11992
  return requiredFields.includes(kind);
12083
11993
  };
12084
11994
  var isDisabledFieldLabel = isFieldLabelDisabled !== null && isFieldLabelDisabled !== void 0 ? isFieldLabelDisabled : function () {
@@ -12096,9 +12006,9 @@ var BuildForm = function BuildForm(_ref) {
12096
12006
  },
12097
12007
  validationSchema: formValidationSchema,
12098
12008
  onSubmit: handleSubmit
12099
- }, function (_ref4) {
12100
- var errors = _ref4.errors,
12101
- setFieldError = _ref4.setFieldError;
12009
+ }, function (_ref3) {
12010
+ var errors = _ref3.errors,
12011
+ setFieldError = _ref3.setFieldError;
12102
12012
  return /*#__PURE__*/React__default.createElement(Form, _extends$8({}, _objectSpread$c(_objectSpread$c({}, formDomProps), {}, {
12103
12013
  availableLanguages: availableLanguages,
12104
12014
  cancelButtonProps: cancelButtonProps,