@bigbinary/neeto-message-templates-frontend 0.0.9 → 0.2.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/README.md +19 -2
- package/dist/index.cjs.js +213 -52
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +220 -59
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/types.d.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import React, { useContext, useState, useRef, useEffect } from 'react';
|
|
2
|
-
import { isNotEmpty, noop as noop$1, findBy } from '@bigbinary/neeto-commons-frontend/pure';
|
|
2
|
+
import { isNotEmpty, noop as noop$1, findBy, capitalize as capitalize$1, nullSafe } from '@bigbinary/neeto-commons-frontend/pure';
|
|
3
3
|
import { buildFiltersFromURL, Bar } from '@bigbinary/neeto-filters-frontend';
|
|
4
4
|
import Container from '@bigbinary/neeto-molecules/Container';
|
|
5
5
|
import NeetoHeader from '@bigbinary/neeto-molecules/Header';
|
|
6
6
|
import SubHeader from '@bigbinary/neeto-molecules/SubHeader';
|
|
7
|
-
import { Dropdown, Typography, Button, Pane, Table, NoData, Alert, Select } from '@bigbinary/neetoui';
|
|
8
|
-
import { prop, equals, includes, pick, omit,
|
|
9
|
-
import { QueryClient, QueryCache, QueryClientProvider, useQuery
|
|
7
|
+
import { Dropdown, Typography, Button, Pane, Table, NoData, Alert, Select, Textarea } from '@bigbinary/neetoui';
|
|
8
|
+
import { isEmpty, prop, equals, includes, pick, omit, assoc, mergeAll, pluck } from 'ramda';
|
|
9
|
+
import { QueryClient, QueryCache, QueryClientProvider, useQuery } from 'react-query';
|
|
10
10
|
import { ReactQueryDevtools } from 'react-query/devtools';
|
|
11
11
|
import { MenuHorizontal } from '@bigbinary/neeto-icons';
|
|
12
|
+
import { useMutationWithInvalidation, withImmutableActions } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
12
13
|
import axios from 'axios';
|
|
13
|
-
import { withImmutableActions } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
14
14
|
import { create as create$1 } from 'zustand';
|
|
15
15
|
import { FormikEditor } from '@bigbinary/neeto-editor';
|
|
16
|
-
import { Input, Form as Form$
|
|
16
|
+
import { Input, Form as Form$1, Select as Select$1, Button as Button$1 } from '@bigbinary/neetoui/formik';
|
|
17
17
|
import { isPhoneNumberValid } from '@bigbinary/neeto-molecules/PhoneNumber';
|
|
18
18
|
import * as yup from 'yup';
|
|
19
19
|
import { useFormikContext } from 'formik';
|
|
@@ -5248,9 +5248,11 @@ var template = {
|
|
|
5248
5248
|
search: "Search {{what}}",
|
|
5249
5249
|
markAsActive: "Mark as active",
|
|
5250
5250
|
markAsInactive: "Mark as inactive",
|
|
5251
|
+
close: "Close",
|
|
5251
5252
|
"delete": "Delete",
|
|
5252
5253
|
edit: "Edit",
|
|
5253
5254
|
saveChanges: "Save changes",
|
|
5255
|
+
send: "Send",
|
|
5254
5256
|
cancel: "Cancel",
|
|
5255
5257
|
emailAddress: "Email address",
|
|
5256
5258
|
phoneNumber: "Phone number",
|
|
@@ -5271,13 +5273,16 @@ var template = {
|
|
|
5271
5273
|
sendTestEmail: "Send test email",
|
|
5272
5274
|
sendTestSms: "Send test sms",
|
|
5273
5275
|
filtersEmptyState: "There are no {{type}} to show for applied filters.",
|
|
5276
|
+
preview: "Template Preview",
|
|
5277
|
+
resolveVariable: "Resolve {{type}} variables",
|
|
5274
5278
|
validation: {
|
|
5275
5279
|
namePresence: "Name is required",
|
|
5276
5280
|
subjectPresence: "Subject is required",
|
|
5277
5281
|
bodyPresence: "Body is required",
|
|
5278
5282
|
emailAddressPresence: "Email address is required",
|
|
5279
5283
|
emailAddressFormatValidation: "Invalid email address",
|
|
5280
|
-
validPhoneNumber: "Enter valid phone number"
|
|
5284
|
+
validPhoneNumber: "Enter valid phone number",
|
|
5285
|
+
variablePresence: "Variable should not be empty"
|
|
5281
5286
|
}
|
|
5282
5287
|
};
|
|
5283
5288
|
var sendMessage = {
|
|
@@ -5390,18 +5395,31 @@ var fetchMessageTemplates = function fetchMessageTemplates(params) {
|
|
|
5390
5395
|
params: params
|
|
5391
5396
|
});
|
|
5392
5397
|
};
|
|
5393
|
-
var createMessageTemplate = function createMessageTemplate(
|
|
5398
|
+
var createMessageTemplate = function createMessageTemplate(_ref) {
|
|
5399
|
+
var messageTemplate = _ref.messageTemplate,
|
|
5400
|
+
ownerId = _ref.ownerId;
|
|
5394
5401
|
return axios.post(MESSAGE_TEMPLATE_BASE_URL, {
|
|
5395
|
-
messageTemplate:
|
|
5402
|
+
messageTemplate: messageTemplate,
|
|
5403
|
+
ownerId: ownerId
|
|
5396
5404
|
});
|
|
5397
5405
|
};
|
|
5398
|
-
var updateMessageTemplate = function updateMessageTemplate(
|
|
5406
|
+
var updateMessageTemplate = function updateMessageTemplate(_ref2) {
|
|
5407
|
+
var id = _ref2.id,
|
|
5408
|
+
messageTemplate = _ref2.messageTemplate,
|
|
5409
|
+
ownerId = _ref2.ownerId;
|
|
5399
5410
|
return axios.patch("".concat(MESSAGE_TEMPLATE_BASE_URL, "/").concat(id), {
|
|
5400
|
-
messageTemplate:
|
|
5411
|
+
messageTemplate: messageTemplate,
|
|
5412
|
+
ownerId: ownerId
|
|
5401
5413
|
});
|
|
5402
5414
|
};
|
|
5403
|
-
var deleteMessageTemplate = function deleteMessageTemplate(
|
|
5404
|
-
|
|
5415
|
+
var deleteMessageTemplate = function deleteMessageTemplate(_ref3) {
|
|
5416
|
+
var id = _ref3.id,
|
|
5417
|
+
ownerId = _ref3.ownerId;
|
|
5418
|
+
return axios["delete"]("".concat(MESSAGE_TEMPLATE_BASE_URL, "/").concat(id), {
|
|
5419
|
+
data: {
|
|
5420
|
+
ownerId: ownerId
|
|
5421
|
+
}
|
|
5422
|
+
});
|
|
5405
5423
|
};
|
|
5406
5424
|
var messageTemplatesApi = {
|
|
5407
5425
|
fetchAll: fetchMessageTemplates,
|
|
@@ -5414,42 +5432,46 @@ var QUERY_KEYS = {
|
|
|
5414
5432
|
MESSAGE_TEMPLATE: "message-templates"
|
|
5415
5433
|
};
|
|
5416
5434
|
|
|
5435
|
+
var ownerIdValue = function ownerIdValue(ownerId) {
|
|
5436
|
+
return isEmpty(ownerId) ? undefined : ownerId;
|
|
5437
|
+
};
|
|
5417
5438
|
var useFetchTemplates = function useFetchTemplates(params) {
|
|
5418
5439
|
return useQuery([QUERY_KEYS.MESSAGE_TEMPLATE, params], function () {
|
|
5419
5440
|
return messageTemplatesApi.fetchAll(params);
|
|
5420
5441
|
});
|
|
5421
5442
|
};
|
|
5422
|
-
var useCreateTemplate = function useCreateTemplate(options) {
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5443
|
+
var useCreateTemplate = function useCreateTemplate(ownerId, options) {
|
|
5444
|
+
return useMutationWithInvalidation(function (messageTemplate) {
|
|
5445
|
+
return messageTemplatesApi.create({
|
|
5446
|
+
messageTemplate: messageTemplate,
|
|
5447
|
+
ownerId: ownerIdValue(ownerId)
|
|
5448
|
+
});
|
|
5426
5449
|
}, {
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
options === null || options === void 0 ? void 0 : options.onSuccess();
|
|
5430
|
-
}
|
|
5450
|
+
keysToInvalidate: [QUERY_KEYS.MESSAGE_TEMPLATE],
|
|
5451
|
+
onSuccess: options === null || options === void 0 ? void 0 : options.onSuccess
|
|
5431
5452
|
});
|
|
5432
5453
|
};
|
|
5433
|
-
var useUpdateTemplate = function useUpdateTemplate() {
|
|
5434
|
-
|
|
5435
|
-
return useMutation(function (_ref) {
|
|
5454
|
+
var useUpdateTemplate = function useUpdateTemplate(ownerId) {
|
|
5455
|
+
return useMutationWithInvalidation(function (_ref) {
|
|
5436
5456
|
var id = _ref.id,
|
|
5437
5457
|
payload = _ref.payload;
|
|
5438
|
-
return messageTemplatesApi.update(
|
|
5458
|
+
return messageTemplatesApi.update({
|
|
5459
|
+
id: id,
|
|
5460
|
+
messageTemplate: payload,
|
|
5461
|
+
ownerId: ownerIdValue(ownerId)
|
|
5462
|
+
});
|
|
5439
5463
|
}, {
|
|
5440
|
-
|
|
5441
|
-
queryClient.invalidateQueries(QUERY_KEYS.MESSAGE_TEMPLATE);
|
|
5442
|
-
}
|
|
5464
|
+
keysToInvalidate: [QUERY_KEYS.MESSAGE_TEMPLATE]
|
|
5443
5465
|
});
|
|
5444
5466
|
};
|
|
5445
|
-
var useDeleteTemplate = function useDeleteTemplate() {
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5467
|
+
var useDeleteTemplate = function useDeleteTemplate(ownerId) {
|
|
5468
|
+
return useMutationWithInvalidation(function (id) {
|
|
5469
|
+
return messageTemplatesApi["delete"]({
|
|
5470
|
+
id: id,
|
|
5471
|
+
ownerId: ownerIdValue(ownerId)
|
|
5472
|
+
});
|
|
5449
5473
|
}, {
|
|
5450
|
-
|
|
5451
|
-
queryClient.invalidateQueries(QUERY_KEYS.MESSAGE_TEMPLATE);
|
|
5452
|
-
}
|
|
5474
|
+
keysToInvalidate: [QUERY_KEYS.MESSAGE_TEMPLATE]
|
|
5453
5475
|
});
|
|
5454
5476
|
};
|
|
5455
5477
|
|
|
@@ -5465,10 +5487,11 @@ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if
|
|
|
5465
5487
|
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5466
5488
|
var RowActions = function RowActions(_ref) {
|
|
5467
5489
|
var template = _ref.template,
|
|
5468
|
-
setManageTemplatePane = _ref.setManageTemplatePane
|
|
5490
|
+
setManageTemplatePane = _ref.setManageTemplatePane,
|
|
5491
|
+
ownerId = _ref.ownerId;
|
|
5469
5492
|
var _useTranslation = useTranslation(),
|
|
5470
5493
|
t = _useTranslation.t;
|
|
5471
|
-
var _useUpdateTemplate = useUpdateTemplate(),
|
|
5494
|
+
var _useUpdateTemplate = useUpdateTemplate(ownerId),
|
|
5472
5495
|
update = _useUpdateTemplate.mutate;
|
|
5473
5496
|
var Menu = Dropdown.Menu,
|
|
5474
5497
|
MenuItem = Dropdown.MenuItem;
|
|
@@ -5526,7 +5549,7 @@ var renderSearchProps = function renderSearchProps(label, setSearchTerm, searchT
|
|
|
5526
5549
|
value: searchTerm
|
|
5527
5550
|
};
|
|
5528
5551
|
};
|
|
5529
|
-
var buildTableColumnData = function buildTableColumnData(setManageTemplatePane) {
|
|
5552
|
+
var buildTableColumnData = function buildTableColumnData(setManageTemplatePane, ownerId) {
|
|
5530
5553
|
return [{
|
|
5531
5554
|
dataIndex: "name",
|
|
5532
5555
|
key: "name",
|
|
@@ -5540,6 +5563,7 @@ var buildTableColumnData = function buildTableColumnData(setManageTemplatePane)
|
|
|
5540
5563
|
}, /*#__PURE__*/React.createElement(Typography, {
|
|
5541
5564
|
style: "body2"
|
|
5542
5565
|
}, name), /*#__PURE__*/React.createElement(RowActions, {
|
|
5566
|
+
ownerId: ownerId,
|
|
5543
5567
|
setManageTemplatePane: setManageTemplatePane,
|
|
5544
5568
|
template: template
|
|
5545
5569
|
}));
|
|
@@ -6054,7 +6078,7 @@ var TestMessage = function TestMessage(_ref) {
|
|
|
6054
6078
|
|
|
6055
6079
|
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; }
|
|
6056
6080
|
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; }
|
|
6057
|
-
var Form
|
|
6081
|
+
var Form = function Form(_ref) {
|
|
6058
6082
|
var onClose = _ref.onClose,
|
|
6059
6083
|
isEdit = _ref.isEdit,
|
|
6060
6084
|
_ref$template = _ref.template,
|
|
@@ -6092,7 +6116,7 @@ var Form$1 = function Form(_ref) {
|
|
|
6092
6116
|
}
|
|
6093
6117
|
});
|
|
6094
6118
|
};
|
|
6095
|
-
return /*#__PURE__*/React.createElement(Form$
|
|
6119
|
+
return /*#__PURE__*/React.createElement(Form$1, {
|
|
6096
6120
|
formProps: {
|
|
6097
6121
|
noValidate: true,
|
|
6098
6122
|
className: "flex w-full flex-col gap-y-4 pb-6"
|
|
@@ -6172,7 +6196,7 @@ var AddEdit = function AddEdit(_ref) {
|
|
|
6172
6196
|
}, /*#__PURE__*/React.createElement(Pane.Header, null, /*#__PURE__*/React.createElement(Typography, {
|
|
6173
6197
|
style: "h2",
|
|
6174
6198
|
weight: "semibold"
|
|
6175
|
-
}, label)), /*#__PURE__*/React.createElement(Pane.Body, null, /*#__PURE__*/React.createElement(Form
|
|
6199
|
+
}, label)), /*#__PURE__*/React.createElement(Pane.Body, null, /*#__PURE__*/React.createElement(Form, {
|
|
6176
6200
|
createUpdateTemplate: createUpdateTemplate,
|
|
6177
6201
|
handleSubmitTestTemplate: handleSubmitTestTemplate,
|
|
6178
6202
|
isEdit: isEdit,
|
|
@@ -6204,7 +6228,7 @@ var useFilters = function useFilters() {
|
|
|
6204
6228
|
};
|
|
6205
6229
|
};
|
|
6206
6230
|
|
|
6207
|
-
var useTemplates = function useTemplates(type) {
|
|
6231
|
+
var useTemplates = function useTemplates(type, ownerId) {
|
|
6208
6232
|
var _useState = useState(buildFiltersFromURL(buildTableColumnData().filter(prop("node")))),
|
|
6209
6233
|
_useState2 = _slicedToArray(_useState, 2),
|
|
6210
6234
|
filters = _useState2[0],
|
|
@@ -6219,16 +6243,17 @@ var useTemplates = function useTemplates(type) {
|
|
|
6219
6243
|
pageIndex: pageIndex,
|
|
6220
6244
|
pageSize: pageSize,
|
|
6221
6245
|
filters: JSON.stringify(filters),
|
|
6222
|
-
templateType: MESSAGE_TEMPLATES[type].value
|
|
6246
|
+
templateType: MESSAGE_TEMPLATES[type].value,
|
|
6247
|
+
ownerId: isEmpty(ownerId) ? undefined : ownerId
|
|
6223
6248
|
};
|
|
6224
6249
|
var _useFetchTemplates = useFetchTemplates(templateParams),
|
|
6225
6250
|
_useFetchTemplates$da = _useFetchTemplates.data,
|
|
6226
6251
|
templatesData = _useFetchTemplates$da === void 0 ? {} : _useFetchTemplates$da,
|
|
6227
6252
|
isLoadingTemplates = _useFetchTemplates.isLoading,
|
|
6228
6253
|
isFetching = _useFetchTemplates.isFetching;
|
|
6229
|
-
var _useCreateTemplate = useCreateTemplate(),
|
|
6254
|
+
var _useCreateTemplate = useCreateTemplate(ownerId),
|
|
6230
6255
|
create = _useCreateTemplate.mutate;
|
|
6231
|
-
var _useUpdateTemplate = useUpdateTemplate(),
|
|
6256
|
+
var _useUpdateTemplate = useUpdateTemplate(ownerId),
|
|
6232
6257
|
update = _useUpdateTemplate.mutate;
|
|
6233
6258
|
var createUpdateTemplate = function createUpdateTemplate(_ref, options) {
|
|
6234
6259
|
var isEdit = _ref.isEdit,
|
|
@@ -6262,10 +6287,11 @@ var List = function List(_ref) {
|
|
|
6262
6287
|
pageProperties = _ref.pageProperties,
|
|
6263
6288
|
label = _ref.label,
|
|
6264
6289
|
addText = _ref.addText,
|
|
6265
|
-
isFilterApplied = _ref.isFilterApplied
|
|
6290
|
+
isFilterApplied = _ref.isFilterApplied,
|
|
6291
|
+
ownerId = _ref.ownerId;
|
|
6266
6292
|
var _useTranslation = useTranslation(),
|
|
6267
6293
|
t = _useTranslation.t;
|
|
6268
|
-
var _useDeleteTemplate = useDeleteTemplate(),
|
|
6294
|
+
var _useDeleteTemplate = useDeleteTemplate(ownerId),
|
|
6269
6295
|
deleteTemplate = _useDeleteTemplate.mutate,
|
|
6270
6296
|
isDeleting = _useDeleteTemplate.isLoading;
|
|
6271
6297
|
var templates = templatesData.templates,
|
|
@@ -6286,7 +6312,7 @@ var List = function List(_ref) {
|
|
|
6286
6312
|
}, !isEmpty(templates) ? /*#__PURE__*/React.createElement(TableWrapper, {
|
|
6287
6313
|
hasPagination: totalCount > pageSize
|
|
6288
6314
|
}, /*#__PURE__*/React.createElement(Table, {
|
|
6289
|
-
columnData: buildTableColumnData(setManageTemplatePane),
|
|
6315
|
+
columnData: buildTableColumnData(setManageTemplatePane, ownerId),
|
|
6290
6316
|
currentPageNumber: pageIndex,
|
|
6291
6317
|
defaultPageSize: pageSize,
|
|
6292
6318
|
loading: isLoading,
|
|
@@ -6348,7 +6374,9 @@ var MessageTemplates = function MessageTemplates(_ref) {
|
|
|
6348
6374
|
_ref$shouldIncludeTes = _ref.shouldIncludeTestTemplate,
|
|
6349
6375
|
shouldIncludeTestTemplate = _ref$shouldIncludeTes === void 0 ? true : _ref$shouldIncludeTes,
|
|
6350
6376
|
_ref$templateVariable = _ref.templateVariables,
|
|
6351
|
-
templateVariables = _ref$templateVariable === void 0 ? {} : _ref$templateVariable
|
|
6377
|
+
templateVariables = _ref$templateVariable === void 0 ? {} : _ref$templateVariable,
|
|
6378
|
+
_ref$ownerId = _ref.ownerId,
|
|
6379
|
+
ownerId = _ref$ownerId === void 0 ? "" : _ref$ownerId;
|
|
6352
6380
|
var _useState = useState(MESSAGE_TEMPLATE_INITIAL_STATE),
|
|
6353
6381
|
_useState2 = _slicedToArray(_useState, 2),
|
|
6354
6382
|
manageTemplatePane = _useState2[0],
|
|
@@ -6362,7 +6390,7 @@ var MessageTemplates = function MessageTemplates(_ref) {
|
|
|
6362
6390
|
filterColumns = _useFilters.filterColumns,
|
|
6363
6391
|
setSearchTerm = _useFilters.setSearchTerm,
|
|
6364
6392
|
searchTerm = _useFilters.searchTerm;
|
|
6365
|
-
var _useTemplates = useTemplates(type),
|
|
6393
|
+
var _useTemplates = useTemplates(type, ownerId),
|
|
6366
6394
|
isLoading = _useTemplates.isLoading,
|
|
6367
6395
|
templatesData = _useTemplates.templatesData,
|
|
6368
6396
|
createUpdateTemplate = _useTemplates.createUpdateTemplate,
|
|
@@ -6423,6 +6451,7 @@ var MessageTemplates = function MessageTemplates(_ref) {
|
|
|
6423
6451
|
label: label,
|
|
6424
6452
|
labelSingular: labelSingular,
|
|
6425
6453
|
manageTemplatePane: manageTemplatePane,
|
|
6454
|
+
ownerId: ownerId,
|
|
6426
6455
|
pageProperties: pageProperties,
|
|
6427
6456
|
setManageTemplatePane: setManageTemplatePane,
|
|
6428
6457
|
setPageProperties: setPageProperties,
|
|
@@ -6443,13 +6472,13 @@ var MessageTemplates = function MessageTemplates(_ref) {
|
|
|
6443
6472
|
};
|
|
6444
6473
|
var index$1 = withReactQuery(MessageTemplates);
|
|
6445
6474
|
|
|
6475
|
+
var formatEditorContent = function formatEditorContent(value) {
|
|
6476
|
+
return value === null || value === void 0 ? void 0 : value.replaceAll(/<\/?(?!img)\w*\b[^>]*>/gi, "").trim();
|
|
6477
|
+
};
|
|
6446
6478
|
var SEND_MESSAGE_INITIAL_VALUES = {
|
|
6447
6479
|
subject: "",
|
|
6448
6480
|
body: ""
|
|
6449
6481
|
};
|
|
6450
|
-
var formatEditorContent = function formatEditorContent(value) {
|
|
6451
|
-
return value === null || value === void 0 ? void 0 : value.replaceAll(/<\/?(?!img)\w*\b[^>]*>/gi, "").trim();
|
|
6452
|
-
};
|
|
6453
6482
|
var EMAIL_MESSAGE_FORM_SCHEMA = yup.object().shape({
|
|
6454
6483
|
subject: yup.string().trim().required(t$1("template.validation.subjectPresence")),
|
|
6455
6484
|
body: yup.string().test("body", t$1("template.validation.bodyPresence"), function (value) {
|
|
@@ -6461,10 +6490,15 @@ var SMS_MESSAGE_FORM_VALIDATION_SCHEMA = yup.object().shape({
|
|
|
6461
6490
|
return !!formatEditorContent(value);
|
|
6462
6491
|
})
|
|
6463
6492
|
});
|
|
6493
|
+
var WHATSAPP_MESSAGE_FORM_VALIDATIONS_SCHEMA = yup.object().shape({
|
|
6494
|
+
variableContents: yup.object().shape({
|
|
6495
|
+
body: yup.array().of(yup.string().required(t$1("template.validation.variablePresence")))
|
|
6496
|
+
})
|
|
6497
|
+
});
|
|
6464
6498
|
|
|
6465
6499
|
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; }
|
|
6466
6500
|
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; }
|
|
6467
|
-
var
|
|
6501
|
+
var EmailAndSms = function EmailAndSms(_ref) {
|
|
6468
6502
|
var isEmailTemplate = _ref.isEmailTemplate,
|
|
6469
6503
|
onClose = _ref.onClose,
|
|
6470
6504
|
templates = _ref.templates,
|
|
@@ -6484,7 +6518,7 @@ var Form = function Form(_ref) {
|
|
|
6484
6518
|
var updatedInitialValues = mergeAll([INITIAL_VALUES, customFieldsInitialValues]);
|
|
6485
6519
|
var updatedValidationSchema = yup.object().shape(_objectSpread(_objectSpread({}, SEND_MESSAGE_FORM_SCHEMA === null || SEND_MESSAGE_FORM_SCHEMA === void 0 ? void 0 : SEND_MESSAGE_FORM_SCHEMA.fields), customFieldsValidationSchema === null || customFieldsValidationSchema === void 0 ? void 0 : customFieldsValidationSchema.fields));
|
|
6486
6520
|
var initialValueKeys = Object.keys(INITIAL_VALUES);
|
|
6487
|
-
return /*#__PURE__*/React.createElement(Form$
|
|
6521
|
+
return /*#__PURE__*/React.createElement(Form$1, {
|
|
6488
6522
|
formProps: {
|
|
6489
6523
|
noValidate: true,
|
|
6490
6524
|
className: "flex w-full flex-col gap-y-4 pb-6"
|
|
@@ -6541,7 +6575,7 @@ var Form = function Form(_ref) {
|
|
|
6541
6575
|
className: "absolute bottom-0 left-0 flex gap-x-2"
|
|
6542
6576
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
6543
6577
|
disabled: !dirty || isSubmitting,
|
|
6544
|
-
label: t("template.
|
|
6578
|
+
label: t("template.send"),
|
|
6545
6579
|
loading: isSubmitting,
|
|
6546
6580
|
type: "submit"
|
|
6547
6581
|
}), /*#__PURE__*/React.createElement(Button, {
|
|
@@ -6553,6 +6587,125 @@ var Form = function Form(_ref) {
|
|
|
6553
6587
|
});
|
|
6554
6588
|
};
|
|
6555
6589
|
|
|
6590
|
+
var Whatsapp = function Whatsapp(_ref) {
|
|
6591
|
+
var _templates$, _templates$2, _templates$3, _templates$4;
|
|
6592
|
+
var templates = _ref.templates,
|
|
6593
|
+
onClose = _ref.onClose,
|
|
6594
|
+
handleSubmit = _ref.handleSubmit;
|
|
6595
|
+
var _useTranslation = useTranslation(),
|
|
6596
|
+
t = _useTranslation.t;
|
|
6597
|
+
var getInitialVariableComponents = function getInitialVariableComponents(variables) {
|
|
6598
|
+
var initialComponents = {};
|
|
6599
|
+
variables.forEach(function (_ref2) {
|
|
6600
|
+
var type = _ref2.type,
|
|
6601
|
+
count = _ref2.count;
|
|
6602
|
+
initialComponents[type] = Array(count).fill("");
|
|
6603
|
+
});
|
|
6604
|
+
return initialComponents;
|
|
6605
|
+
};
|
|
6606
|
+
var getTemplateMessage = function getTemplateMessage(components) {
|
|
6607
|
+
return nullSafe(pluck)("text", components).join("\n");
|
|
6608
|
+
};
|
|
6609
|
+
if (isEmpty(templates)) {
|
|
6610
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Typography, null, t("template.emptyState", {
|
|
6611
|
+
type: t("template.whatsappTemplates")
|
|
6612
|
+
})), /*#__PURE__*/React.createElement(Pane.Footer, {
|
|
6613
|
+
className: "absolute bottom-0 left-0"
|
|
6614
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
6615
|
+
label: t("template.close"),
|
|
6616
|
+
onClick: onClose
|
|
6617
|
+
})));
|
|
6618
|
+
}
|
|
6619
|
+
var initialFormValues = {
|
|
6620
|
+
selectedTemplate: {
|
|
6621
|
+
label: (_templates$ = templates[0]) === null || _templates$ === void 0 ? void 0 : _templates$.name,
|
|
6622
|
+
value: (_templates$2 = templates[0]) === null || _templates$2 === void 0 ? void 0 : _templates$2.id
|
|
6623
|
+
},
|
|
6624
|
+
templateMessage: getTemplateMessage((_templates$3 = templates[0]) === null || _templates$3 === void 0 ? void 0 : _templates$3.components),
|
|
6625
|
+
variableContents: getInitialVariableComponents((_templates$4 = templates[0]) === null || _templates$4 === void 0 ? void 0 : _templates$4.variableCount)
|
|
6626
|
+
};
|
|
6627
|
+
return /*#__PURE__*/React.createElement(Form$1, {
|
|
6628
|
+
formProps: {
|
|
6629
|
+
noValidate: true,
|
|
6630
|
+
className: "flex w-full flex-col gap-y-4 pb-6"
|
|
6631
|
+
},
|
|
6632
|
+
formikProps: {
|
|
6633
|
+
initialValues: initialFormValues,
|
|
6634
|
+
validationSchema: WHATSAPP_MESSAGE_FORM_VALIDATIONS_SCHEMA,
|
|
6635
|
+
onSubmit: handleSubmit
|
|
6636
|
+
}
|
|
6637
|
+
}, function (_ref3) {
|
|
6638
|
+
var dirty = _ref3.dirty,
|
|
6639
|
+
isSubmitting = _ref3.isSubmitting,
|
|
6640
|
+
values = _ref3.values,
|
|
6641
|
+
setValues = _ref3.setValues;
|
|
6642
|
+
var handleTemplateChange = function handleTemplateChange(value) {
|
|
6643
|
+
if (!value) return;
|
|
6644
|
+
var template = findBy({
|
|
6645
|
+
id: value === null || value === void 0 ? void 0 : value.value
|
|
6646
|
+
}, templates);
|
|
6647
|
+
setValues({
|
|
6648
|
+
selectedTemplate: {
|
|
6649
|
+
label: template.name,
|
|
6650
|
+
value: template.id
|
|
6651
|
+
},
|
|
6652
|
+
templateMessage: getTemplateMessage(template.components),
|
|
6653
|
+
variableContents: getInitialVariableComponents(template.variableCount)
|
|
6654
|
+
});
|
|
6655
|
+
};
|
|
6656
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Select$1, {
|
|
6657
|
+
required: true,
|
|
6658
|
+
defaultValue: initialFormValues.selectedTemplate,
|
|
6659
|
+
label: t("template.title"),
|
|
6660
|
+
name: "selectedTemplate",
|
|
6661
|
+
options: templates.map(function (_ref4) {
|
|
6662
|
+
var name = _ref4.name,
|
|
6663
|
+
id = _ref4.id;
|
|
6664
|
+
return {
|
|
6665
|
+
label: name,
|
|
6666
|
+
value: id
|
|
6667
|
+
};
|
|
6668
|
+
}),
|
|
6669
|
+
onChange: handleTemplateChange
|
|
6670
|
+
}), /*#__PURE__*/React.createElement(Textarea, {
|
|
6671
|
+
disabled: true,
|
|
6672
|
+
nakedTextarea: true,
|
|
6673
|
+
label: t("template.preview"),
|
|
6674
|
+
value: values.templateMessage
|
|
6675
|
+
}), isNotEmpty(values.variableContents) && /*#__PURE__*/React.createElement(React.Fragment, null, Object.keys(values.variableContents).map(function (group) {
|
|
6676
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
6677
|
+
className: "flex flex-col gap-y-2",
|
|
6678
|
+
key: group
|
|
6679
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
6680
|
+
style: "h4"
|
|
6681
|
+
}, t("template.resolveVariable", {
|
|
6682
|
+
type: capitalize$1(group)
|
|
6683
|
+
})), values.variableContents[group].map(function (_, index) {
|
|
6684
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
6685
|
+
key: "".concat(group, "-").concat(index)
|
|
6686
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
6687
|
+
required: true,
|
|
6688
|
+
key: "".concat(group, "-").concat(index),
|
|
6689
|
+
label: "{{".concat(index + 1, "}}"),
|
|
6690
|
+
name: "variableContents.".concat(group, ".").concat(index)
|
|
6691
|
+
}));
|
|
6692
|
+
}));
|
|
6693
|
+
})), /*#__PURE__*/React.createElement(Pane.Footer, {
|
|
6694
|
+
className: "absolute bottom-0 left-0 flex gap-x-2"
|
|
6695
|
+
}, /*#__PURE__*/React.createElement(Button$1, {
|
|
6696
|
+
disabled: !dirty || isSubmitting,
|
|
6697
|
+
label: t("template.send"),
|
|
6698
|
+
loading: isSubmitting,
|
|
6699
|
+
type: "submit"
|
|
6700
|
+
}), /*#__PURE__*/React.createElement(Button$1, {
|
|
6701
|
+
label: t("template.cancel"),
|
|
6702
|
+
style: "text",
|
|
6703
|
+
type: "reset",
|
|
6704
|
+
onClick: onClose
|
|
6705
|
+
})));
|
|
6706
|
+
});
|
|
6707
|
+
};
|
|
6708
|
+
|
|
6556
6709
|
var SendMessagePane = function SendMessagePane(_ref) {
|
|
6557
6710
|
var _ref$isOpen = _ref.isOpen,
|
|
6558
6711
|
isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen,
|
|
@@ -6569,7 +6722,9 @@ var SendMessagePane = function SendMessagePane(_ref) {
|
|
|
6569
6722
|
_ref$customFieldsVali = _ref.customFieldsValidationSchema,
|
|
6570
6723
|
customFieldsValidationSchema = _ref$customFieldsVali === void 0 ? {} : _ref$customFieldsVali,
|
|
6571
6724
|
_ref$templateVariable = _ref.templateVariables,
|
|
6572
|
-
templateVariables = _ref$templateVariable === void 0 ? {} : _ref$templateVariable
|
|
6725
|
+
templateVariables = _ref$templateVariable === void 0 ? {} : _ref$templateVariable,
|
|
6726
|
+
_ref$ownerId = _ref.ownerId,
|
|
6727
|
+
ownerId = _ref$ownerId === void 0 ? "" : _ref$ownerId;
|
|
6573
6728
|
var _useTranslation = useTranslation(),
|
|
6574
6729
|
t = _useTranslation.t;
|
|
6575
6730
|
var initialFocusField = useRef();
|
|
@@ -6579,7 +6734,8 @@ var SendMessagePane = function SendMessagePane(_ref) {
|
|
|
6579
6734
|
var value = MESSAGE_TEMPLATES[type].value;
|
|
6580
6735
|
var templateParams = {
|
|
6581
6736
|
status: "active",
|
|
6582
|
-
templateType: value
|
|
6737
|
+
templateType: value,
|
|
6738
|
+
ownerId: ownerId
|
|
6583
6739
|
};
|
|
6584
6740
|
var _useFetchTemplates = useFetchTemplates(templateParams),
|
|
6585
6741
|
_useFetchTemplates$da = _useFetchTemplates.data,
|
|
@@ -6587,6 +6743,7 @@ var SendMessagePane = function SendMessagePane(_ref) {
|
|
|
6587
6743
|
_useFetchTemplates$da3 = _useFetchTemplates$da2.templates,
|
|
6588
6744
|
templates = _useFetchTemplates$da3 === void 0 ? [] : _useFetchTemplates$da3;
|
|
6589
6745
|
var isEmailTemplate = type === "email";
|
|
6746
|
+
var isWhatsappTemplate = type === "whatsapp";
|
|
6590
6747
|
return /*#__PURE__*/React.createElement(Pane, {
|
|
6591
6748
|
initialFocusRef: initialFocusField,
|
|
6592
6749
|
isOpen: isOpen,
|
|
@@ -6594,7 +6751,11 @@ var SendMessagePane = function SendMessagePane(_ref) {
|
|
|
6594
6751
|
}, /*#__PURE__*/React.createElement(Pane.Header, null, /*#__PURE__*/React.createElement(Typography, {
|
|
6595
6752
|
style: "h2",
|
|
6596
6753
|
weight: "semibold"
|
|
6597
|
-
}, t("common.send"), " ", type)), /*#__PURE__*/React.createElement(Pane.Body, null, /*#__PURE__*/React.createElement(
|
|
6754
|
+
}, t("common.send"), " ", type)), /*#__PURE__*/React.createElement(Pane.Body, null, isWhatsappTemplate ? /*#__PURE__*/React.createElement(Whatsapp, {
|
|
6755
|
+
handleSubmit: handleSubmit,
|
|
6756
|
+
templates: templates,
|
|
6757
|
+
onClose: onClose
|
|
6758
|
+
}) : /*#__PURE__*/React.createElement(EmailAndSms, {
|
|
6598
6759
|
customFields: customFields,
|
|
6599
6760
|
customFieldsInitialValues: customFieldsInitialValues,
|
|
6600
6761
|
customFieldsValidationSchema: customFieldsValidationSchema,
|