@bigbinary/neeto-integrations-frontend 2.3.1 → 2.4.0
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/Twilio.cjs.js +540 -0
- package/dist/Twilio.cjs.js.map +1 -0
- package/dist/Twilio.js +512 -0
- package/dist/Twilio.js.map +1 -0
- package/dist/index.cjs.js +441 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +441 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/translations/en.json +22 -1
- package/types.d.ts +10 -5
package/dist/index.cjs.js
CHANGED
|
@@ -10,6 +10,13 @@ var neetoui = require('@bigbinary/neetoui');
|
|
|
10
10
|
var ramda = require('ramda');
|
|
11
11
|
var reactI18next = require('react-i18next');
|
|
12
12
|
var neetoIcons = require('@bigbinary/neeto-icons');
|
|
13
|
+
var i18next = require('i18next');
|
|
14
|
+
var formik = require('@bigbinary/neetoui/formik');
|
|
15
|
+
var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
|
|
16
|
+
var constants = require('@bigbinary/neeto-commons-frontend/constants');
|
|
17
|
+
var reactQuery = require('react-query');
|
|
18
|
+
var axios = require('axios');
|
|
19
|
+
var yup = require('yup');
|
|
13
20
|
|
|
14
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
22
|
|
|
@@ -34,6 +41,9 @@ function _interopNamespace(e) {
|
|
|
34
41
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
35
42
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
36
43
|
var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
|
|
44
|
+
var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
|
|
45
|
+
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
46
|
+
var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
|
|
37
47
|
|
|
38
48
|
function _extends$1() {
|
|
39
49
|
_extends$1 = Object.assign ? Object.assign.bind() : function (target) {
|
|
@@ -679,6 +689,436 @@ var WalkthroughModal = function WalkthroughModal(_ref) {
|
|
|
679
689
|
})));
|
|
680
690
|
};
|
|
681
691
|
|
|
692
|
+
function _arrayWithHoles(arr) {
|
|
693
|
+
if (Array.isArray(arr)) return arr;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function _iterableToArrayLimit(arr, i) {
|
|
697
|
+
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
698
|
+
if (null != _i) {
|
|
699
|
+
var _s,
|
|
700
|
+
_e,
|
|
701
|
+
_x,
|
|
702
|
+
_r,
|
|
703
|
+
_arr = [],
|
|
704
|
+
_n = !0,
|
|
705
|
+
_d = !1;
|
|
706
|
+
try {
|
|
707
|
+
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
708
|
+
if (Object(_i) !== _i) return;
|
|
709
|
+
_n = !1;
|
|
710
|
+
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
711
|
+
} catch (err) {
|
|
712
|
+
_d = !0, _e = err;
|
|
713
|
+
} finally {
|
|
714
|
+
try {
|
|
715
|
+
if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
|
|
716
|
+
} finally {
|
|
717
|
+
if (_d) throw _e;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return _arr;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
function _arrayLikeToArray(arr, len) {
|
|
725
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
726
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
727
|
+
return arr2;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
731
|
+
if (!o) return;
|
|
732
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
733
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
734
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
735
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
736
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function _nonIterableRest() {
|
|
740
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function _slicedToArray(arr, i) {
|
|
744
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
var TWILIO_INTEGRATION_STEPS = [{
|
|
748
|
+
step: "1",
|
|
749
|
+
label: i18next__default["default"].t("neetoIntegrations.steps.configure"),
|
|
750
|
+
isActive: true,
|
|
751
|
+
isCompleted: false
|
|
752
|
+
}];
|
|
753
|
+
|
|
754
|
+
function _typeof(obj) {
|
|
755
|
+
"@babel/helpers - typeof";
|
|
756
|
+
|
|
757
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
758
|
+
return typeof obj;
|
|
759
|
+
} : function (obj) {
|
|
760
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
761
|
+
}, _typeof(obj);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function _toPrimitive(input, hint) {
|
|
765
|
+
if (_typeof(input) !== "object" || input === null) return input;
|
|
766
|
+
var prim = input[Symbol.toPrimitive];
|
|
767
|
+
if (prim !== undefined) {
|
|
768
|
+
var res = prim.call(input, hint || "default");
|
|
769
|
+
if (_typeof(res) !== "object") return res;
|
|
770
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
771
|
+
}
|
|
772
|
+
return (hint === "string" ? String : Number)(input);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function _toPropertyKey(arg) {
|
|
776
|
+
var key = _toPrimitive(arg, "string");
|
|
777
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function _defineProperty(obj, key, value) {
|
|
781
|
+
key = _toPropertyKey(key);
|
|
782
|
+
if (key in obj) {
|
|
783
|
+
Object.defineProperty(obj, key, {
|
|
784
|
+
value: value,
|
|
785
|
+
enumerable: true,
|
|
786
|
+
configurable: true,
|
|
787
|
+
writable: true
|
|
788
|
+
});
|
|
789
|
+
} else {
|
|
790
|
+
obj[key] = value;
|
|
791
|
+
}
|
|
792
|
+
return obj;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
796
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
797
|
+
var ConfigurationForm = function ConfigurationForm(_ref) {
|
|
798
|
+
var _errors$twilioPhoneNu;
|
|
799
|
+
var phoneNumberOptions = _ref.phoneNumberOptions,
|
|
800
|
+
_ref$selectedPhoneNum = _ref.selectedPhoneNumber,
|
|
801
|
+
selectedPhoneNumber = _ref$selectedPhoneNum === void 0 ? null : _ref$selectedPhoneNum,
|
|
802
|
+
_ref$initialFocusRef = _ref.initialFocusRef,
|
|
803
|
+
initialFocusRef = _ref$initialFocusRef === void 0 ? null : _ref$initialFocusRef,
|
|
804
|
+
_ref$isUsingOverlay = _ref.isUsingOverlay,
|
|
805
|
+
isUsingOverlay = _ref$isUsingOverlay === void 0 ? false : _ref$isUsingOverlay,
|
|
806
|
+
_ref$formikProps = _ref.formikProps,
|
|
807
|
+
formikProps = _ref$formikProps === void 0 ? {} : _ref$formikProps;
|
|
808
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
809
|
+
t = _useTranslation.t;
|
|
810
|
+
var setFieldValue = formikProps.setFieldValue,
|
|
811
|
+
setValues = formikProps.setValues,
|
|
812
|
+
errors = formikProps.errors,
|
|
813
|
+
values = formikProps.values,
|
|
814
|
+
initialValues = formikProps.initialValues;
|
|
815
|
+
React.useEffect(function () {
|
|
816
|
+
selectedPhoneNumber && setFieldValue("twilioPhoneNumber", selectedPhoneNumber);
|
|
817
|
+
}, [selectedPhoneNumber, initialValues]);
|
|
818
|
+
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
819
|
+
className: "flex w-full flex-col gap-4"
|
|
820
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
821
|
+
className: "flex w-full"
|
|
822
|
+
}, /*#__PURE__*/React__default["default"].createElement(formik.Input, {
|
|
823
|
+
required: true,
|
|
824
|
+
autoFocus: !isUsingOverlay,
|
|
825
|
+
"data-testid": "integrations-twilio-sid",
|
|
826
|
+
label: t("neetoIntegrations.twilio.sid"),
|
|
827
|
+
name: "twilioSid",
|
|
828
|
+
ref: initialFocusRef
|
|
829
|
+
})), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
830
|
+
className: "flex w-full"
|
|
831
|
+
}, /*#__PURE__*/React__default["default"].createElement(formik.Input, {
|
|
832
|
+
required: true,
|
|
833
|
+
"data-testid": "integrations-twilio-auth-token",
|
|
834
|
+
label: t("neetoIntegrations.twilio.authToken"),
|
|
835
|
+
name: "twilioAuthToken"
|
|
836
|
+
})), phoneNumberOptions && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
837
|
+
className: "flex w-full"
|
|
838
|
+
}, /*#__PURE__*/React__default["default"].createElement(formik.Select, {
|
|
839
|
+
error: (_errors$twilioPhoneNu = errors.twilioPhoneNumber) === null || _errors$twilioPhoneNu === void 0 ? void 0 : _errors$twilioPhoneNu.value,
|
|
840
|
+
label: t("neetoIntegrations.common.phNo"),
|
|
841
|
+
name: "twilioPhoneNumber",
|
|
842
|
+
options: phoneNumberOptions,
|
|
843
|
+
size: "large",
|
|
844
|
+
onChange: function onChange(selected) {
|
|
845
|
+
return setValues(_objectSpread$2(_objectSpread$2({}, values), {}, {
|
|
846
|
+
twilioPhoneNumber: selected
|
|
847
|
+
}));
|
|
848
|
+
}
|
|
849
|
+
})));
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
function _arrayWithoutHoles(arr) {
|
|
853
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
function _iterableToArray(iter) {
|
|
857
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
function _nonIterableSpread() {
|
|
861
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function _toConsumableArray(arr) {
|
|
865
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
var queryClient = new reactQuery.QueryClient({
|
|
869
|
+
queryCache: new reactQuery.QueryCache()
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
var TWILIO_CONFIGURATION_BASE_URL = "/neeto_integrations/twilio/sms_configurations";
|
|
873
|
+
|
|
874
|
+
var twilioApi = {
|
|
875
|
+
fetchTwilioSmsConfiguration: function fetchTwilioSmsConfiguration() {
|
|
876
|
+
return axios__default["default"].get(TWILIO_CONFIGURATION_BASE_URL);
|
|
877
|
+
},
|
|
878
|
+
removeTwilioConfiguration: function removeTwilioConfiguration() {
|
|
879
|
+
return axios__default["default"]["delete"](TWILIO_CONFIGURATION_BASE_URL);
|
|
880
|
+
},
|
|
881
|
+
getTwilioPhoneNumbers: function getTwilioPhoneNumbers(data) {
|
|
882
|
+
return axios__default["default"].get("".concat(TWILIO_CONFIGURATION_BASE_URL, "/new"), {
|
|
883
|
+
params: data
|
|
884
|
+
});
|
|
885
|
+
},
|
|
886
|
+
createTwilioConfiguration: function createTwilioConfiguration(payload) {
|
|
887
|
+
return axios__default["default"].post(TWILIO_CONFIGURATION_BASE_URL, payload);
|
|
888
|
+
}
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
var QUERY_KEYS = {
|
|
892
|
+
TWILIO_SMS_CONFIGURATION: "twilio-sms-configuration",
|
|
893
|
+
TWILIO_PHONE_NUMBERS: "twilio-phone-numbers"
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
var useFetchTwilioSmsConfiguration = function useFetchTwilioSmsConfiguration() {
|
|
897
|
+
return reactQuery.useQuery(QUERY_KEYS.TWILIO_SMS_CONFIGURATION, twilioApi.fetchTwilioSmsConfiguration, {
|
|
898
|
+
staleTime: constants.DEFAULT_STALE_TIME,
|
|
899
|
+
select: function select(response) {
|
|
900
|
+
var _smsConfiguration$twi, _smsConfiguration$twi2, _smsConfiguration$twi3;
|
|
901
|
+
var smsConfiguration = response.smsConfiguration;
|
|
902
|
+
return {
|
|
903
|
+
twilioSid: (_smsConfiguration$twi = smsConfiguration === null || smsConfiguration === void 0 ? void 0 : smsConfiguration.twilioSid) !== null && _smsConfiguration$twi !== void 0 ? _smsConfiguration$twi : "",
|
|
904
|
+
twilioAuthToken: (_smsConfiguration$twi2 = smsConfiguration === null || smsConfiguration === void 0 ? void 0 : smsConfiguration.twilioAuthToken) !== null && _smsConfiguration$twi2 !== void 0 ? _smsConfiguration$twi2 : "",
|
|
905
|
+
twilioPhoneNumber: (_smsConfiguration$twi3 = smsConfiguration === null || smsConfiguration === void 0 ? void 0 : smsConfiguration.twilioPhoneNumber) !== null && _smsConfiguration$twi3 !== void 0 ? _smsConfiguration$twi3 : ""
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
};
|
|
910
|
+
var useFetchTwilioPhoneNumbers = function useFetchTwilioPhoneNumbers(_ref) {
|
|
911
|
+
var credentials = _ref.credentials;
|
|
912
|
+
return reactQuery.useQuery([QUERY_KEYS.TWILIO_PHONE_NUMBERS, {
|
|
913
|
+
credentials: credentials
|
|
914
|
+
}], function () {
|
|
915
|
+
return twilioApi.getTwilioPhoneNumbers(pure.keysToSnakeCase(credentials));
|
|
916
|
+
}, {
|
|
917
|
+
staleTime: constants.DEFAULT_STALE_TIME,
|
|
918
|
+
enabled: !!(credentials !== null && credentials !== void 0 && credentials.twilio_sid) || !!(credentials !== null && credentials !== void 0 && credentials.twilioSid),
|
|
919
|
+
select: ramda.prop("phoneNumbers"),
|
|
920
|
+
retry: false
|
|
921
|
+
});
|
|
922
|
+
};
|
|
923
|
+
var useCreateTwilioConfiguration = function useCreateTwilioConfiguration() {
|
|
924
|
+
return reactQuery.useMutation(twilioApi.createTwilioConfiguration, {
|
|
925
|
+
onSuccess: function onSuccess() {
|
|
926
|
+
return queryClient.invalidateQueries(QUERY_KEYS.TWILIO_SMS_CONFIGURATION);
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
932
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
933
|
+
var useTwilio = function useTwilio(_ref) {
|
|
934
|
+
var _ref$onSave = _ref.onSave,
|
|
935
|
+
onSave = _ref$onSave === void 0 ? pure.noop : _ref$onSave,
|
|
936
|
+
_ref$setSteps = _ref.setSteps,
|
|
937
|
+
setSteps = _ref$setSteps === void 0 ? pure.noop : _ref$setSteps,
|
|
938
|
+
_ref$useConnect = _ref.useConnect,
|
|
939
|
+
useConnect = _ref$useConnect === void 0 ? pure.noop : _ref$useConnect;
|
|
940
|
+
var _useFetchTwilioSmsCon = useFetchTwilioSmsConfiguration(),
|
|
941
|
+
configuration = _useFetchTwilioSmsCon.data,
|
|
942
|
+
isConfigurationLoading = _useFetchTwilioSmsCon.isLoading,
|
|
943
|
+
refetchTwilioSmsConfiguration = _useFetchTwilioSmsCon.refetch;
|
|
944
|
+
var _useStateWithDependen = reactUtils.useStateWithDependency(configuration),
|
|
945
|
+
_useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 2),
|
|
946
|
+
credentials = _useStateWithDependen2[0],
|
|
947
|
+
setCredentials = _useStateWithDependen2[1];
|
|
948
|
+
var _useFetchTwilioPhoneN = useFetchTwilioPhoneNumbers({
|
|
949
|
+
credentials: credentials
|
|
950
|
+
}),
|
|
951
|
+
phoneNumbers = _useFetchTwilioPhoneN.data,
|
|
952
|
+
isPhoneNumbersLoading = _useFetchTwilioPhoneN.isLoading;
|
|
953
|
+
var _useCreateTwilioConfi = useCreateTwilioConfiguration(),
|
|
954
|
+
saveConfiguration = _useCreateTwilioConfi.mutate,
|
|
955
|
+
isSubmitting = _useCreateTwilioConfi.isLoading;
|
|
956
|
+
var _useConnect = useConnect(),
|
|
957
|
+
installIntegration = _useConnect.mutate;
|
|
958
|
+
var connectTwilioApp = function connectTwilioApp() {
|
|
959
|
+
return installIntegration({
|
|
960
|
+
id: "twilio"
|
|
961
|
+
}, {});
|
|
962
|
+
};
|
|
963
|
+
React.useEffect(function () {
|
|
964
|
+
if (!(configuration !== null && configuration !== void 0 && configuration.twilioPhoneNumber)) return;
|
|
965
|
+
setSteps(function (steps) {
|
|
966
|
+
var stepsClone = _toConsumableArray(steps);
|
|
967
|
+
stepsClone[0] = _objectSpread$1(_objectSpread$1({}, steps[0]), {}, {
|
|
968
|
+
isCompleted: true
|
|
969
|
+
});
|
|
970
|
+
return stepsClone;
|
|
971
|
+
});
|
|
972
|
+
}, [configuration]);
|
|
973
|
+
var handleSubmit = function handleSubmit(values) {
|
|
974
|
+
var _values$twilioPhoneNu;
|
|
975
|
+
var payload = {
|
|
976
|
+
twilio_sid: values.twilioSid,
|
|
977
|
+
twilio_auth_token: values.twilioAuthToken,
|
|
978
|
+
twilio_phone_number_sid: (_values$twilioPhoneNu = values.twilioPhoneNumber) === null || _values$twilioPhoneNu === void 0 ? void 0 : _values$twilioPhoneNu.value
|
|
979
|
+
};
|
|
980
|
+
if (!phoneNumbers && !(configuration !== null && configuration !== void 0 && configuration.twilioPhoneNumber)) {
|
|
981
|
+
setCredentials(payload);
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
saveConfiguration(payload, {
|
|
985
|
+
onSuccess: function onSuccess() {
|
|
986
|
+
onSave();
|
|
987
|
+
connectTwilioApp();
|
|
988
|
+
refetchTwilioSmsConfiguration();
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
};
|
|
992
|
+
return {
|
|
993
|
+
handleSubmit: handleSubmit,
|
|
994
|
+
phoneNumbers: phoneNumbers,
|
|
995
|
+
isConfigurationLoading: isConfigurationLoading,
|
|
996
|
+
isPhoneNumbersLoading: isPhoneNumbersLoading,
|
|
997
|
+
isSubmitting: isSubmitting,
|
|
998
|
+
configuration: configuration
|
|
999
|
+
};
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
var buildTwilioConfigurationValidationSchema = function buildTwilioConfigurationValidationSchema(isTwilioPhoneRequired) {
|
|
1003
|
+
return yup__namespace.object().shape({
|
|
1004
|
+
twilioSid: yup__namespace.string().required(i18next__default["default"].t("neetoIntegrations.twilio.validations.sidReq")),
|
|
1005
|
+
twilioAuthToken: yup__namespace.string().required(i18next__default["default"].t("neetoIntegrations.twilio.validations.authTokenReq")),
|
|
1006
|
+
twilioPhoneNumber: isTwilioPhoneRequired ? yup__namespace.object().shape({
|
|
1007
|
+
label: yup__namespace.string(),
|
|
1008
|
+
value: yup__namespace.string().required(i18next__default["default"].t("neetoIntegrations.twilio.validations.phNumReq"))
|
|
1009
|
+
}) : null
|
|
1010
|
+
});
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1014
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1015
|
+
var TwilioConfiguration = function TwilioConfiguration(_ref) {
|
|
1016
|
+
var _ref$onCancel = _ref.onCancel,
|
|
1017
|
+
onCancel = _ref$onCancel === void 0 ? pure.noop : _ref$onCancel,
|
|
1018
|
+
_ref$onSave = _ref.onSave,
|
|
1019
|
+
onSave = _ref$onSave === void 0 ? pure.noop : _ref$onSave,
|
|
1020
|
+
_ref$setSteps = _ref.setSteps,
|
|
1021
|
+
setSteps = _ref$setSteps === void 0 ? pure.noop : _ref$setSteps,
|
|
1022
|
+
_ref$useConnect = _ref.useConnect,
|
|
1023
|
+
useConnect = _ref$useConnect === void 0 ? pure.noop : _ref$useConnect,
|
|
1024
|
+
_ref$isModal = _ref.isModal,
|
|
1025
|
+
isModal = _ref$isModal === void 0 ? false : _ref$isModal;
|
|
1026
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
1027
|
+
t = _useTranslation.t;
|
|
1028
|
+
var initialFocusRef = React.useRef();
|
|
1029
|
+
var _useTwilio = useTwilio({
|
|
1030
|
+
onSave: onSave,
|
|
1031
|
+
setSteps: setSteps,
|
|
1032
|
+
useConnect: useConnect
|
|
1033
|
+
}),
|
|
1034
|
+
handleSubmit = _useTwilio.handleSubmit,
|
|
1035
|
+
phoneNumbers = _useTwilio.phoneNumbers,
|
|
1036
|
+
isConfigurationLoading = _useTwilio.isConfigurationLoading,
|
|
1037
|
+
isPhoneNumbersLoading = _useTwilio.isPhoneNumbersLoading,
|
|
1038
|
+
isSubmitting = _useTwilio.isSubmitting,
|
|
1039
|
+
configuration = _useTwilio.configuration;
|
|
1040
|
+
var phoneNumberOptions = phoneNumbers === null || phoneNumbers === void 0 ? void 0 : phoneNumbers.map(function (_ref2) {
|
|
1041
|
+
var phoneNumber = _ref2.phoneNumber,
|
|
1042
|
+
sid = _ref2.sid;
|
|
1043
|
+
return {
|
|
1044
|
+
label: phoneNumber,
|
|
1045
|
+
value: sid
|
|
1046
|
+
};
|
|
1047
|
+
});
|
|
1048
|
+
var selectedPhoneNumber = pure._findBy({
|
|
1049
|
+
label: configuration === null || configuration === void 0 ? void 0 : configuration.twilioPhoneNumber
|
|
1050
|
+
}, phoneNumberOptions);
|
|
1051
|
+
var wrapInModalBody = function wrapInModalBody(children) {
|
|
1052
|
+
return /*#__PURE__*/React__default["default"].createElement(neetoui.Modal.Body, null, children);
|
|
1053
|
+
};
|
|
1054
|
+
var wrapInModalFooter = function wrapInModalFooter(children) {
|
|
1055
|
+
return /*#__PURE__*/React__default["default"].createElement(neetoui.Modal.Footer, null, children);
|
|
1056
|
+
};
|
|
1057
|
+
var isLoading = isPhoneNumbersLoading || isConfigurationLoading;
|
|
1058
|
+
var isSubmitDisabled = function isSubmitDisabled(values) {
|
|
1059
|
+
return ramda.equals(_objectSpread(_objectSpread({}, configuration), {}, {
|
|
1060
|
+
twilioPhoneNumber: selectedPhoneNumber
|
|
1061
|
+
}), values) || isLoading;
|
|
1062
|
+
};
|
|
1063
|
+
var renderActionBlock = function renderActionBlock(values) {
|
|
1064
|
+
return /*#__PURE__*/React__default["default"].createElement(formik.ActionBlock, {
|
|
1065
|
+
cancelButtonProps: {
|
|
1066
|
+
onClick: onCancel,
|
|
1067
|
+
disabled: false
|
|
1068
|
+
},
|
|
1069
|
+
className: "space-x-3",
|
|
1070
|
+
submitButtonProps: {
|
|
1071
|
+
label: phoneNumberOptions ? t("neetoIntegrations.common.saveChanges") : t("neetoIntegrations.common.verify"),
|
|
1072
|
+
disabled: isSubmitDisabled(values),
|
|
1073
|
+
loading: isSubmitting || isPhoneNumbersLoading && !configuration.twilioAuthToken
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
};
|
|
1077
|
+
var renderForm = function renderForm(formikProps) {
|
|
1078
|
+
return /*#__PURE__*/React__default["default"].createElement(ConfigurationForm, {
|
|
1079
|
+
formikProps: formikProps,
|
|
1080
|
+
initialFocusRef: initialFocusRef,
|
|
1081
|
+
isUsingOverlay: isModal,
|
|
1082
|
+
phoneNumberOptions: phoneNumberOptions,
|
|
1083
|
+
selectedPhoneNumber: selectedPhoneNumber
|
|
1084
|
+
});
|
|
1085
|
+
};
|
|
1086
|
+
return /*#__PURE__*/React__default["default"].createElement(formik.Form, {
|
|
1087
|
+
className: "mx-auto flex w-full max-w-md flex-col",
|
|
1088
|
+
formikProps: {
|
|
1089
|
+
enableReinitialize: true,
|
|
1090
|
+
validationSchema: buildTwilioConfigurationValidationSchema(!!phoneNumbers),
|
|
1091
|
+
initialValues: configuration,
|
|
1092
|
+
onSubmit: handleSubmit
|
|
1093
|
+
}
|
|
1094
|
+
}, function (formikProps) {
|
|
1095
|
+
return isModal ? /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, wrapInModalBody(renderForm(formikProps)), wrapInModalFooter(renderActionBlock(formikProps.values))) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, "renderForm(formikProps)", /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1096
|
+
className: "mt-4 flex items-center gap-x-2"
|
|
1097
|
+
}, renderActionBlock(formikProps.values)));
|
|
1098
|
+
});
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
var Twilio = function Twilio(_ref) {
|
|
1102
|
+
var _ref$onClose = _ref.onClose,
|
|
1103
|
+
onClose = _ref$onClose === void 0 ? pure.noop : _ref$onClose,
|
|
1104
|
+
_ref$useConnect = _ref.useConnect,
|
|
1105
|
+
useConnect = _ref$useConnect === void 0 ? pure.noop : _ref$useConnect;
|
|
1106
|
+
var _useState = React.useState(TWILIO_INTEGRATION_STEPS),
|
|
1107
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1108
|
+
steps = _useState2[0],
|
|
1109
|
+
setSteps = _useState2[1];
|
|
1110
|
+
return /*#__PURE__*/React__default["default"].createElement(Modal, {
|
|
1111
|
+
isOpen: true,
|
|
1112
|
+
steps: steps,
|
|
1113
|
+
onClose: onClose
|
|
1114
|
+
}, /*#__PURE__*/React__default["default"].createElement(TwilioConfiguration, {
|
|
1115
|
+
isModal: true,
|
|
1116
|
+
setSteps: setSteps,
|
|
1117
|
+
useConnect: useConnect,
|
|
1118
|
+
onCancel: onClose
|
|
1119
|
+
}));
|
|
1120
|
+
};
|
|
1121
|
+
|
|
682
1122
|
var e = [],
|
|
683
1123
|
t = [];
|
|
684
1124
|
function n(n, r) {
|
|
@@ -710,5 +1150,6 @@ exports.Demo = Demo;
|
|
|
710
1150
|
exports.DisconnectAlert = DisconnectAlert;
|
|
711
1151
|
exports.Finish = Finish;
|
|
712
1152
|
exports.Modal = Modal;
|
|
1153
|
+
exports.Twilio = Twilio;
|
|
713
1154
|
exports.WalkthroughModal = WalkthroughModal;
|
|
714
1155
|
//# sourceMappingURL=index.cjs.js.map
|