@bigbinary/neeto-integrations-frontend 4.1.1 → 4.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.
Files changed (63) hide show
  1. package/README.md +1 -0
  2. package/app/javascript/src/translations/en.json +75 -0
  3. package/dist/.ready +1 -1
  4. package/dist/Daily.js +2 -2
  5. package/dist/DailyForm.js +2 -2
  6. package/dist/Telnyx.js +2 -2
  7. package/dist/Twilio.js +2 -2
  8. package/dist/Zoom.js +2 -2
  9. package/dist/cjs/Daily.js +2 -2
  10. package/dist/cjs/DailyForm.js +2 -2
  11. package/dist/cjs/Telnyx.js +2 -2
  12. package/dist/cjs/Twilio.js +2 -2
  13. package/dist/cjs/Zoom.js +2 -2
  14. package/dist/cjs/index.js +6 -6
  15. package/dist/cjs/v2/Daily.js +2 -2
  16. package/dist/cjs/v2/DailyForm.js +2 -2
  17. package/dist/cjs/v2/DisconnectedIntegrationsRibbon.js +2 -2
  18. package/dist/cjs/v2/SmsLogs.js +784 -0
  19. package/dist/cjs/v2/SmsLogs.js.map +1 -0
  20. package/dist/cjs/v2/Telnyx.js +2 -2
  21. package/dist/cjs/v2/Twilio.js +2 -2
  22. package/dist/cjs/v2/Zoom.js +2 -2
  23. package/dist/cjs/v2/index.js +13 -6
  24. package/dist/cjs/v2/index.js.map +1 -1
  25. package/dist/index.js +6 -6
  26. package/dist/{query-BF3HFRA7.js → query-DJngL7gT.js} +6 -2
  27. package/dist/query-DJngL7gT.js.map +1 -0
  28. package/dist/{query-gurbhBqu.js → query-Dy_oZzH0.js} +6 -3
  29. package/dist/query-Dy_oZzH0.js.map +1 -0
  30. package/dist/{useDailiesApi-CEJPknLb.js → useDailiesApi-BqGt8Lap.js} +2 -2
  31. package/dist/{useDailiesApi-CEJPknLb.js.map → useDailiesApi-BqGt8Lap.js.map} +1 -1
  32. package/dist/{useDailiesApi-aQmuxf-5.js → useDailiesApi-CiaD7Sm9.js} +2 -2
  33. package/dist/{useDailiesApi-aQmuxf-5.js.map → useDailiesApi-CiaD7Sm9.js.map} +1 -1
  34. package/dist/{useDisconnectionAlertsApi-BYcHEQ9K.js → useDisconnectionAlertsApi-BtVaHyF9.js} +2 -2
  35. package/dist/{useDisconnectionAlertsApi-BYcHEQ9K.js.map → useDisconnectionAlertsApi-BtVaHyF9.js.map} +1 -1
  36. package/dist/{useDisconnectionAlertsApi-OgxKnneU.js → useDisconnectionAlertsApi-DEZp8XAE.js} +2 -2
  37. package/dist/{useDisconnectionAlertsApi-OgxKnneU.js.map → useDisconnectionAlertsApi-DEZp8XAE.js.map} +1 -1
  38. package/dist/{useTelnyxApi-CMOWQ9Rq.js → useTelnyxApi-BZHgKq_v.js} +2 -2
  39. package/dist/{useTelnyxApi-CMOWQ9Rq.js.map → useTelnyxApi-BZHgKq_v.js.map} +1 -1
  40. package/dist/{useTelnyxApi-Iegy-UzC.js → useTelnyxApi-DUL4eIKW.js} +2 -2
  41. package/dist/{useTelnyxApi-Iegy-UzC.js.map → useTelnyxApi-DUL4eIKW.js.map} +1 -1
  42. package/dist/{useTwilioApi-YSNLrDpP.js → useTwilioApi-00tz9iTn.js} +2 -2
  43. package/dist/{useTwilioApi-YSNLrDpP.js.map → useTwilioApi-00tz9iTn.js.map} +1 -1
  44. package/dist/{useTwilioApi-C067pCq3.js → useTwilioApi-c-f8LcO6.js} +2 -2
  45. package/dist/{useTwilioApi-C067pCq3.js.map → useTwilioApi-c-f8LcO6.js.map} +1 -1
  46. package/dist/{useZoomApi-C8AUYMlp.js → useZoomApi-DEqrcL4c.js} +2 -2
  47. package/dist/{useZoomApi-C8AUYMlp.js.map → useZoomApi-DEqrcL4c.js.map} +1 -1
  48. package/dist/{useZoomApi-CkhVE1e8.js → useZoomApi-fSvs1Qpv.js} +2 -2
  49. package/dist/{useZoomApi-CkhVE1e8.js.map → useZoomApi-fSvs1Qpv.js.map} +1 -1
  50. package/dist/v2/Daily.js +2 -2
  51. package/dist/v2/DailyForm.js +2 -2
  52. package/dist/v2/DisconnectedIntegrationsRibbon.js +2 -2
  53. package/dist/v2/SmsLogs.js +782 -0
  54. package/dist/v2/SmsLogs.js.map +1 -0
  55. package/dist/v2/Telnyx.js +2 -2
  56. package/dist/v2/Twilio.js +2 -2
  57. package/dist/v2/Zoom.js +2 -2
  58. package/dist/v2/index.js +12 -6
  59. package/dist/v2/index.js.map +1 -1
  60. package/package.json +3 -3
  61. package/types.d.ts +22 -0
  62. package/dist/query-BF3HFRA7.js.map +0 -1
  63. package/dist/query-gurbhBqu.js.map +0 -1
