@bigbinary/neeto-form-frontend 1.2.41 → 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';
@@ -27,6 +27,7 @@ import utc from 'dayjs/plugin/utc';
27
27
  import weekday from 'dayjs/plugin/weekday';
28
28
  import weekOfYear from 'dayjs/plugin/weekOfYear';
29
29
  import path$1 from 'path';
30
+ import { renderToString } from 'react-dom/server';
30
31
 
31
32
  function _extends$8() {
32
33
  _extends$8 = Object.assign ? Object.assign.bind() : function (target) {
@@ -604,20 +605,14 @@ var useUpdateForm = function useUpdateForm(options) {
604
605
  }, _objectSpread$g(_objectSpread$g({}, options), {}, {
605
606
  onSuccess: function onSuccess(data, _ref3) {
606
607
  var id = _ref3.id;
607
- queryClient.setQueryData([QUERY_KEYS.QUESTIONS, id, language], function (form) {
608
- return _objectSpread$g(_objectSpread$g({}, form), {}, {
609
- title: data.title
610
- });
611
- });
612
- queryClient.setQueryData([QUERY_KEYS.QUESTIONS, "preview/".concat(id), language], function (form) {
613
- return _objectSpread$g(_objectSpread$g({}, form), {}, {
614
- title: data.title,
615
- questions: data.questions
616
- });
617
- });
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
+ }));
618
613
  queryClient.invalidateQueries([QUERY_KEYS.FORMS]);
619
- queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, id, language]);
620
- 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)]);
621
616
  options.onSuccess && options.onSuccess(data);
622
617
  }
623
618
  }));
@@ -635,6 +630,8 @@ var useUpdateQuestions = function useUpdateQuestions(options, language) {
635
630
  }
636
631
  var data = args[0],
637
632
  id = args[1].id;
633
+ queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, id]);
634
+ queryClient.invalidateQueries([QUERY_KEYS.QUESTIONS, "preview/".concat(id)]);
638
635
  queryClient.setQueryData([QUERY_KEYS.QUESTIONS, id, language], assoc("questions", data.questions));
639
636
  queryClient.setQueryData([QUERY_KEYS.QUESTIONS, "preview/".concat(id), language], assoc("questions", data.questions));
640
637
  options.onSuccess && options.onSuccess.apply(options, args);
@@ -713,102 +710,12 @@ var useUpdateSubmission = function useUpdateSubmission(options) {
713
710
  }));
714
711
  };
715
712
 
716
- ({
717
- questions: [{
718
- id: "bb101126-4183-4ddf-adff-7563a2be0b19",
719
- kind: "paragraph",
720
- displayOrder: 1,
721
- displayKind: "Description Field",
722
- label: t$4("neetoForm.common.fillTheFormToChat"),
723
- placeholder: "",
724
- isRequired: false,
725
- options: [],
726
- nodeId: "bb101126-4183-4ddf-adff-7563a2be0b19"
727
- }, {
728
- id: "a8e0178e-44df-465e-8acb-ef5d1c08d541",
729
- kind: "email",
730
- displayOrder: 2,
731
- displayKind: "Email Input Field",
732
- label: t$4("neetoForm.common.email"),
733
- placeholder: "",
734
- isRequired: true,
735
- options: [],
736
- nodeId: "a8e0178e-44df-465e-8acb-ef5d1c08d541"
737
- }, {
738
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62d8f6",
739
- label: t$4("neetoForm.common.selectOne"),
740
- isRequired: false,
741
- options: [{
742
- label: "ABC",
743
- id: "ABC"
744
- }, {
745
- label: "EFG",
746
- id: "EFG"
747
- }, {
748
- label: "QWE",
749
- id: "QWE"
750
- }],
751
- kind: "checkbox",
752
- nodeId: "f32ad8aa-039a-4b70-b3af-b97ed6fc67a6"
753
- }, {
754
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62wew",
755
- label: t$4("neetoForm.common.rate"),
756
- isRequired: true,
757
- highestRatingLabel: "",
758
- averageRatingLabel: "",
759
- lowestRatingLabel: "",
760
- kind: "rating",
761
- nodeId: "236a8cb3-b86d-4c30-9c18-f0d69788f6bc"
762
- }, {
763
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62d8as",
764
- label: t$4("neetoForm.common.phone"),
765
- kind: "phone",
766
- nodeId: "5dd3be53-ec99-48e2-bf21-298b6108cb00"
767
- }, {
768
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62d8f32",
769
- label: t$4("neetoForm.common.select"),
770
- isRequired: false,
771
- options: [{
772
- label: "A",
773
- id: "A"
774
- }, {
775
- label: "B",
776
- id: "B"
777
- }, {
778
- label: "C",
779
- id: "C"
780
- }],
781
- kind: "dropdown",
782
- nodeId: "e65f27ea-a9b9-45b1-a8de-efb27a5b3e72"
783
- }, {
784
- id: "a7d3e47d-f7a2-4bf9-aaea-d301ad62d8f8",
785
- label: "Nice",
786
- kind: "paragraph",
787
- nodeId: "15507c92-4bb5-4428-bc2b-0a7b078a144a"
788
- }, {
789
- id: "a7d3e47d-f7a2-4bf9-aaea-d301addw2d8f9",
790
- label: t$4("neetoForm.common.singleChoice"),
791
- isRequired: false,
792
- options: [{
793
- label: "A",
794
- id: "A"
795
- }, {
796
- label: "B",
797
- id: "B"
798
- }, {
799
- label: "C",
800
- id: "C"
801
- }],
802
- kind: "radio",
803
- nodeId: "37683bae-da1b-4890-ade9-0664006dc57d"
804
- }]
805
- });
806
- var QUESTIONS_WITHOUT_FIELD_CODE = ["paragraph", "termsandcondition", "condition", "file_upload"];
807
- var RESERVED_FIELD_CODES = ["month", "date", "time"];
808
713
  var DEFAULT_AVAILABLE_LANGUAGES = [{
809
714
  code: "en",
810
715
  name: "English"
811
716
  }];
