@bigbinary/neeto-integrations-frontend 2.3.1 → 2.5.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.js ADDED
@@ -0,0 +1,681 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { noop, keysToSnakeCase, _findBy } from '@bigbinary/neeto-commons-frontend/pure';
3
+ import '@bigbinary/neeto-molecules/IntegrationCard';
4
+ import '@bigbinary/neeto-molecules/IntegrationDisconnectAlert';
5
+ import '@bigbinary/neeto-molecules/IntegrationWalkthroughModal';
6
+ import { Typography, Modal as Modal$1 } from '@bigbinary/neetoui';
7
+ import classnames from 'classnames';
8
+ import { useTranslation } from 'react-i18next';
9
+ import { prop, equals } from 'ramda';
10
+ import i18next from 'i18next';
11
+ import { Input, Select, Form, ActionBlock } from '@bigbinary/neetoui/formik';
12
+ import { useStateWithDependency } from '@bigbinary/neeto-commons-frontend/react-utils';
13
+ import { DEFAULT_STALE_TIME } from '@bigbinary/neeto-commons-frontend/constants';
14
+ import { QueryClient, QueryCache, useQuery, useMutation } from 'react-query';
15
+ import axios from 'axios';
16
+ import * as yup from 'yup';
17
+
18
+ function _arrayWithHoles(arr) {
19
+ if (Array.isArray(arr)) return arr;
20
+ }
21
+
22
+ function _iterableToArrayLimit(arr, i) {
23
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
24
+ if (null != _i) {
25
+ var _s,
26
+ _e,
27
+ _x,
28
+ _r,
29
+ _arr = [],
30
+ _n = !0,
31
+ _d = !1;
32
+ try {
33
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
34
+ if (Object(_i) !== _i) return;
35
+ _n = !1;
36
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
37
+ } catch (err) {
38
+ _d = !0, _e = err;
39
+ } finally {
40
+ try {
41
+ if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
42
+ } finally {
43
+ if (_d) throw _e;
44
+ }
45
+ }
46
+ return _arr;
47
+ }
48
+ }
49
+
50
+ function _arrayLikeToArray(arr, len) {
51
+ if (len == null || len > arr.length) len = arr.length;
52
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
53
+ return arr2;
54
+ }
55
+
56
+ function _unsupportedIterableToArray(o, minLen) {
57
+ if (!o) return;
58
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
59
+ var n = Object.prototype.toString.call(o).slice(8, -1);
60
+ if (n === "Object" && o.constructor) n = o.constructor.name;
61
+ if (n === "Map" || n === "Set") return Array.from(o);
62
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
63
+ }
64
+
65
+ function _nonIterableRest() {
66
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
67
+ }
68
+
69
+ function _slicedToArray(arr, i) {
70
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
71
+ }
72
+
73
+ var Stepper = function Stepper(_ref) {
74
+ var _ref$steps = _ref.steps,
75
+ steps = _ref$steps === void 0 ? {} : _ref$steps;
76
+ var isActiveOrCompleted = function isActiveOrCompleted(activeStatus, completedStatus) {
77
+ return activeStatus || completedStatus;
78
+ };
79
+ return /*#__PURE__*/React.createElement("ul", {
80
+ className: "flex gap-4"
81
+ }, steps === null || steps === void 0 ? void 0 : steps.map(function (_ref2) {
82
+ var step = _ref2.step,
83
+ label = _ref2.label,
84
+ isActive = _ref2.isActive,
85
+ isCompleted = _ref2.isCompleted;
86
+ return /*#__PURE__*/React.createElement("li", {
87
+ className: "flex items-center gap-4",
88
+ key: step
89
+ }, step !== "1" && /*#__PURE__*/React.createElement("div", {
90
+ className: classnames("w-10 border-b", {
91
+ "neeto-ui-border-gray-800": isActiveOrCompleted(isActive, isCompleted),
92
+ "neeto-ui-border-gray-400": !isActiveOrCompleted(isActive, isCompleted)
93
+ })
94
+ }), /*#__PURE__*/React.createElement("div", {
95
+ className: "flex items-center gap-2"
96
+ }, /*#__PURE__*/React.createElement("div", {
97
+ className: classnames("neeto-ui-rounded-full neeto-ui-gray-600 flex h-6 w-6 items-center justify-center border", {
98
+ "neeto-ui-bg-success-600 neeto-ui-border-success-600 neeto-ui-text-white": isActive,
99
+ "neeto-ui-bg-primary-600 neeto-ui-border-primary-600 neeto-ui-text-white": isCompleted,
100
+ "neeto-ui-border-gray-400": !isActiveOrCompleted(isActive, isCompleted)
101
+ })
102
+ }, /*#__PURE__*/React.createElement(Typography, {
103
+ component: "span",
104
+ style: "body2",
105
+ weight: "normal"
106
+ }, step)), /*#__PURE__*/React.createElement(Typography, {
107
+ style: "body2",
108
+ weight: "normal",
109
+ className: classnames({
110
+ "neeto-ui-text-gray-800": isActiveOrCompleted(isActive, isCompleted),
111
+ "neeto-ui-text-gray-600": !isActiveOrCompleted(isActive, isCompleted)
112
+ })
113
+ }, label)));
114
+ }));
115
+ };
116
+
117
+ var Modal = function Modal(_ref) {
118
+ var _ref$isOpen = _ref.isOpen,
119
+ isOpen = _ref$isOpen === void 0 ? noop : _ref$isOpen,
120
+ _ref$onClose = _ref.onClose,
121
+ onClose = _ref$onClose === void 0 ? noop : _ref$onClose,
122
+ _ref$steps = _ref.steps,
123
+ steps = _ref$steps === void 0 ? {} : _ref$steps,
124
+ children = _ref.children;
125
+ return /*#__PURE__*/React.createElement(Modal$1, {
126
+ className: "neeto-ui-flex neeto-ui-flex-col neeto-ui-transform-none w-screen overflow-y-auto",
127
+ isOpen: isOpen,
128
+ size: "fullScreen",
129
+ onClose: onClose
130
+ }, /*#__PURE__*/React.createElement(Modal$1.Header, null, /*#__PURE__*/React.createElement(Stepper, {
131
+ steps: steps
132
+ })), /*#__PURE__*/React.createElement(Modal$1.Body, {
133
+ className: "neeto-ui-flex neeto-ui-justify-center neeto-ui-items-center neeto-ui-flex-grow"
134
+ }, /*#__PURE__*/React.createElement("div", {
135
+ className: "neeto-ui-w-full py-10"
136
+ }, children)));
137
+ };
138
+
139
+ var propTypes = {exports: {}};
140
+
141
+ /**
142
+ * Copyright (c) 2013-present, Facebook, Inc.
143
+ *
144
+ * This source code is licensed under the MIT license found in the
145
+ * LICENSE file in the root directory of this source tree.
146
+ */
147
+ var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
148
+ var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
149
+
150
+ /**
151
+ * Copyright (c) 2013-present, Facebook, Inc.
152
+ *
153
+ * This source code is licensed under the MIT license found in the
154
+ * LICENSE file in the root directory of this source tree.
155
+ */
156
+ var ReactPropTypesSecret = ReactPropTypesSecret_1;
157
+ function emptyFunction() {}
158
+ function emptyFunctionWithReset() {}
159
+ emptyFunctionWithReset.resetWarningCache = emptyFunction;
160
+ var factoryWithThrowingShims = function factoryWithThrowingShims() {
161
+ function shim(props, propName, componentName, location, propFullName, secret) {
162
+ if (secret === ReactPropTypesSecret) {
163
+ // It is still safe when called from React.
164
+ return;
165
+ }
166
+ var err = new Error('Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use PropTypes.checkPropTypes() to call them. ' + 'Read more at http://fb.me/use-check-prop-types');
167
+ err.name = 'Invariant Violation';
168
+ throw err;
169
+ }
170
+ shim.isRequired = shim;
171
+ function getShim() {
172
+ return shim;
173
+ }
174
+ // Important!
175
+ // Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
176
+ var ReactPropTypes = {
177
+ array: shim,
178
+ bigint: shim,
179
+ bool: shim,
180
+ func: shim,
181
+ number: shim,
182
+ object: shim,
183
+ string: shim,
184
+ symbol: shim,
185
+ any: shim,
186
+ arrayOf: getShim,
187
+ element: shim,
188
+ elementType: shim,
189
+ instanceOf: getShim,
190
+ node: shim,
191
+ objectOf: getShim,
192
+ oneOf: getShim,
193
+ oneOfType: getShim,
194
+ shape: getShim,
195
+ exact: getShim,
196
+ checkPropTypes: emptyFunctionWithReset,
197
+ resetWarningCache: emptyFunction
198
+ };
199
+ ReactPropTypes.PropTypes = ReactPropTypes;
200
+ return ReactPropTypes;
201
+ };
202
+
203
+ /**
204
+ * Copyright (c) 2013-present, Facebook, Inc.
205
+ *
206
+ * This source code is licensed under the MIT license found in the
207
+ * LICENSE file in the root directory of this source tree.
208
+ */
209
+ {
210
+ // By explicitly using `prop-types` you are opting into new production behavior.
211
+ // http://fb.me/prop-types-in-prod
212
+ propTypes.exports = factoryWithThrowingShims();
213
+ }
214
+
215
+ ({
216
+ /**
217
+ * To specify the Icon to be shown
218
+ */
219
+ Icon: propTypes.exports.PropTypes.node,
220
+ /**
221
+ * To specify the title of the connect component
222
+ */
223
+ title: propTypes.exports.PropTypes.string,
224
+ /**
225
+ * To specify the description for connect component
226
+ */
227
+ description: propTypes.exports.PropTypes.string,
228
+ /**
229
+ * To specify the props for the connect button
230
+ */
231
+ buttonProps: propTypes.exports.PropTypes.object,
232
+ /**
233
+ * Handler function that is triggered when the connect button is clicked.
234
+ */
235
+ onConnect: propTypes.exports.PropTypes.func
236
+ });
237
+
238
+ ({
239
+ /**
240
+ * To specify whether the integration modal should be opened or closed.
241
+ */
242
+ onClose: propTypes.exports.func,
243
+ /**
244
+ * To specify the walkthrough video link
245
+ */
246
+ videoUrl: propTypes.exports.string,
247
+ /**
248
+ * To specify the title of the demo component
249
+ */
250
+ title: propTypes.exports.string,
251
+ /**
252
+ * To specify the subtitle of the demo component
253
+ */
254
+ subtitle: propTypes.exports.string,
255
+ /**
256
+ * To specify the title of the video in the iframe
257
+ */
258
+ iframeTitle: propTypes.exports.string
259
+ });
260
+
261
+ ({
262
+ /**
263
+ * To specify whether the integration modal should be opened or closed.
264
+ */
265
+ onClick: propTypes.exports.func,
266
+ /**
267
+ * To show the title of the Finish component
268
+ */
269
+ title: propTypes.exports.string,
270
+ /**
271
+ * To specify props for primary button
272
+ */
273
+ buttonProps: propTypes.exports.object,
274
+ /**
275
+ * To specify props for secondary button
276
+ */
277
+ secondaryButtonProps: propTypes.exports.object
278
+ });
279
+
280
+ var e = [],
281
+ t = [];
282
+ function n(n, r) {
283
+ if (n && "undefined" != typeof document) {
284
+ var a,
285
+ s = !0 === r.prepend ? "prepend" : "append",
286
+ d = !0 === r.singleTag,
287
+ i = "string" == typeof r.container ? document.querySelector(r.container) : document.getElementsByTagName("head")[0];
288
+ if (d) {
289
+ var u = e.indexOf(i);
290
+ -1 === u && (u = e.push(i) - 1, t[u] = {}), a = t[u] && t[u][s] ? t[u][s] : t[u][s] = c();
291
+ } else a = c();
292
+ 65279 === n.charCodeAt(0) && (n = n.substring(1)), a.styleSheet ? a.styleSheet.cssText += n : a.appendChild(document.createTextNode(n));
293
+ }
294
+ function c() {
295
+ var e = document.createElement("style");
296
+ if (e.setAttribute("type", "text/css"), r.attributes) for (var t = Object.keys(r.attributes), n = 0; n < t.length; n++) e.setAttribute(t[n], r.attributes[t[n]]);
297
+ var a = "prepend" === s ? "afterbegin" : "beforeend";
298
+ return i.insertAdjacentElement(a, e), e;
299
+ }
300
+ }
301
+
302
+ var css = ".intrinsic-container{height:0;overflow:hidden;position:relative}.intrinsic-container-16x9{padding-bottom:56.25%}.intrinsic-container-4x3{padding-bottom:75%}.intrinsic-container iframe{height:100%;left:0;position:absolute;top:0;width:100%}";
303
+ n(css,{});
304
+
305
+ var TWILIO_INTEGRATION_STEPS = [{
306
+ step: "1",
307
+ label: i18next.t("neetoIntegrations.steps.configure"),
308
+ isActive: true,
309
+ isCompleted: false
310
+ }];
311
+
312
+ function _typeof(obj) {
313
+ "@babel/helpers - typeof";
314
+
315
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
316
+ return typeof obj;
317
+ } : function (obj) {
318
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
319
+ }, _typeof(obj);
320
+ }
321
+
322
+ function _toPrimitive(input, hint) {
323
+ if (_typeof(input) !== "object" || input === null) return input;
324
+ var prim = input[Symbol.toPrimitive];
325
+ if (prim !== undefined) {
326
+ var res = prim.call(input, hint || "default");
327
+ if (_typeof(res) !== "object") return res;
328
+ throw new TypeError("@@toPrimitive must return a primitive value.");
329
+ }
330
+ return (hint === "string" ? String : Number)(input);
331
+ }
332
+
333
+ function _toPropertyKey(arg) {
334
+ var key = _toPrimitive(arg, "string");
335
+ return _typeof(key) === "symbol" ? key : String(key);
336
+ }
337
+
338
+ function _defineProperty(obj, key, value) {
339
+ key = _toPropertyKey(key);
340
+ if (key in obj) {
341
+ Object.defineProperty(obj, key, {
342
+ value: value,
343
+ enumerable: true,
344
+ configurable: true,
345
+ writable: true
346
+ });
347
+ } else {
348
+ obj[key] = value;
349
+ }
350
+ return obj;
351
+ }
352
+
353
+ 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; }
354
+ 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; }
355
+ var ConfigurationForm = function ConfigurationForm(_ref) {
356
+ var _errors$twilioPhoneNu;
357
+ var phoneNumberOptions = _ref.phoneNumberOptions,
358
+ _ref$selectedPhoneNum = _ref.selectedPhoneNumber,
359
+ selectedPhoneNumber = _ref$selectedPhoneNum === void 0 ? null : _ref$selectedPhoneNum,
360
+ _ref$initialFocusRef = _ref.initialFocusRef,
361
+ initialFocusRef = _ref$initialFocusRef === void 0 ? null : _ref$initialFocusRef,
362
+ _ref$isUsingOverlay = _ref.isUsingOverlay,
363
+ isUsingOverlay = _ref$isUsingOverlay === void 0 ? false : _ref$isUsingOverlay,
364
+ _ref$formikProps = _ref.formikProps,
365
+ formikProps = _ref$formikProps === void 0 ? {} : _ref$formikProps;
366
+ var _useTranslation = useTranslation(),
367
+ t = _useTranslation.t;
368
+ var setFieldValue = formikProps.setFieldValue,
369
+ setValues = formikProps.setValues,
370
+ errors = formikProps.errors,
371
+ values = formikProps.values,
372
+ initialValues = formikProps.initialValues;
373
+ useEffect(function () {
374
+ selectedPhoneNumber && setFieldValue("twilioPhoneNumber", selectedPhoneNumber);
375
+ }, [selectedPhoneNumber, initialValues]);
376
+ return /*#__PURE__*/React.createElement("div", {
377
+ className: "flex w-full flex-col gap-4"
378
+ }, /*#__PURE__*/React.createElement("div", {
379
+ className: "flex w-full"
380
+ }, /*#__PURE__*/React.createElement(Input, {
381
+ required: true,
382
+ autoFocus: !isUsingOverlay,
383
+ "data-testid": "integrations-twilio-sid",
384
+ label: t("neetoIntegrations.twilio.sid"),
385
+ name: "twilioSid",
386
+ ref: initialFocusRef
387
+ })), /*#__PURE__*/React.createElement("div", {
388
+ className: "flex w-full"
389
+ }, /*#__PURE__*/React.createElement(Input, {
390
+ required: true,
391
+ "data-testid": "integrations-twilio-auth-token",
392
+ label: t("neetoIntegrations.twilio.authToken"),
393
+ name: "twilioAuthToken"
394
+ })), phoneNumberOptions && /*#__PURE__*/React.createElement("div", {
395
+ className: "flex w-full"
396
+ }, /*#__PURE__*/React.createElement(Select, {
397
+ error: (_errors$twilioPhoneNu = errors.twilioPhoneNumber) === null || _errors$twilioPhoneNu === void 0 ? void 0 : _errors$twilioPhoneNu.value,
398
+ label: t("neetoIntegrations.common.phNo"),
399
+ name: "twilioPhoneNumber",
400
+ options: phoneNumberOptions,
401
+ size: "large",
402
+ onChange: function onChange(selected) {
403
+ return setValues(_objectSpread$2(_objectSpread$2({}, values), {}, {
404
+ twilioPhoneNumber: selected
405
+ }));
406
+ }
407
+ })));
408
+ };
409
+
410
+ function _arrayWithoutHoles(arr) {
411
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
412
+ }
413
+
414
+ function _iterableToArray(iter) {
415
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
416
+ }
417
+
418
+ function _nonIterableSpread() {
419
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
420
+ }
421
+
422
+ function _toConsumableArray(arr) {
423
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
424
+ }
425
+
426
+ var queryClient = new QueryClient({
427
+ queryCache: new QueryCache()
428
+ });
429
+
430
+ var TWILIO_CONFIGURATION_BASE_URL = "/neeto_integrations/twilio/sms_configurations";
431
+
432
+ var twilioApi = {
433
+ fetchTwilioSmsConfiguration: function fetchTwilioSmsConfiguration() {
434
+ return axios.get(TWILIO_CONFIGURATION_BASE_URL);
435
+ },
436
+ removeTwilioConfiguration: function removeTwilioConfiguration() {
437
+ return axios["delete"](TWILIO_CONFIGURATION_BASE_URL);
438
+ },
439
+ getTwilioPhoneNumbers: function getTwilioPhoneNumbers(data) {
440
+ return axios.get("".concat(TWILIO_CONFIGURATION_BASE_URL, "/new"), {
441
+ params: data
442
+ });
443
+ },
444
+ createTwilioConfiguration: function createTwilioConfiguration(payload) {
445
+ return axios.post(TWILIO_CONFIGURATION_BASE_URL, payload);
446
+ }
447
+ };
448
+
449
+ var QUERY_KEYS = {
450
+ TWILIO_SMS_CONFIGURATION: "twilio-sms-configuration",
451
+ TWILIO_PHONE_NUMBERS: "twilio-phone-numbers"
452
+ };
453
+
454
+ var useFetchTwilioSmsConfiguration = function useFetchTwilioSmsConfiguration() {
455
+ return useQuery(QUERY_KEYS.TWILIO_SMS_CONFIGURATION, twilioApi.fetchTwilioSmsConfiguration, {
456
+ staleTime: DEFAULT_STALE_TIME,
457
+ select: function select(response) {
458
+ var _smsConfiguration$twi, _smsConfiguration$twi2, _smsConfiguration$twi3;
459
+ var smsConfiguration = response.smsConfiguration;
460
+ return {
461
+ twilioSid: (_smsConfiguration$twi = smsConfiguration === null || smsConfiguration === void 0 ? void 0 : smsConfiguration.twilioSid) !== null && _smsConfiguration$twi !== void 0 ? _smsConfiguration$twi : "",
462
+ twilioAuthToken: (_smsConfiguration$twi2 = smsConfiguration === null || smsConfiguration === void 0 ? void 0 : smsConfiguration.twilioAuthToken) !== null && _smsConfiguration$twi2 !== void 0 ? _smsConfiguration$twi2 : "",
463
+ twilioPhoneNumber: (_smsConfiguration$twi3 = smsConfiguration === null || smsConfiguration === void 0 ? void 0 : smsConfiguration.twilioPhoneNumber) !== null && _smsConfiguration$twi3 !== void 0 ? _smsConfiguration$twi3 : ""
464
+ };
465
+ }
466
+ });
467
+ };
468
+ var useFetchTwilioPhoneNumbers = function useFetchTwilioPhoneNumbers(_ref) {
469
+ var credentials = _ref.credentials;
470
+ return useQuery([QUERY_KEYS.TWILIO_PHONE_NUMBERS, {
471
+ credentials: credentials
472
+ }], function () {
473
+ return twilioApi.getTwilioPhoneNumbers(keysToSnakeCase(credentials));
474
+ }, {
475
+ staleTime: DEFAULT_STALE_TIME,
476
+ enabled: !!(credentials !== null && credentials !== void 0 && credentials.twilio_sid) || !!(credentials !== null && credentials !== void 0 && credentials.twilioSid),
477
+ select: prop("phoneNumbers"),
478
+ retry: false
479
+ });
480
+ };
481
+ var useCreateTwilioConfiguration = function useCreateTwilioConfiguration() {
482
+ return useMutation(twilioApi.createTwilioConfiguration, {
483
+ onSuccess: function onSuccess() {
484
+ return queryClient.invalidateQueries(QUERY_KEYS.TWILIO_SMS_CONFIGURATION);
485
+ }
486
+ });
487
+ };
488
+
489
+ 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; }
490
+ 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; }
491
+ var useTwilio = function useTwilio(_ref) {
492
+ var _ref$onSave = _ref.onSave,
493
+ onSave = _ref$onSave === void 0 ? noop : _ref$onSave,
494
+ _ref$setSteps = _ref.setSteps,
495
+ setSteps = _ref$setSteps === void 0 ? noop : _ref$setSteps,
496
+ _ref$useConnect = _ref.useConnect,
497
+ useConnect = _ref$useConnect === void 0 ? noop : _ref$useConnect;
498
+ var _useFetchTwilioSmsCon = useFetchTwilioSmsConfiguration(),
499
+ configuration = _useFetchTwilioSmsCon.data,
500
+ isConfigurationLoading = _useFetchTwilioSmsCon.isLoading,
501
+ refetchTwilioSmsConfiguration = _useFetchTwilioSmsCon.refetch;
502
+ var _useStateWithDependen = useStateWithDependency(configuration),
503
+ _useStateWithDependen2 = _slicedToArray(_useStateWithDependen, 2),
504
+ credentials = _useStateWithDependen2[0],
505
+ setCredentials = _useStateWithDependen2[1];
506
+ var _useFetchTwilioPhoneN = useFetchTwilioPhoneNumbers({
507
+ credentials: credentials
508
+ }),
509
+ phoneNumbers = _useFetchTwilioPhoneN.data,
510
+ isPhoneNumbersLoading = _useFetchTwilioPhoneN.isLoading;
511
+ var _useCreateTwilioConfi = useCreateTwilioConfiguration(),
512
+ saveConfiguration = _useCreateTwilioConfi.mutate,
513
+ isSubmitting = _useCreateTwilioConfi.isLoading;
514
+ var _useConnect = useConnect(),
515
+ installIntegration = _useConnect.mutate;
516
+ var connectTwilioApp = function connectTwilioApp() {
517
+ return installIntegration({
518
+ id: "twilio"
519
+ }, {});
520
+ };
521
+ useEffect(function () {
522
+ if (!(configuration !== null && configuration !== void 0 && configuration.twilioPhoneNumber)) return;
523
+ setSteps(function (steps) {
524
+ var stepsClone = _toConsumableArray(steps);
525
+ stepsClone[0] = _objectSpread$1(_objectSpread$1({}, steps[0]), {}, {
526
+ isCompleted: true
527
+ });
528
+ return stepsClone;
529
+ });
530
+ }, [configuration]);
531
+ var handleSubmit = function handleSubmit(values) {
532
+ var _values$twilioPhoneNu;
533
+ var payload = {
534
+ twilio_sid: values.twilioSid,
535
+ twilio_auth_token: values.twilioAuthToken,
536
+ twilio_phone_number_sid: (_values$twilioPhoneNu = values.twilioPhoneNumber) === null || _values$twilioPhoneNu === void 0 ? void 0 : _values$twilioPhoneNu.value
537
+ };
538
+ if (!phoneNumbers && !(configuration !== null && configuration !== void 0 && configuration.twilioPhoneNumber)) {
539
+ setCredentials(payload);
540
+ return;
541
+ }
542
+ saveConfiguration(payload, {
543
+ onSuccess: function onSuccess() {
544
+ onSave();
545
+ connectTwilioApp();
546
+ refetchTwilioSmsConfiguration();
547
+ }
548
+ });
549
+ };
550
+ return {
551
+ handleSubmit: handleSubmit,
552
+ phoneNumbers: phoneNumbers,
553
+ isConfigurationLoading: isConfigurationLoading,
554
+ isPhoneNumbersLoading: isPhoneNumbersLoading,
555
+ isSubmitting: isSubmitting,
556
+ configuration: configuration
557
+ };
558
+ };
559
+
560
+ var buildTwilioConfigurationValidationSchema = function buildTwilioConfigurationValidationSchema(isTwilioPhoneRequired) {
561
+ return yup.object().shape({
562
+ twilioSid: yup.string().required(i18next.t("neetoIntegrations.twilio.validations.sidReq")),
563
+ twilioAuthToken: yup.string().required(i18next.t("neetoIntegrations.twilio.validations.authTokenReq")),
564
+ twilioPhoneNumber: isTwilioPhoneRequired ? yup.object().shape({
565
+ label: yup.string(),
566
+ value: yup.string().required(i18next.t("neetoIntegrations.twilio.validations.phNumReq"))
567
+ }) : null
568
+ });
569
+ };
570
+
571
+ 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; }
572
+ 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; }
573
+ var TwilioConfiguration = function TwilioConfiguration(_ref) {
574
+ var _ref$onCancel = _ref.onCancel,
575
+ onCancel = _ref$onCancel === void 0 ? noop : _ref$onCancel,
576
+ _ref$onSave = _ref.onSave,
577
+ onSave = _ref$onSave === void 0 ? noop : _ref$onSave,
578
+ _ref$setSteps = _ref.setSteps,
579
+ setSteps = _ref$setSteps === void 0 ? noop : _ref$setSteps,
580
+ _ref$useConnect = _ref.useConnect,
581
+ useConnect = _ref$useConnect === void 0 ? noop : _ref$useConnect,
582
+ _ref$isModal = _ref.isModal,
583
+ isModal = _ref$isModal === void 0 ? false : _ref$isModal;
584
+ var _useTranslation = useTranslation(),
585
+ t = _useTranslation.t;
586
+ var initialFocusRef = useRef();
587
+ var _useTwilio = useTwilio({
588
+ onSave: onSave,
589
+ setSteps: setSteps,
590
+ useConnect: useConnect
591
+ }),
592
+ handleSubmit = _useTwilio.handleSubmit,
593
+ phoneNumbers = _useTwilio.phoneNumbers,
594
+ isConfigurationLoading = _useTwilio.isConfigurationLoading,
595
+ isPhoneNumbersLoading = _useTwilio.isPhoneNumbersLoading,
596
+ isSubmitting = _useTwilio.isSubmitting,
597
+ configuration = _useTwilio.configuration;
598
+ var phoneNumberOptions = phoneNumbers === null || phoneNumbers === void 0 ? void 0 : phoneNumbers.map(function (_ref2) {
599
+ var phoneNumber = _ref2.phoneNumber,
600
+ sid = _ref2.sid;
601
+ return {
602
+ label: phoneNumber,
603
+ value: sid
604
+ };
605
+ });
606
+ var selectedPhoneNumber = _findBy({
607
+ label: configuration === null || configuration === void 0 ? void 0 : configuration.twilioPhoneNumber
608
+ }, phoneNumberOptions);
609
+ var wrapInModalBody = function wrapInModalBody(children) {
610
+ return /*#__PURE__*/React.createElement(Modal$1.Body, null, children);
611
+ };
612
+ var wrapInModalFooter = function wrapInModalFooter(children) {
613
+ return /*#__PURE__*/React.createElement(Modal$1.Footer, null, children);
614
+ };
615
+ var isLoading = isPhoneNumbersLoading || isConfigurationLoading;
616
+ var isSubmitDisabled = function isSubmitDisabled(values) {
617
+ return equals(_objectSpread(_objectSpread({}, configuration), {}, {
618
+ twilioPhoneNumber: selectedPhoneNumber
619
+ }), values) || isLoading;
620
+ };
621
+ var renderActionBlock = function renderActionBlock(values) {
622
+ return /*#__PURE__*/React.createElement(ActionBlock, {
623
+ cancelButtonProps: {
624
+ onClick: onCancel,
625
+ disabled: false
626
+ },
627
+ className: "space-x-3",
628
+ submitButtonProps: {
629
+ label: phoneNumberOptions ? t("neetoIntegrations.common.saveChanges") : t("neetoIntegrations.common.verify"),
630
+ disabled: isSubmitDisabled(values),
631
+ loading: isSubmitting || isPhoneNumbersLoading && !configuration.twilioAuthToken
632
+ }
633
+ });
634
+ };
635
+ var renderForm = function renderForm(formikProps) {
636
+ return /*#__PURE__*/React.createElement(ConfigurationForm, {
637
+ formikProps: formikProps,
638
+ initialFocusRef: initialFocusRef,
639
+ isUsingOverlay: isModal,
640
+ phoneNumberOptions: phoneNumberOptions,
641
+ selectedPhoneNumber: selectedPhoneNumber
642
+ });
643
+ };
644
+ return /*#__PURE__*/React.createElement(Form, {
645
+ className: "mx-auto flex w-full max-w-md flex-col",
646
+ formikProps: {
647
+ enableReinitialize: true,
648
+ validationSchema: buildTwilioConfigurationValidationSchema(!!phoneNumbers),
649
+ initialValues: configuration,
650
+ onSubmit: handleSubmit
651
+ }
652
+ }, function (formikProps) {
653
+ return isModal ? /*#__PURE__*/React.createElement(React.Fragment, null, wrapInModalBody(renderForm(formikProps)), wrapInModalFooter(renderActionBlock(formikProps.values))) : /*#__PURE__*/React.createElement(React.Fragment, null, "renderForm(formikProps)", /*#__PURE__*/React.createElement("div", {
654
+ className: "mt-4 flex items-center gap-x-2"
655
+ }, renderActionBlock(formikProps.values)));
656
+ });
657
+ };
658
+
659
+ var Twilio = function Twilio(_ref) {
660
+ var _ref$onClose = _ref.onClose,
661
+ onClose = _ref$onClose === void 0 ? noop : _ref$onClose,
662
+ _ref$useConnect = _ref.useConnect,
663
+ useConnect = _ref$useConnect === void 0 ? noop : _ref$useConnect;
664
+ var _useState = useState(TWILIO_INTEGRATION_STEPS),
665
+ _useState2 = _slicedToArray(_useState, 2),
666
+ steps = _useState2[0],
667
+ setSteps = _useState2[1];
668
+ return /*#__PURE__*/React.createElement(Modal, {
669
+ isOpen: true,
670
+ steps: steps,
671
+ onClose: onClose
672
+ }, /*#__PURE__*/React.createElement(TwilioConfiguration, {
673
+ isModal: true,
674
+ setSteps: setSteps,
675
+ useConnect: useConnect,
676
+ onCancel: onClose
677
+ }));
678
+ };
679
+
680
+ export { Twilio as default };
681
+ //# sourceMappingURL=Twilio.js.map