@@ -0,0 +1,782 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
+ import { useMemo, useState } from 'react';
4
+ import { MessageSquare } from 'lucide-react';
5
+ import { Typography, Spinner, Badge, Sheet, Callout, Button, DataTable, Empty } from '@bigbinary/neeto-atoms';
6
+ import { isNotEmpty, humanize, findBy, isPresent } from '@bigbinary/neeto-cist';
7
+ import { DEFAULT_PAGE_SIZE } from '@bigbinary/neeto-commons-frontend/constants';
8
+ import { withT, useQueryParams, PageTitle } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
9
+ import { dateFormat, getQueryParams, buildUrl } from '@bigbinary/neeto-commons-frontend/v2/utils';
10
+ import { buildFiltersFromURL } from '@bigbinary/neeto-filters-frontend/v2/utils';
11
+ import Container from '@bigbinary/neeto-molecules/v2/Container';
12
+ import Header from '@bigbinary/neeto-molecules/v2/Header';
13
+ import TableWrapper from '@bigbinary/neeto-molecules/v2/TableWrapper';
14
+ import { prop, propOr, isEmpty, assoc, omit } from 'ramda';
15
+ import { useTranslation } from 'react-i18next';
16
+ import { useHistory } from 'react-router-dom';
17
+ import { useQuery, keepPreviousData } from '@tanstack/react-query';
18
+ import axios from 'axios';
19
+ import { S as SMS_LOGS_URL, Q as QUERY_KEYS } from '../query-Dy_oZzH0.js';
20
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
21
+ import { t } from 'i18next';
22
+ import classnames from 'classnames';
23
+ import FiltersBar from '@bigbinary/neeto-filters-frontend/v2/Bar';
24
+ import NeetoSubHeader from '@bigbinary/neeto-molecules/v2/SubHeader';
25
+
26
+ var fetch = function fetch(params) {
27
+ return axios.get(SMS_LOGS_URL, {
28
+ params: params
29
+ });
30
+ };
31
+ var show = function show(id) {
32
+ return axios.get("".concat(SMS_LOGS_URL, "/").concat(id));
33
+ };
34
+ var smsLogsApi = {
35
+ fetch: fetch,
36
+ show: show
37
+ };
38
+
39
+ function ownKeys$2(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; }
40
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
41
+ var useFetchSmsLogs = function useFetchSmsLogs(params) {
42
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
43
+ return useQuery(_objectSpread$2({
44
+ queryKey: [QUERY_KEYS.SMS_LOGS, params],
45
+ queryFn: function queryFn() {
46
+ return smsLogsApi.fetch(params);
47
+ },
48
+ placeholderData: keepPreviousData
49
+ }, options));
50
+ };
51
+ var useShowSmsLog = function useShowSmsLog(id) {
52
+ return useQuery({
53
+ queryKey: [QUERY_KEYS.SMS_LOG, id],
54
+ queryFn: function queryFn() {
55
+ return smsLogsApi.show(id);
56
+ },
57
+ select: prop("smsLog"),
58
+ enabled: !!id
59
+ });
60
+ };
61
+
62
+ var STATUSES = ["queued", "sent", "delivered", "undelivered", "failed", "dropped"];
63
+ var STATUS_BADGE_VARIANTS = {
64
+ queued: "gray-subtle",
65
+ sent: "blue-subtle",
66
+ delivered: "green-subtle",
67
+ undelivered: "red-subtle",
68
+ failed: "red-subtle",
69
+ dropped: "amber-subtle"
70
+ };
71
+ var CALLOUT_VARIANTS = {
72
+ failed: "danger",
73
+ undelivered: "danger",
74
+ dropped: "warning"
75
+ };
76
+ var PROVIDERS = ["twilio", "telnyx"];
77
+ var NO_OPTIONS = Object.freeze([]);
78
+ var ERROR_CODES_WITH_HINTS = ["21211", "21610", "21614", "30003", "30004", "30005", "30006", "30007", "30008"];
79
+ var GSM_7_BASIC_CHARACTERS = "@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà";
80
+ var GSM_7_EXTENDED_CHARACTERS = "^{}\\[~]|€\f";
81
+
82
+ var DetailField = function DetailField(_ref) {
83
+ var label = _ref.label,
84
+ value = _ref.value,
85
+ testId = _ref.testId;
86
+ if (!value) return null;
87
+ return /*#__PURE__*/jsxs("div", {
88
+ className: "mb-3",
89
+ children: [/*#__PURE__*/jsx(Typography, {
90
+ as: "p",
91
+ className: "mb-0.5",
92
+ color: "muted",
93
+ variant: "body3",
94
+ children: label
95
+ }), /*#__PURE__*/jsx(Typography, {
96
+ as: "div",
97
+ className: "[overflow-wrap:anywhere]",
98
+ "data-testid": testId,
99
+ variant: "body2",
100
+ children: value
101
+ })]
102
+ });
103
+ };
104
+
105
+ var isGsm7Character = function isGsm7Character(character) {
106
+ return GSM_7_BASIC_CHARACTERS.includes(character) || GSM_7_EXTENDED_CHARACTERS.includes(character);
107
+ };
108
+ var getSmsSegmentInfo = function getSmsSegmentInfo() {
109
+ var body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
110
+ var characters = Array.from(body);
111
+ if (isEmpty(characters)) {
112
+ return {
113
+ encoding: "GSM-7",
114
+ characterCount: 0,
115
+ segmentCount: 0
116
+ };
117
+ }
118
+ if (characters.every(isGsm7Character)) {
119
+ var septets = characters.reduce(function (count, character) {
120
+ return count + (GSM_7_EXTENDED_CHARACTERS.includes(character) ? 2 : 1);
121
+ }, 0);
122
+ return {
123
+ encoding: "GSM-7",
124
+ characterCount: characters.length,
125
+ segmentCount: septets <= 160 ? 1 : Math.ceil(septets / 153)
126
+ };
127
+ }
128
+ return {
129
+ encoding: "UCS-2",
130
+ characterCount: characters.length,
131
+ segmentCount: body.length <= 70 ? 1 : Math.ceil(body.length / 67)
132
+ };
133
+ };
134
+ var findOptionLabel = function findOptionLabel(options, value) {
135
+ var _findBy$label, _findBy;
136
+ return (_findBy$label = (_findBy = findBy({
137
+ value: value
138
+ }, options)) === null || _findBy === void 0 ? void 0 : _findBy.label) !== null && _findBy$label !== void 0 ? _findBy$label : value ? humanize(value) : null;
139
+ };
140
+ var getStatusLabel = function getStatusLabel(status) {
141
+ return t("neetoIntegrations.smsLogs.statuses.".concat(status), {
142
+ defaultValue: humanize(status)
143
+ });
144
+ };
145
+ var getStatusBadgeVariant = function getStatusBadgeVariant(status) {
146
+ return propOr("gray-subtle", status, STATUS_BADGE_VARIANTS);
147
+ };
148
+ var getCalloutVariant = function getCalloutVariant(status) {
149
+ return propOr("info", status, CALLOUT_VARIANTS);
150
+ };
151
+ var getProviderLabel = function getProviderLabel(provider) {
152
+ return provider ? t("neetoIntegrations.smsLogs.providers.".concat(provider), {
153
+ defaultValue: humanize(provider)
154
+ }) : null;
155
+ };
156
+ var toPercentage = function toPercentage(count, total) {
157
+ return parseFloat((count / total * 100).toFixed(1));
158
+ };
159
+ var buildStatsSummary = function buildStatsSummary(stats, retentionDays) {
160
+ var total = (stats === null || stats === void 0 ? void 0 : stats.total) || 0;
161
+ if (total === 0) return null;
162
+ return t("neetoIntegrations.smsLogs.subtitle", {
163
+ retentionDays: retentionDays,
164
+ total: total.toLocaleString(),
165
+ deliveredPercentage: toPercentage(stats.delivered, total),
166
+ failedPercentage: toPercentage(stats.failed + stats.undelivered, total),
167
+ droppedPercentage: toPercentage(stats.dropped, total)
168
+ });
169
+ };
170
+ var buildFilterColumns = function buildFilterColumns(_ref) {
171
+ var kindOptions = _ref.kindOptions,
172
+ recipientRoleOptions = _ref.recipientRoleOptions,
173
+ providers = _ref.providers;
174
+ return [{
175
+ node: "status",
176
+ key: "status",
177
+ label: t("neetoIntegrations.smsLogs.filters.status"),
178
+ type: "multi_option",
179
+ values: STATUSES.map(function (status) {
180
+ return {
181
+ label: getStatusLabel(status),
182
+ value: status
183
+ };
184
+ })
185
+ }, isNotEmpty(kindOptions) && {
186
+ node: "kind",
187
+ key: "kind",
188
+ label: t("neetoIntegrations.smsLogs.filters.type"),
189
+ type: "multi_option",
190
+ values: kindOptions
191
+ }, isNotEmpty(recipientRoleOptions) && {
192
+ node: "recipient_role",
193
+ key: "recipient_role",
194
+ label: t("neetoIntegrations.smsLogs.filters.recipient"),
195
+ type: "multi_option",
196
+ values: recipientRoleOptions
197
+ }, providers.length > 1 && {
198
+ node: "provider",
199
+ key: "provider",
200
+ label: t("neetoIntegrations.smsLogs.filters.provider"),
201
+ type: "multi_option",
202
+ values: providers.map(function (provider) {
203
+ return {
204
+ label: getProviderLabel(provider),
205
+ value: provider
206
+ };
207
+ })
208
+ }, {
209
+ node: "created_at",
210
+ key: "created_at",
211
+ label: t("neetoIntegrations.smsLogs.filters.date"),
212
+ type: "date"
213
+ }].filter(Boolean);
214
+ };
215
+
216
+ var MessagePreview = function MessagePreview(_ref) {
217
+ var body = _ref.body,
218
+ from = _ref.from,
219
+ isLoading = _ref.isLoading;
220
+ var _useTranslation = useTranslation(),
221
+ t = _useTranslation.t;
222
+ if (isLoading) {
223
+ return /*#__PURE__*/jsxs("div", {
224
+ className: "flex h-full items-center justify-center gap-2",
225
+ children: [/*#__PURE__*/jsx(Spinner, {}), /*#__PURE__*/jsx(Typography, {
226
+ color: "muted",
227
+ variant: "body3",
228
+ children: t("neetoIntegrations.smsLogs.pane.loadingMessage")
229
+ })]
230
+ });
231
+ }
232
+ if (!body) {
233
+ return /*#__PURE__*/jsx("div", {
234
+ className: "flex h-full items-center justify-center",
235
+ children: /*#__PURE__*/jsx(Typography, {
236
+ color: "muted",
237
+ variant: "body2",
238
+ children: t("neetoIntegrations.smsLogs.pane.noMessage")
239
+ })
240
+ });
241
+ }
242
+ var _getSmsSegmentInfo = getSmsSegmentInfo(body),
243
+ encoding = _getSmsSegmentInfo.encoding,
244
+ characterCount = _getSmsSegmentInfo.characterCount,
245
+ segmentCount = _getSmsSegmentInfo.segmentCount;
246
+ return /*#__PURE__*/jsxs("div", {
247
+ className: "flex flex-col items-center gap-4",
248
+ children: [/*#__PURE__*/jsxs("div", {
249
+ className: "border-border bg-muted/40 w-full max-w-72 rounded-3xl border px-4 pb-6 pt-4",
250
+ children: [/*#__PURE__*/jsx("div", {
251
+ className: "bg-border mx-auto mb-4 h-1.5 w-16 rounded-full"
252
+ }), from && /*#__PURE__*/jsx(Typography, {
253
+ as: "p",
254
+ className: "mb-3 text-center",
255
+ color: "muted",
256
+ variant: "body3",
257
+ children: from
258
+ }), /*#__PURE__*/jsx(Typography, {
259
+ as: "p",
260
+ className: "bg-muted whitespace-pre-line rounded-2xl rounded-bl px-3 py-2 [overflow-wrap:anywhere]",
261
+ "data-testid": "sms-logs-pane-body",
262
+ variant: "body2",
263
+ children: body
264
+ })]
265
+ }), /*#__PURE__*/jsxs("div", {
266
+ className: "flex flex-wrap justify-center gap-2",
267
+ children: [/*#__PURE__*/jsx(Badge, {
268
+ variant: "secondary",
269
+ label: t("neetoIntegrations.smsLogs.pane.characters", {
270
+ count: characterCount
271
+ })
272
+ }), /*#__PURE__*/jsx(Badge, {
273
+ label: encoding,
274
+ variant: "secondary"
275
+ }), /*#__PURE__*/jsx(Badge, {
276
+ variant: "secondary",
277
+ label: t("neetoIntegrations.smsLogs.pane.segments", {
278
+ count: segmentCount
279
+ })
280
+ })]
281
+ })]
282
+ });
283
+ };
284
+
285
+ var Timeline = function Timeline(_ref) {
286
+ var entries = _ref.entries;
287
+ var visibleEntries = entries.filter(prop("timestamp")).sort(function (first, second) {
288
+ return new Date(first.timestamp) - new Date(second.timestamp);
289
+ });
290
+ return visibleEntries.map(function (entry, index) {
291
+ var isLast = index === visibleEntries.length - 1;
292
+ return /*#__PURE__*/jsxs("div", {
293
+ className: "flex gap-3",
294
+ "data-testid": entry.testId,
295
+ children: [/*#__PURE__*/jsxs("div", {
296
+ className: "flex flex-col items-center",
297
+ children: [/*#__PURE__*/jsx("div", {
298
+ className: classnames("mt-1.5 h-2 w-2 flex-shrink-0 rounded-full", entry.isError ? "bg-destructive" : "bg-primary")
299
+ }), !isLast && /*#__PURE__*/jsx("div", {
300
+ className: "bg-muted-foreground/30 w-px flex-1"
301
+ })]
302
+ }), /*#__PURE__*/jsxs("div", {
303
+ className: "pb-4",
304
+ children: [/*#__PURE__*/jsx(Typography, {
305
+ as: "p",
306
+ variant: "body2",
307
+ children: entry.label
308
+ }), /*#__PURE__*/jsx(Typography, {
309
+ as: "p",
310
+ color: "muted",
311
+ variant: "body3",
312
+ children: dateFormat.dateTime(entry.timestamp)
313
+ })]
314
+ })]
315
+ }, entry.key);
316
+ });
317
+ };
318
+
319
+ function ownKeys$1(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; }
320
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
321
+ var Pane = function Pane(_ref) {
322
+ var smsLog = _ref.smsLog,
323
+ onClose = _ref.onClose,
324
+ kindOptions = _ref.kindOptions,
325
+ recipientRoleOptions = _ref.recipientRoleOptions,
326
+ recordColumn = _ref.recordColumn;
327
+ var _useTranslation = useTranslation(),
328
+ t = _useTranslation.t;
329
+ var _useShowSmsLog = useShowSmsLog(smsLog === null || smsLog === void 0 ? void 0 : smsLog.id),
330
+ fetchedSmsLog = _useShowSmsLog.data,
331
+ isLoading = _useShowSmsLog.isLoading;
332
+ if (!smsLog) return null;
333
+ var log = _objectSpread$1(_objectSpread$1({}, smsLog), fetchedSmsLog);
334
+ var status = log.status,
335
+ statusDetail = log.statusDetail,
336
+ errorCode = log.errorCode,
337
+ toPhoneNumber = log.toPhoneNumber,
338
+ fromIdentity = log.fromIdentity,
339
+ provider = log.provider,
340
+ providerMessageId = log.providerMessageId,
341
+ kind = log.kind,
342
+ recipientRole = log.recipientRole,
343
+ body = log.body;
344
+ var recipient = [toPhoneNumber || t("neetoIntegrations.smsLogs.noPhoneNumber"), findOptionLabel(recipientRoleOptions, recipientRole)].filter(Boolean).join(" · ");
345
+ var from = [fromIdentity, getProviderLabel(provider)].filter(Boolean).join(" · ");
346
+ var errorHint = ERROR_CODES_WITH_HINTS.includes(errorCode) ? t("neetoIntegrations.smsLogs.errorHints.".concat(errorCode)) : statusDetail;
347
+ var getCalloutText = function getCalloutText() {
348
+ if (!errorCode) return statusDetail;
349
+ return errorHint ? t("neetoIntegrations.smsLogs.pane.errorWithCode", {
350
+ code: errorCode,
351
+ message: errorHint
352
+ }) : t("neetoIntegrations.smsLogs.pane.errorCode", {
353
+ code: errorCode
354
+ });
355
+ };
356
+ var calloutText = getCalloutText();
357
+ var timelineEntries = [{
358
+ key: "queued",
359
+ label: t("neetoIntegrations.smsLogs.pane.timeline.queued"),
360
+ timestamp: log.queuedAt
361
+ }, {
362
+ key: "dropped",
363
+ label: t("neetoIntegrations.smsLogs.pane.timeline.dropped"),
364
+ timestamp: log.droppedAt,
365
+ isError: true
366
+ }, {
367
+ key: "sent",
368
+ label: t("neetoIntegrations.smsLogs.pane.timeline.sent"),
369
+ timestamp: log.sentAt
370
+ }, {
371
+ key: "delivered",
372
+ label: t("neetoIntegrations.smsLogs.pane.timeline.delivered"),
373
+ timestamp: log.deliveredAt
374
+ }, {
375
+ key: "failed",
376
+ label: t("neetoIntegrations.smsLogs.pane.timeline.".concat(status), {
377
+ defaultValue: t("neetoIntegrations.smsLogs.pane.timeline.failed")
378
+ }),
379
+ timestamp: log.failedAt,
380
+ isError: true
381
+ }];
382
+ return /*#__PURE__*/jsxs(Sheet, {
383
+ onClose: onClose,
384
+ isOpen: !!smsLog,
385
+ size: "extraLarge",
386
+ children: [/*#__PURE__*/jsx(Sheet.Header, {
387
+ children: /*#__PURE__*/jsx(Sheet.Title, {
388
+ children: t("neetoIntegrations.smsLogs.pane.title")
389
+ })
390
+ }), /*#__PURE__*/jsx(Sheet.Body, {
391
+ hasFooter: false,
392
+ children: /*#__PURE__*/jsxs("div", {
393
+ className: "grid w-full flex-1 grid-cols-1 gap-6 pb-8 md:grid-cols-[minmax(0,2fr)_minmax(0,3fr)]",
394
+ children: [/*#__PURE__*/jsxs("div", {
395
+ className: "min-w-0",
396
+ children: [/*#__PURE__*/jsx("div", {
397
+ className: "mb-4",
398
+ children: /*#__PURE__*/jsx(Badge, {
399
+ label: getStatusLabel(status),
400
+ variant: getStatusBadgeVariant(status)
401
+ })
402
+ }), /*#__PURE__*/jsx(DetailField, {
403
+ label: t("neetoIntegrations.smsLogs.pane.recipient"),
404
+ testId: "sms-logs-pane-recipient",
405
+ value: recipient
406
+ }), /*#__PURE__*/jsx(DetailField, {
407
+ label: t("neetoIntegrations.smsLogs.pane.from"),
408
+ testId: "sms-logs-pane-from",
409
+ value: from
410
+ }), /*#__PURE__*/jsx(DetailField, {
411
+ label: t("neetoIntegrations.smsLogs.pane.type"),
412
+ testId: "sms-logs-pane-type",
413
+ value: findOptionLabel(kindOptions, kind)
414
+ }), recordColumn && /*#__PURE__*/jsx(DetailField, {
415
+ label: recordColumn.title,
416
+ testId: "sms-logs-pane-record",
417
+ value: recordColumn.render(log)
418
+ }), /*#__PURE__*/jsx(DetailField, {
419
+ label: t("neetoIntegrations.smsLogs.pane.providerMessageId"),
420
+ testId: "sms-logs-pane-provider-message-id",
421
+ value: providerMessageId
422
+ }), /*#__PURE__*/jsxs("div", {
423
+ className: "border-border mt-5 border-t pt-4",
424
+ children: [/*#__PURE__*/jsx(Typography, {
425
+ as: "p",
426
+ className: "mb-3",
427
+ color: "muted",
428
+ variant: "body3",
429
+ children: t("neetoIntegrations.smsLogs.pane.timeline.title")
430
+ }), /*#__PURE__*/jsx(Timeline, {
431
+ entries: timelineEntries
432
+ })]
433
+ }), calloutText && /*#__PURE__*/jsx(Callout, {
434
+ className: "mt-4",
435
+ "data-testid": "sms-logs-pane-status-detail",
436
+ variant: getCalloutVariant(status),
437
+ children: calloutText
438
+ })]
439
+ }), /*#__PURE__*/jsx("div", {
440
+ className: "border-border min-w-0 border-t pt-6 md:border-l md:border-t-0 md:pl-6 md:pt-0",
441
+ children: /*#__PURE__*/jsx(MessagePreview, {
442
+ body: body,
443
+ isLoading: isLoading,
444
+ from: fromIdentity
445
+ })
446
+ })]
447
+ })
448
+ })]
449
+ });
450
+ };
451
+
452
+ var SubHeader = withT(function (_ref) {
453
+ var t = _ref.t,
454
+ totalCount = _ref.totalCount,
455
+ filters = _ref.filters,
456
+ filterColumns = _ref.filterColumns,
457
+ searchTerm = _ref.searchTerm,
458
+ genericSearchProps = _ref.genericSearchProps,
459
+ isFilterPaneOpen = _ref.isFilterPaneOpen,
460
+ setIsFilterPaneOpen = _ref.setIsFilterPaneOpen,
461
+ onFiltersChange = _ref.onFiltersChange;
462
+ return /*#__PURE__*/jsxs(Fragment, {
463
+ children: [/*#__PURE__*/jsx(NeetoSubHeader, {
464
+ className: "mb-4",
465
+ leftActionBlock: totalCount > 0 && /*#__PURE__*/jsx(Typography, {
466
+ weight: "semibold",
467
+ children: t("neetoIntegrations.smsLogs.smsWithCount", {
468
+ count: totalCount
469
+ })
470
+ }),
471
+ rightActionBlock: /*#__PURE__*/jsx(NeetoSubHeader.RightBlock, {
472
+ filterProps: {
473
+ columns: filterColumns,
474
+ isOpen: isFilterPaneOpen,
475
+ keyword: genericSearchProps,
476
+ setIsOpen: setIsFilterPaneOpen,
477
+ onChange: onFiltersChange
478
+ }
479
+ })
480
+ }), (isPresent(filters) || isPresent(searchTerm)) && /*#__PURE__*/jsx(FiltersBar, {
481
+ className: "mb-4",
482
+ columns: filterColumns,
483
+ keyword: genericSearchProps,
484
+ setIsPaneOpen: setIsFilterPaneOpen,
485
+ onChange: onFiltersChange
486
+ })]
487
+ });
488
+ });
489
+
490
+ var Table = function Table(_ref) {
491
+ var smsLogs = _ref.smsLogs,
492
+ isLoading = _ref.isLoading,
493
+ totalCount = _ref.totalCount,
494
+ currentPage = _ref.currentPage,
495
+ onPageChange = _ref.onPageChange,
496
+ onRowClick = _ref.onRowClick,
497
+ kindOptions = _ref.kindOptions,
498
+ recipientRoleOptions = _ref.recipientRoleOptions,
499
+ recordColumn = _ref.recordColumn;
500
+ var _useTranslation = useTranslation(),
501
+ t = _useTranslation.t;
502
+ var columns = useMemo(function () {
503
+ return [{
504
+ accessorKey: "toPhoneNumber",
505
+ id: "toPhoneNumber",
506
+ header: t("neetoIntegrations.smsLogs.columns.recipient"),
507
+ size: 180,
508
+ cell: function cell(_ref2) {
509
+ var smsLog = _ref2.row.original;
510
+ return /*#__PURE__*/jsxs("div", {
511
+ className: "flex flex-col items-start",
512
+ children: [/*#__PURE__*/jsx(Button, {
513
+ className: "max-w-full text-start [&>span]:block [&>span]:min-w-0 [&>span]:truncate",
514
+ "data-testid": "sms-logs-recipient-button",
515
+ variant: "link",
516
+ label: smsLog.toPhoneNumber || t("neetoIntegrations.smsLogs.noPhoneNumber"),
517
+ onClick: function onClick() {
518
+ return onRowClick(smsLog);
519
+ }
520
+ }), smsLog.recipientRole && /*#__PURE__*/jsx(Typography, {
521
+ color: "muted",
522
+ variant: "body3",
523
+ children: findOptionLabel(recipientRoleOptions, smsLog.recipientRole)
524
+ })]
525
+ });
526
+ }
527
+ }, {
528
+ accessorKey: "bodyPreview",
529
+ id: "bodyPreview",
530
+ header: t("neetoIntegrations.smsLogs.columns.message"),
531
+ size: 360,
532
+ cell: function cell(_ref3) {
533
+ var smsLog = _ref3.row.original;
534
+ return /*#__PURE__*/jsxs("div", {
535
+ className: "min-w-0",
536
+ children: [smsLog.kind && /*#__PURE__*/jsx(Typography, {
537
+ variant: "body2",
538
+ weight: "semibold",
539
+ children: findOptionLabel(kindOptions, smsLog.kind)
540
+ }), /*#__PURE__*/jsx(Typography, {
541
+ className: "truncate",
542
+ color: "muted",
543
+ variant: "body3",
544
+ children: smsLog.status === "dropped" ? smsLog.statusDetail : smsLog.bodyPreview
545
+ })]
546
+ });
547
+ }
548
+ }, recordColumn && {
549
+ accessorKey: "recordId",
550
+ id: "record",
551
+ header: recordColumn.title,
552
+ size: 170,
553
+ cell: function cell(_ref4) {
554
+ var smsLog = _ref4.row.original;
555
+ return recordColumn.render(smsLog);
556
+ }
557
+ }, {
558
+ accessorKey: "status",
559
+ id: "status",
560
+ header: t("neetoIntegrations.smsLogs.columns.status"),
561
+ size: 110,
562
+ cell: function cell(_ref5) {
563
+ var getValue = _ref5.getValue;
564
+ return /*#__PURE__*/jsx(Badge, {
565
+ label: getStatusLabel(getValue()),
566
+ variant: getStatusBadgeVariant(getValue())
567
+ });
568
+ }
569
+ }, {
570
+ accessorKey: "createdAt",
571
+ id: "createdAt",
572
+ header: t("neetoIntegrations.smsLogs.columns.date"),
573
+ size: 180,
574
+ cell: function cell(_ref6) {
575
+ var getValue = _ref6.getValue;
576
+ return dateFormat.dateTime(getValue());
577
+ }
578
+ }].filter(Boolean);
579
+ }, [onRowClick, kindOptions, recipientRoleOptions, recordColumn, t]);
580
+ return /*#__PURE__*/jsx(DataTable, {
581
+ columns: columns,
582
+ currentPage: currentPage,
583
+ onPageChange: onPageChange,
584
+ totalCount: totalCount,
585
+ allowRowClick: false,
586
+ data: smsLogs,
587
+ enableURLPagination: false,
588
+ getRowId: prop("id"),
589
+ loading: isLoading,
590
+ pageSize: DEFAULT_PAGE_SIZE
591
+ });
592
+ };
593
+
594
+ function ownKeys(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; }
595
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
596
+ var SmsLogs = function SmsLogs(_ref) {
597
+ var _ref$canViewSmsLogs = _ref.canViewSmsLogs,
598
+ canViewSmsLogs = _ref$canViewSmsLogs === void 0 ? false : _ref$canViewSmsLogs,
599
+ breadcrumbs = _ref.breadcrumbs,
600
+ helpUrl = _ref.helpUrl,
601
+ pageTitle = _ref.pageTitle,
602
+ _ref$kindOptions = _ref.kindOptions,
603
+ kindOptions = _ref$kindOptions === void 0 ? NO_OPTIONS : _ref$kindOptions,
604
+ _ref$recipientRoleOpt = _ref.recipientRoleOptions,
605
+ recipientRoleOptions = _ref$recipientRoleOpt === void 0 ? NO_OPTIONS : _ref$recipientRoleOpt,
606
+ recordColumn = _ref.recordColumn,
607
+ _ref$providers = _ref.providers,
608
+ providers = _ref$providers === void 0 ? PROVIDERS : _ref$providers,
609
+ _ref$isSmsIntegration = _ref.isSmsIntegrationConnected,
610
+ isSmsIntegrationConnected = _ref$isSmsIntegration === void 0 ? true : _ref$isSmsIntegration,
611
+ connectIntegrationButtonProps = _ref.connectIntegrationButtonProps;
612
+ var _useTranslation = useTranslation(),
613
+ t = _useTranslation.t;
614
+ var history = useHistory();
615
+ var _useQueryParams = useQueryParams(),
616
+ _useQueryParams$searc = _useQueryParams.searchTerm,
617
+ searchTerm = _useQueryParams$searc === void 0 ? "" : _useQueryParams$searc;
618
+ var filterColumns = buildFilterColumns({
619
+ kindOptions: kindOptions,
620
+ recipientRoleOptions: recipientRoleOptions,
621
+ providers: providers
622
+ });
623
+ var _useState = useState(1),
624
+ _useState2 = _slicedToArray(_useState, 2),
625
+ page = _useState2[0],
626
+ setPage = _useState2[1];
627
+ var _useState3 = useState(function () {
628
+ return buildFiltersFromURL(filterColumns);
629
+ }),
630
+ _useState4 = _slicedToArray(_useState3, 2),
631
+ filters = _useState4[0],
632
+ setFilters = _useState4[1];
633
+ var _useState5 = useState(false),
634
+ _useState6 = _slicedToArray(_useState5, 2),
635
+ isFilterPaneOpen = _useState6[0],
636
+ setIsFilterPaneOpen = _useState6[1];
637
+ var _useState7 = useState(null),
638
+ _useState8 = _slicedToArray(_useState7, 2),
639
+ selectedSmsLog = _useState8[0],
640
+ setSelectedSmsLog = _useState8[1];
641
+ var queryParams = _objectSpread(_objectSpread({
642
+ page: page,
643
+ pageSize: DEFAULT_PAGE_SIZE
644
+ }, isPresent(searchTerm) && {
645
+ searchTerm: searchTerm
646
+ }), isPresent(filters) && {
647
+ neetoFilters: filters
648
+ });
649
+ var _useFetchSmsLogs = useFetchSmsLogs(queryParams, {
650
+ enabled: canViewSmsLogs
651
+ }),
652
+ data = _useFetchSmsLogs.data,
653
+ isLoading = _useFetchSmsLogs.isLoading,
654
+ isPlaceholderData = _useFetchSmsLogs.isPlaceholderData;
655
+ if (!canViewSmsLogs) return null;
656
+ var _ref2 = data !== null && data !== void 0 ? data : {},
657
+ _ref2$smsLogs = _ref2.smsLogs,
658
+ smsLogs = _ref2$smsLogs === void 0 ? [] : _ref2$smsLogs,
659
+ _ref2$totalCount = _ref2.totalCount,
660
+ totalCount = _ref2$totalCount === void 0 ? 0 : _ref2$totalCount,
661
+ stats = _ref2.stats,
662
+ _ref2$retentionDays = _ref2.retentionDays,
663
+ retentionDays = _ref2$retentionDays === void 0 ? 30 : _ref2$retentionDays;
664
+ var title = t("neetoIntegrations.smsLogs.title");
665
+ var statsSummary = buildStatsSummary(stats, retentionDays);
666
+ var isFiltered = isPresent(filters) || isPresent(searchTerm);
667
+ var hasNoSmsLogs = !isLoading && (stats === null || stats === void 0 ? void 0 : stats.total) === 0 && !isFiltered;
668
+ var genericSearchProps = {
669
+ key: "search_term",
670
+ node: "to_phone_number",
671
+ value: searchTerm,
672
+ model: ""
673
+ };
674
+ var handleFiltersChange = function handleFiltersChange(newFilters) {
675
+ setFilters(newFilters);
676
+ setPage(1);
677
+ };
678
+ var handleSearch = function handleSearch(value) {
679
+ var queryParams = getQueryParams({
680
+ toCamelCase: false
681
+ });
682
+ var params = value ? assoc("search_term", value, queryParams) : omit(["search_term"], queryParams);
683
+ setPage(1);
684
+ history.push(buildUrl(window.location.pathname, params, {
685
+ toSnakeCase: false
686
+ }));
687
+ };
688
+ var renderNoData = function renderNoData() {
689
+ return isSmsIntegrationConnected ? /*#__PURE__*/jsx(Empty, {
690
+ description: t("neetoIntegrations.smsLogs.noData.description"),
691
+ icon: MessageSquare,
692
+ title: t("neetoIntegrations.smsLogs.noData.title", {
693
+ retentionDays: retentionDays
694
+ })
695
+ }) : /*#__PURE__*/jsx(Empty, {
696
+ icon: MessageSquare,
697
+ primaryButtonProps: connectIntegrationButtonProps,
698
+ title: t("neetoIntegrations.smsLogs.noData.noIntegrationTitle"),
699
+ description: t("neetoIntegrations.smsLogs.noData.noIntegrationDescription", {
700
+ retentionDays: retentionDays
701
+ })
702
+ });
703
+ };
704
+ var renderContent = function renderContent() {
705
+ if (isLoading) {
706
+ return /*#__PURE__*/jsx("div", {
707
+ className: "flex h-full w-full items-center justify-center",
708
+ children: /*#__PURE__*/jsx(Spinner, {})
709
+ });
710
+ }
711
+ if (hasNoSmsLogs) {
712
+ return /*#__PURE__*/jsx("div", {
713
+ className: "flex h-full w-full items-center justify-center",
714
+ children: renderNoData()
715
+ });
716
+ }
717
+ return /*#__PURE__*/jsxs(Fragment, {
718
+ children: [/*#__PURE__*/jsx(SubHeader, {
719
+ filterColumns: filterColumns,
720
+ filters: filters,
721
+ genericSearchProps: genericSearchProps,
722
+ isFilterPaneOpen: isFilterPaneOpen,
723
+ searchTerm: searchTerm,
724
+ setIsFilterPaneOpen: setIsFilterPaneOpen,
725
+ totalCount: totalCount,
726
+ onFiltersChange: handleFiltersChange
727
+ }), /*#__PURE__*/jsx(TableWrapper, {
728
+ children: /*#__PURE__*/jsx(Table, {
729
+ kindOptions: kindOptions,
730
+ recipientRoleOptions: recipientRoleOptions,
731
+ recordColumn: recordColumn,
732
+ smsLogs: smsLogs,
733
+ totalCount: totalCount,
734
+ currentPage: page,
735
+ isLoading: isPlaceholderData,
736
+ onPageChange: setPage,
737
+ onRowClick: setSelectedSmsLog
738
+ })
739
+ })]
740
+ });
741
+ };
742
+ return /*#__PURE__*/jsxs(Container, {
743
+ children: [/*#__PURE__*/jsx(PageTitle, {
744
+ title: pageTitle || title
745
+ }), /*#__PURE__*/jsx(Header, _objectSpread({
746
+ breadcrumbs: breadcrumbs,
747
+ title: title,
748
+ searchProps: isLoading || hasNoSmsLogs ? undefined : {
749
+ className: "w-72",
750
+ enableUrlSync: true,
751
+ placeholder: t("neetoIntegrations.smsLogs.searchPlaceholder"),
752
+ onSearch: handleSearch
753
+ }
754
+ }, helpUrl && {
755
+ titleHelpPopoverProps: {
756
+ title: title,
757
+ description: t("neetoIntegrations.smsLogs.helpDescription"),
758
+ helpLinkProps: {
759
+ href: helpUrl
760
+ }
761
+ }
762
+ })), statsSummary && /*#__PURE__*/jsx(Typography, {
763
+ as: "p",
764
+ className: "-mt-3 mb-2",
765
+ color: "muted",
766
+ "data-testid": "sms-logs-stats-summary",
767
+ variant: "body2",
768
+ children: statsSummary
769
+ }), renderContent(), /*#__PURE__*/jsx(Pane, {
770
+ kindOptions: kindOptions,
771
+ recipientRoleOptions: recipientRoleOptions,
772
+ recordColumn: recordColumn,
773
+ smsLog: selectedSmsLog,
774
+ onClose: function onClose() {
775
+ return setSelectedSmsLog(null);
776
+ }
777
+ })]
778
+ });
779
+ };
780
+
781
+ export { SmsLogs as default };
782
+ //# sourceMappingURL=SmsLogs.js.map