@capillarytech/creatives-library 9.2.3 → 9.2.4-alpha.feature-rcs-multi-account.52
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/package.json +1 -1
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +9 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +44 -3
- package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +14 -0
- package/v2Components/CommonTestAndPreview/SendTestMessage.js +14 -0
- package/v2Components/CommonTestAndPreview/index.js +118 -11
- package/v2Components/CommonTestAndPreview/reducer.js +8 -2
- package/v2Components/CommonTestAndPreview/selectors.js +6 -0
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +11 -0
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +92 -0
- package/v2Components/CommonTestAndPreview/tests/index.test.js +200 -0
- package/v2Components/CommonTestAndPreview/tests/reducer.test.js +4 -0
- package/v2Components/CommonTestAndPreview/tests/selectors.test.js +10 -0
- package/v2Components/TestAndPreviewSlidebox/index.js +8 -0
- package/v2Containers/CommunicationFlow/CommunicationFlow.js +9 -1
- package/v2Containers/CommunicationFlow/Tests/CommunicationFlow.test.js +76 -1
- package/v2Containers/CommunicationFlow/messages.js +12 -0
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/ChannelSelectionStep.js +5 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js +195 -19
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/SenderDetails.js +37 -4
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/DeliverySettingsSection.test.js +360 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/SenderDetails.test.js +25 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/deliverySettingsConfig.test.js +80 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/deliverySettingsConfig.js +39 -8
- package/v2Containers/CreativesContainer/index.js +24 -0
- package/v2Containers/CreativesContainer/tests/index.test.js +82 -0
- package/v2Containers/Rcs/accountUtils.js +126 -0
- package/v2Containers/Rcs/index.js +30 -4
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +108 -0
- package/v2Containers/Rcs/tests/accountUtils.test.js +178 -0
- package/v2Containers/Rcs/tests/testAndPreviewAccount.test.js +193 -0
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +27 -0
- package/v2Containers/Templates/ChannelTypeIllustration.js +12 -0
- package/v2Containers/Templates/index.js +10 -5
- package/v2Containers/Templates/messages.js +4 -0
- package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +14 -2
- package/v2Containers/Templates/tests/index.test.js +112 -0
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js
CHANGED
|
@@ -15,12 +15,16 @@ import CapRow from '@capillarytech/cap-ui-library/CapRow';
|
|
|
15
15
|
import CapHeading from '@capillarytech/cap-ui-library/CapHeading';
|
|
16
16
|
import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
|
|
17
17
|
import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
|
|
18
|
+
import CapError from '@capillarytech/cap-ui-library/CapError';
|
|
19
|
+
import CapLink from '@capillarytech/cap-ui-library/CapLink';
|
|
18
20
|
import SenderDetails, { parseSenderDetailsFromEntity } from './SenderDetails';
|
|
19
21
|
import {
|
|
20
22
|
buildChannelSettingFromFieldValues,
|
|
21
23
|
parseChannelSettingForDisplay,
|
|
22
24
|
getWhatsappAccountName,
|
|
23
25
|
hasRcsSmsFallbackContent,
|
|
26
|
+
isRcsAccountNotConfiguredForEntity,
|
|
27
|
+
getRcsSenderValuesForAccount,
|
|
24
28
|
RCS_SMS_FALLBACK_CHANNEL,
|
|
25
29
|
} from './deliverySettingsConfig';
|
|
26
30
|
import { getDomainProperties, fetchWeCrmAccounts } from '../../../../services/api';
|
|
@@ -29,6 +33,7 @@ import { CHANNELS_WITHOUT_DELIVERY } from '../../constants';
|
|
|
29
33
|
import messages from '../../messages';
|
|
30
34
|
import './DeliverySettingsSection.scss';
|
|
31
35
|
import { WHATSAPP, SMS, RCS } from "../../../CreativesContainer/constants";
|
|
36
|
+
import { resolveRcsAccountKey } from '../../../Rcs/accountUtils';
|
|
32
37
|
|
|
33
38
|
const DeliverySettingsSection = ({
|
|
34
39
|
contentItems = [],
|
|
@@ -36,18 +41,28 @@ const DeliverySettingsSection = ({
|
|
|
36
41
|
deliverySetting = {},
|
|
37
42
|
onDeliverySettingChange,
|
|
38
43
|
onDomainPropertiesLoaded,
|
|
44
|
+
onRcsAccountPendingChange,
|
|
39
45
|
orgUnitId,
|
|
40
46
|
domainPropertiesPriority,
|
|
41
47
|
intl,
|
|
42
48
|
}) => {
|
|
43
49
|
const [showSlidebox, setShowSlidebox] = useState(false);
|
|
44
50
|
const [domainPropertiesData, setDomainPropertiesData] = useState(null);
|
|
51
|
+
// Channel set (deliveryChannelKey) the loaded domainPropertiesData belongs to. While a new channel set is being
|
|
52
|
+
// fetched the previous response is kept, so RCS decisions must wait until the current request has settled.
|
|
53
|
+
const [loadedDomainChannelKey, setLoadedDomainChannelKey] = useState('');
|
|
45
54
|
const [wecrmViberData, setWecrmViberData] = useState(null);
|
|
55
|
+
// WeCRM RCS accounts: only fetched to resolve a reopened template's saved accountId (WeCRM id) to its account.
|
|
56
|
+
// status: idle | loading | success | failed; retryCount re-runs the request after a failure.
|
|
57
|
+
const [wecrmRcsLookup, setWecrmRcsLookup] = useState({ status: 'idle', accounts: [] });
|
|
58
|
+
const [wecrmRcsRetryCount, setWecrmRcsRetryCount] = useState(0);
|
|
46
59
|
// Drives SenderDetails' loading spinner — true only while the domain-properties
|
|
47
60
|
// fetch below is actually in flight (previously nothing tracked this, so opening
|
|
48
61
|
// the slidebox before the background fetch resolved showed a blank panel).
|
|
49
62
|
const [isFetchingDomains, setIsFetchingDomains] = useState(false);
|
|
50
|
-
|
|
63
|
+
// Channel set of the domainProperties request currently in flight (null when none). Keyed by channel set so a
|
|
64
|
+
// change of channels during a request starts the new request instead of being skipped.
|
|
65
|
+
const inFlightChannelKeyRef = useRef(null);
|
|
51
66
|
const lastChannelKeyRef = useRef('');
|
|
52
67
|
const { formatMessage } = intl || {};
|
|
53
68
|
|
|
@@ -90,6 +105,15 @@ const DeliverySettingsSection = ({
|
|
|
90
105
|
return waContentItem?.templateData?.sourceAccountIdentifier || '';
|
|
91
106
|
}, [contentItems]);
|
|
92
107
|
|
|
108
|
+
// RCS template account. templateData.sourceAccountIdentifier is set by CreativesContainer when a template is
|
|
109
|
+
// picked; a reopened template only carries accountId (WeCRM id), resolved below via the WeCRM RCS accounts.
|
|
110
|
+
const rcsTemplateData = useMemo(() => {
|
|
111
|
+
const rcsContentItem = contentItems.find((contentItem) => (contentItem.channel)?.toUpperCase() === RCS);
|
|
112
|
+
return rcsContentItem?.templateData || null;
|
|
113
|
+
}, [contentItems]);
|
|
114
|
+
const rcsTemplateSourceAccountId = String(rcsTemplateData?.sourceAccountIdentifier || '').trim();
|
|
115
|
+
const rcsTemplateAccountId = rcsTemplateData?.accountId ?? rcsTemplateData?.rcsContent?.accountId ?? '';
|
|
116
|
+
|
|
93
117
|
// Extract WhatsApp account name from contentItems (set by Whatsapp/index.js)
|
|
94
118
|
const whatsappAccNameFromContent = useMemo(() => {
|
|
95
119
|
const waContentItem = contentItems.find((contentItem) => (contentItem.channel)?.toUpperCase() === WHATSAPP);
|
|
@@ -103,14 +127,16 @@ const DeliverySettingsSection = ({
|
|
|
103
127
|
useEffect(() => {
|
|
104
128
|
if (!deliveryEnabled || deliveryFetchChannels.length === 0) {
|
|
105
129
|
setDomainPropertiesData(null);
|
|
130
|
+
setLoadedDomainChannelKey('');
|
|
106
131
|
lastChannelKeyRef.current = '';
|
|
107
132
|
return undefined;
|
|
108
133
|
}
|
|
109
134
|
if (lastChannelKeyRef.current === deliveryChannelKey && domainPropertiesData) {
|
|
110
135
|
return undefined;
|
|
111
136
|
}
|
|
112
|
-
|
|
113
|
-
|
|
137
|
+
// Same channel set already being fetched (effect re-run): don't issue a duplicate request.
|
|
138
|
+
if (inFlightChannelKeyRef.current === deliveryChannelKey) return undefined;
|
|
139
|
+
inFlightChannelKeyRef.current = deliveryChannelKey;
|
|
114
140
|
setIsFetchingDomains(true);
|
|
115
141
|
lastChannelKeyRef.current = deliveryChannelKey;
|
|
116
142
|
let cancelled = false;
|
|
@@ -130,22 +156,25 @@ const DeliverySettingsSection = ({
|
|
|
130
156
|
)
|
|
131
157
|
: raw;
|
|
132
158
|
setDomainPropertiesData(entity);
|
|
159
|
+
setLoadedDomainChannelKey(deliveryChannelKey);
|
|
133
160
|
onDomainPropertiesLoaded?.(entity);
|
|
134
161
|
}
|
|
135
162
|
} catch (err) {
|
|
136
|
-
if (!cancelled) setDomainPropertiesData(null);
|
|
137
|
-
} finally {
|
|
138
163
|
if (!cancelled) {
|
|
139
|
-
|
|
140
|
-
|
|
164
|
+
setDomainPropertiesData(null);
|
|
165
|
+
setLoadedDomainChannelKey('');
|
|
141
166
|
}
|
|
167
|
+
} finally {
|
|
168
|
+
// Release the in-flight marker only if no newer request (other channel set) replaced it.
|
|
169
|
+
if (inFlightChannelKeyRef.current === deliveryChannelKey) inFlightChannelKeyRef.current = null;
|
|
170
|
+
if (!cancelled) setIsFetchingDomains(false);
|
|
142
171
|
}
|
|
143
172
|
};
|
|
144
173
|
fetchData();
|
|
145
174
|
return function cleanup() {
|
|
175
|
+
// A superseded request's response is ignored; a request for a new channel set can start right away.
|
|
146
176
|
cancelled = true;
|
|
147
|
-
|
|
148
|
-
// fetchInFlightRef is reset in finally when the fetch completes.
|
|
177
|
+
if (inFlightChannelKeyRef.current === deliveryChannelKey) inFlightChannelKeyRef.current = null;
|
|
149
178
|
};
|
|
150
179
|
}, [deliveryEnabled, deliveryChannelKey, orgUnitId]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
151
180
|
|
|
@@ -206,6 +235,71 @@ const DeliverySettingsSection = ({
|
|
|
206
235
|
return merged;
|
|
207
236
|
}, [domainPropertiesData, wecrmViberData]);
|
|
208
237
|
|
|
238
|
+
// Fetch WeCRM RCS accounts only when the RCS account must be resolved from a saved accountId
|
|
239
|
+
const needsWecrmRcs = deliveryChannels.includes(RCS) && !rcsTemplateSourceAccountId
|
|
240
|
+
&& String(rcsTemplateAccountId).trim() !== '';
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
if (!needsWecrmRcs) {
|
|
243
|
+
setWecrmRcsLookup({ status: 'idle', accounts: [] });
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
let cancelled = false;
|
|
247
|
+
setWecrmRcsLookup({ status: 'loading', accounts: [] });
|
|
248
|
+
const fetchWecrmRcs = async () => {
|
|
249
|
+
try {
|
|
250
|
+
const res = await fetchWeCrmAccounts(RCS);
|
|
251
|
+
if (cancelled) return;
|
|
252
|
+
const accounts = res?.response;
|
|
253
|
+
if (Array.isArray(accounts)) setWecrmRcsLookup({ status: 'success', accounts });
|
|
254
|
+
else if (accounts) setWecrmRcsLookup({ status: 'success', accounts: [accounts] });
|
|
255
|
+
else setWecrmRcsLookup({ status: 'failed', accounts: [] });
|
|
256
|
+
} catch {
|
|
257
|
+
if (!cancelled) setWecrmRcsLookup({ status: 'failed', accounts: [] });
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
fetchWecrmRcs();
|
|
261
|
+
return () => { cancelled = true; };
|
|
262
|
+
}, [needsWecrmRcs, wecrmRcsRetryCount]);
|
|
263
|
+
|
|
264
|
+
// RCS account of the template: picked template's sourceAccountIdentifier, else the saved accountId (WeCRM id)
|
|
265
|
+
// resolved against the WeCRM RCS accounts. No account identity at all → '' (first-domain behaviour). While the
|
|
266
|
+
// lookup is pending or failed the account stays unresolved; an account no longer in WeCRM → not configured.
|
|
267
|
+
const rcsAccount = useMemo(() => {
|
|
268
|
+
if (rcsTemplateSourceAccountId) return { status: 'resolved', accountKey: rcsTemplateSourceAccountId };
|
|
269
|
+
return resolveRcsAccountKey({
|
|
270
|
+
accountId: rcsTemplateAccountId,
|
|
271
|
+
accounts: wecrmRcsLookup.accounts,
|
|
272
|
+
isLoaded: wecrmRcsLookup.status === 'success',
|
|
273
|
+
hasFailed: wecrmRcsLookup.status === 'failed',
|
|
274
|
+
});
|
|
275
|
+
}, [rcsTemplateSourceAccountId, rcsTemplateAccountId, wecrmRcsLookup]);
|
|
276
|
+
const rcsSourceAccountId = rcsAccount.accountKey;
|
|
277
|
+
// Sender sync waits while the RCS account is unresolved (pending, or failed until retried).
|
|
278
|
+
const isRcsAccountResolving = deliveryChannels.includes(RCS) && ['pending', 'failed'].includes(rcsAccount.status);
|
|
279
|
+
const isRcsAccountLookupFailed = deliveryChannels.includes(RCS) && rcsAccount.status === 'failed';
|
|
280
|
+
const retryRcsAccountLookup = useCallback((event) => {
|
|
281
|
+
event?.stopPropagation?.();
|
|
282
|
+
setWecrmRcsRetryCount((count) => count + 1);
|
|
283
|
+
}, []);
|
|
284
|
+
|
|
285
|
+
// Domains loaded for the current channel set (not a previous response kept while the new one is fetched).
|
|
286
|
+
const isDomainEntityCurrent = !!domainPropertiesData && loadedDomainChannelKey === deliveryChannelKey;
|
|
287
|
+
|
|
288
|
+
// Let CommunicationFlow block Save while the RCS template's account is unresolved (pending / failed lookup).
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
onRcsAccountPendingChange?.(isRcsAccountResolving);
|
|
291
|
+
}, [isRcsAccountResolving]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
292
|
+
useEffect(() => () => onRcsAccountPendingChange?.(false), []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
293
|
+
|
|
294
|
+
const isRcsAccountNotConfigured = deliveryChannels.includes(RCS) && !isRcsAccountResolving && isDomainEntityCurrent
|
|
295
|
+
&& isRcsAccountNotConfiguredForEntity(entityWithWecrmViber, rcsSourceAccountId);
|
|
296
|
+
|
|
297
|
+
// Account context for account-bound fields (WhatsApp WABA, RCS account)
|
|
298
|
+
const accountContext = useMemo(() => ({
|
|
299
|
+
whatsappSourceAccountId,
|
|
300
|
+
rcsSourceAccountId,
|
|
301
|
+
}), [whatsappSourceAccountId, rcsSourceAccountId]);
|
|
302
|
+
|
|
209
303
|
// Helper: returns true if a channelSetting entry has at least one real (non-empty) value
|
|
210
304
|
const hasRealData = (settings) => settings && Object.values(settings).some((value) => value !== null && value !== '' && value !== undefined);
|
|
211
305
|
|
|
@@ -219,9 +313,12 @@ const DeliverySettingsSection = ({
|
|
|
219
313
|
// - Never overwrite a channel the user has already configured manually
|
|
220
314
|
useEffect(() => {
|
|
221
315
|
if (!entityWithWecrmViber || !onDeliverySettingChange || deliveryChannels.length === 0) return;
|
|
316
|
+
// Wait until the domains of the current channel set have loaded (a previous, e.g. SMS-only, response has no RCS
|
|
317
|
+
// domains). An unresolved RCS account only skips the RCS channel below; other channels still get their defaults.
|
|
318
|
+
if (!isDomainEntityCurrent) return;
|
|
222
319
|
|
|
223
320
|
// Convert the API entity into the channelSetting shape (e.g. { SMS: { gsmSenderId: '...' } })
|
|
224
|
-
const senderDetailsFromAPI = parseSenderDetailsFromEntity(entityWithWecrmViber,
|
|
321
|
+
const senderDetailsFromAPI = parseSenderDetailsFromEntity(entityWithWecrmViber, accountContext);
|
|
225
322
|
const channelSettingFromAPI = buildChannelSettingFromFieldValues(senderDetailsFromAPI);
|
|
226
323
|
|
|
227
324
|
const savedChannelSetting = deliverySetting?.channelSetting || {};
|
|
@@ -229,6 +326,8 @@ const DeliverySettingsSection = ({
|
|
|
229
326
|
let didChange = false;
|
|
230
327
|
|
|
231
328
|
deliveryChannels.forEach((channel) => {
|
|
329
|
+
// RCS template account still resolving (pending / failed): its sender comes from that account's domain later.
|
|
330
|
+
if (channel === RCS && isRcsAccountResolving) return;
|
|
232
331
|
let apiDataForChannel = channelSettingFromAPI[channel];
|
|
233
332
|
// Show RCS SMS-fallback fields only when fallback content is configured, not merely when SMS is selected.
|
|
234
333
|
if (channel === RCS && !hasRcsSmsFallback && apiDataForChannel) {
|
|
@@ -240,6 +339,26 @@ const DeliverySettingsSection = ({
|
|
|
240
339
|
const apiHasRealSenderId = hasRealData(apiDataForChannel);
|
|
241
340
|
const userAlreadyConfigured = hasRealData(userSavedDataForChannel);
|
|
242
341
|
|
|
342
|
+
// RCS multi-account: a saved RCS sender must belong to the template account's domain. When the account
|
|
343
|
+
// changed (another account's template) or has no domain, re-pick the sender from that account's domain
|
|
344
|
+
// (empty when not configured, which blocks save), keeping the SMS-fallback values.
|
|
345
|
+
if (channel === RCS && userAlreadyConfigured && rcsSourceAccountId) {
|
|
346
|
+
const savedRcsSender = userSavedDataForChannel?.rcsSender || userSavedDataForChannel?.senderMobNum || '';
|
|
347
|
+
const accountRcsSenders = getRcsSenderValuesForAccount(entityWithWecrmViber, rcsSourceAccountId);
|
|
348
|
+
if (!accountRcsSenders.includes(savedRcsSender)) {
|
|
349
|
+
const nextRcsSender = apiDataForChannel?.rcsSender || '';
|
|
350
|
+
if (nextRcsSender !== savedRcsSender) {
|
|
351
|
+
updatedChannelSetting[channel] = {
|
|
352
|
+
...userSavedDataForChannel,
|
|
353
|
+
senderMobNum: nextRcsSender,
|
|
354
|
+
rcsSender: nextRcsSender,
|
|
355
|
+
};
|
|
356
|
+
didChange = true;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
243
362
|
if (apiHasRealSenderId && !userAlreadyConfigured) {
|
|
244
363
|
updatedChannelSetting[channel] = apiDataForChannel;
|
|
245
364
|
didChange = true;
|
|
@@ -248,17 +367,35 @@ const DeliverySettingsSection = ({
|
|
|
248
367
|
|
|
249
368
|
if (!didChange) return;
|
|
250
369
|
onDeliverySettingChange({ ...deliverySetting, channelSetting: updatedChannelSetting });
|
|
251
|
-
}, [entityWithWecrmViber]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
370
|
+
}, [entityWithWecrmViber, rcsSourceAccountId, isRcsAccountResolving, isDomainEntityCurrent]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
371
|
+
|
|
372
|
+
// Saved values for display / the slidebox. RCS multi-account: a saved RCS sender that is not from the template
|
|
373
|
+
// account's domain (template switched to another account) must not override the sender of the new account —
|
|
374
|
+
// it is dropped here so the account's own sender (or none, when not configured) is used. SMS-fallback is kept.
|
|
375
|
+
const savedFieldValuesForAccount = useMemo(() => {
|
|
376
|
+
const fromSaved = parseChannelSettingForDisplay(deliverySetting?.channelSetting);
|
|
377
|
+
if (!rcsSourceAccountId || !entityWithWecrmViber || !fromSaved.rcsSenderNumber) return fromSaved;
|
|
378
|
+
const accountRcsSenders = getRcsSenderValuesForAccount(entityWithWecrmViber, rcsSourceAccountId);
|
|
379
|
+
if (accountRcsSenders.includes(fromSaved.rcsSenderNumber)) return fromSaved;
|
|
380
|
+
const { rcsSenderNumber, ...withoutStaleRcsSender } = fromSaved;
|
|
381
|
+
return withoutStaleRcsSender;
|
|
382
|
+
}, [deliverySetting, rcsSourceAccountId, entityWithWecrmViber]);
|
|
252
383
|
|
|
253
384
|
const parsedSenderDetails = useMemo(() => {
|
|
254
385
|
if (!entityWithWecrmViber) return null;
|
|
255
|
-
const fromEntity = parseSenderDetailsFromEntity(entityWithWecrmViber,
|
|
256
|
-
const fromSaved =
|
|
386
|
+
const fromEntity = parseSenderDetailsFromEntity(entityWithWecrmViber, accountContext);
|
|
387
|
+
const fromSaved = savedFieldValuesForAccount;
|
|
257
388
|
// Derive WhatsApp account name: from entity domain or from content templateData
|
|
258
389
|
const waAccountName = whatsappAccNameFromContent
|
|
259
390
|
|| getWhatsappAccountName(entityWithWecrmViber, whatsappSourceAccountId);
|
|
260
|
-
|
|
261
|
-
|
|
391
|
+
const merged = { ...fromEntity, ...fromSaved, whatsappAccountName: waAccountName || fromEntity.whatsappAccountName };
|
|
392
|
+
// RCS account lookup pending / failed: show no RCS sender (neither the first domain's nor an unverified saved one).
|
|
393
|
+
if (isRcsAccountResolving) {
|
|
394
|
+
merged.rcsSenderNumber = '';
|
|
395
|
+
merged.rcsAccountName = '';
|
|
396
|
+
}
|
|
397
|
+
return merged;
|
|
398
|
+
}, [entityWithWecrmViber, savedFieldValuesForAccount, accountContext, whatsappSourceAccountId, whatsappAccNameFromContent, isRcsAccountResolving]);
|
|
262
399
|
|
|
263
400
|
// Map channel -> { labelKey, valueKey } or array of { labelKey, valueKey } for summary display
|
|
264
401
|
// SMS, RCS, EMAIL, VIBER: Sender ID | WHATSAPP: Sender number | LINE: Account
|
|
@@ -276,14 +413,25 @@ const DeliverySettingsSection = ({
|
|
|
276
413
|
|
|
277
414
|
const handleDeliverySettingSave = useCallback((fieldValues) => {
|
|
278
415
|
if (!onDeliverySettingChange) return;
|
|
416
|
+
const channelSettingFromFields = buildChannelSettingFromFieldValues(fieldValues);
|
|
417
|
+
// RCS account unresolved (pending / failed): the slidebox can only offer another account's (first domain's)
|
|
418
|
+
// sender, so it is never persisted — the saved RCS sender is kept; SMS-fallback edits still apply.
|
|
419
|
+
if (isRcsAccountResolving && channelSettingFromFields[RCS]) {
|
|
420
|
+
const savedRcsSetting = deliverySetting?.channelSetting?.[RCS] || {};
|
|
421
|
+
channelSettingFromFields[RCS] = {
|
|
422
|
+
...channelSettingFromFields[RCS],
|
|
423
|
+
senderMobNum: savedRcsSetting.senderMobNum ?? '',
|
|
424
|
+
rcsSender: savedRcsSetting.rcsSender ?? '',
|
|
425
|
+
};
|
|
426
|
+
}
|
|
279
427
|
onDeliverySettingChange({
|
|
280
428
|
...deliverySetting,
|
|
281
429
|
channelSetting: {
|
|
282
430
|
...(deliverySetting?.channelSetting || {}),
|
|
283
|
-
...
|
|
431
|
+
...channelSettingFromFields,
|
|
284
432
|
},
|
|
285
433
|
});
|
|
286
|
-
}, [onDeliverySettingChange, deliverySetting]);
|
|
434
|
+
}, [onDeliverySettingChange, deliverySetting, isRcsAccountResolving]);
|
|
287
435
|
|
|
288
436
|
if (!deliverySettingsData || !shouldShow) {
|
|
289
437
|
return null;
|
|
@@ -323,6 +471,27 @@ const DeliverySettingsSection = ({
|
|
|
323
471
|
</CapRow>
|
|
324
472
|
));
|
|
325
473
|
})}
|
|
474
|
+
{isRcsAccountLookupFailed && (
|
|
475
|
+
<CapRow useLegacy key="RCS-accountLookupFailed" type="flex" align="middle" className="delivery-settings-section__field-row">
|
|
476
|
+
<CapError type="error" className="delivery-settings-section__error">
|
|
477
|
+
{formatMessage(messages.rcsAccountLookupFailedError)}
|
|
478
|
+
</CapError>
|
|
479
|
+
<CapLink
|
|
480
|
+
type="false"
|
|
481
|
+
fontWeight="m"
|
|
482
|
+
className="delivery-settings-section__retry-link"
|
|
483
|
+
title={formatMessage(messages.retry)}
|
|
484
|
+
onClick={retryRcsAccountLookup}
|
|
485
|
+
/>
|
|
486
|
+
</CapRow>
|
|
487
|
+
)}
|
|
488
|
+
{isRcsAccountNotConfigured && (
|
|
489
|
+
<CapRow useLegacy key="RCS-accountNotConfigured" type="flex" align="middle" className="delivery-settings-section__field-row">
|
|
490
|
+
<CapError type="error" className="delivery-settings-section__error">
|
|
491
|
+
{formatMessage(messages.rcsAccountNotConfiguredError)}
|
|
492
|
+
</CapError>
|
|
493
|
+
</CapRow>
|
|
494
|
+
)}
|
|
326
495
|
{hasRcsSmsFallback && parsedSenderDetails?.rcsSmsFallbackSenderId && (
|
|
327
496
|
<CapRow useLegacy key="RCS-rcsSmsFallbackSenderId" type="flex" align="middle" justify="space-between" className="delivery-settings-section__field-row">
|
|
328
497
|
<CapHeading type="label4" className="delivery-settings-section__label">
|
|
@@ -347,10 +516,14 @@ const DeliverySettingsSection = ({
|
|
|
347
516
|
show={showSlidebox}
|
|
348
517
|
onClose={() => setShowSlidebox(false)}
|
|
349
518
|
channels={senderDetailsChannels}
|
|
350
|
-
|
|
519
|
+
// Only domain data of the current channel set: while a new set is loading the slidebox shows its spinner
|
|
520
|
+
// instead of treating the previous (e.g. SMS-only) response as loaded.
|
|
521
|
+
preloadedDomainProperties={isDomainEntityCurrent ? entityWithWecrmViber : null}
|
|
351
522
|
isLoadingDomainProperties={isFetchingDomains}
|
|
352
|
-
savedFieldValues={
|
|
523
|
+
savedFieldValues={savedFieldValuesForAccount}
|
|
353
524
|
whatsappSourceAccountId={whatsappSourceAccountId}
|
|
525
|
+
rcsSourceAccountId={rcsSourceAccountId}
|
|
526
|
+
isRcsAccountPending={isRcsAccountResolving}
|
|
354
527
|
whatsappAccountName={whatsappAccNameFromContent || getWhatsappAccountName(entityWithWecrmViber, whatsappSourceAccountId)}
|
|
355
528
|
onSave={handleDeliverySettingSave}
|
|
356
529
|
/>
|
|
@@ -365,6 +538,8 @@ DeliverySettingsSection.propTypes = {
|
|
|
365
538
|
deliverySetting: PropTypes.object,
|
|
366
539
|
onDeliverySettingChange: PropTypes.func,
|
|
367
540
|
onDomainPropertiesLoaded: PropTypes.func,
|
|
541
|
+
/** Called with true while the RCS template's account lookup is pending / failed (Save must be blocked). */
|
|
542
|
+
onRcsAccountPendingChange: PropTypes.func,
|
|
368
543
|
orgUnitId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
369
544
|
// Consumer opt-in (config.context.domainPropertiesPriority) — switches to domainPropertiesByPriority.
|
|
370
545
|
domainPropertiesPriority: PropTypes.string,
|
|
@@ -376,6 +551,7 @@ DeliverySettingsSection.defaultProps = {
|
|
|
376
551
|
deliverySettingsData: null,
|
|
377
552
|
deliverySetting: null,
|
|
378
553
|
onDeliverySettingChange: null,
|
|
554
|
+
onRcsAccountPendingChange: null,
|
|
379
555
|
orgUnitId: undefined,
|
|
380
556
|
domainPropertiesPriority: undefined,
|
|
381
557
|
};
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
getRcsAccountName,
|
|
32
32
|
getEmailDomainGatewayMapIdByDomainId,
|
|
33
33
|
getRcsSmsFallbackDefaultDomain,
|
|
34
|
+
isRcsAccountNotConfiguredForEntity,
|
|
34
35
|
} from './deliverySettingsConfig';
|
|
35
36
|
import messages from '../../messages';
|
|
36
37
|
import './SenderDetails.scss';
|
|
@@ -47,6 +48,8 @@ const SenderDetails = ({
|
|
|
47
48
|
savedFieldValues,
|
|
48
49
|
onSave,
|
|
49
50
|
whatsappSourceAccountId,
|
|
51
|
+
rcsSourceAccountId,
|
|
52
|
+
isRcsAccountPending,
|
|
50
53
|
whatsappAccountName,
|
|
51
54
|
intl,
|
|
52
55
|
}) => {
|
|
@@ -64,7 +67,8 @@ const SenderDetails = ({
|
|
|
64
67
|
// Context for WABA-bound fields (WhatsApp sender number filtered by sourceAccountIdentifier)
|
|
65
68
|
const wabaContext = useMemo(() => ({
|
|
66
69
|
whatsappSourceAccountId: whatsappSourceAccountId || '',
|
|
67
|
-
|
|
70
|
+
rcsSourceAccountId: rcsSourceAccountId || '',
|
|
71
|
+
}), [whatsappSourceAccountId, rcsSourceAccountId]);
|
|
68
72
|
|
|
69
73
|
// Only use preloaded data from parent (DeliverySettingsSection) - no fetch here to avoid duplicate API calls
|
|
70
74
|
// When reopening, use savedFieldValues to restore user's last saved selections
|
|
@@ -82,8 +86,9 @@ const SenderDetails = ({
|
|
|
82
86
|
if (whatsappAccountName) {
|
|
83
87
|
initial.whatsappAccount = whatsappAccountName;
|
|
84
88
|
}
|
|
85
|
-
// Set RCS account name (disabled field)
|
|
86
|
-
|
|
89
|
+
// Set RCS account name (disabled field). Hidden while the template's RCS account is unresolved (lookup
|
|
90
|
+
// pending / failed): the first domain's name could belong to another account.
|
|
91
|
+
const rcsAccName = isRcsAccountPending ? '' : getRcsAccountName(preloadedDomainProperties, rcsSourceAccountId);
|
|
87
92
|
if (rcsAccName) {
|
|
88
93
|
initial.rcsAccount = rcsAccName;
|
|
89
94
|
}
|
|
@@ -100,7 +105,7 @@ const SenderDetails = ({
|
|
|
100
105
|
setFieldValues({});
|
|
101
106
|
setInitialFieldValues({});
|
|
102
107
|
}
|
|
103
|
-
}, [show, channels, preloadedDomainProperties, isLoadingDomainProperties, savedFieldValues, fieldConfigs, whatsappAccountName, wabaContext]);
|
|
108
|
+
}, [show, channels, preloadedDomainProperties, isLoadingDomainProperties, savedFieldValues, fieldConfigs, whatsappAccountName, wabaContext, isRcsAccountPending]);
|
|
104
109
|
|
|
105
110
|
const handleFieldChange = useCallback((fieldKey, value) => {
|
|
106
111
|
setFieldValues((prev) => {
|
|
@@ -213,6 +218,28 @@ const SenderDetails = ({
|
|
|
213
218
|
const optionContext = { fieldValues, ...wabaContext };
|
|
214
219
|
const options = entity && getOptions ? (getOptions(entity, optionContext) || []) : [];
|
|
215
220
|
|
|
221
|
+
// RCS account with no domain of its own: show the account as not configured (no other account's sender)
|
|
222
|
+
if (fieldKey === 'rcsAccount' && isRcsAccountNotConfiguredForEntity(entity, rcsSourceAccountId)) {
|
|
223
|
+
return (
|
|
224
|
+
<CapRow useLegacy key={fieldKey} className="sender-details__field">
|
|
225
|
+
<CapHeading type="h4">{formatMessage(messages[messageKey] || { defaultMessage: messageKey })}</CapHeading>
|
|
226
|
+
<CapRow useLegacy type="flex" align="middle" className="sender-details__field-row">
|
|
227
|
+
<CapSelect
|
|
228
|
+
value=""
|
|
229
|
+
placeholder={formatMessage(messages.select)}
|
|
230
|
+
className="sender-details__select"
|
|
231
|
+
options={[]}
|
|
232
|
+
style={{ width: '20.375rem' }}
|
|
233
|
+
disabled
|
|
234
|
+
/>
|
|
235
|
+
</CapRow>
|
|
236
|
+
<CapError type="error" className="sender-details__field-error">
|
|
237
|
+
{formatMessage(messages.rcsAccountNotConfiguredError)}
|
|
238
|
+
</CapError>
|
|
239
|
+
</CapRow>
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
216
243
|
// WhatsApp/RCS account: disabled field showing account name, build options from value
|
|
217
244
|
if (isDisabled && (fieldKey === 'whatsappAccount' || fieldKey === 'rcsAccount') && value) {
|
|
218
245
|
const accountOptions = [{ label: value, value }];
|
|
@@ -322,6 +349,10 @@ SenderDetails.propTypes = {
|
|
|
322
349
|
savedFieldValues: PropTypes.object,
|
|
323
350
|
onSave: PropTypes.func,
|
|
324
351
|
whatsappSourceAccountId: PropTypes.string,
|
|
352
|
+
/** RCS multi-account: template account's sourceAccountIdentifier; binds RCS fields to its domain. */
|
|
353
|
+
rcsSourceAccountId: PropTypes.string,
|
|
354
|
+
/** RCS template account still unresolved (lookup pending / failed): the RCS account name is not shown. */
|
|
355
|
+
isRcsAccountPending: PropTypes.bool,
|
|
325
356
|
whatsappAccountName: PropTypes.string,
|
|
326
357
|
intl: PropTypes.object.isRequired,
|
|
327
358
|
};
|
|
@@ -333,6 +364,8 @@ SenderDetails.defaultProps = {
|
|
|
333
364
|
savedFieldValues: null,
|
|
334
365
|
onSave: null,
|
|
335
366
|
whatsappSourceAccountId: '',
|
|
367
|
+
rcsSourceAccountId: '',
|
|
368
|
+
isRcsAccountPending: false,
|
|
336
369
|
whatsappAccountName: '',
|
|
337
370
|
};
|
|
338
371
|
|