717
+ var QUESTIONS_WITHOUT_FIELD_CODE = ["paragraph", "termsandcondition", "condition", "file_upload"];
718
+ var RESERVED_FIELD_CODES = ["month", "date", "time"];
812
719
 
813
720
  function _arrayWithHoles$3(arr) {
814
721
  if (Array.isArray(arr)) return arr;
@@ -9866,8 +9773,7 @@ var useBuildFormState = function useBuildFormState() {
9866
9773
  };
9867
9774
 
9868
9775
  var ChangeLanguageDropdown = function ChangeLanguageDropdown(_ref) {
9869
- var dirty = _ref.dirty,
9870
- initialLanguage = _ref.initialLanguage,
9776
+ var initialLanguage = _ref.initialLanguage,
9871
9777
  languages = _ref.languages,
9872
9778
  onChange = _ref.onChange;
9873
9779
  var _useState = useState(false),
@@ -9880,6 +9786,8 @@ var ChangeLanguageDropdown = function ChangeLanguageDropdown(_ref) {
9880
9786
  setSelectedLanguage = _useState4[1];
9881
9787
  var _useTranslation = useTranslation(),
9882
9788
  t = _useTranslation.t;
9789
+ var _useFormikContext = useFormikContext(),
9790
+ dirty = _useFormikContext.dirty;
9883
9791
  var languageChangeHandler = function languageChangeHandler(code) {
9884
9792
  if (!dirty) {
9885
9793
  onChange(code);
@@ -9924,7 +9832,6 @@ var Overview = function Overview(_ref) {
9924
9832
  description = _ref.description,
9925
9833
  availableLanguages = _ref.availableLanguages,
9926
9834
  selectedLanguage = _ref.selectedLanguage,
9927
- dirty = _ref.dirty,
9928
9835
  onLanguageChange = _ref.onLanguageChange;
9929
9836
  return /*#__PURE__*/React__default.createElement("div", {
9930
9837
  className: "mb-4 flex-shrink-0"
@@ -9936,7 +9843,6 @@ var Overview = function Overview(_ref) {
9936
9843
  style: "h4",
9937
9844
  weight: "semibold"
9938
9845
  }, title), availableLanguages.length > 1 && /*#__PURE__*/React__default.createElement(ChangeLanguageDropdown, {
9939
- dirty: dirty,
9940
9846
  initialLanguage: selectedLanguage,
9941
9847
  languages: availableLanguages,
9942
9848
  onChange: onLanguageChange
@@ -11616,12 +11522,6 @@ var getAvailableQuestionKinds = function getAvailableQuestionKinds(_ref5) {
11616
11522
  });
11617
11523
  }, allQuestionKinds);
11618
11524
  };
11619
- var sliceLabel = function sliceLabel(label) {
11620
- if (label && label.length > 23) {
11621
- return "".concat(label.slice(0, 20), "...");
11622
- }
11623
- return label;
11624
- };
11625
11525
 
11626
11526
  var _path$2, _path2, _path3, _path4, _path5, _path6, _path7;
11627
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); }
@@ -11704,7 +11604,6 @@ var _excluded$6 = ["questionKinds", "showAddQuestionDivider", "onValueChange", "
11704
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; }
11705
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; }
11706
11606
  var Form = function Form(_ref) {
11707
- var _INDEPENDENT_LABELS_M, _questions$deleteQues, _questions$deleteQues2;
11708
11607
  var questionKinds = _ref.questionKinds,
11709
11608
  showAddQuestionDivider = _ref.showAddQuestionDivider,
11710
11609
  onValueChange = _ref.onValueChange,
@@ -11816,14 +11715,23 @@ var Form = function Form(_ref) {
11816
11715
  resetForm();
11817
11716
  onLanguageChange(code);
11818
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
+ };
11819
11726
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Alert, {
11820
11727
  isOpen: deleteQuestionIndex !== null,
11821
11728
  submitButtonLabel: t("neetoForm.common.delete"),
11822
11729
  title: t("neetoForm.questions.deleteAlert.title"),
11823
- message: /*#__PURE__*/React__default.createElement(Trans, {
11730
+ message: deleteQuestionIndex && /*#__PURE__*/React__default.createElement(Trans, {
11824
11731
  i18nKey: "neetoForm.questions.deleteAlert.message",
11825
11732
  values: {
11826
- 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()
11827
11735
  }
11828
11736
  }),
11829
11737
  onClose: function onClose() {
@@ -11842,7 +11750,6 @@ var Form = function Form(_ref) {
11842
11750
  noValidate: true
11843
11751
  }), formTitle && /*#__PURE__*/React__default.createElement(Overview, {
11844
11752
  availableLanguages: availableLanguages,
11845
- dirty: dirty,
11846
11753
  selectedLanguage: selectedLanguage,
11847
11754
  description: formDescription,
11848
11755
  title: formTitle,
@@ -11936,29 +11843,34 @@ var getActiveQuestionKindDetails = function getActiveQuestionKindDetails(_ref) {
11936
11843
  };
11937
11844
 
11938
11845
  /* eslint-disable @bigbinary/neeto/file-name-and-export-name-standards */
11939
- var requiredLabel = function requiredLabel() {
11940
- var errorMessage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : i18next.t("neetoForm.common.fieldReq", {
11941
- field: i18next.t("neetoForm.questions.common.questionFields.field.label")
11942
- });
11943
- return string().required(errorMessage);
11846
+ var requiredLabelValidation = function requiredLabelValidation(schema, field) {
11847
+ return schema.required(i18next.t("neetoForm.common.fieldReq", {
11848
+ field: field
11849
+ }));
11944
11850
  };
11945
11851
  var formValidationSchema = object().shape({
11946
11852
  questions: array().of(object().shape({
11947
- label: requiredLabel().when("kind", {
11948
- is: "paragraph",
11949
- 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
+ }
11950
11866
  }),
11951
11867
  kind: string().required(),
11952
11868
  fieldCode: string().trim().notOneOf(RESERVED_FIELD_CODES, i18next.t("neetoForm.error.invalidFieldCode")).when("kind", function (kind, schema) {
11953
- return QUESTIONS_WITHOUT_FIELD_CODE.includes(kind) ? schema.notRequired() : schema.required(i18next.t("neetoForm.common.fieldReq", {
11954
- field: i18next.t("neetoForm.questions.common.questionFields.field.fieldCode")
11955
- }));
11869
+ return QUESTIONS_WITHOUT_FIELD_CODE.includes(kind) ? schema.notRequired() : requiredLabelValidation(schema, i18next.t("neetoForm.questions.common.questionFields.field.fieldCode"));
11956
11870
  }),
11957
11871
  optionsAttributes: array().when("kind", function (kind, schema) {
11958
11872
  return ["radio", "checkbox", "dropdown"].includes(kind) ? schema.of(object().shape({
11959
- label: requiredLabel(i18next.t("neetoForm.common.fieldReq", {
11960
- field: i18next.t("neetoForm.questions.common.questionFields.field.option")
11961
- }))
11873
+ label: requiredLabelValidation(string(), i18next.t("neetoForm.questions.common.questionFields.field.option"))
11962
11874
  })) : schema.notRequired();
11963
11875
  }),
11964
11876
  highestRatingLabel: string().nullable(),
@@ -12047,23 +11959,22 @@ var BuildForm = function BuildForm(_ref) {
12047
11959
  } : _useForm$data,
12048
11960
  questions = _useForm$data2.questions,
12049
11961
  isQuestionsLoading = _useForm$data2.isQuestionsLoading,
12050
- isLoading = _useForm.isLoading;
11962
+ isLoading = _useForm.isLoading,
11963
+ refetch = _useForm.refetch;
12051
11964
  if (isLoading || showLoader && isQuestionsLoading) {
12052
11965
  return /*#__PURE__*/React__default.createElement("div", {
12053
11966
  className: "flex h-full w-full items-center justify-center py-6"
12054
11967
  }, /*#__PURE__*/React__default.createElement(PageLoader, null));
12055
11968
  }
12056
- var handleSubmit = function handleSubmit(payload, _ref2) {
12057
- var resetForm = _ref2.resetForm;
11969
+ var handleSubmit = function handleSubmit(payload) {
12058
11970
  updateQuestions({
12059
11971
  id: id,
12060
11972
  values: _objectSpread$c({
12061
- neetoFormQuestion: _objectSpread$c(_objectSpread$c({}, payload), {}, {
12062
- language: selectedLanguage
12063
- })
11973
+ language: selectedLanguage,
11974
+ neetoFormQuestion: payload
12064
11975
  }, buildRequestArgs)
12065
11976
  }, {
12066
- onSuccess: resetForm
11977
+ onSuccess: refetch
12067
11978
  });
12068
11979
  };
12069
11980
  var onValueChange = function onValueChange(questions) {
@@ -12076,8 +11987,8 @@ var BuildForm = function BuildForm(_ref) {
12076
11987
  var isDeletable = isQuestionDeletable !== null && isQuestionDeletable !== void 0 ? isQuestionDeletable : function (question) {
12077
11988
  return !nonRemovableFields.includes(question.kind);
12078
11989
  };
12079
- var isRequiredField = isFieldRequired !== null && isFieldRequired !== void 0 ? isFieldRequired : function (_ref3) {
12080
- var kind = _ref3.kind;
11990
+ var isRequiredField = isFieldRequired !== null && isFieldRequired !== void 0 ? isFieldRequired : function (_ref2) {
11991
+ var kind = _ref2.kind;
12081
11992
  return requiredFields.includes(kind);
12082
11993
  };
12083
11994
  var isDisabledFieldLabel = isFieldLabelDisabled !== null && isFieldLabelDisabled !== void 0 ? isFieldLabelDisabled : function () {
@@ -12095,9 +12006,9 @@ var BuildForm = function BuildForm(_ref) {
12095
12006
  },
12096
12007
  validationSchema: formValidationSchema,
12097
12008
  onSubmit: handleSubmit
12098
- }, function (_ref4) {
12099
- var errors = _ref4.errors,
12100
- setFieldError = _ref4.setFieldError;
12009
+ }, function (_ref3) {
12010
+ var errors = _ref3.errors,
12011
+ setFieldError = _ref3.setFieldError;
12101
12012
  return /*#__PURE__*/React__default.createElement(Form, _extends$8({}, _objectSpread$c(_objectSpread$c({}, formDomProps), {}, {
12102
12013
  availableLanguages: availableLanguages,
12103
12014
  cancelButtonProps: cancelButtonProps,
@@ -29937,6 +29848,12 @@ var getValue = function getValue(_ref2) {
29937
29848
  }
29938
29849
  return value;
29939
29850
  };
29851
+ var getEditorContent = function getEditorContent(value) {
29852
+ if (typeof value !== "string") {
29853
+ return renderToString(value);
29854
+ }
29855
+ return value;
29856
+ };
29940
29857
  var Submission = function Submission(_ref3) {
29941
29858
  var _ref3$formId = _ref3.formId,
29942
29859
  formId = _ref3$formId === void 0 ? "" : _ref3$formId,
@@ -29963,10 +29880,10 @@ var Submission = function Submission(_ref3) {
29963
29880
  switch (kind) {
29964
29881
  case QUESTION_KIND.RICH_TEXT.value:
29965
29882
  return /*#__PURE__*/React__default.createElement(EditorContent, {
29966
- content: getValue({
29883
+ content: getEditorContent(getValue({
29967
29884
  value: value,
29968
29885
  kind: kind
29969
- })
29886
+ }))
29970
29887
  });
29971
29888
  case QUESTION_KIND.PHONE.value:
29972
29889
  return isPresent$1(value) ? /*#__PURE__*/React__default.createElement(PhoneNumber$1, {