@capillarytech/creatives-library 8.0.345-alpha.16 → 8.0.345-alpha.17
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/constants/unified.js +29 -0
- package/package.json +1 -1
- package/services/tests/api.test.js +13 -0
- package/utils/commonUtils.js +19 -1
- package/utils/rcsPayloadUtils.js +92 -0
- package/utils/templateVarUtils.js +201 -0
- package/utils/tests/rcsPayloadUtils.test.js +226 -0
- package/utils/tests/templateVarUtils.test.js +204 -0
- package/v2Components/CapActionButton/constants.js +7 -0
- package/v2Components/CapActionButton/index.js +167 -109
- package/v2Components/CapActionButton/index.scss +157 -6
- package/v2Components/CapActionButton/messages.js +19 -3
- package/v2Components/CapActionButton/tests/index.test.js +41 -17
- package/v2Components/CapTagList/index.js +10 -0
- package/v2Components/CommonTestAndPreview/CustomValuesEditor.js +70 -49
- package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +8 -2
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +207 -21
- package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +16 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +85 -10
- package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +30 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +79 -11
- package/v2Components/CommonTestAndPreview/SendTestMessage.js +10 -5
- package/v2Components/CommonTestAndPreview/UnifiedPreview/RcsPreviewContent.js +160 -15
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +341 -76
- package/v2Components/CommonTestAndPreview/UnifiedPreview/index.js +133 -4
- package/v2Components/CommonTestAndPreview/_commonTestAndPreview.scss +11 -0
- package/v2Components/CommonTestAndPreview/constants.js +38 -2
- package/v2Components/CommonTestAndPreview/index.js +676 -186
- package/v2Components/CommonTestAndPreview/messages.js +45 -3
- package/v2Components/CommonTestAndPreview/previewApiUtils.js +59 -0
- package/v2Components/CommonTestAndPreview/sagas.js +15 -6
- package/v2Components/CommonTestAndPreview/tests/CustomValuesEditor.test.js +308 -284
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +231 -65
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +118 -5
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +341 -0
- package/v2Components/CommonTestAndPreview/tests/PreviewSection.test.js +8 -1
- package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +34 -13
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/RcsPreviewContent.test.js +281 -283
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/index.test.js +199 -1
- package/v2Components/CommonTestAndPreview/tests/index.test.js +132 -4
- package/v2Components/CommonTestAndPreview/tests/previewApiUtils.test.js +67 -0
- package/v2Components/CommonTestAndPreview/tests/sagas.test.js +2 -2
- package/v2Components/FormBuilder/index.js +8 -10
- package/v2Components/SmsFallback/SmsFallbackLocalSelector.js +87 -0
- package/v2Components/SmsFallback/constants.js +73 -0
- package/v2Components/SmsFallback/index.js +955 -0
- package/v2Components/SmsFallback/index.scss +265 -0
- package/v2Components/SmsFallback/messages.js +78 -0
- package/v2Components/SmsFallback/smsFallbackUtils.js +118 -0
- package/v2Components/SmsFallback/tests/SmsFallbackLocalSelector.test.js +50 -0
- package/v2Components/SmsFallback/tests/rcsSmsFallback.acceptance.test.js +147 -0
- package/v2Components/SmsFallback/tests/smsFallbackHandlers.test.js +304 -0
- package/v2Components/SmsFallback/tests/smsFallbackUi.test.js +197 -0
- package/v2Components/SmsFallback/tests/smsFallbackUtils.test.js +277 -0
- package/v2Components/SmsFallback/tests/useLocalTemplateList.test.js +422 -0
- package/v2Components/SmsFallback/useLocalTemplateList.js +92 -0
- package/v2Components/TemplatePreview/_templatePreview.scss +33 -23
- package/v2Components/TemplatePreview/constants.js +2 -0
- package/v2Components/TemplatePreview/index.js +143 -28
- package/v2Components/TemplatePreview/tests/index.test.js +142 -0
- package/v2Components/TestAndPreviewSlidebox/index.js +13 -1
- package/v2Components/TestAndPreviewSlidebox/sagas.js +11 -4
- package/v2Components/TestAndPreviewSlidebox/tests/saga.test.js +3 -1
- package/v2Components/VarSegmentMessageEditor/constants.js +2 -0
- package/v2Components/VarSegmentMessageEditor/index.js +125 -0
- package/v2Components/VarSegmentMessageEditor/index.scss +46 -0
- package/v2Containers/CreativesContainer/CreativesSlideBoxWrapper.js +43 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +36 -4
- package/v2Containers/CreativesContainer/SlideBoxFooter.js +10 -1
- package/v2Containers/CreativesContainer/SlideBoxHeader.js +29 -4
- package/v2Containers/CreativesContainer/constants.js +9 -0
- package/v2Containers/CreativesContainer/embeddedSlideboxUtils.js +67 -0
- package/v2Containers/CreativesContainer/index.js +294 -96
- package/v2Containers/CreativesContainer/index.scss +51 -1
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.localTemplates.test.js +90 -0
- package/v2Containers/CreativesContainer/tests/SlideBoxFooter.test.js +78 -34
- package/v2Containers/CreativesContainer/tests/SlideBoxHeader.test.js +79 -16
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +8 -0
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxHeader.test.js.snap +357 -98
- package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +20 -15
- package/v2Containers/CreativesContainer/tests/embeddedSlideboxUtils.test.js +258 -0
- package/v2Containers/CreativesContainer/tests/index.test.js +71 -9
- package/v2Containers/CreativesContainer/tests/useLocalTemplatesProp.test.js +125 -0
- package/v2Containers/Email/reducer.js +3 -12
- package/v2Containers/Email/sagas.js +4 -9
- package/v2Containers/Email/tests/__snapshots__/reducer.test.js.snap +0 -4
- package/v2Containers/Email/tests/reducer.test.js +0 -47
- package/v2Containers/Email/tests/sagas.test.js +6 -146
- package/v2Containers/Rcs/constants.js +119 -10
- package/v2Containers/Rcs/index.js +2456 -815
- package/v2Containers/Rcs/index.scss +276 -6
- package/v2Containers/Rcs/messages.js +34 -3
- package/v2Containers/Rcs/rcsLibraryHydrationUtils.js +225 -0
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +98018 -70073
- package/v2Containers/Rcs/tests/__snapshots__/utils.test.js.snap +0 -5
- package/v2Containers/Rcs/tests/index.test.js +152 -121
- package/v2Containers/Rcs/tests/mockData.js +38 -0
- package/v2Containers/Rcs/tests/rcsLibraryHydrationUtils.test.js +318 -0
- package/v2Containers/Rcs/tests/utils.test.js +646 -30
- package/v2Containers/Rcs/utils.js +478 -11
- package/v2Containers/Sms/Create/index.js +100 -40
- package/v2Containers/Sms/smsFormDataHelpers.js +67 -0
- package/v2Containers/Sms/tests/smsFormDataHelpers.test.js +253 -0
- package/v2Containers/SmsTrai/Create/index.js +9 -4
- package/v2Containers/SmsTrai/Edit/constants.js +2 -0
- package/v2Containers/SmsTrai/Edit/index.js +636 -130
- package/v2Containers/SmsTrai/Edit/index.scss +121 -0
- package/v2Containers/SmsTrai/Edit/messages.js +14 -4
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +4328 -2375
- package/v2Containers/SmsWrapper/index.js +37 -8
- package/v2Containers/TagList/index.js +6 -0
- package/v2Containers/Templates/TemplatesActionBar.js +101 -0
- package/v2Containers/Templates/_templates.scss +163 -2
- package/v2Containers/Templates/actions.js +11 -0
- package/v2Containers/Templates/constants.js +2 -0
- package/v2Containers/Templates/index.js +119 -54
- package/v2Containers/Templates/sagas.js +57 -12
- package/v2Containers/Templates/tests/TemplatesActionBar.test.js +120 -0
- package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1043 -1079
- package/v2Containers/Templates/tests/sagas.test.js +193 -123
- package/v2Containers/Templates/tests/smsTemplatesListApi.test.js +180 -0
- package/v2Containers/Templates/utils/smsTemplatesListApi.js +79 -0
- package/v2Containers/TemplatesV2/TemplatesV2.style.js +72 -1
- package/v2Containers/TemplatesV2/index.js +86 -23
- package/v2Containers/TemplatesV2/tests/TemplatesV2.localTemplates.test.js +131 -0
- package/v2Containers/Whatsapp/index.js +3 -20
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +578 -34
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/* eslint-disable no-unused-expressions */
|
|
2
|
-
import React, { useState, useEffect, useCallback } from 'react';
|
|
2
|
+
import React, { useState, useEffect, useCallback, useRef, useMemo } from 'react';
|
|
3
3
|
import { bindActionCreators } from 'redux';
|
|
4
4
|
import { createStructuredSelector } from 'reselect';
|
|
5
|
-
import {
|
|
5
|
+
import { FormattedMessage } from 'react-intl';
|
|
6
6
|
import get from 'lodash/get';
|
|
7
7
|
import isEmpty from 'lodash/isEmpty';
|
|
8
8
|
import cloneDeep from 'lodash/cloneDeep';
|
|
9
9
|
import isNil from 'lodash/isNil';
|
|
10
|
-
import styled from 'styled-components';
|
|
11
10
|
import CapSpin from '@capillarytech/cap-ui-library/CapSpin';
|
|
12
11
|
import CapRow from '@capillarytech/cap-ui-library/CapRow';
|
|
13
12
|
import CapColumn from '@capillarytech/cap-ui-library/CapColumn';
|
|
@@ -34,6 +33,14 @@ import CapError from '@capillarytech/cap-ui-library/CapError';
|
|
|
34
33
|
import CapCheckbox from '@capillarytech/cap-ui-library/CapCheckbox';
|
|
35
34
|
import CapAskAira from '@capillarytech/cap-ui-library/CapAskAira';
|
|
36
35
|
import CapLink from '@capillarytech/cap-ui-library/CapLink';
|
|
36
|
+
import CapTab from '@capillarytech/cap-ui-library/CapTab';
|
|
37
|
+
import { flushSync } from 'react-dom';
|
|
38
|
+
import { isUrl, isValidText } from '../Line/Container/Wrapper/utils';
|
|
39
|
+
import {
|
|
40
|
+
invalidVarRegex,
|
|
41
|
+
RCS_CTA_URL_TYPE,
|
|
42
|
+
URL_MAX_LENGTH,
|
|
43
|
+
} from '../../v2Components/CapActionButton/constants';
|
|
37
44
|
|
|
38
45
|
import {
|
|
39
46
|
CAP_G01,
|
|
@@ -49,17 +56,30 @@ import {
|
|
|
49
56
|
import CapVideoUpload from '../../v2Components/CapVideoUpload';
|
|
50
57
|
import * as globalActions from '../Cap/actions';
|
|
51
58
|
import CapActionButton from '../../v2Components/CapActionButton';
|
|
59
|
+
import TemplatePreview from '../../v2Components/TemplatePreview';
|
|
52
60
|
import { makeSelectRcs, makeSelectAccount } from './selectors';
|
|
53
61
|
import { DATE_DISPLAY_FORMAT, TIME_DISPLAY_FORMAT } from '../App/constants';
|
|
54
62
|
import {
|
|
55
63
|
isLoadingMetaEntities,
|
|
56
64
|
makeSelectMetaEntities,
|
|
57
65
|
setInjectedTags,
|
|
66
|
+
selectCurrentOrgDetails,
|
|
58
67
|
} from '../Cap/selectors';
|
|
59
68
|
import * as RcsActions from './actions';
|
|
60
69
|
import { isAiContentBotDisabled } from '../../utils/common';
|
|
61
70
|
import * as TemplatesActions from '../Templates/actions';
|
|
62
71
|
import './index.scss';
|
|
72
|
+
import {
|
|
73
|
+
normalizeLibraryLoadedTitleDesc,
|
|
74
|
+
mergeRcsSmsFallBackContentFromDetails,
|
|
75
|
+
mergeRcsSmsFallbackVarMapLayers,
|
|
76
|
+
extractRegisteredSenderIdsFromSmsFallbackRecord,
|
|
77
|
+
pickFirstSmsFallbackTemplateString,
|
|
78
|
+
syncCardVarMappedSemanticsFromSlots,
|
|
79
|
+
hasMeaningfulSmsFallbackShape,
|
|
80
|
+
getLibrarySmsFallbackApiBaselineFromTemplateData,
|
|
81
|
+
pickRcsCardVarMappedEntries,
|
|
82
|
+
} from './rcsLibraryHydrationUtils';
|
|
63
83
|
import {
|
|
64
84
|
RCS,
|
|
65
85
|
SMS,
|
|
@@ -76,6 +96,7 @@ import {
|
|
|
76
96
|
RCS_IMG_SIZE,
|
|
77
97
|
RCS_DLT_MODE,
|
|
78
98
|
CTA,
|
|
99
|
+
AI_CONTENT_BOT_DISABLED,
|
|
79
100
|
RCS_STATUSES,
|
|
80
101
|
TITLE_TEXT,
|
|
81
102
|
MESSAGE_TEXT,
|
|
@@ -90,9 +111,15 @@ import {
|
|
|
90
111
|
rcsVarTestRegex,
|
|
91
112
|
RCS_IMAGE_DIMENSIONS,
|
|
92
113
|
RCS_TEXT_MESSAGE_MAX_LENGTH,
|
|
114
|
+
RCS_TEXT_MESSAGE_MAX_LENGTH_INFOBIP,
|
|
93
115
|
RCS_RICH_CARD_MAX_LENGTH,
|
|
94
116
|
RCS_VIDEO_THUMBNAIL_DIMENSIONS,
|
|
117
|
+
RCS_CAROUSEL_IMAGE_DIMENSIONS,
|
|
118
|
+
RCS_CAROUSEL_VIDEO_THUMBNAIL_DIMENSIONS,
|
|
119
|
+
RCS_CAROUSEL_IMG_SIZE,
|
|
120
|
+
RCS_CAROUSEL_VIDEO_SIZE,
|
|
95
121
|
MAX_BUTTONS,
|
|
122
|
+
INITIAL_SUGGESTIONS,
|
|
96
123
|
INITIAL_SUGGESTIONS_DATA_STOP,
|
|
97
124
|
RCS_BUTTON_TYPES,
|
|
98
125
|
titletype,
|
|
@@ -102,25 +129,47 @@ import {
|
|
|
102
129
|
SMALL,
|
|
103
130
|
MEDIUM,
|
|
104
131
|
RICHCARD,
|
|
132
|
+
HOST_INFOBIP,
|
|
133
|
+
HOST_ICS,
|
|
134
|
+
CAROUSEL_HEIGHT_OPTIONS,
|
|
135
|
+
CAROUSEL_WIDTH_OPTIONS,
|
|
136
|
+
STOP,
|
|
137
|
+
RCS_CAROUSEL_FIRST_CARD_DEFAULT_SUGGESTIONS,
|
|
138
|
+
RCS_NUMERIC_VAR_NAME_REGEX,
|
|
139
|
+
RCS_NUMERIC_VAR_TOKEN_REGEX,
|
|
140
|
+
RCS_TAG_AREA_FIELD_TITLE,
|
|
141
|
+
RCS_TAG_AREA_FIELD_DESC,
|
|
105
142
|
} from './constants';
|
|
106
143
|
import globalMessages from '../Cap/messages';
|
|
107
144
|
import messages from './messages';
|
|
108
145
|
import creativesMessages from '../CreativesContainer/messages';
|
|
109
146
|
import withCreatives from '../../hoc/withCreatives';
|
|
110
147
|
import UnifiedPreview from '../../v2Components/CommonTestAndPreview/UnifiedPreview';
|
|
111
|
-
import
|
|
148
|
+
import VarSegmentMessageEditor from '../../v2Components/VarSegmentMessageEditor';
|
|
149
|
+
import { ANDROID, RCS_SMS_FALLBACK_VAR_MAPPED_PROP } from '../../v2Components/CommonTestAndPreview/constants';
|
|
112
150
|
import TestAndPreviewSlidebox from '../../v2Components/TestAndPreviewSlidebox';
|
|
151
|
+
import { splitTemplateVarString } from '../../utils/templateVarUtils';
|
|
113
152
|
import CapImageUpload from '../../v2Components/CapImageUpload';
|
|
114
|
-
import addCreativesIcon from '../Assets/images/addCreativesIllustration.svg';
|
|
115
153
|
import Templates from '../Templates';
|
|
116
154
|
import SmsTraiEdit from '../SmsTrai/Edit';
|
|
155
|
+
import SmsFallback from '../../v2Components/SmsFallback';
|
|
156
|
+
import { CHANNELS_TO_HIDE_FOR_SMS_ONLY } from '../../v2Components/SmsFallback/constants';
|
|
117
157
|
import TagList from '../TagList';
|
|
118
158
|
import { validateTags } from '../../utils/tagValidations';
|
|
119
|
-
import {
|
|
159
|
+
import { isTraiDLTEnable } from '../../utils/common';
|
|
120
160
|
import { isTagIncluded } from '../../utils/commonUtils';
|
|
121
161
|
import injectReducer from '../../utils/injectReducer';
|
|
122
162
|
import v2RcsReducer from './reducer';
|
|
123
|
-
import {
|
|
163
|
+
import {
|
|
164
|
+
areAllRcsSmsFallbackVarSlotsFilled,
|
|
165
|
+
buildRcsNumericMustachePlaceholderRegex,
|
|
166
|
+
getTemplateStatusType,
|
|
167
|
+
normalizeCardVarMapped,
|
|
168
|
+
coalesceCardVarMappedToTemplate,
|
|
169
|
+
getRcsSemanticVarNamesSpanningTitleAndDesc,
|
|
170
|
+
resolveCardVarMappedSlotValue,
|
|
171
|
+
sanitizeCardVarMappedValue,
|
|
172
|
+
} from './utils';
|
|
124
173
|
|
|
125
174
|
|
|
126
175
|
const { Group: CapCheckboxGroup } = CapCheckbox;
|
|
@@ -137,19 +186,18 @@ export const Rcs = (props) => {
|
|
|
137
186
|
templatesActions,
|
|
138
187
|
globalActions,
|
|
139
188
|
location,
|
|
140
|
-
handleClose,
|
|
141
189
|
getDefaultTags,
|
|
142
190
|
supportedTags,
|
|
143
191
|
metaEntities,
|
|
144
192
|
injectedTags,
|
|
145
193
|
loadingTags,
|
|
146
194
|
getFormData,
|
|
147
|
-
isDltEnabled,
|
|
148
195
|
smsRegister,
|
|
196
|
+
orgUnitId,
|
|
149
197
|
selectedOfferDetails,
|
|
150
198
|
eventContextTags,
|
|
151
|
-
waitEventContextTags,
|
|
152
199
|
accountData = {},
|
|
200
|
+
currentOrgDetails,
|
|
153
201
|
// TestAndPreviewSlidebox props
|
|
154
202
|
showTestAndPreviewSlidebox: propsShowTestAndPreviewSlidebox,
|
|
155
203
|
handleTestAndPreview: propsHandleTestAndPreview,
|
|
@@ -158,7 +206,25 @@ export const Rcs = (props) => {
|
|
|
158
206
|
const { formatMessage } = intl;
|
|
159
207
|
const { TextArea } = CapInput;
|
|
160
208
|
const { CapCustomCardList } = CapCustomCard;
|
|
209
|
+
|
|
210
|
+
// Defensive: React cannot render plain objects as children (crashes with
|
|
211
|
+
// "Objects are not valid as a React child"). Some campaigns (!isFullMode) flows
|
|
212
|
+
// can accidentally set an error state to an object (e.g. `{}`).
|
|
213
|
+
const normalizeErrorMessage = (err) => {
|
|
214
|
+
if (!err) return '';
|
|
215
|
+
if (React.isValidElement(err)) return err;
|
|
216
|
+
if (typeof err === 'string') return err;
|
|
217
|
+
if (typeof err === 'number') return String(err);
|
|
218
|
+
if (typeof err === 'object' && typeof err.message === 'string') return err.message;
|
|
219
|
+
try {
|
|
220
|
+
return JSON.stringify(err);
|
|
221
|
+
} catch (e) {
|
|
222
|
+
return String(err);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
161
226
|
const [isEditFlow, setEditFlow] = useState(false);
|
|
227
|
+
const isEditLike = isEditFlow || !isFullMode;
|
|
162
228
|
const [tags, updateTags] = useState([]);
|
|
163
229
|
const [spin, setSpin] = useState(false);
|
|
164
230
|
//template
|
|
@@ -167,33 +233,21 @@ export const Rcs = (props) => {
|
|
|
167
233
|
const [templateMediaType, setTemplateMediaType] = useState(
|
|
168
234
|
RCS_MEDIA_TYPES.NONE,
|
|
169
235
|
);
|
|
170
|
-
const [templateRejectionReason, setTemplateRejectionReason] = useState(null);
|
|
171
236
|
const [templateTitle, setTemplateTitle] = useState('');
|
|
172
237
|
const [templateDesc, setTemplateDesc] = useState('');
|
|
173
238
|
const [templateDescError, setTemplateDescError] = useState(false);
|
|
174
239
|
const [templateStatus, setTemplateStatus] = useState('');
|
|
175
|
-
const [templateDate, setTemplateDate] = useState('');
|
|
176
|
-
//fallback
|
|
177
|
-
const [fallbackMessage, setFallbackMessage] = useState('');
|
|
178
|
-
const [fallbackMessageError, setFallbackMessageError] = useState(false);
|
|
179
240
|
//fallback dlt
|
|
180
241
|
const [showDltContainer, setShowDltContainer] = useState(false);
|
|
181
242
|
const [dltMode, setDltMode] = useState('');
|
|
182
243
|
const [dltEditData, setDltEditData] = useState({});
|
|
183
|
-
|
|
184
|
-
const [
|
|
185
|
-
const [dltPreviewData, setDltPreviewData] = useState('');
|
|
244
|
+
/** `undefined` = not hydrated yet; `null` = no fallback / user removed template; object = selected fallback */
|
|
245
|
+
const [smsFallbackData, setSmsFallbackData] = useState(undefined);
|
|
186
246
|
const [suggestions, setSuggestions] = useState(INITIAL_SUGGESTIONS_DATA_STOP);
|
|
187
|
-
const
|
|
247
|
+
const buttonType = RCS_BUTTON_TYPES.NONE;
|
|
188
248
|
const [suggestionError, setSuggestionError] = useState(true);
|
|
249
|
+
const [isTestAndPreviewMode, setIsTestAndPreviewMode] = useState(false);
|
|
189
250
|
const [templateType, setTemplateType] = useState('text_message');
|
|
190
|
-
const [templateHeader, setTemplateHeader] = useState('');
|
|
191
|
-
const [templateMessage, setTemplateMessage] = useState('');
|
|
192
|
-
const [templateHeaderError, setTemplateHeaderError] = useState('');
|
|
193
|
-
const [templateMessageError, setTemplateMessageError] = useState('');
|
|
194
|
-
const validVarRegex = /\{\{(\d+)\}\}/g;
|
|
195
|
-
const [updatedTitleData, setUpdatedTitleData] = useState([]);
|
|
196
|
-
const [updatedDescData, setUpdatedDescData] = useState([]);
|
|
197
251
|
const [titleVarMappedData, setTitleVarMappedData] = useState({});
|
|
198
252
|
const [descVarMappedData, setDescVarMappedData] = useState({});
|
|
199
253
|
const [titleTextAreaId, setTitleTextAreaId] = useState();
|
|
@@ -204,75 +258,58 @@ export const Rcs = (props) => {
|
|
|
204
258
|
const [rcsVideoSrc, setRcsVideoSrc] = useState({});
|
|
205
259
|
const [rcsThumbnailSrc, setRcsThumbnailSrc] = useState('');
|
|
206
260
|
const [selectedDimension, setSelectedDimension] = useState(RCS_IMAGE_DIMENSIONS.MEDIUM_HEIGHT.type);
|
|
207
|
-
|
|
261
|
+
// Carousel (UI-only) state
|
|
262
|
+
const [selectedCarousel, setSelectedCarousel] = useState('');
|
|
263
|
+
const [selectedCarouselHeight, setSelectedCarouselHeight] = useState(MEDIUM);
|
|
264
|
+
const [selectedCarouselWidth, setSelectedCarouselWidth] = useState(SMALL);
|
|
265
|
+
const [carouselData, setCarouselData] = useState([]);
|
|
266
|
+
const [carouselErrors, setCarouselErrors] = useState([]); // [{ title: string|false, description: string|false }]
|
|
267
|
+
const [activeCarouselIndex, setActiveCarouselIndex] = useState('0');
|
|
268
|
+
const [carouselResetNonce, setCarouselResetNonce] = useState(0);
|
|
269
|
+
const [carouselFocusedVarId, setCarouselFocusedVarId] = useState('');
|
|
270
|
+
const [imageError, setImageError] = useState(null);
|
|
208
271
|
const [templateTitleError, setTemplateTitleError] = useState(false);
|
|
209
272
|
const [cardVarMapped, setCardVarMapped] = useState({});
|
|
273
|
+
/** Bump when hydrated cardVarMapped payload changes so VarSegment TextAreas remount with fresh valueMap (controlled-input sync). */
|
|
274
|
+
const [rcsVarSegmentEditorRemountKey, setRcsVarSegmentEditorRemountKey] = useState(0);
|
|
275
|
+
const lastHydratedRcsCardVarSignatureRef = useRef(null);
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Hydrate only from template payload — not from full `rcsData`. Uploads/asset updates change `rcsData`
|
|
279
|
+
* without changing `templateDetails`; re-running hydration then cleared `smsFallbackData`, so the SMS
|
|
280
|
+
* fallback card / content stopped appearing until re-selected.
|
|
281
|
+
*/
|
|
282
|
+
const rcsHydrationDetails = useMemo(
|
|
283
|
+
() => (isFullMode ? rcsData?.templateDetails : templateData),
|
|
284
|
+
[isFullMode, rcsData?.templateDetails, templateData],
|
|
285
|
+
);
|
|
210
286
|
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const isMediaTypeVideo = templateMediaType === RCS_MEDIA_TYPES.VIDEO;
|
|
225
|
-
const isMediaTypeText = templateMediaType === RCS_MEDIA_TYPES.NONE;
|
|
226
|
-
|
|
227
|
-
// Build media preview object (same pattern as getRcsPreview)
|
|
228
|
-
const mediaPreview = {};
|
|
229
|
-
if (isMediaTypeImage && rcsImageSrc) {
|
|
230
|
-
mediaPreview.rcsImageSrc = rcsImageSrc;
|
|
231
|
-
}
|
|
232
|
-
if (isMediaTypeVideo && !isMediaTypeText) {
|
|
233
|
-
// For video, use thumbnailSrc as rcsVideoSrc (same as getRcsPreview line 2104)
|
|
234
|
-
if (rcsThumbnailSrc) {
|
|
235
|
-
mediaPreview.rcsVideoSrc = rcsThumbnailSrc;
|
|
236
|
-
} else if (rcsVideoSrc?.videoSrc) {
|
|
237
|
-
mediaPreview.rcsVideoSrc = rcsVideoSrc.videoSrc;
|
|
238
|
-
}
|
|
239
|
-
// Also include thumbnailSrc separately if available
|
|
240
|
-
if (rcsThumbnailSrc) {
|
|
241
|
-
mediaPreview.rcsThumbnailSrc = rcsThumbnailSrc;
|
|
287
|
+
/** Skip duplicate /meta/TAG fetches: same query is triggered from (1) useEffect below, (2) title TagList mount, (3) description TagList mount — each calls getTagsforContext('Outbound'). */
|
|
288
|
+
const lastTagSchemaQueryKeyRef = useRef(null);
|
|
289
|
+
/**
|
|
290
|
+
* Library: parent often passes a new `templateData` object reference every render. Re-applying the same
|
|
291
|
+
* SMS fallback snapshot was resetting `smsFallbackData` and caused VarSegment inputs to flicker old/new.
|
|
292
|
+
*/
|
|
293
|
+
const lastSmsFallbackHydrationKeyRef = useRef(null);
|
|
294
|
+
|
|
295
|
+
const fetchTagSchemaIfNewQuery = useCallback(
|
|
296
|
+
(query) => {
|
|
297
|
+
const key = JSON.stringify(query);
|
|
298
|
+
if (lastTagSchemaQueryKeyRef.current === key) {
|
|
299
|
+
return;
|
|
242
300
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
// templateDesc is used for ALL types (text message body or rich card description)
|
|
249
|
-
// For UnifiedPreview, we map templateTitle -> templateHeader and templateDesc -> templateMessage
|
|
250
|
-
const contentObj = {
|
|
251
|
-
// Map templateTitle to templateHeader and templateDesc to templateMessage
|
|
252
|
-
templateHeader: templateTitle,
|
|
253
|
-
templateMessage: templateDesc,
|
|
254
|
-
...mediaPreview,
|
|
255
|
-
...(suggestions.length > 0 && {
|
|
256
|
-
suggestions: suggestions,
|
|
257
|
-
}),
|
|
258
|
-
};
|
|
301
|
+
lastTagSchemaQueryKeyRef.current = key;
|
|
302
|
+
globalActions.fetchSchemaForEntity(query);
|
|
303
|
+
},
|
|
304
|
+
[globalActions],
|
|
305
|
+
);
|
|
259
306
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
templateMediaType,
|
|
263
|
-
templateTitle,
|
|
264
|
-
templateDesc,
|
|
265
|
-
rcsImageSrc,
|
|
266
|
-
rcsVideoSrc,
|
|
267
|
-
rcsThumbnailSrc,
|
|
268
|
-
suggestions,
|
|
269
|
-
selectedDimension,
|
|
270
|
-
]);
|
|
307
|
+
// TestAndPreviewSlidebox state
|
|
308
|
+
const [showTestAndPreviewSlidebox, setShowTestAndPreviewSlidebox] = useState(false);
|
|
271
309
|
|
|
272
310
|
// Handle Test and Preview button click
|
|
273
311
|
const handleTestAndPreview = useCallback(() => {
|
|
274
312
|
setShowTestAndPreviewSlidebox(true);
|
|
275
|
-
setIsTestAndPreviewMode(true);
|
|
276
313
|
if (propsHandleTestAndPreview) {
|
|
277
314
|
propsHandleTestAndPreview();
|
|
278
315
|
}
|
|
@@ -296,31 +333,723 @@ export const Rcs = (props) => {
|
|
|
296
333
|
// For video
|
|
297
334
|
return RCS_VIDEO_THUMBNAIL_DIMENSIONS[selectedDimension]?.orientation || VERTICAL;
|
|
298
335
|
};
|
|
336
|
+
/** Merge editor slot map into `smsFallbackData` (like `cardVarMapped` for title/desc). */
|
|
337
|
+
const handleSmsFallbackEditorStateChange = useCallback((patch) => {
|
|
338
|
+
setSmsFallbackData((prev) => {
|
|
339
|
+
if (!patch || typeof patch !== 'object') return prev;
|
|
340
|
+
// Bail out when no template has been selected yet — SmsTraiEdit fires
|
|
341
|
+
// onRcsFallbackEditorStateChange on mount (unicodeValidity, varMapped),
|
|
342
|
+
// which would create a non-null smsFallbackData from nothing and cause
|
|
343
|
+
// the card to appear as "Untitled creative" before any save.
|
|
344
|
+
if (!prev) return prev;
|
|
345
|
+
return { ...prev, ...patch };
|
|
346
|
+
});
|
|
347
|
+
}, []);
|
|
299
348
|
|
|
349
|
+
/** RCS template save / edit API: `rcsContent.accountId` must stay `sourceAccountIdentifier` (pairs with accessToken). */
|
|
300
350
|
const [accountId, setAccountId] = useState('');
|
|
351
|
+
/** WeCRM list row `id` — only for CommonTestAndPreview → createMessageMeta payload, not for template save. */
|
|
352
|
+
const [wecrmAccountId, setWecrmAccountId] = useState('');
|
|
301
353
|
const [accessToken, setAccessToken] = useState('');
|
|
302
354
|
const [hostName, setHostName] = useState('');
|
|
303
355
|
const [accountName, setAccountName] = useState('');
|
|
356
|
+
const isHostInfoBip = hostName === HOST_INFOBIP;
|
|
357
|
+
const isHostIcs = hostName === HOST_ICS;
|
|
358
|
+
|
|
359
|
+
useEffect(() => {
|
|
360
|
+
setSuggestions(isHostIcs ? INITIAL_SUGGESTIONS_DATA_STOP : []);
|
|
361
|
+
}, [isHostIcs]);
|
|
304
362
|
const [rcsAccount, setRcsAccount] = useState('');
|
|
305
363
|
useEffect(() => {
|
|
306
364
|
const accountObj = accountData.selectedRcsAccount || {};
|
|
307
365
|
if (!isEmpty(accountObj)) {
|
|
308
366
|
const {
|
|
367
|
+
id: wecrmId,
|
|
309
368
|
sourceAccountIdentifier = '',
|
|
310
369
|
configs = {},
|
|
311
370
|
} = accountObj;
|
|
312
|
-
|
|
313
371
|
setAccountId(sourceAccountIdentifier);
|
|
372
|
+
setWecrmAccountId(
|
|
373
|
+
wecrmId != null && String(wecrmId).trim() !== '' ? String(wecrmId) : '',
|
|
374
|
+
);
|
|
314
375
|
setAccessToken(configs.accessToken || '');
|
|
315
376
|
setHostName(accountObj.hostName || '');
|
|
316
377
|
setAccountName(accountObj.name || '');
|
|
317
378
|
setRcsAccount(accountObj.id || '');
|
|
379
|
+
} else {
|
|
380
|
+
setAccountId('');
|
|
381
|
+
setWecrmAccountId('');
|
|
382
|
+
setAccessToken('');
|
|
383
|
+
setHostName('');
|
|
384
|
+
setAccountName('');
|
|
318
385
|
}
|
|
319
386
|
}, [accountData.selectedRcsAccount]);
|
|
320
387
|
|
|
321
388
|
const isMediaTypeText = templateMediaType === RCS_MEDIA_TYPES.NONE;
|
|
322
389
|
const isMediaTypeImage = templateMediaType === RCS_MEDIA_TYPES.IMAGE;
|
|
323
390
|
const isMediaTypeVideo = templateMediaType === RCS_MEDIA_TYPES.VIDEO;
|
|
391
|
+
const isCarouselType = templateType === contentType.carousel;
|
|
392
|
+
|
|
393
|
+
const MAX_RCS_CAROUSEL_ALLOWED = 10;
|
|
394
|
+
// Uploads for RCS are stored in redux under dynamic keys `uploadedAssetData${index}`.
|
|
395
|
+
// Carousel needs per-card indices; otherwise all cards "restore" the last uploaded asset
|
|
396
|
+
// and show the same media/thumbnail.
|
|
397
|
+
const RCS_CAROUSEL_ASSET_INDEX_BASE = 10; // keep away from standalone indices 0 (media) and 1 (thumbnail)
|
|
398
|
+
const getCarouselImageAssetIndex = (cardIndex) =>
|
|
399
|
+
RCS_CAROUSEL_ASSET_INDEX_BASE + (cardIndex * 3);
|
|
400
|
+
const getCarouselVideoAssetIndex = (cardIndex) =>
|
|
401
|
+
RCS_CAROUSEL_ASSET_INDEX_BASE + (cardIndex * 3) + 1;
|
|
402
|
+
const getCarouselThumbnailAssetIndex = (cardIndex) =>
|
|
403
|
+
RCS_CAROUSEL_ASSET_INDEX_BASE + (cardIndex * 3) + 2;
|
|
404
|
+
const isThumbnailAssetIndex = (index) => {
|
|
405
|
+
if (index === 1) return true; // standalone thumbnail
|
|
406
|
+
if (index >= RCS_CAROUSEL_ASSET_INDEX_BASE) {
|
|
407
|
+
return ((index - RCS_CAROUSEL_ASSET_INDEX_BASE) % 3) === 2; // carousel thumbnail slot
|
|
408
|
+
}
|
|
409
|
+
return false;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// Carousel dimension key: `${HEIGHT}_${WIDTH}` (e.g., SHORT_SMALL)
|
|
413
|
+
const getCarouselDimensionKey = () => `${selectedCarouselHeight}_${selectedCarouselWidth}`;
|
|
414
|
+
|
|
415
|
+
const clearCarouselCardMedia = (cardIndex, { clearImage = true, clearVideo = true, clearThumb = true } = {}) => {
|
|
416
|
+
setCarouselData((prev = []) => {
|
|
417
|
+
const updated = cloneDeep(prev);
|
|
418
|
+
if (!updated?.[cardIndex]) return updated;
|
|
419
|
+
if (clearImage) updated[cardIndex].imageSrc = '';
|
|
420
|
+
if (clearVideo) updated[cardIndex].videoAsset = {};
|
|
421
|
+
if (clearThumb) updated[cardIndex].thumbnailSrc = '';
|
|
422
|
+
return updated;
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
if (clearImage) actions.clearRcsMediaAsset(getCarouselImageAssetIndex(cardIndex));
|
|
426
|
+
if (clearVideo) actions.clearRcsMediaAsset(getCarouselVideoAssetIndex(cardIndex));
|
|
427
|
+
if (clearThumb) actions.clearRcsMediaAsset(getCarouselThumbnailAssetIndex(cardIndex));
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
const resetCarouselMediaForAllCards = () => {
|
|
431
|
+
setCarouselData((prev = []) => {
|
|
432
|
+
const updated = cloneDeep(prev);
|
|
433
|
+
updated.forEach((card) => {
|
|
434
|
+
if (!card) return;
|
|
435
|
+
card.imageSrc = '';
|
|
436
|
+
card.videoAsset = {};
|
|
437
|
+
card.thumbnailSrc = '';
|
|
438
|
+
});
|
|
439
|
+
return updated;
|
|
440
|
+
});
|
|
441
|
+
(carouselData || []).forEach((_, idx) => {
|
|
442
|
+
actions.clearRcsMediaAsset(getCarouselImageAssetIndex(idx));
|
|
443
|
+
actions.clearRcsMediaAsset(getCarouselVideoAssetIndex(idx));
|
|
444
|
+
actions.clearRcsMediaAsset(getCarouselThumbnailAssetIndex(idx));
|
|
445
|
+
});
|
|
446
|
+
// Force tab panes to remount after global reset (some tab implementations cache inactive panes)
|
|
447
|
+
setCarouselResetNonce((n) => n + 1);
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const RCS_CAROUSEL_INITIAL_CARD = {
|
|
451
|
+
title: '',
|
|
452
|
+
description: '',
|
|
453
|
+
mediaType: RCS_MEDIA_TYPES.IMAGE, // per-card
|
|
454
|
+
imageSrc: '',
|
|
455
|
+
videoAsset: {}, // CapVideoUpload object shape
|
|
456
|
+
thumbnailSrc: '',
|
|
457
|
+
suggestions: [],
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
const RCS_CAROUSEL_INITIAL_FIRST_CARD = {
|
|
461
|
+
...RCS_CAROUSEL_INITIAL_CARD,
|
|
462
|
+
suggestions: cloneDeep(RCS_CAROUSEL_FIRST_CARD_DEFAULT_SUGGESTIONS),
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
const ensureFirstCardDefaultPhoneSuggestions = (cards) => {
|
|
466
|
+
const next = cloneDeep(cards || []);
|
|
467
|
+
if (next.length === 0) return next;
|
|
468
|
+
const s = next[0].suggestions;
|
|
469
|
+
if (!Array.isArray(s) || s.length === 0) {
|
|
470
|
+
next[0] = {
|
|
471
|
+
...next[0],
|
|
472
|
+
suggestions: cloneDeep(RCS_CAROUSEL_FIRST_CARD_DEFAULT_SUGGESTIONS),
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
return next;
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// Always use functional updates: image upload completes in CapImageUpload's useEffect and calls
|
|
479
|
+
// updateImageSrc → this handler. If we cloned carouselData from render, we'd overwrite title/body/
|
|
480
|
+
// suggestions typed since the last commit (stale closure).
|
|
481
|
+
const handleCarouselValueChange = (carouselIndex, fields) => {
|
|
482
|
+
setCarouselData((prev = []) => {
|
|
483
|
+
const updated = cloneDeep(prev);
|
|
484
|
+
if (!updated[carouselIndex]) return prev;
|
|
485
|
+
fields.forEach(({ fieldName, value }) => {
|
|
486
|
+
updated[carouselIndex][fieldName] = value;
|
|
487
|
+
});
|
|
488
|
+
return updated;
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const updateCarouselErrors = (carouselIndex, patch) => {
|
|
493
|
+
setCarouselErrors((prev = []) => {
|
|
494
|
+
const next = Array.isArray(prev) ? [...prev] : [];
|
|
495
|
+
next[carouselIndex] = { ...(next[carouselIndex] || {}), ...patch };
|
|
496
|
+
return next;
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
const deleteCarouselCard = (index) => {
|
|
501
|
+
let nextIdx = 0;
|
|
502
|
+
flushSync(() => {
|
|
503
|
+
setCarouselData((prev = []) => {
|
|
504
|
+
const updated = cloneDeep(prev);
|
|
505
|
+
if (index < 0 || index >= updated.length) return updated;
|
|
506
|
+
updated.splice(index, 1);
|
|
507
|
+
nextIdx = Math.max(0, Math.min(index - 1, updated.length - 1));
|
|
508
|
+
return ensureFirstCardDefaultPhoneSuggestions(updated);
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
setCarouselErrors((prev = []) => {
|
|
512
|
+
const next = Array.isArray(prev) ? [...prev] : [];
|
|
513
|
+
next.splice(index, 1);
|
|
514
|
+
return next;
|
|
515
|
+
});
|
|
516
|
+
setActiveCarouselIndex(`${nextIdx}`);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
const carouselButtonTextHasForbiddenChars = (value) => {
|
|
520
|
+
if (!value) return false;
|
|
521
|
+
if (value.includes('[') || value.includes(']')) return true;
|
|
522
|
+
const withoutValidVariables = value.replace(/\{\{[^}]*\}\}/g, '');
|
|
523
|
+
if (withoutValidVariables.includes('{') || withoutValidVariables.includes('}')) return true;
|
|
524
|
+
return false;
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
const isCompleteSavedCarouselSuggestion = (s) => {
|
|
528
|
+
if (!s || !s.isSaved) return false;
|
|
529
|
+
const text = (s.text || '').trim();
|
|
530
|
+
if (!text || !isValidText(text) || carouselButtonTextHasForbiddenChars(text)) return false;
|
|
531
|
+
if (s.type === RCS_BUTTON_TYPES.PHONE_NUMBER) {
|
|
532
|
+
return String(s.phoneNumber || '').length >= 5;
|
|
533
|
+
}
|
|
534
|
+
if (s.type === RCS_BUTTON_TYPES.CTA) {
|
|
535
|
+
const url = String(s.url || '').trim();
|
|
536
|
+
if (!url || url.length > URL_MAX_LENGTH) return false;
|
|
537
|
+
const subtype = s.urlType || RCS_CTA_URL_TYPE.STATIC;
|
|
538
|
+
if (subtype === RCS_CTA_URL_TYPE.DYNAMIC) {
|
|
539
|
+
return true;
|
|
540
|
+
}
|
|
541
|
+
if (!isUrl(url)) return false;
|
|
542
|
+
const varMatches = url.match(invalidVarRegex);
|
|
543
|
+
return !(varMatches && varMatches.length > 0);
|
|
544
|
+
}
|
|
545
|
+
if (s.type === RCS_BUTTON_TYPES.QUICK_REPLY) {
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
548
|
+
return false;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
const isCarouselCardValid = (card, cardIndex) => {
|
|
552
|
+
if (!card) return false;
|
|
553
|
+
if (!card.title || !card.title.trim()) return false;
|
|
554
|
+
if ((card.title || '').length > TEMPLATE_TITLE_MAX_LENGTH) return false;
|
|
555
|
+
if (!card.description || !card.description.trim()) return false;
|
|
556
|
+
if ((card.description || '').length > RCS_RICH_CARD_MAX_LENGTH) return false;
|
|
557
|
+
let mediaOk = false;
|
|
558
|
+
if (card.mediaType === RCS_MEDIA_TYPES.IMAGE) {
|
|
559
|
+
mediaOk = !!(card.imageSrc && String(card.imageSrc).trim());
|
|
560
|
+
} else if (card.mediaType === RCS_MEDIA_TYPES.VIDEO) {
|
|
561
|
+
const hasVideo = !!(card.videoAsset && card.videoAsset.videoSrc && String(card.videoAsset.videoSrc).trim());
|
|
562
|
+
const hasThumb = !!(card.thumbnailSrc && String(card.thumbnailSrc).trim());
|
|
563
|
+
mediaOk = hasVideo && hasThumb;
|
|
564
|
+
} else {
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
if (!mediaOk) return false;
|
|
568
|
+
if (cardIndex === 0) {
|
|
569
|
+
const sugg = Array.isArray(card.suggestions) ? card.suggestions : [];
|
|
570
|
+
if (!sugg.some(isCompleteSavedCarouselSuggestion)) return false;
|
|
571
|
+
}
|
|
572
|
+
return true;
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
const checkDisableAddCarouselButton = () => {
|
|
576
|
+
const idx = parseInt(activeCarouselIndex, 10);
|
|
577
|
+
const activeCard = carouselData?.[idx];
|
|
578
|
+
return !isCarouselCardValid(activeCard, idx);
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
const addCarouselCard = () => {
|
|
582
|
+
let newIndex = 0;
|
|
583
|
+
flushSync(() => {
|
|
584
|
+
setCarouselData((prev = []) => {
|
|
585
|
+
const updated = cloneDeep(prev);
|
|
586
|
+
updated.push(cloneDeep(RCS_CAROUSEL_INITIAL_CARD));
|
|
587
|
+
newIndex = updated.length - 1;
|
|
588
|
+
return updated;
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
setCarouselErrors((prev = []) => ([...(Array.isArray(prev) ? prev : []), {}]));
|
|
592
|
+
setActiveCarouselIndex(`${newIndex}`);
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// Initialize carousel data when switching to carousel type
|
|
596
|
+
useEffect(() => {
|
|
597
|
+
if (!isCarouselType) return;
|
|
598
|
+
if (!carouselData || carouselData.length === 0) {
|
|
599
|
+
setCarouselData([cloneDeep(RCS_CAROUSEL_INITIAL_FIRST_CARD)]);
|
|
600
|
+
setCarouselErrors([{}]);
|
|
601
|
+
setActiveCarouselIndex('0');
|
|
602
|
+
}
|
|
603
|
+
}, [isCarouselType]);
|
|
604
|
+
|
|
605
|
+
// keep derived carousel key in sync
|
|
606
|
+
useEffect(() => {
|
|
607
|
+
if (!isCarouselType) return;
|
|
608
|
+
if (!selectedCarouselHeight || !selectedCarouselWidth) return;
|
|
609
|
+
// Required format: HEIGHT_WIDTH
|
|
610
|
+
setSelectedCarousel(`${selectedCarouselHeight}_${selectedCarouselWidth}`);
|
|
611
|
+
}, [isCarouselType, selectedCarouselHeight, selectedCarouselWidth]);
|
|
612
|
+
|
|
613
|
+
const renderCarouselDimensionSelection = () => {
|
|
614
|
+
if (!isCarouselType) return null;
|
|
615
|
+
return (
|
|
616
|
+
<CapRow className="rcs-carousel-dimension-section">
|
|
617
|
+
<CapRow gutter={16} className="rcs-carousel-dimension-row">
|
|
618
|
+
<CapColumn span={12}>
|
|
619
|
+
<CapHeading type="h4" className="rcs-carousel-dimension-label">Card height</CapHeading>
|
|
620
|
+
<CapSelect
|
|
621
|
+
id="rcs-carousel-height-select"
|
|
622
|
+
value={selectedCarouselHeight}
|
|
623
|
+
onChange={(val) => {
|
|
624
|
+
// Like rich-card dimension changes: clear media so user re-uploads matching new dimensions.
|
|
625
|
+
resetCarouselMediaForAllCards();
|
|
626
|
+
setSelectedCarouselHeight(val);
|
|
627
|
+
}}
|
|
628
|
+
options={CAROUSEL_HEIGHT_OPTIONS}
|
|
629
|
+
disabled={isEditFlow || !isFullMode}
|
|
630
|
+
/>
|
|
631
|
+
</CapColumn>
|
|
632
|
+
<CapColumn span={12}>
|
|
633
|
+
<CapHeading type="h4" className="rcs-carousel-dimension-label">Card width</CapHeading>
|
|
634
|
+
<CapSelect
|
|
635
|
+
id="rcs-carousel-width-select"
|
|
636
|
+
value={selectedCarouselWidth}
|
|
637
|
+
onChange={(val) => {
|
|
638
|
+
// Like rich-card dimension changes: clear media so user re-uploads matching new dimensions.
|
|
639
|
+
resetCarouselMediaForAllCards();
|
|
640
|
+
setSelectedCarouselWidth(val);
|
|
641
|
+
}}
|
|
642
|
+
options={CAROUSEL_WIDTH_OPTIONS}
|
|
643
|
+
disabled={isEditFlow || !isFullMode}
|
|
644
|
+
/>
|
|
645
|
+
</CapColumn>
|
|
646
|
+
</CapRow>
|
|
647
|
+
{!!selectedCarousel && (
|
|
648
|
+
<CapLabel type="label3" className="rcs-carousel-selected-dimension">
|
|
649
|
+
Selected: {selectedCarousel}
|
|
650
|
+
</CapLabel>
|
|
651
|
+
)}
|
|
652
|
+
</CapRow>
|
|
653
|
+
);
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// Reuse rich-card buttons UI per carousel card
|
|
657
|
+
const renderButtonComponentForCarouselCard = (cardIndex) => {
|
|
658
|
+
const card = carouselData?.[cardIndex] || {};
|
|
659
|
+
const suggestionsForCard = card.suggestions || [];
|
|
660
|
+
return (
|
|
661
|
+
<>
|
|
662
|
+
<CapHeader
|
|
663
|
+
className="rcs-button-cta"
|
|
664
|
+
title={(
|
|
665
|
+
<CapRow type="flex">
|
|
666
|
+
<CapHeading type="h4">
|
|
667
|
+
{formatMessage(messages.btnLabel)}
|
|
668
|
+
</CapHeading>
|
|
669
|
+
</CapRow>
|
|
670
|
+
)}
|
|
671
|
+
description={(
|
|
672
|
+
<CapLabel type="label3">{formatMessage(messages.btnDesc)}</CapLabel>
|
|
673
|
+
)}
|
|
674
|
+
/>
|
|
675
|
+
<CapActionButton
|
|
676
|
+
buttonType={RCS_BUTTON_TYPES.NONE}
|
|
677
|
+
updateButtonChange={(data, btnIndex) => {
|
|
678
|
+
// Match existing behavior: allow CapActionButton to manage save gating.
|
|
679
|
+
const updated = cloneDeep(suggestionsForCard);
|
|
680
|
+
if (btnIndex === MAX_BUTTONS) {
|
|
681
|
+
handleCarouselValueChange(cardIndex, [{ fieldName: 'suggestions', value: data }]);
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
updated[btnIndex] = data;
|
|
685
|
+
handleCarouselValueChange(cardIndex, [{ fieldName: 'suggestions', value: updated }]);
|
|
686
|
+
}}
|
|
687
|
+
deleteButtonHandler={(btnIndex) => {
|
|
688
|
+
if (cardIndex === 0 && btnIndex === 0) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const savedCount = (suggestionsForCard || []).filter((x) => x && x.isSaved).length;
|
|
692
|
+
const target = (suggestionsForCard || []).find((s) => s && s.index === btnIndex);
|
|
693
|
+
if (cardIndex === 0 && target?.isSaved && savedCount <= 1) {
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const updated = cloneDeep(suggestionsForCard)
|
|
697
|
+
.filter((i) => i.index !== btnIndex)
|
|
698
|
+
.map((i, idx) => ({ ...i, index: idx }));
|
|
699
|
+
handleCarouselValueChange(cardIndex, [{ fieldName: 'suggestions', value: updated }]);
|
|
700
|
+
}}
|
|
701
|
+
suggestions={suggestionsForCard}
|
|
702
|
+
isEditFlow={isEditFlow}
|
|
703
|
+
isFullMode={isFullMode}
|
|
704
|
+
maxButtons={MAX_BUTTONS}
|
|
705
|
+
host={hostName}
|
|
706
|
+
minSavedSuggestions={cardIndex === 0 ? 1 : 0}
|
|
707
|
+
hideDeleteSuggestionIndexes={cardIndex === 0 ? [0] : []}
|
|
708
|
+
/>
|
|
709
|
+
</>
|
|
710
|
+
);
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
const renderCarouselCardMedia = (cardIndex) => {
|
|
714
|
+
const card = carouselData?.[cardIndex] || {};
|
|
715
|
+
const dimKey = getCarouselDimensionKey();
|
|
716
|
+
|
|
717
|
+
if (card.mediaType === RCS_MEDIA_TYPES.VIDEO) {
|
|
718
|
+
return (
|
|
719
|
+
<>
|
|
720
|
+
<CapHeading type="h4" className="rcs-image-dimensions-label">Upload Video</CapHeading>
|
|
721
|
+
<CapVideoUpload
|
|
722
|
+
index={getCarouselVideoAssetIndex(cardIndex)}
|
|
723
|
+
allowedExtensionsRegex={ALLOWED_EXTENSIONS_VIDEO_REGEX}
|
|
724
|
+
videoSize={RCS_CAROUSEL_VIDEO_SIZE}
|
|
725
|
+
isFullMode={isFullMode}
|
|
726
|
+
uploadAsset={uploadRcsVideo}
|
|
727
|
+
uploadedAssetList={card.videoAsset || {}}
|
|
728
|
+
onVideoUploadUpdateAssestList={(_, val) => {
|
|
729
|
+
handleCarouselValueChange(cardIndex, [{ fieldName: 'videoAsset', value: val }]);
|
|
730
|
+
}}
|
|
731
|
+
videoData={rcsData}
|
|
732
|
+
className="cap-custom-video-upload"
|
|
733
|
+
formClassName={"rcs-video-upload"}
|
|
734
|
+
channel={RCS}
|
|
735
|
+
errorMessage={formatMessage(messages.videoErrorMessage)}
|
|
736
|
+
showVideoNameAndDuration={false}
|
|
737
|
+
showReUploadButton={!isEditFlow && isFullMode}
|
|
738
|
+
channelSpecificStyle={!isFullMode}
|
|
739
|
+
/>
|
|
740
|
+
|
|
741
|
+
<CapHeading type="h4" className="rcs-image-dimensions-label">Upload Thumbnail</CapHeading>
|
|
742
|
+
<CapImageUpload
|
|
743
|
+
allowedExtensionsRegex={ALLOWED_IMAGE_EXTENSIONS_REGEX}
|
|
744
|
+
imgWidth={RCS_CAROUSEL_VIDEO_THUMBNAIL_DIMENSIONS?.[dimKey]?.width}
|
|
745
|
+
imgHeight={RCS_CAROUSEL_VIDEO_THUMBNAIL_DIMENSIONS?.[dimKey]?.height}
|
|
746
|
+
imgSize={RCS_THUMBNAIL_MAX_SIZE}
|
|
747
|
+
uploadAsset={uploadRcsImage}
|
|
748
|
+
isFullMode={isFullMode}
|
|
749
|
+
imageSrc={card.thumbnailSrc}
|
|
750
|
+
updateImageSrc={(val) => handleCarouselValueChange(cardIndex, [{ fieldName: 'thumbnailSrc', value: val }])}
|
|
751
|
+
updateOnReUpload={() => handleCarouselValueChange(cardIndex, [{ fieldName: 'thumbnailSrc', value: '' }])}
|
|
752
|
+
minImgSize={RCS_THUMBNAIL_MIN_SIZE}
|
|
753
|
+
index={getCarouselThumbnailAssetIndex(cardIndex)}
|
|
754
|
+
className="cap-custom-image-upload"
|
|
755
|
+
key={`rcs-carousel-thumb-${cardIndex}-${dimKey}`}
|
|
756
|
+
imageData={rcsData}
|
|
757
|
+
channel={RCS}
|
|
758
|
+
channelSpecificStyle={!isFullMode}
|
|
759
|
+
skipDimensionValidation={true}
|
|
760
|
+
showReUploadButton={!isEditFlow && isFullMode}
|
|
761
|
+
disabled={isEditFlow || !isFullMode}
|
|
762
|
+
/>
|
|
763
|
+
</>
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Default: IMAGE
|
|
768
|
+
return (
|
|
769
|
+
<>
|
|
770
|
+
<CapHeading type="h4" className="rcs-image-dimensions-label">Upload Image</CapHeading>
|
|
771
|
+
<CapImageUpload
|
|
772
|
+
allowedExtensionsRegex={ALLOWED_IMAGE_EXTENSIONS_REGEX}
|
|
773
|
+
imgWidth={RCS_CAROUSEL_IMAGE_DIMENSIONS?.[dimKey]?.width}
|
|
774
|
+
imgHeight={RCS_CAROUSEL_IMAGE_DIMENSIONS?.[dimKey]?.height}
|
|
775
|
+
imgSize={RCS_CAROUSEL_IMG_SIZE}
|
|
776
|
+
uploadAsset={uploadRcsImage}
|
|
777
|
+
isFullMode={isFullMode}
|
|
778
|
+
imageSrc={card.imageSrc}
|
|
779
|
+
updateImageSrc={(val) => handleCarouselValueChange(cardIndex, [{ fieldName: 'imageSrc', value: val }])}
|
|
780
|
+
updateOnReUpload={() => handleCarouselValueChange(cardIndex, [{ fieldName: 'imageSrc', value: '' }])}
|
|
781
|
+
index={getCarouselImageAssetIndex(cardIndex)}
|
|
782
|
+
className="cap-custom-image-upload"
|
|
783
|
+
key={`rcs-carousel-image-${cardIndex}-${dimKey}`}
|
|
784
|
+
imageData={rcsData}
|
|
785
|
+
channel={RCS}
|
|
786
|
+
channelSpecificStyle={!isFullMode}
|
|
787
|
+
skipDimensionValidation={true}
|
|
788
|
+
showReUploadButton={!isEditFlow && isFullMode}
|
|
789
|
+
disabled={isEditFlow || !isFullMode}
|
|
790
|
+
/>
|
|
791
|
+
</>
|
|
792
|
+
);
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
const renderCarouselCardButtons = (cardIndex) => {
|
|
796
|
+
return renderButtonComponentForCarouselCard(cardIndex);
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
const getCarouselTabPanes = () => {
|
|
800
|
+
return (carouselData || []).map((card, index) => {
|
|
801
|
+
return {
|
|
802
|
+
key: index,
|
|
803
|
+
tab: index + 1,
|
|
804
|
+
content: (
|
|
805
|
+
<CapCard
|
|
806
|
+
title={`Card ${index + 1}`}
|
|
807
|
+
extra={
|
|
808
|
+
!isEditFlow &&
|
|
809
|
+
(carouselData.length === 1 ? (
|
|
810
|
+
<CapTooltip title={formatMessage(messages.rcsCarouselMinCardDeleteTooltip)}>
|
|
811
|
+
<span className="button-disabled-tooltip-wrapper rcs-carousel-delete-tooltip-wrap">
|
|
812
|
+
<CapButton
|
|
813
|
+
className="rcs-carousel-card-delete"
|
|
814
|
+
type="flat"
|
|
815
|
+
onClick={() => deleteCarouselCard(index)}
|
|
816
|
+
disabled
|
|
817
|
+
aria-label={formatMessage(messages.rcsCarouselMinCardDeleteTooltip)}
|
|
818
|
+
>
|
|
819
|
+
<CapIcon type="delete" />
|
|
820
|
+
</CapButton>
|
|
821
|
+
</span>
|
|
822
|
+
</CapTooltip>
|
|
823
|
+
) : (
|
|
824
|
+
<CapButton
|
|
825
|
+
className="rcs-carousel-card-delete"
|
|
826
|
+
type="flat"
|
|
827
|
+
onClick={() => deleteCarouselCard(index)}
|
|
828
|
+
aria-label={formatMessage(globalMessages.delete)}
|
|
829
|
+
>
|
|
830
|
+
<CapIcon type="delete" />
|
|
831
|
+
</CapButton>
|
|
832
|
+
))
|
|
833
|
+
}
|
|
834
|
+
className="rcs-carousel-card"
|
|
835
|
+
>
|
|
836
|
+
{/* Media selection should be at top of card */}
|
|
837
|
+
<CapRow className="rcs-carousel-media-selection">
|
|
838
|
+
<CapColumn className="rcs-carousel-media-selection-heading">
|
|
839
|
+
<CapHeading type="h4">{formatMessage(messages.mediaTypeLabel)}</CapHeading>
|
|
840
|
+
</CapColumn>
|
|
841
|
+
<CapColumn>
|
|
842
|
+
<CapRadioGroup
|
|
843
|
+
id={`rcs-carousel-media-radio-${index}`}
|
|
844
|
+
options={mediaRadioOptions}
|
|
845
|
+
value={card.mediaType}
|
|
846
|
+
onChange={({ target: { value } }) => {
|
|
847
|
+
// Reset media fields when switching type
|
|
848
|
+
if (value === RCS_MEDIA_TYPES.IMAGE) {
|
|
849
|
+
// Switching to IMAGE: clear video + thumbnail uploads so they don't auto-restore.
|
|
850
|
+
clearCarouselCardMedia(index, { clearImage: false, clearVideo: true, clearThumb: true });
|
|
851
|
+
handleCarouselValueChange(index, [
|
|
852
|
+
{ fieldName: 'mediaType', value },
|
|
853
|
+
{ fieldName: 'videoAsset', value: {} },
|
|
854
|
+
{ fieldName: 'thumbnailSrc', value: '' },
|
|
855
|
+
]);
|
|
856
|
+
} else {
|
|
857
|
+
// Switching to VIDEO: clear image upload so it doesn't auto-restore.
|
|
858
|
+
clearCarouselCardMedia(index, { clearImage: true, clearVideo: false, clearThumb: false });
|
|
859
|
+
handleCarouselValueChange(index, [
|
|
860
|
+
{ fieldName: 'mediaType', value },
|
|
861
|
+
{ fieldName: 'imageSrc', value: '' },
|
|
862
|
+
]);
|
|
863
|
+
}
|
|
864
|
+
}}
|
|
865
|
+
disabled={isEditFlow || !isFullMode}
|
|
866
|
+
className="rcs-radio"
|
|
867
|
+
/>
|
|
868
|
+
</CapColumn>
|
|
869
|
+
</CapRow>
|
|
870
|
+
|
|
871
|
+
<CapRow className="rcs-carousel-media-upload">
|
|
872
|
+
{renderCarouselCardMedia(index)}
|
|
873
|
+
</CapRow>
|
|
874
|
+
|
|
875
|
+
{/* Title after media */}
|
|
876
|
+
<CapRow className="rcs-carousel-card-row">
|
|
877
|
+
<CapHeader
|
|
878
|
+
className="rcs-template-title-label"
|
|
879
|
+
title={<CapHeading type="h4">Card title</CapHeading>}
|
|
880
|
+
suffix={
|
|
881
|
+
(isEditFlow || !isFullMode) ? (
|
|
882
|
+
<TagList
|
|
883
|
+
label={formatMessage(globalMessages.addLabels)}
|
|
884
|
+
onTagSelect={onCarouselTagSelect}
|
|
885
|
+
location={location}
|
|
886
|
+
tags={getRcsTags()}
|
|
887
|
+
onContextChange={handleOnTagsContextChange}
|
|
888
|
+
injectedTags={injectedTags || {}}
|
|
889
|
+
selectedOfferDetails={selectedOfferDetails}
|
|
890
|
+
/>
|
|
891
|
+
) : (
|
|
892
|
+
<CapButton
|
|
893
|
+
data-testid={`rcs-carousel-title-add-var-${index}`}
|
|
894
|
+
type="flat"
|
|
895
|
+
isAddBtn
|
|
896
|
+
onClick={() => appendVarToCarouselField(index, 'title')}
|
|
897
|
+
disabled={!!carouselErrors?.[index]?.title}
|
|
898
|
+
>
|
|
899
|
+
{formatMessage(messages.addVar)}
|
|
900
|
+
</CapButton>
|
|
901
|
+
)
|
|
902
|
+
}
|
|
903
|
+
/>
|
|
904
|
+
<CapRow className="rcs_text_area_wrapper">
|
|
905
|
+
{(isEditFlow || !isFullMode) ? (
|
|
906
|
+
renderCarouselEditMessage(card.title || '')
|
|
907
|
+
) : (
|
|
908
|
+
<CapInput
|
|
909
|
+
value={card.title || ''}
|
|
910
|
+
placeholder={formatMessage(messages.templateTitlePlaceholder)}
|
|
911
|
+
onChange={({ target: { value } }) => {
|
|
912
|
+
let error = false;
|
|
913
|
+
if (value?.length > TEMPLATE_TITLE_MAX_LENGTH) {
|
|
914
|
+
error = formatMessage(messages.templateHeaderLengthError);
|
|
915
|
+
} else {
|
|
916
|
+
error = variableErrorHandling(value);
|
|
917
|
+
}
|
|
918
|
+
updateCarouselErrors(index, { title: error });
|
|
919
|
+
handleCarouselValueChange(index, [{ fieldName: 'title', value }]);
|
|
920
|
+
}}
|
|
921
|
+
disabled={isEditFlow || !isFullMode}
|
|
922
|
+
errorMessage={carouselErrors?.[index]?.title}
|
|
923
|
+
/>
|
|
924
|
+
)}
|
|
925
|
+
</CapRow>
|
|
926
|
+
</CapRow>
|
|
927
|
+
{!isEditFlow && (
|
|
928
|
+
<CapRow className="rcs-carousel-character-count-row">
|
|
929
|
+
{renderCarouselCharacterCount(
|
|
930
|
+
getCarouselTitleCharacterCount(index),
|
|
931
|
+
getTitleMaxLength(),
|
|
932
|
+
)}
|
|
933
|
+
</CapRow>
|
|
934
|
+
)}
|
|
935
|
+
|
|
936
|
+
{/* Description after title */}
|
|
937
|
+
<CapRow className="rcs-carousel-card-row">
|
|
938
|
+
<CapHeader
|
|
939
|
+
title={<CapHeading type="h4">Card body text</CapHeading>}
|
|
940
|
+
suffix={
|
|
941
|
+
(isEditFlow || !isFullMode) ? (
|
|
942
|
+
<TagList
|
|
943
|
+
label={formatMessage(globalMessages.addLabels)}
|
|
944
|
+
onTagSelect={onCarouselTagSelect}
|
|
945
|
+
location={location}
|
|
946
|
+
tags={getRcsTags()}
|
|
947
|
+
onContextChange={handleOnTagsContextChange}
|
|
948
|
+
injectedTags={injectedTags || {}}
|
|
949
|
+
selectedOfferDetails={selectedOfferDetails}
|
|
950
|
+
/>
|
|
951
|
+
) : (
|
|
952
|
+
<CapButton
|
|
953
|
+
data-testid={`rcs-carousel-desc-add-var-${index}`}
|
|
954
|
+
type="flat"
|
|
955
|
+
isAddBtn
|
|
956
|
+
onClick={() => appendVarToCarouselField(index, 'description')}
|
|
957
|
+
disabled={!!carouselErrors?.[index]?.description}
|
|
958
|
+
>
|
|
959
|
+
{formatMessage(messages.addVar)}
|
|
960
|
+
</CapButton>
|
|
961
|
+
)
|
|
962
|
+
}
|
|
963
|
+
/>
|
|
964
|
+
<CapRow className="rcs_text_area_wrapper">
|
|
965
|
+
{(isEditFlow || !isFullMode) ? (
|
|
966
|
+
renderCarouselEditMessage(card.description || '')
|
|
967
|
+
) : (
|
|
968
|
+
<TextArea
|
|
969
|
+
autosize={{ minRows: 3, maxRows: 5 }}
|
|
970
|
+
value={card.description || ''}
|
|
971
|
+
placeholder={formatMessage(messages.templateDescPlaceholder)}
|
|
972
|
+
onChange={({ target: { value } }) => {
|
|
973
|
+
let error = false;
|
|
974
|
+
if (value?.length > RCS_RICH_CARD_MAX_LENGTH) {
|
|
975
|
+
error = formatMessage(messages.templateMessageLengthError);
|
|
976
|
+
} else {
|
|
977
|
+
error = variableErrorHandling(value);
|
|
978
|
+
}
|
|
979
|
+
updateCarouselErrors(index, { description: error });
|
|
980
|
+
handleCarouselValueChange(index, [{ fieldName: 'description', value }]);
|
|
981
|
+
}}
|
|
982
|
+
disabled={isEditFlow || !isFullMode}
|
|
983
|
+
errorMessage={
|
|
984
|
+
carouselErrors?.[index]?.description && (
|
|
985
|
+
<CapError className="rcs-template-message-error">
|
|
986
|
+
{carouselErrors[index].description}
|
|
987
|
+
</CapError>
|
|
988
|
+
)
|
|
989
|
+
}
|
|
990
|
+
/>
|
|
991
|
+
)}
|
|
992
|
+
</CapRow>
|
|
993
|
+
</CapRow>
|
|
994
|
+
{!isEditFlow && (
|
|
995
|
+
<CapRow className="rcs-carousel-character-count-row">
|
|
996
|
+
{renderCarouselCharacterCount(
|
|
997
|
+
getCarouselDescriptionCharacterCount(index),
|
|
998
|
+
getDescriptionMaxLength(),
|
|
999
|
+
)}
|
|
1000
|
+
</CapRow>
|
|
1001
|
+
)}
|
|
1002
|
+
|
|
1003
|
+
<CapDivider className="rcs-carousel-card-divider" />
|
|
1004
|
+
{renderCarouselCardButtons(index)}
|
|
1005
|
+
</CapCard>
|
|
1006
|
+
),
|
|
1007
|
+
};
|
|
1008
|
+
});
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
const renderCarouselSection = () => {
|
|
1012
|
+
if (!isCarouselType) return null;
|
|
1013
|
+
|
|
1014
|
+
const operations = (
|
|
1015
|
+
<>
|
|
1016
|
+
<CapDivider type="vertical" />
|
|
1017
|
+
<CapButton
|
|
1018
|
+
onClick={addCarouselCard}
|
|
1019
|
+
type="flat"
|
|
1020
|
+
className="add-carousel-content-button"
|
|
1021
|
+
disabled={
|
|
1022
|
+
isEditFlow ||
|
|
1023
|
+
!isFullMode ||
|
|
1024
|
+
MAX_RCS_CAROUSEL_ALLOWED === (carouselData?.length || 0) ||
|
|
1025
|
+
checkDisableAddCarouselButton()
|
|
1026
|
+
}
|
|
1027
|
+
>
|
|
1028
|
+
<CapIcon type="plus" />
|
|
1029
|
+
</CapButton>
|
|
1030
|
+
</>
|
|
1031
|
+
);
|
|
1032
|
+
|
|
1033
|
+
return (
|
|
1034
|
+
<CapRow className="rcs-carousel-section">
|
|
1035
|
+
{renderCarouselDimensionSelection()}
|
|
1036
|
+
<CapRow className="rcs-carousel-tab">
|
|
1037
|
+
<CapTab
|
|
1038
|
+
key={`rcs-carousel-tab-${carouselResetNonce}`}
|
|
1039
|
+
defaultActiveKey="0"
|
|
1040
|
+
activeKey={activeCarouselIndex}
|
|
1041
|
+
tabBarExtraContent={operations}
|
|
1042
|
+
onChange={(key) => {
|
|
1043
|
+
setActiveCarouselIndex(`${key}`);
|
|
1044
|
+
// reset focused var when switching cards (as per requirement)
|
|
1045
|
+
setCarouselFocusedVarId('');
|
|
1046
|
+
}}
|
|
1047
|
+
panes={getCarouselTabPanes()}
|
|
1048
|
+
/>
|
|
1049
|
+
</CapRow>
|
|
1050
|
+
</CapRow>
|
|
1051
|
+
);
|
|
1052
|
+
};
|
|
324
1053
|
|
|
325
1054
|
const mediaRadioOptions = [
|
|
326
1055
|
{
|
|
@@ -329,11 +1058,16 @@ export const Rcs = (props) => {
|
|
|
329
1058
|
},
|
|
330
1059
|
{
|
|
331
1060
|
value: RCS_MEDIA_TYPES.VIDEO,
|
|
332
|
-
label: formatMessage(
|
|
1061
|
+
label: formatMessage(
|
|
1062
|
+
templateType === contentType.carousel
|
|
1063
|
+
? messages.carouselMediaVideoOption
|
|
1064
|
+
: messages.mediaVideo,
|
|
1065
|
+
),
|
|
333
1066
|
},
|
|
334
1067
|
];
|
|
335
1068
|
const aiContentBotDisabled = isAiContentBotDisabled();
|
|
336
1069
|
|
|
1070
|
+
|
|
337
1071
|
const updateButtonChange = (data, index) => {
|
|
338
1072
|
if (data && data.text) {
|
|
339
1073
|
const forbiddenError = forbiddenCharactersValidation(data.text);
|
|
@@ -370,7 +1104,9 @@ export const Rcs = (props) => {
|
|
|
370
1104
|
if (isFullMode) return;
|
|
371
1105
|
if (loadingTags || !tags || tags.length === 0) return;
|
|
372
1106
|
const templateStr = type === TITLE_TEXT ? templateTitle : templateDesc;
|
|
373
|
-
const
|
|
1107
|
+
const slotOffset =
|
|
1108
|
+
type === TITLE_TEXT ? 0 : (templateTitle ? templateTitle.match(rcsVarRegex) || [] : []).length;
|
|
1109
|
+
const resolved = resolveTemplateWithMap(templateStr, slotOffset); // placeholders -> mapped value (or '')
|
|
374
1110
|
if (!resolved) {
|
|
375
1111
|
if (type === TITLE_TEXT) setTemplateTitleError(false);
|
|
376
1112
|
if (type === MESSAGE_TEXT) setTemplateDescError(false);
|
|
@@ -397,10 +1133,16 @@ export const Rcs = (props) => {
|
|
|
397
1133
|
tagModule: getDefaultTags,
|
|
398
1134
|
isFullMode,
|
|
399
1135
|
}) || {};
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1136
|
+
const unsupportedTagsLengthCheck =
|
|
1137
|
+
validationResponse?.unsupportedTags?.length > 0;
|
|
1138
|
+
const errorMsg =
|
|
1139
|
+
(unsupportedTagsLengthCheck &&
|
|
1140
|
+
formatMessage(globalMessages.unsupportedTagsValidationError, {
|
|
1141
|
+
unsupportedTags: validationResponse.unsupportedTags,
|
|
1142
|
+
})) ||
|
|
1143
|
+
(validationResponse.isBraceError &&
|
|
1144
|
+
formatMessage(globalMessages.unbalanacedCurlyBraces)) ||
|
|
1145
|
+
false;
|
|
404
1146
|
if (type === TITLE_TEXT) setTemplateTitleError(errorMsg);
|
|
405
1147
|
if (type === MESSAGE_TEXT) setTemplateDescError(errorMsg);
|
|
406
1148
|
};
|
|
@@ -413,15 +1155,98 @@ export const Rcs = (props) => {
|
|
|
413
1155
|
validateResolvedTagsForType(MESSAGE_TEXT);
|
|
414
1156
|
}, [cardVarMapped, templateDesc, tags, injectedTags, loadingTags]);
|
|
415
1157
|
|
|
1158
|
+
useEffect(() => {
|
|
1159
|
+
if (isFullMode || !isCarouselType) return;
|
|
1160
|
+
if (loadingTags || !tags || tags.length === 0) return;
|
|
1161
|
+
(carouselData || []).forEach((card, idx) => {
|
|
1162
|
+
['title', 'description'].forEach((field) => {
|
|
1163
|
+
const templateStr = card?.[field] || '';
|
|
1164
|
+
if (!templateStr) return;
|
|
1165
|
+
const resolved = resolveTemplateWithMap(templateStr);
|
|
1166
|
+
if (!resolved) {
|
|
1167
|
+
updateCarouselErrors(idx, { [field]: false });
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
let contentForValidation = resolved;
|
|
1171
|
+
const placeholderTokens = templateStr.match(rcsVarRegex) || [];
|
|
1172
|
+
placeholderTokens.forEach((t) => {
|
|
1173
|
+
const escaped = t.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
1174
|
+
contentForValidation = contentForValidation.replace(new RegExp(escaped, 'g'), '');
|
|
1175
|
+
});
|
|
1176
|
+
if (!contentForValidation.trim()) {
|
|
1177
|
+
updateCarouselErrors(idx, { [field]: false });
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
const validationResponse = validateTags({
|
|
1181
|
+
content: contentForValidation,
|
|
1182
|
+
tagsParam: tags,
|
|
1183
|
+
injectedTagsParams: injectedTags,
|
|
1184
|
+
location,
|
|
1185
|
+
tagModule: getDefaultTags,
|
|
1186
|
+
eventContextTags,
|
|
1187
|
+
isFullMode,
|
|
1188
|
+
}) || {};
|
|
1189
|
+
const errorMsg =
|
|
1190
|
+
(validationResponse?.unsupportedTags?.length > 0 &&
|
|
1191
|
+
formatMessage(globalMessages.unsupportedTagsValidationError, {
|
|
1192
|
+
unsupportedTags: validationResponse.unsupportedTags,
|
|
1193
|
+
})) ||
|
|
1194
|
+
(validationResponse.isBraceError &&
|
|
1195
|
+
formatMessage(globalMessages.unbalanacedCurlyBraces)) ||
|
|
1196
|
+
false;
|
|
1197
|
+
updateCarouselErrors(idx, { [field]: errorMsg });
|
|
1198
|
+
});
|
|
1199
|
+
});
|
|
1200
|
+
}, [cardVarMapped, carouselData, tags, injectedTags, loadingTags, isCarouselType]);
|
|
1201
|
+
|
|
416
1202
|
const getVarNameFromToken = (token = '') => token.replace(/^\{\{|\}\}$/g, '');
|
|
417
1203
|
|
|
418
|
-
const
|
|
1204
|
+
const splitTemplateVarStringRcs = (str) => splitTemplateVarString(str, rcsVarRegex);
|
|
1205
|
+
|
|
1206
|
+
/** Same `{{tag}}` in both title and description must not share one semantic map entry. */
|
|
1207
|
+
const rcsSpanningSemanticVarNames = useMemo(
|
|
1208
|
+
() => getRcsSemanticVarNamesSpanningTitleAndDesc(templateTitle, templateDesc, rcsVarRegex),
|
|
1209
|
+
[templateTitle, templateDesc],
|
|
1210
|
+
);
|
|
1211
|
+
|
|
1212
|
+
/** Global slot index (0-based, title vars then desc) for a VarSegmentMessageEditor `id` (`{{tok}}_segIdx`), or null if not found. */
|
|
1213
|
+
const getGlobalSlotIndexForRcsFieldId = (varSegmentCompositeId, fieldTemplateStr, fieldType) => {
|
|
1214
|
+
const titleVarTokenMatches = templateTitle?.match(rcsVarRegex) ?? [];
|
|
1215
|
+
const offset = fieldType === TITLE_TEXT ? 0 : titleVarTokenMatches.length;
|
|
1216
|
+
const templateSegments = splitTemplateVarStringRcs(fieldTemplateStr ?? '');
|
|
1217
|
+
let varOrdinal = 0;
|
|
1218
|
+
for (let segmentIndexInField = 0; segmentIndexInField < templateSegments.length; segmentIndexInField += 1) {
|
|
1219
|
+
const segmentToken = templateSegments[segmentIndexInField];
|
|
1220
|
+
if (rcsVarTestRegex.test(segmentToken)) {
|
|
1221
|
+
if (`${segmentToken}_${segmentIndexInField}` === varSegmentCompositeId) {
|
|
1222
|
+
return offset + varOrdinal;
|
|
1223
|
+
}
|
|
1224
|
+
varOrdinal += 1;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return null;
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* Master-branch resolve: uses numeric slot keys + semantic spanning detection for correct
|
|
1232
|
+
* multi-field variable resolution.
|
|
1233
|
+
*/
|
|
1234
|
+
const resolveTemplateWithMap = (str = '', slotOffset = 0) => {
|
|
419
1235
|
if (!str) return '';
|
|
420
|
-
const arr =
|
|
1236
|
+
const arr = splitTemplateVarStringRcs(str);
|
|
1237
|
+
let varOrdinal = 0;
|
|
421
1238
|
return arr.map((elem) => {
|
|
422
1239
|
if (rcsVarTestRegex.test(elem)) {
|
|
423
1240
|
const key = getVarNameFromToken(elem);
|
|
424
|
-
const
|
|
1241
|
+
const globalSlot = slotOffset + varOrdinal;
|
|
1242
|
+
varOrdinal += 1;
|
|
1243
|
+
const v = resolveCardVarMappedSlotValue(
|
|
1244
|
+
cardVarMapped,
|
|
1245
|
+
key,
|
|
1246
|
+
globalSlot,
|
|
1247
|
+
isEditLike,
|
|
1248
|
+
rcsSpanningSemanticVarNames.has(key),
|
|
1249
|
+
);
|
|
425
1250
|
if (isNil(v) || String(v)?.trim?.() === '') return elem;
|
|
426
1251
|
return String(v);
|
|
427
1252
|
}
|
|
@@ -429,39 +1254,128 @@ export const Rcs = (props) => {
|
|
|
429
1254
|
}).join('');
|
|
430
1255
|
};
|
|
431
1256
|
|
|
1257
|
+
const buildCarouselCardsForPreview = (cards = []) => (cards || []).map((card = {}) => {
|
|
1258
|
+
const videoThumb = card.thumbnailSrc || card.videoAsset?.videoThumbnail || '';
|
|
1259
|
+
const videoSrc = card.videoAsset?.videoSrc || '';
|
|
1260
|
+
const resolvedTitle = !isFullMode ? resolveTemplateWithMap(card.title || '') : (card.title || '');
|
|
1261
|
+
const resolvedDesc = !isFullMode ? resolveTemplateWithMap(card.description || '') : (card.description || '');
|
|
1262
|
+
return {
|
|
1263
|
+
mediaType: (card.mediaType || '').toLowerCase(),
|
|
1264
|
+
imageSrc: card.imageSrc || '',
|
|
1265
|
+
videoSrc,
|
|
1266
|
+
videoPreviewImg: videoThumb,
|
|
1267
|
+
title: resolvedTitle,
|
|
1268
|
+
bodyText: resolvedDesc,
|
|
1269
|
+
suggestions: card.suggestions || [],
|
|
1270
|
+
};
|
|
1271
|
+
});
|
|
432
1272
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
if (
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
1273
|
+
/**
|
|
1274
|
+
* Content for TestAndPreviewSlidebox — apply cardVarMapped whenever the slot editor is shown
|
|
1275
|
+
* (VarSegmentMessageEditor: isEditFlow || !isFullMode). Full-mode create without edit uses plain
|
|
1276
|
+
* TextArea only — no mapping. Full-mode + edit uses slots; !isFullMode alone is not enough.
|
|
1277
|
+
*/
|
|
1278
|
+
const getTemplateContent = useCallback(() => {
|
|
1279
|
+
if (templateType === contentType.carousel) {
|
|
1280
|
+
const carouselDimKey = getCarouselDimensionKey();
|
|
1281
|
+
const carouselImgDims =
|
|
1282
|
+
RCS_CAROUSEL_IMAGE_DIMENSIONS[carouselDimKey] || RCS_CAROUSEL_IMAGE_DIMENSIONS.MEDIUM_MEDIUM;
|
|
1283
|
+
const carouselVidDims =
|
|
1284
|
+
RCS_CAROUSEL_VIDEO_THUMBNAIL_DIMENSIONS[carouselDimKey]
|
|
1285
|
+
|| RCS_CAROUSEL_VIDEO_THUMBNAIL_DIMENSIONS.MEDIUM_MEDIUM;
|
|
1286
|
+
return {
|
|
1287
|
+
carouselData: buildCarouselCardsForPreview(carouselData),
|
|
1288
|
+
carouselPreviewDimensions: {
|
|
1289
|
+
imageWidth: carouselImgDims.width,
|
|
1290
|
+
imageHeight: carouselImgDims.height,
|
|
1291
|
+
videoThumbWidth: carouselVidDims.width,
|
|
1292
|
+
videoThumbHeight: carouselVidDims.height,
|
|
1293
|
+
},
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
const isMediaTypeImage = templateMediaType === RCS_MEDIA_TYPES.IMAGE;
|
|
1297
|
+
const isMediaTypeVideo = templateMediaType === RCS_MEDIA_TYPES.VIDEO;
|
|
1298
|
+
const isMediaTypeText = templateMediaType === RCS_MEDIA_TYPES.NONE;
|
|
1299
|
+
|
|
1300
|
+
const isSlotMappingMode = isEditFlow || !isFullMode;
|
|
1301
|
+
const titleVarCountForResolve = isMediaTypeText
|
|
1302
|
+
? 0
|
|
1303
|
+
: ((templateTitle ? (templateTitle.match(rcsVarRegex) || []) : []).length);
|
|
1304
|
+
const resolvedTitle = isMediaTypeText
|
|
1305
|
+
? ''
|
|
1306
|
+
: (isSlotMappingMode ? resolveTemplateWithMap(templateTitle, 0) : templateTitle);
|
|
1307
|
+
const resolvedDesc = isSlotMappingMode
|
|
1308
|
+
? resolveTemplateWithMap(templateDesc, titleVarCountForResolve)
|
|
1309
|
+
: templateDesc;
|
|
1310
|
+
|
|
1311
|
+
const mediaPreview = {};
|
|
1312
|
+
if (isMediaTypeImage && rcsImageSrc) {
|
|
1313
|
+
mediaPreview.rcsImageSrc = rcsImageSrc;
|
|
1314
|
+
}
|
|
1315
|
+
if (isMediaTypeVideo && !isMediaTypeText) {
|
|
1316
|
+
if (rcsThumbnailSrc) {
|
|
1317
|
+
mediaPreview.rcsVideoSrc = rcsThumbnailSrc;
|
|
1318
|
+
} else if (rcsVideoSrc?.videoSrc) {
|
|
1319
|
+
mediaPreview.rcsVideoSrc = rcsVideoSrc.videoSrc;
|
|
1320
|
+
}
|
|
1321
|
+
if (rcsThumbnailSrc) {
|
|
1322
|
+
mediaPreview.rcsThumbnailSrc = rcsThumbnailSrc;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
453
1325
|
|
|
1326
|
+
const contentObj = {
|
|
1327
|
+
templateHeader: resolvedTitle,
|
|
1328
|
+
templateMessage: resolvedDesc,
|
|
1329
|
+
...mediaPreview,
|
|
1330
|
+
...(suggestions.length > 0 && {
|
|
1331
|
+
suggestions: suggestions,
|
|
1332
|
+
}),
|
|
1333
|
+
};
|
|
1334
|
+
|
|
1335
|
+
return contentObj;
|
|
1336
|
+
}, [
|
|
1337
|
+
templateMediaType,
|
|
1338
|
+
templateTitle,
|
|
1339
|
+
templateDesc,
|
|
1340
|
+
rcsImageSrc,
|
|
1341
|
+
rcsVideoSrc,
|
|
1342
|
+
rcsThumbnailSrc,
|
|
1343
|
+
suggestions,
|
|
1344
|
+
selectedDimension,
|
|
1345
|
+
isFullMode,
|
|
1346
|
+
isEditFlow,
|
|
1347
|
+
cardVarMapped,
|
|
1348
|
+
rcsSpanningSemanticVarNames,
|
|
1349
|
+
carouselData,
|
|
1350
|
+
selectedCarouselHeight,
|
|
1351
|
+
selectedCarouselWidth,
|
|
1352
|
+
]);
|
|
1353
|
+
|
|
1354
|
+
const testAndPreviewContent = useMemo(() => getTemplateContent(), [getTemplateContent]);
|
|
454
1355
|
|
|
455
|
-
const RcsLabel = styled.div`
|
|
456
|
-
display: flex;
|
|
457
|
-
margin-top: 20px;
|
|
458
|
-
`;
|
|
459
1356
|
const paramObj = params || {};
|
|
460
1357
|
useEffect(() => {
|
|
461
1358
|
const { id } = paramObj;
|
|
462
1359
|
if (id && isFullMode) {
|
|
463
1360
|
setSpin(true);
|
|
464
1361
|
actions.getTemplateDetails(id, setSpin);
|
|
1362
|
+
} else if (!id && isFullMode) {
|
|
1363
|
+
// Create New: clear standalone media and ALL possible carousel card Redux slots.
|
|
1364
|
+
// Redux persists across mounts so we must clear unconditionally (carouselData may be [] on fresh mount).
|
|
1365
|
+
updateRcsImageSrc('');
|
|
1366
|
+
setRcsVideoSrc({});
|
|
1367
|
+
setRcsThumbnailSrc('');
|
|
1368
|
+
setAssetList({});
|
|
1369
|
+
setEditFlow(false);
|
|
1370
|
+
actions.clearRcsMediaAsset(0);
|
|
1371
|
+
actions.clearRcsMediaAsset(1);
|
|
1372
|
+
for (let cardIdx = 0; cardIdx < MAX_RCS_CAROUSEL_ALLOWED; cardIdx += 1) {
|
|
1373
|
+
actions.clearRcsMediaAsset(getCarouselImageAssetIndex(cardIdx));
|
|
1374
|
+
actions.clearRcsMediaAsset(getCarouselVideoAssetIndex(cardIdx));
|
|
1375
|
+
actions.clearRcsMediaAsset(getCarouselThumbnailAssetIndex(cardIdx));
|
|
1376
|
+
}
|
|
1377
|
+
setCarouselData([]);
|
|
1378
|
+
setCarouselErrors([]);
|
|
465
1379
|
}
|
|
466
1380
|
return () => {
|
|
467
1381
|
actions.clearEditResponse();
|
|
@@ -469,67 +1383,79 @@ export const Rcs = (props) => {
|
|
|
469
1383
|
}, [paramObj.id]);
|
|
470
1384
|
|
|
471
1385
|
useEffect(() => {
|
|
472
|
-
|
|
1386
|
+
if (!(isEditFlow || !isFullMode)) return;
|
|
473
1387
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
1388
|
+
const titleTokenCount = (templateTitle ? (templateTitle.match(rcsVarRegex) || []) : []).length;
|
|
1389
|
+
|
|
1390
|
+
const initField = (targetString, setVarMap, slotOffset) => {
|
|
1391
|
+
const arr = splitTemplateVarStringRcs(targetString);
|
|
1392
|
+
if (!arr?.length) {
|
|
1393
|
+
setVarMap({});
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
const nextVarMap = {};
|
|
1397
|
+
let varOrdinal = 0;
|
|
1398
|
+
arr.forEach((elem, idx) => {
|
|
1399
|
+
// Mustache tokens: {{1}}, {{user_name}}, {{tag.FORMAT_1}}, etc.
|
|
1400
|
+
if (rcsVarTestRegex.test(elem)) {
|
|
1401
|
+
const id = `${elem}_${idx}`;
|
|
1402
|
+
const varName = getVarNameFromToken(elem);
|
|
1403
|
+
const globalSlot = slotOffset + varOrdinal;
|
|
1404
|
+
varOrdinal += 1;
|
|
1405
|
+
const mappedValue = resolveCardVarMappedSlotValue(
|
|
1406
|
+
cardVarMapped,
|
|
1407
|
+
varName,
|
|
1408
|
+
globalSlot,
|
|
1409
|
+
isEditLike,
|
|
1410
|
+
rcsSpanningSemanticVarNames.has(varName),
|
|
1411
|
+
);
|
|
1412
|
+
nextVarMap[id] = mappedValue;
|
|
480
1413
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
// RCS placeholders are alphanumeric/underscore (e.g. {{user_name}}), not numeric-only
|
|
485
|
-
if (rcsVarTestRegex.test(elem)) {
|
|
486
|
-
const id = `${elem}_${idx}`;
|
|
487
|
-
const varName = getVarNameFromToken(elem);
|
|
488
|
-
const mappedValue = (cardVarMapped?.[varName] ?? '').toString();
|
|
489
|
-
nextVarMap[id] = mappedValue;
|
|
490
|
-
if (mappedValue !== '') {
|
|
491
|
-
nextUpdated[idx] = mappedValue;
|
|
492
|
-
} else {
|
|
493
|
-
nextUpdated[idx] = elem;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
setVarMap(nextVarMap);
|
|
498
|
-
setUpdated(nextUpdated);
|
|
499
|
-
};
|
|
1414
|
+
});
|
|
1415
|
+
setVarMap(nextVarMap);
|
|
1416
|
+
};
|
|
500
1417
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
1418
|
+
initField(templateTitle, setTitleVarMappedData, 0);
|
|
1419
|
+
initField(templateDesc, setDescVarMappedData, titleTokenCount);
|
|
1420
|
+
}, [templateTitle, templateDesc, cardVarMapped, isEditFlow, isFullMode, rcsSpanningSemanticVarNames]);
|
|
1421
|
+
|
|
1422
|
+
useEffect(() => {
|
|
1423
|
+
if (!isEditFlow && isFullMode) {
|
|
507
1424
|
setRcsVideoSrc({});
|
|
508
1425
|
updateRcsImageSrc('');
|
|
509
|
-
|
|
510
|
-
updateRcsThumbnailSrc('');
|
|
1426
|
+
setRcsThumbnailSrc('');
|
|
511
1427
|
setAssetList({});
|
|
512
|
-
|
|
513
|
-
|
|
1428
|
+
}
|
|
1429
|
+
}, [templateMediaType]);
|
|
514
1430
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
1431
|
+
/** Status on first card — same merged card as title/description/cardVarMapped (library may only set rcsContent at root). */
|
|
1432
|
+
const templateStatusHelper = (cardContentFirst) => {
|
|
1433
|
+
const raw =
|
|
1434
|
+
cardContentFirst?.Status
|
|
1435
|
+
?? cardContentFirst?.status
|
|
1436
|
+
?? cardContentFirst?.approvalStatus
|
|
1437
|
+
?? '';
|
|
1438
|
+
const status = typeof raw === 'string' ? raw.trim() : String(raw);
|
|
1439
|
+
const n = status.toLowerCase();
|
|
1440
|
+
switch (n) {
|
|
1441
|
+
case 'approved':
|
|
519
1442
|
setTemplateStatus(RCS_STATUSES.approved);
|
|
520
1443
|
break;
|
|
521
|
-
case
|
|
1444
|
+
case 'pending':
|
|
522
1445
|
setTemplateStatus(RCS_STATUSES.pending);
|
|
523
1446
|
break;
|
|
524
|
-
case
|
|
1447
|
+
case 'awaitingapproval':
|
|
525
1448
|
setTemplateStatus(RCS_STATUSES.awaitingApproval);
|
|
526
1449
|
break;
|
|
527
|
-
case
|
|
1450
|
+
case 'unavailable':
|
|
528
1451
|
setTemplateStatus(RCS_STATUSES.unavailable);
|
|
529
1452
|
break;
|
|
530
|
-
case
|
|
1453
|
+
case 'rejected':
|
|
531
1454
|
setTemplateStatus(RCS_STATUSES.rejected);
|
|
532
1455
|
break;
|
|
1456
|
+
case 'created':
|
|
1457
|
+
setTemplateStatus(RCS_STATUSES.created);
|
|
1458
|
+
break;
|
|
533
1459
|
default:
|
|
534
1460
|
setTemplateStatus(status);
|
|
535
1461
|
break;
|
|
@@ -583,48 +1509,287 @@ export const Rcs = (props) => {
|
|
|
583
1509
|
};
|
|
584
1510
|
|
|
585
1511
|
useEffect(() => {
|
|
586
|
-
const details =
|
|
1512
|
+
const details = rcsHydrationDetails;
|
|
587
1513
|
if (details && Object.keys(details).length > 0) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
1514
|
+
// Library/campaign: match SMS fallback — read from versions… and from top-level rcsContent (getCreativesData / parent shape).
|
|
1515
|
+
const cardFromVersions = get(
|
|
1516
|
+
details,
|
|
1517
|
+
'versions.base.content.RCS.rcsContent.cardContent[0]',
|
|
1518
|
+
);
|
|
1519
|
+
const rcsContent = get(details, 'versions.base.content.RCS.rcsContent', {});
|
|
1520
|
+
const cardType = (rcsContent?.cardType || '').toString().toLowerCase();
|
|
1521
|
+
|
|
1522
|
+
setEditFlow(true);
|
|
1523
|
+
setTemplateName(details?.name || details?.creativeName || '');
|
|
1524
|
+
|
|
1525
|
+
const cardFromTop = get(details, 'rcsContent.cardContent[0]');
|
|
1526
|
+
const card0 = { ...(cardFromTop || {}), ...(cardFromVersions || {}) };
|
|
1527
|
+
const cardVarMappedFromCardContent =
|
|
1528
|
+
card0?.cardVarMapped != null && typeof card0.cardVarMapped === 'object'
|
|
1529
|
+
? card0.cardVarMapped
|
|
1530
|
+
: {};
|
|
1531
|
+
const cardVarMappedFromRootMirror =
|
|
1532
|
+
details?.rcsCardVarMapped != null && typeof details.rcsCardVarMapped === 'object'
|
|
1533
|
+
? details.rcsCardVarMapped
|
|
1534
|
+
: {};
|
|
1535
|
+
// Root mirror from getCreativesData / getFormData — campaigns often preserve flat fields when
|
|
1536
|
+
// nested versions.cardContent[0].cardVarMapped is dropped on reload.
|
|
1537
|
+
const mergedCardVarMappedFromPayload = {
|
|
1538
|
+
...cardVarMappedFromRootMirror,
|
|
1539
|
+
...cardVarMappedFromCardContent,
|
|
1540
|
+
};
|
|
1541
|
+
const loadedTitleForMap = card0?.title != null ? String(card0.title) : '';
|
|
1542
|
+
const loadedDescForMap = card0?.description != null ? String(card0.description) : '';
|
|
1543
|
+
const hydratedCardVarPayloadSignature = `${loadedTitleForMap}\u0000${loadedDescForMap}\u0000${JSON.stringify(
|
|
1544
|
+
Object.keys(mergedCardVarMappedFromPayload)
|
|
1545
|
+
.sort()
|
|
1546
|
+
.reduce((accumulator, mapKey) => {
|
|
1547
|
+
accumulator[mapKey] = mergedCardVarMappedFromPayload[mapKey];
|
|
1548
|
+
return accumulator;
|
|
1549
|
+
}, {}),
|
|
1550
|
+
)}`;
|
|
1551
|
+
if (lastHydratedRcsCardVarSignatureRef.current !== hydratedCardVarPayloadSignature) {
|
|
1552
|
+
lastHydratedRcsCardVarSignatureRef.current = hydratedCardVarPayloadSignature;
|
|
1553
|
+
setRcsVarSegmentEditorRemountKey((previousKey) => previousKey + 1);
|
|
1554
|
+
}
|
|
1555
|
+
const tokenListForMap = [
|
|
1556
|
+
...(loadedTitleForMap ? loadedTitleForMap.match(rcsVarRegex) ?? [] : []),
|
|
1557
|
+
...(loadedDescForMap ? loadedDescForMap.match(rcsVarRegex) ?? [] : []),
|
|
1558
|
+
];
|
|
1559
|
+
const orderedTagNamesForMap = tokenListForMap.map((token) => getVarNameFromToken(token)).filter(Boolean);
|
|
1560
|
+
// Full-mode library/API payloads need normalize for legacy slot shapes. Campaign round-trip from
|
|
1561
|
+
// getFormData already stores TagList values as {{TagName}}; normalize can strip or remap them.
|
|
1562
|
+
const cardVarMappedBeforeCoalesce = isFullMode
|
|
1563
|
+
? normalizeCardVarMapped(mergedCardVarMappedFromPayload, orderedTagNamesForMap)
|
|
1564
|
+
: { ...mergedCardVarMappedFromPayload };
|
|
1565
|
+
const cardVarMappedAfterCoalesce = coalesceCardVarMappedToTemplate(
|
|
1566
|
+
cardVarMappedBeforeCoalesce,
|
|
1567
|
+
loadedTitleForMap,
|
|
1568
|
+
loadedDescForMap,
|
|
1569
|
+
rcsVarRegex,
|
|
1570
|
+
);
|
|
1571
|
+
const cardVarMappedAfterNumericSlotSync = !isFullMode
|
|
1572
|
+
? syncCardVarMappedSemanticsFromSlots(
|
|
1573
|
+
cardVarMappedAfterCoalesce,
|
|
1574
|
+
loadedTitleForMap,
|
|
1575
|
+
loadedDescForMap,
|
|
1576
|
+
rcsVarRegex,
|
|
1577
|
+
)
|
|
1578
|
+
: cardVarMappedAfterCoalesce;
|
|
1579
|
+
const hydratedCardVarMappedResult = { ...cardVarMappedAfterNumericSlotSync };
|
|
1580
|
+
// Pre-populate variable/tag mappings while opening an existing template in edit flows
|
|
1581
|
+
setCardVarMapped((previousVarMapState) => {
|
|
1582
|
+
const previousVarMap = previousVarMapState ?? {};
|
|
1583
|
+
if (previousVarMap === hydratedCardVarMappedResult) return previousVarMapState;
|
|
1584
|
+
const previousVarMapKeys = Object.keys(previousVarMap);
|
|
1585
|
+
const nextVarMapKeys = Object.keys(hydratedCardVarMappedResult);
|
|
1586
|
+
if (previousVarMapKeys.length === nextVarMapKeys.length) {
|
|
1587
|
+
const allSlotValuesMatchPrevious = previousVarMapKeys.every(
|
|
1588
|
+
(key) => previousVarMap[key] === hydratedCardVarMappedResult[key],
|
|
1589
|
+
);
|
|
1590
|
+
if (allSlotValuesMatchPrevious) return previousVarMapState;
|
|
1591
|
+
}
|
|
1592
|
+
return hydratedCardVarMappedResult;
|
|
1593
|
+
});
|
|
1594
|
+
|
|
1595
|
+
if (cardType === contentType.carousel) {
|
|
1596
|
+
|
|
1597
|
+
setTemplateType(contentType.carousel);
|
|
1598
|
+
setTemplateMediaType(RCS_MEDIA_TYPES.NONE);
|
|
1599
|
+
const cardSettings = rcsContent?.cardSettings || {};
|
|
1600
|
+
const cardWidth = cardSettings?.cardWidth || SMALL;
|
|
1601
|
+
setSelectedCarouselWidth(cardWidth);
|
|
1602
|
+
|
|
1603
|
+
const cards = Array.isArray(rcsContent?.cardContent) ? rcsContent.cardContent : [];
|
|
1604
|
+
const firstHeight = cards?.[0]?.media?.height || MEDIUM;
|
|
1605
|
+
setSelectedCarouselHeight(firstHeight);
|
|
1606
|
+
setSelectedCarousel(`${firstHeight}_${cardWidth}`);
|
|
1607
|
+
setActiveCarouselIndex('0');
|
|
1608
|
+
|
|
1609
|
+
const hydratedCards = cards.map((c = {}, idx) => {
|
|
1610
|
+
const mediaType = c.mediaType;
|
|
1611
|
+
const media = c.media || {};
|
|
1612
|
+
const mediaUrl = media.mediaUrl || '';
|
|
1613
|
+
const thumbUrl = media.thumbnailUrl || '';
|
|
1614
|
+
const rawSuggestions = Array.isArray(c.suggestions) ? c.suggestions : [];
|
|
1615
|
+
const suggestions = idx === 0 && rawSuggestions.length === 0
|
|
1616
|
+
? cloneDeep(RCS_CAROUSEL_FIRST_CARD_DEFAULT_SUGGESTIONS)
|
|
1617
|
+
: rawSuggestions;
|
|
1618
|
+
return {
|
|
1619
|
+
title: c.title || '',
|
|
1620
|
+
description: c.description || '',
|
|
1621
|
+
mediaType,
|
|
1622
|
+
imageSrc: mediaType === RCS_MEDIA_TYPES.IMAGE ? mediaUrl : '',
|
|
1623
|
+
videoAsset: mediaType === RCS_MEDIA_TYPES.VIDEO ? {
|
|
1624
|
+
videoSrc: mediaUrl,
|
|
1625
|
+
previewUrl: thumbUrl,
|
|
1626
|
+
videoThumbnail: thumbUrl,
|
|
1627
|
+
videoName: c?.media?.videoName || '',
|
|
1628
|
+
} : {},
|
|
1629
|
+
thumbnailSrc: mediaType === RCS_MEDIA_TYPES.VIDEO ? thumbUrl : '',
|
|
1630
|
+
suggestions,
|
|
1631
|
+
};
|
|
1632
|
+
});
|
|
1633
|
+
setCarouselData(
|
|
1634
|
+
hydratedCards.length > 0
|
|
1635
|
+
? ensureFirstCardDefaultPhoneSuggestions(hydratedCards)
|
|
1636
|
+
: [cloneDeep(RCS_CAROUSEL_INITIAL_FIRST_CARD)],
|
|
1637
|
+
);
|
|
1638
|
+
setCarouselErrors(new Array(hydratedCards.length > 0 ? hydratedCards.length : 1).fill({}));
|
|
1639
|
+
|
|
1640
|
+
// Status bar uses first card's Status, keep existing behavior.
|
|
1641
|
+
if (isHostInfoBip) {
|
|
1642
|
+
setTemplateStatus('');
|
|
1643
|
+
} else {
|
|
1644
|
+
const firstCard = cards?.[0] || {};
|
|
1645
|
+
const cardForCarouselStatus = {
|
|
1646
|
+
...firstCard,
|
|
1647
|
+
Status:
|
|
1648
|
+
firstCard.Status
|
|
1649
|
+
?? firstCard.status
|
|
1650
|
+
?? firstCard.approvalStatus
|
|
1651
|
+
?? get(details, 'templateStatus')
|
|
1652
|
+
?? get(details, 'approvalStatus')
|
|
1653
|
+
?? get(details, 'creativeStatus')
|
|
1654
|
+
?? get(details, 'versions.base.content.RCS.templateApprovalStatus')
|
|
1655
|
+
?? '',
|
|
1656
|
+
};
|
|
1657
|
+
templateStatusHelper(cardForCarouselStatus);
|
|
1658
|
+
}
|
|
1659
|
+
return;
|
|
591
1660
|
}
|
|
592
|
-
|
|
593
|
-
|
|
1661
|
+
|
|
1662
|
+
const mediaType =
|
|
1663
|
+
card0.mediaType
|
|
1664
|
+
|| get(details, 'versions.base.content.RCS.rcsContent.cardContent[0].mediaType', '');
|
|
1665
|
+
if (cardType !== contentType.carousel && mediaType === RCS_MEDIA_TYPES.NONE) {
|
|
594
1666
|
setTemplateType(contentType.text_message);
|
|
595
|
-
} else {
|
|
1667
|
+
} else if (cardType !== contentType.carousel && mediaType !== RCS_MEDIA_TYPES.NONE) {
|
|
596
1668
|
setTemplateType(contentType.rich_card);
|
|
597
1669
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
const
|
|
601
|
-
const
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
1670
|
+
|
|
1671
|
+
const loadedTitle = loadedTitleForMap;
|
|
1672
|
+
const loadedDesc = loadedDescForMap;
|
|
1673
|
+
const { normalizedTitle, normalizedDesc } = normalizeLibraryLoadedTitleDesc({
|
|
1674
|
+
loadedTitle,
|
|
1675
|
+
loadedDesc,
|
|
1676
|
+
isFullMode,
|
|
1677
|
+
cardVarMappedAfterHydration: hydratedCardVarMappedResult,
|
|
1678
|
+
rcsVarRegex,
|
|
1679
|
+
});
|
|
605
1680
|
setTemplateTitle(normalizedTitle);
|
|
606
1681
|
setTemplateDesc(normalizedDesc);
|
|
607
|
-
setSuggestions(
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
1682
|
+
setSuggestions(
|
|
1683
|
+
Array.isArray(card0.suggestions)
|
|
1684
|
+
? card0.suggestions
|
|
1685
|
+
: get(details, 'versions.base.content.RCS.rcsContent.cardContent[0].suggestions', []),
|
|
1686
|
+
);
|
|
1687
|
+
const cardForStatus = {
|
|
1688
|
+
...card0,
|
|
1689
|
+
Status:
|
|
1690
|
+
card0.Status
|
|
1691
|
+
?? card0.status
|
|
1692
|
+
?? card0.approvalStatus
|
|
1693
|
+
?? get(details, 'templateStatus')
|
|
1694
|
+
?? get(details, 'approvalStatus')
|
|
1695
|
+
?? get(details, 'creativeStatus')
|
|
1696
|
+
?? get(details, 'versions.base.content.RCS.templateApprovalStatus')
|
|
1697
|
+
?? '',
|
|
1698
|
+
};
|
|
1699
|
+
if (isHostInfoBip) {
|
|
1700
|
+
setTemplateStatus('');
|
|
1701
|
+
} else {
|
|
1702
|
+
templateStatusHelper(cardForStatus);
|
|
1703
|
+
}
|
|
1704
|
+
const mediaData =
|
|
1705
|
+
card0.media != null && card0.media !== ''
|
|
1706
|
+
? card0.media
|
|
1707
|
+
: get(details, 'versions.base.content.RCS.rcsContent.cardContent[0].media', '');
|
|
1708
|
+
const cardSettings =
|
|
1709
|
+
get(details, 'versions.base.content.RCS.rcsContent.cardSettings', '')
|
|
1710
|
+
|| get(details, 'rcsContent.cardSettings', '');
|
|
611
1711
|
setMediaData(mediaData, mediaType, cardSettings);
|
|
612
1712
|
if (details?.edit) {
|
|
613
1713
|
const rcsAccountId = get(details, 'versions.base.content.RCS.rcsContent.accountId', '');
|
|
614
1714
|
setRcsAccount(rcsAccountId);
|
|
615
1715
|
}
|
|
1716
|
+
|
|
1717
|
+
const smsFallbackContent = mergeRcsSmsFallBackContentFromDetails(details);
|
|
1718
|
+
const base = get(smsFallbackContent, 'versions.base', {});
|
|
1719
|
+
const updatedEditor = base['updated-sms-editor'] ?? base['sms-editor'];
|
|
1720
|
+
const smsEditor = base['sms-editor'];
|
|
1721
|
+
const fromNested = Array.isArray(updatedEditor)
|
|
1722
|
+
? updatedEditor.join('')
|
|
1723
|
+
: (typeof updatedEditor === 'string' ? updatedEditor : (smsEditor || ''));
|
|
1724
|
+
const fallbackMessage = smsFallbackContent.smsContent
|
|
1725
|
+
|| smsFallbackContent.smsTemplateContent
|
|
1726
|
+
|| smsFallbackContent.message
|
|
1727
|
+
|| fromNested
|
|
1728
|
+
|| '';
|
|
1729
|
+
const varMappedFromPayload = smsFallbackContent[RCS_SMS_FALLBACK_VAR_MAPPED_PROP] || {};
|
|
1730
|
+
const hasVarMapped = Object.keys(varMappedFromPayload).length > 0;
|
|
1731
|
+
const hasFallbackPayload =
|
|
1732
|
+
smsFallbackContent
|
|
1733
|
+
&& Object.keys(smsFallbackContent).length > 0
|
|
1734
|
+
&& (
|
|
1735
|
+
!!smsFallbackContent.smsTemplateName
|
|
1736
|
+
|| !!fallbackMessage
|
|
1737
|
+
|| hasVarMapped
|
|
1738
|
+
);
|
|
1739
|
+
if (hasFallbackPayload) {
|
|
1740
|
+
if (!fallbackMessage && !hasVarMapped && process.env.NODE_ENV !== 'production') {
|
|
1741
|
+
console.warn('[RCS SMS Fallback] No message text found in API response. Inspect shape:', smsFallbackContent);
|
|
1742
|
+
}
|
|
1743
|
+
const unicodeFromApi =
|
|
1744
|
+
typeof smsFallbackContent.unicodeValidity === 'boolean'
|
|
1745
|
+
? smsFallbackContent.unicodeValidity
|
|
1746
|
+
: (typeof base['unicode-validity'] === 'boolean' ? base['unicode-validity'] : true);
|
|
1747
|
+
const registeredSenderIdsFromApi =
|
|
1748
|
+
extractRegisteredSenderIdsFromSmsFallbackRecord(smsFallbackContent);
|
|
1749
|
+
const nextSmsState = {
|
|
1750
|
+
templateName: smsFallbackContent.smsTemplateName || '',
|
|
1751
|
+
content: fallbackMessage,
|
|
1752
|
+
templateContent: fallbackMessage,
|
|
1753
|
+
unicodeValidity: unicodeFromApi,
|
|
1754
|
+
...(hasVarMapped && { rcsSmsFallbackVarMapped: varMappedFromPayload }),
|
|
1755
|
+
...(Array.isArray(registeredSenderIdsFromApi) && registeredSenderIdsFromApi.length > 0
|
|
1756
|
+
? { registeredSenderIds: registeredSenderIdsFromApi }
|
|
1757
|
+
: {}),
|
|
1758
|
+
};
|
|
1759
|
+
const hydrationKey = JSON.stringify({
|
|
1760
|
+
creativeKey: details._id || details.name || details.creativeName || '',
|
|
1761
|
+
templateName: nextSmsState.templateName,
|
|
1762
|
+
content: nextSmsState.content,
|
|
1763
|
+
unicodeValidity: nextSmsState.unicodeValidity,
|
|
1764
|
+
varMapped: nextSmsState.rcsSmsFallbackVarMapped || {},
|
|
1765
|
+
senderIds:
|
|
1766
|
+
Array.isArray(registeredSenderIdsFromApi)
|
|
1767
|
+
? registeredSenderIdsFromApi.join('\u001f')
|
|
1768
|
+
: '',
|
|
1769
|
+
});
|
|
1770
|
+
if (
|
|
1771
|
+
isFullMode
|
|
1772
|
+
|| lastSmsFallbackHydrationKeyRef.current !== hydrationKey
|
|
1773
|
+
) {
|
|
1774
|
+
lastSmsFallbackHydrationKeyRef.current = hydrationKey;
|
|
1775
|
+
setSmsFallbackData(nextSmsState);
|
|
1776
|
+
}
|
|
1777
|
+
} else if (isFullMode || lastSmsFallbackHydrationKeyRef.current !== '__EMPTY__') {
|
|
1778
|
+
lastSmsFallbackHydrationKeyRef.current = '__EMPTY__';
|
|
1779
|
+
setSmsFallbackData(null);
|
|
1780
|
+
}
|
|
616
1781
|
}
|
|
617
|
-
}, [
|
|
618
|
-
|
|
1782
|
+
}, [rcsHydrationDetails, isFullMode, isHostInfoBip]);
|
|
619
1783
|
|
|
620
1784
|
useEffect(() => {
|
|
621
1785
|
if (templateType === contentType.text_message) {
|
|
622
1786
|
setTemplateMediaType(RCS_MEDIA_TYPES.NONE);
|
|
623
|
-
|
|
624
|
-
|
|
1787
|
+
// Full-mode create only: switching to plain text clears draft title/media. Never clear when
|
|
1788
|
+
// hydrating library/edit (would wipe templateData after load) — regression seen after SMS fallback work.
|
|
625
1789
|
if (!isEditFlow && isFullMode) {
|
|
1790
|
+
setTemplateTitle('');
|
|
1791
|
+
setTemplateTitleError('');
|
|
626
1792
|
setUpdateRcsImageSrc('');
|
|
627
|
-
setUpdateRcsVideoSrc({});
|
|
628
1793
|
setRcsVideoSrc({});
|
|
629
1794
|
setSelectedDimension(RCS_IMAGE_DIMENSIONS.MEDIUM_HEIGHT.type);
|
|
630
1795
|
}
|
|
@@ -651,7 +1816,8 @@ export const Rcs = (props) => {
|
|
|
651
1816
|
if (!showDltContainer) {
|
|
652
1817
|
const { type, module } = location.query || {};
|
|
653
1818
|
const isEmbedded = type === EMBEDDED;
|
|
654
|
-
|
|
1819
|
+
// Match TagList initial fetch (getTagsforContext('Outbound') → context "outbound") so we do not request a different context than the two TagList headers.
|
|
1820
|
+
const context = isEmbedded ? module : 'outbound';
|
|
655
1821
|
const embedded = isEmbedded ? type : FULL;
|
|
656
1822
|
const query = {
|
|
657
1823
|
layout: SMS,
|
|
@@ -662,9 +1828,9 @@ export const Rcs = (props) => {
|
|
|
662
1828
|
if (getDefaultTags) {
|
|
663
1829
|
query.context = getDefaultTags;
|
|
664
1830
|
}
|
|
665
|
-
|
|
1831
|
+
fetchTagSchemaIfNewQuery(query);
|
|
666
1832
|
}
|
|
667
|
-
}, [showDltContainer]);
|
|
1833
|
+
}, [showDltContainer, fetchTagSchemaIfNewQuery]);
|
|
668
1834
|
|
|
669
1835
|
useEffect(() => {
|
|
670
1836
|
let tag = get(metaEntities, `tags.standard`, []);
|
|
@@ -687,16 +1853,114 @@ export const Rcs = (props) => {
|
|
|
687
1853
|
context,
|
|
688
1854
|
embedded,
|
|
689
1855
|
};
|
|
1856
|
+
if (getDefaultTags) {
|
|
1857
|
+
query.context = getDefaultTags;
|
|
1858
|
+
}
|
|
1859
|
+
fetchTagSchemaIfNewQuery(query);
|
|
690
1860
|
globalActions.fetchSchemaForEntity(query);
|
|
691
1861
|
};
|
|
692
1862
|
|
|
693
|
-
const
|
|
694
|
-
if (!
|
|
695
|
-
const
|
|
1863
|
+
const replaceNumericPlaceholderWithTagInTemplate = (templateStr, numericVarName, tagName) => {
|
|
1864
|
+
if (!templateStr || !numericVarName || !tagName) return templateStr;
|
|
1865
|
+
const re = buildRcsNumericMustachePlaceholderRegex(numericVarName);
|
|
1866
|
+
return templateStr.replace(re, `{{${tagName}}}`);
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
const onTagSelect = (selectedTagNameFromPicker, varSegmentCompositeDomId, tagAreaField) => {
|
|
1870
|
+
if (!varSegmentCompositeDomId) return;
|
|
1871
|
+
const underscoreIndexInCompositeId = varSegmentCompositeDomId.lastIndexOf('_');
|
|
1872
|
+
if (underscoreIndexInCompositeId === -1) return;
|
|
1873
|
+
const segmentIndexSuffix = varSegmentCompositeDomId.slice(underscoreIndexInCompositeId + 1);
|
|
1874
|
+
if (segmentIndexSuffix === '' || isNaN(Number(segmentIndexSuffix))) return;
|
|
1875
|
+
const mustacheTokenFromCompositeId = varSegmentCompositeDomId.slice(0, underscoreIndexInCompositeId);
|
|
1876
|
+
const semanticOrNumericVarName = getVarNameFromToken(mustacheTokenFromCompositeId);
|
|
1877
|
+
if (!semanticOrNumericVarName) return;
|
|
1878
|
+
const isNumericPlaceholderSlot = RCS_NUMERIC_VAR_NAME_REGEX.test(String(semanticOrNumericVarName));
|
|
1879
|
+
const templateStringForField =
|
|
1880
|
+
tagAreaField === RCS_TAG_AREA_FIELD_TITLE ? templateTitle : templateDesc;
|
|
1881
|
+
const titleOrMessageFieldType =
|
|
1882
|
+
tagAreaField === RCS_TAG_AREA_FIELD_TITLE ? TITLE_TEXT : MESSAGE_TEXT;
|
|
1883
|
+
const globalVarSlotIndexZeroBased = getGlobalSlotIndexForRcsFieldId(
|
|
1884
|
+
varSegmentCompositeDomId,
|
|
1885
|
+
templateStringForField,
|
|
1886
|
+
titleOrMessageFieldType,
|
|
1887
|
+
);
|
|
1888
|
+
const cardVarMappedNumericSlotKey =
|
|
1889
|
+
globalVarSlotIndexZeroBased !== null && globalVarSlotIndexZeroBased !== undefined
|
|
1890
|
+
? String(globalVarSlotIndexZeroBased + 1)
|
|
1891
|
+
: null;
|
|
1892
|
+
|
|
1893
|
+
setCardVarMapped((previousCardVarMapped) => {
|
|
1894
|
+
const updatedCardVarMapped = { ...(previousCardVarMapped || {}) };
|
|
1895
|
+
if (isNumericPlaceholderSlot) {
|
|
1896
|
+
const existingValueBeforeAppend = (
|
|
1897
|
+
previousCardVarMapped?.[semanticOrNumericVarName] ?? ''
|
|
1898
|
+
).toString();
|
|
1899
|
+
const mappedValueAfterAppendingTag = `${existingValueBeforeAppend}{{${selectedTagNameFromPicker}}}`;
|
|
1900
|
+
delete updatedCardVarMapped[semanticOrNumericVarName];
|
|
1901
|
+
updatedCardVarMapped[selectedTagNameFromPicker] = mappedValueAfterAppendingTag;
|
|
1902
|
+
} else {
|
|
1903
|
+
// Same semantic token (e.g. {{adv}}) in title and body must not share one map key for
|
|
1904
|
+
// "existing value" — that appends the new tag onto the other field. Match handleRcsVarChange:
|
|
1905
|
+
// read/write the global numeric slot only and drop the shared semantic key.
|
|
1906
|
+
const existingValueBeforeAppend = cardVarMappedNumericSlotKey
|
|
1907
|
+
? String(previousCardVarMapped?.[cardVarMappedNumericSlotKey] ?? '')
|
|
1908
|
+
: String(previousCardVarMapped?.[semanticOrNumericVarName] ?? '');
|
|
1909
|
+
const mappedValueAfterAppendingTag = `${existingValueBeforeAppend}{{${selectedTagNameFromPicker}}}`;
|
|
1910
|
+
delete updatedCardVarMapped[semanticOrNumericVarName];
|
|
1911
|
+
if (cardVarMappedNumericSlotKey) {
|
|
1912
|
+
updatedCardVarMapped[cardVarMappedNumericSlotKey] = mappedValueAfterAppendingTag;
|
|
1913
|
+
} else {
|
|
1914
|
+
updatedCardVarMapped[semanticOrNumericVarName] = mappedValueAfterAppendingTag;
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
return updatedCardVarMapped;
|
|
1918
|
+
});
|
|
1919
|
+
|
|
1920
|
+
if (
|
|
1921
|
+
isNumericPlaceholderSlot
|
|
1922
|
+
&& (tagAreaField === RCS_TAG_AREA_FIELD_TITLE || tagAreaField === RCS_TAG_AREA_FIELD_DESC)
|
|
1923
|
+
) {
|
|
1924
|
+
if (tagAreaField === RCS_TAG_AREA_FIELD_TITLE) {
|
|
1925
|
+
setTemplateTitle((previousTitle) => {
|
|
1926
|
+
const titleAfterReplacingNumericPlaceholder = replaceNumericPlaceholderWithTagInTemplate(
|
|
1927
|
+
previousTitle || '',
|
|
1928
|
+
semanticOrNumericVarName,
|
|
1929
|
+
selectedTagNameFromPicker,
|
|
1930
|
+
);
|
|
1931
|
+
if (titleAfterReplacingNumericPlaceholder === previousTitle) return previousTitle;
|
|
1932
|
+
setTemplateTitleError(variableErrorHandling(titleAfterReplacingNumericPlaceholder));
|
|
1933
|
+
// Remount segment editor: tag insert replaces {{n}} with e.g. {{tag.FORMAT_1}} — slot ids change; avoids stale UI vs manual typing in full-mode TextArea
|
|
1934
|
+
setRcsVarSegmentEditorRemountKey((k) => k + 1);
|
|
1935
|
+
return titleAfterReplacingNumericPlaceholder;
|
|
1936
|
+
});
|
|
1937
|
+
} else {
|
|
1938
|
+
setTemplateDesc((previousDescription) => {
|
|
1939
|
+
const descriptionAfterReplacingNumericPlaceholder = replaceNumericPlaceholderWithTagInTemplate(
|
|
1940
|
+
previousDescription || '',
|
|
1941
|
+
semanticOrNumericVarName,
|
|
1942
|
+
selectedTagNameFromPicker,
|
|
1943
|
+
);
|
|
1944
|
+
if (descriptionAfterReplacingNumericPlaceholder === previousDescription) {
|
|
1945
|
+
return previousDescription;
|
|
1946
|
+
}
|
|
1947
|
+
setTemplateDescError(variableErrorHandling(descriptionAfterReplacingNumericPlaceholder));
|
|
1948
|
+
setRcsVarSegmentEditorRemountKey((k) => k + 1);
|
|
1949
|
+
return descriptionAfterReplacingNumericPlaceholder;
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
};
|
|
1954
|
+
|
|
1955
|
+
const onTitleTagSelect = (tagName) => onTagSelect(tagName, titleTextAreaId, RCS_TAG_AREA_FIELD_TITLE);
|
|
1956
|
+
|
|
1957
|
+
const onDescTagSelect = (tagName) => onTagSelect(tagName, descTextAreaId, RCS_TAG_AREA_FIELD_DESC);
|
|
1958
|
+
|
|
1959
|
+
const onCarouselTagSelect = (data) => {
|
|
1960
|
+
if (!carouselFocusedVarId) return;
|
|
1961
|
+
const sep = carouselFocusedVarId.lastIndexOf('_');
|
|
696
1962
|
if (sep === -1) return;
|
|
697
|
-
const
|
|
698
|
-
if (isNaN(numId)) return;
|
|
699
|
-
const token = areaId.slice(0, sep);
|
|
1963
|
+
const token = carouselFocusedVarId.slice(0, sep);
|
|
700
1964
|
const variableName = getVarNameFromToken(token);
|
|
701
1965
|
if (!variableName) return;
|
|
702
1966
|
setCardVarMapped((prev) => {
|
|
@@ -709,15 +1973,11 @@ export const Rcs = (props) => {
|
|
|
709
1973
|
});
|
|
710
1974
|
};
|
|
711
1975
|
|
|
712
|
-
const onTitleTagSelect = (data) => onTagSelect(data, titleTextAreaId);
|
|
713
|
-
|
|
714
|
-
const onDescTagSelect = (data) => onTagSelect(data, descTextAreaId);
|
|
715
|
-
|
|
716
1976
|
const onTagSelectFallback = (data) => {
|
|
717
1977
|
const tempMsg = `${fallbackMessage}{{${data}}}`;
|
|
718
1978
|
const error = fallbackMessageErrorHandler(tempMsg);
|
|
719
|
-
setFallbackMessage(tempMsg);
|
|
720
|
-
setFallbackMessageError(error);
|
|
1979
|
+
// setFallbackMessage(tempMsg);
|
|
1980
|
+
// setFallbackMessageError(error);
|
|
721
1981
|
};
|
|
722
1982
|
|
|
723
1983
|
|
|
@@ -732,15 +1992,14 @@ export const Rcs = (props) => {
|
|
|
732
1992
|
};
|
|
733
1993
|
// tag Code end
|
|
734
1994
|
|
|
735
|
-
const renderLabel = (value,
|
|
736
|
-
const isTemplateApproved = (templateStatus === RCS_STATUSES.approved);
|
|
1995
|
+
const renderLabel = (value, desc) => {
|
|
737
1996
|
return (
|
|
738
1997
|
<>
|
|
739
|
-
<
|
|
1998
|
+
<div className="rcs-form-section-heading">
|
|
740
1999
|
<CapHeading type="h4">{formatMessage(messages[value])}</CapHeading>
|
|
741
|
-
</
|
|
2000
|
+
</div>
|
|
742
2001
|
{desc && (
|
|
743
|
-
<CapLabel type="label3"
|
|
2002
|
+
<CapLabel type="label3" className="rcs-form-field-caption">
|
|
744
2003
|
{formatMessage(messages[desc])}
|
|
745
2004
|
</CapLabel>
|
|
746
2005
|
)}
|
|
@@ -757,15 +2016,14 @@ export const Rcs = (props) => {
|
|
|
757
2016
|
value: contentType.rich_card,
|
|
758
2017
|
label: formatMessage(messages.richCard),
|
|
759
2018
|
},
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
},
|
|
2019
|
+
...(!isHostInfoBip
|
|
2020
|
+
? [
|
|
2021
|
+
{
|
|
2022
|
+
value: contentType.carousel,
|
|
2023
|
+
label: formatMessage(messages.carousel),
|
|
2024
|
+
},
|
|
2025
|
+
]
|
|
2026
|
+
: []),
|
|
769
2027
|
];
|
|
770
2028
|
|
|
771
2029
|
const onTemplateNameChange = ({ target: { value } }) => {
|
|
@@ -776,6 +2034,10 @@ export const Rcs = (props) => {
|
|
|
776
2034
|
|
|
777
2035
|
const onTemplateTypeChange = ({ target: { value } }) => {
|
|
778
2036
|
setTemplateType(value);
|
|
2037
|
+
// Carousel has per-card media; keep template-level media type neutral.
|
|
2038
|
+
if (value === contentType.carousel) {
|
|
2039
|
+
setTemplateMediaType(RCS_MEDIA_TYPES.NONE);
|
|
2040
|
+
}
|
|
779
2041
|
};
|
|
780
2042
|
|
|
781
2043
|
|
|
@@ -796,8 +2058,39 @@ export const Rcs = (props) => {
|
|
|
796
2058
|
const onTemplateMediaTypeChange = ({ target: { value } }) => {
|
|
797
2059
|
setTemplateMediaType(value);
|
|
798
2060
|
};
|
|
799
|
-
|
|
800
|
-
|
|
2061
|
+
const renderedRCSEditMessage = (descArray, type) => {
|
|
2062
|
+
const renderArray = [];
|
|
2063
|
+
if (descArray?.length) {
|
|
2064
|
+
descArray.forEach((elem, index) => {
|
|
2065
|
+
if (rcsVarTestRegex.test(elem)) {
|
|
2066
|
+
// Variable input
|
|
2067
|
+
renderArray.push(
|
|
2068
|
+
<TextArea
|
|
2069
|
+
id={`${elem}_${index}`}
|
|
2070
|
+
key={`${elem}_${index}`}
|
|
2071
|
+
placeholder={`enter the value for ${elem}`}
|
|
2072
|
+
autosize={{ minRows: 1, maxRows: 3 }}
|
|
2073
|
+
onChange={e => textAreaValueChange(e, type)}
|
|
2074
|
+
value={textAreaValue(index, type)}
|
|
2075
|
+
onFocus={(e) => setTextAreaId(e, type)}
|
|
2076
|
+
/>
|
|
2077
|
+
);
|
|
2078
|
+
} else if (elem) {
|
|
2079
|
+
// Static text
|
|
2080
|
+
renderArray.push(
|
|
2081
|
+
<TextArea
|
|
2082
|
+
key={`static_${index}`}
|
|
2083
|
+
value={elem}
|
|
2084
|
+
autosize={{ minRows: 1, maxRows: 3 }}
|
|
2085
|
+
disabled
|
|
2086
|
+
className="rcs-edit-template-message-static-textarea"
|
|
2087
|
+
/>
|
|
2088
|
+
);
|
|
2089
|
+
}
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
return renderArray;
|
|
2093
|
+
};
|
|
801
2094
|
const onTemplateTitleChange = ({ target: { value } }) => {
|
|
802
2095
|
let errorMessage = false;
|
|
803
2096
|
if (templateType === contentType.rich_card && !value.trim()) {
|
|
@@ -813,7 +2106,7 @@ export const Rcs = (props) => {
|
|
|
813
2106
|
|
|
814
2107
|
const onTemplateDescChange = ({ target: { value } }) => {
|
|
815
2108
|
let errorMessage = false;
|
|
816
|
-
if(templateType === contentType.text_message && value?.length > RCS_TEXT_MESSAGE_MAX_LENGTH){
|
|
2109
|
+
if(templateType === contentType.text_message && value?.length > (isHostInfoBip ? RCS_TEXT_MESSAGE_MAX_LENGTH_INFOBIP : RCS_TEXT_MESSAGE_MAX_LENGTH)){
|
|
817
2110
|
errorMessage = formatMessage(messages.templateMessageLengthError);
|
|
818
2111
|
} else if(templateType === contentType.rich_card && value?.length > RCS_RICH_CARD_MAX_LENGTH){
|
|
819
2112
|
errorMessage = formatMessage(messages.templateMessageLengthError);
|
|
@@ -829,16 +2122,16 @@ export const Rcs = (props) => {
|
|
|
829
2122
|
|
|
830
2123
|
const templateDescErrorHandler = (value) => {
|
|
831
2124
|
let errorMessage = false;
|
|
832
|
-
const { isBraceError } = validateTags({
|
|
2125
|
+
const { unsupportedTags, isBraceError } = validateTags({
|
|
833
2126
|
content: value,
|
|
834
2127
|
tagsParam: tags,
|
|
2128
|
+
injectedTagsParams: injectedTags,
|
|
835
2129
|
location,
|
|
836
2130
|
tagModule: getDefaultTags,
|
|
837
|
-
isFullMode,
|
|
838
2131
|
}) || {};
|
|
839
2132
|
|
|
840
2133
|
const maxLength = templateType === contentType.text_message
|
|
841
|
-
? RCS_TEXT_MESSAGE_MAX_LENGTH
|
|
2134
|
+
? (isHostInfoBip ? RCS_TEXT_MESSAGE_MAX_LENGTH_INFOBIP : RCS_TEXT_MESSAGE_MAX_LENGTH)
|
|
842
2135
|
: RCS_RICH_CARD_MAX_LENGTH;
|
|
843
2136
|
|
|
844
2137
|
if (value === '' && isMediaTypeText) {
|
|
@@ -856,15 +2149,30 @@ export const Rcs = (props) => {
|
|
|
856
2149
|
|
|
857
2150
|
const onFallbackMessageChange = ({ target: { value } }) => {
|
|
858
2151
|
const error = fallbackMessageErrorHandler(value);
|
|
859
|
-
setFallbackMessage(value);
|
|
860
|
-
setFallbackMessageError(error);
|
|
2152
|
+
// setFallbackMessage(value);
|
|
2153
|
+
// setFallbackMessageError(error);
|
|
861
2154
|
};
|
|
862
2155
|
|
|
863
2156
|
const fallbackMessageErrorHandler = (value) => {
|
|
2157
|
+
let errorMessage = false;
|
|
2158
|
+
const { unsupportedTags } = validateTags({
|
|
2159
|
+
content: value,
|
|
2160
|
+
tagsParam: tags,
|
|
2161
|
+
injectedTagsParams: injectedTags,
|
|
2162
|
+
location,
|
|
2163
|
+
tagModule: getDefaultTags,
|
|
2164
|
+
}) || {};
|
|
864
2165
|
if (value?.length > FALLBACK_MESSAGE_MAX_LENGTH) {
|
|
865
|
-
|
|
2166
|
+
errorMessage = formatMessage(messages.fallbackMsgLenError);
|
|
2167
|
+
} else if (unsupportedTags?.length > 0) {
|
|
2168
|
+
errorMessage = formatMessage(
|
|
2169
|
+
globalMessages.unsupportedTagsValidationError,
|
|
2170
|
+
{
|
|
2171
|
+
unsupportedTags,
|
|
2172
|
+
},
|
|
2173
|
+
);
|
|
866
2174
|
}
|
|
867
|
-
return
|
|
2175
|
+
return errorMessage;
|
|
868
2176
|
};
|
|
869
2177
|
|
|
870
2178
|
// Check for forbidden characters: square brackets [] and single curly braces {}
|
|
@@ -911,53 +2219,43 @@ export const Rcs = (props) => {
|
|
|
911
2219
|
if(!isFullMode){
|
|
912
2220
|
return false;
|
|
913
2221
|
}
|
|
914
|
-
|
|
2222
|
+
// Allow Liquid-style param names: letters, digits, underscore, dots (e.g. dynamic_expiry_date_after_3_days.FORMAT_1)
|
|
2223
|
+
if (!/^[\w.]+$/.test(paramName)) {
|
|
915
2224
|
return formatMessage(messages.unknownCharactersError);
|
|
916
2225
|
}
|
|
917
2226
|
}
|
|
918
2227
|
return false;
|
|
919
2228
|
};
|
|
920
|
-
|
|
921
|
-
const templateHeaderErrorHandler = (value) => {
|
|
922
|
-
let errorMessage = false;
|
|
923
|
-
if (value?.length > TEMPLATE_HEADER_MAX_LENGTH) {
|
|
924
|
-
errorMessage = formatMessage(messages.templateHeaderLengthError);
|
|
925
|
-
} else {
|
|
926
|
-
errorMessage = variableErrorHandling(value);
|
|
927
|
-
}
|
|
928
|
-
return errorMessage;
|
|
929
|
-
};
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
const templateMessageErrorHandler = (value) => {
|
|
933
|
-
let errorMessage = false;
|
|
934
|
-
if (value === '') {
|
|
935
|
-
errorMessage = formatMessage(messages.emptyTemplateMessageErrorMessage);
|
|
936
|
-
} else if (
|
|
937
|
-
value?.length
|
|
938
|
-
> TEMPLATE_MESSAGE_MAX_LENGTH
|
|
939
|
-
) {
|
|
940
|
-
errorMessage = formatMessage(messages.templateMessageLengthError);
|
|
941
|
-
} else {
|
|
942
|
-
errorMessage = variableErrorHandling(value);
|
|
943
|
-
}
|
|
944
|
-
return errorMessage;
|
|
945
|
-
};
|
|
946
|
-
|
|
947
2229
|
|
|
948
2230
|
const onMessageAddVar = () => {
|
|
949
|
-
onAddVar(
|
|
2231
|
+
onAddVar(templateDesc);
|
|
950
2232
|
};
|
|
951
2233
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
2234
|
+
/**
|
|
2235
|
+
* Returns the smallest positive integer not already used as a `{{N}}` variable
|
|
2236
|
+
* in either the title or description fields, or null if the limit (19) is reached.
|
|
2237
|
+
* Scans both fields so title and description vars never share the same number
|
|
2238
|
+
* (duplicate numbers would share a cardVarMapped key and bleed values across fields).
|
|
2239
|
+
*/
|
|
2240
|
+
const getNextRcsNumericVarNumber = (titleStr, descStr) => {
|
|
2241
|
+
const allExistingVars = [
|
|
2242
|
+
...(titleStr.match(RCS_NUMERIC_VAR_TOKEN_REGEX) || []),
|
|
2243
|
+
...(descStr.match(RCS_NUMERIC_VAR_TOKEN_REGEX) || []),
|
|
2244
|
+
];
|
|
2245
|
+
const existingNumbers = allExistingVars.flatMap(v => {
|
|
2246
|
+
const m = v.match(/\d+/);
|
|
2247
|
+
return m ? [parseInt(m[0], 10)] : [];
|
|
2248
|
+
});
|
|
956
2249
|
let nextNumber = 1;
|
|
957
2250
|
while (existingNumbers.includes(nextNumber)) {
|
|
958
2251
|
nextNumber++;
|
|
959
2252
|
}
|
|
960
|
-
|
|
2253
|
+
return nextNumber > 19 ? null : nextNumber;
|
|
2254
|
+
};
|
|
2255
|
+
|
|
2256
|
+
const onAddVar = (messageContent) => {
|
|
2257
|
+
const nextNumber = getNextRcsNumericVarNumber(templateTitle, messageContent);
|
|
2258
|
+
if (nextNumber === null) {
|
|
961
2259
|
return;
|
|
962
2260
|
}
|
|
963
2261
|
const nextVar = `{{${nextNumber}}}`;
|
|
@@ -969,15 +2267,13 @@ const onAddVar = (type, messageContent, regex) => {
|
|
|
969
2267
|
};
|
|
970
2268
|
|
|
971
2269
|
const onTitleAddVar = () => {
|
|
972
|
-
//
|
|
2270
|
+
// Scan both title AND description so the new title var number doesn't
|
|
2271
|
+
// duplicate a number already used in the description. Duplicate numeric
|
|
2272
|
+
// names would share the same cardVarMapped semantic key, causing the
|
|
2273
|
+
// description slot to reflect the title slot value and vice-versa.
|
|
973
2274
|
const messageContent = templateTitle;
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
let nextNumber = 1;
|
|
977
|
-
while (existingNumbers.includes(nextNumber)) {
|
|
978
|
-
nextNumber++;
|
|
979
|
-
}
|
|
980
|
-
if (nextNumber > 19) {
|
|
2275
|
+
const nextNumber = getNextRcsNumericVarNumber(templateTitle, templateDesc);
|
|
2276
|
+
if (nextNumber === null) {
|
|
981
2277
|
return;
|
|
982
2278
|
}
|
|
983
2279
|
const nextVar = `{{${nextNumber}}}`;
|
|
@@ -989,26 +2285,35 @@ const onTitleAddVar = () => {
|
|
|
989
2285
|
setTemplateTitleError(error);
|
|
990
2286
|
};
|
|
991
2287
|
|
|
992
|
-
|
|
993
|
-
const
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
2288
|
+
// Carousel: global variables across the whole carousel (all cards, title+body)
|
|
2289
|
+
const getNextCarouselVarToken = () => {
|
|
2290
|
+
const nums = [];
|
|
2291
|
+
(carouselData || []).forEach((c = {}) => {
|
|
2292
|
+
const s1 = (c.title || '').match(/\{\{(\d+)\}\}/g) || [];
|
|
2293
|
+
const s2 = (c.description || '').match(/\{\{(\d+)\}\}/g) || [];
|
|
2294
|
+
[...s1, ...s2].forEach((tok) => {
|
|
2295
|
+
const n = parseInt((tok.match(/\d+/) || [])[0], 10);
|
|
2296
|
+
if (!Number.isNaN(n)) nums.push(n);
|
|
2297
|
+
});
|
|
2298
|
+
});
|
|
2299
|
+
const existing = new Set(nums);
|
|
2300
|
+
let nextNumber = 1;
|
|
2301
|
+
while (existing.has(nextNumber)) nextNumber++;
|
|
2302
|
+
if (nextNumber > 19) return '';
|
|
2303
|
+
return `{{${nextNumber}}}`;
|
|
2304
|
+
};
|
|
2305
|
+
|
|
2306
|
+
const appendVarToCarouselField = (cardIndex, fieldName) => {
|
|
2307
|
+
const token = getNextCarouselVarToken();
|
|
2308
|
+
if (!token) return;
|
|
2309
|
+
setCarouselData((prev = []) => {
|
|
2310
|
+
const updated = cloneDeep(prev);
|
|
2311
|
+
if (!updated[cardIndex]) return prev;
|
|
2312
|
+
const current = (updated[cardIndex][fieldName] || '').toString();
|
|
2313
|
+
updated[cardIndex][fieldName] = `${current}${token}`;
|
|
2314
|
+
return updated;
|
|
2315
|
+
});
|
|
2316
|
+
};
|
|
1012
2317
|
|
|
1013
2318
|
const textAreaValue = (idValue, type) => {
|
|
1014
2319
|
if (idValue >= 0) {
|
|
@@ -1024,6 +2329,46 @@ const splitTemplateVarString = (str) => {
|
|
|
1024
2329
|
return "";
|
|
1025
2330
|
};
|
|
1026
2331
|
|
|
2332
|
+
// Carousel: render variable-value editor for a given template string (title/description).
|
|
2333
|
+
// This matches rich-card/text edit behavior: static pieces are read-only, variable tokens are editable.
|
|
2334
|
+
const renderCarouselEditMessage = (templateStr) => {
|
|
2335
|
+
const renderArray = [];
|
|
2336
|
+
const templateArr = splitTemplateVarString(templateStr);
|
|
2337
|
+
if (templateArr?.length) {
|
|
2338
|
+
templateArr.forEach((elem, index) => {
|
|
2339
|
+
if (rcsVarTestRegex.test(elem)) {
|
|
2340
|
+
const varName = getVarNameFromToken(elem);
|
|
2341
|
+
renderArray.push(
|
|
2342
|
+
<div key={`${elem}_${index}`} className="var-segment-message-editor__var-slot">
|
|
2343
|
+
<TextArea
|
|
2344
|
+
id={`${elem}_${index}`}
|
|
2345
|
+
placeholder={`enter the value for ${elem}`}
|
|
2346
|
+
autosize={{ minRows: 1, maxRows: 3 }}
|
|
2347
|
+
onChange={(e) => textAreaValueChange(e, TITLE_TEXT)}
|
|
2348
|
+
value={varName ? ((cardVarMapped?.[varName] ?? '').toString()) : ''}
|
|
2349
|
+
onFocus={(e) => {
|
|
2350
|
+
const id = e?.target?.id || e?.currentTarget?.id || '';
|
|
2351
|
+
setCarouselFocusedVarId(id);
|
|
2352
|
+
}}
|
|
2353
|
+
/>
|
|
2354
|
+
</div>
|
|
2355
|
+
);
|
|
2356
|
+
} else if (elem) {
|
|
2357
|
+
renderArray.push(
|
|
2358
|
+
<CapHeading
|
|
2359
|
+
key={`static_${index}`}
|
|
2360
|
+
type="h4"
|
|
2361
|
+
className="rcs-edit-template-message-split"
|
|
2362
|
+
>
|
|
2363
|
+
{elem}
|
|
2364
|
+
</CapHeading>
|
|
2365
|
+
);
|
|
2366
|
+
}
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
return <CapRow className="rcs-edit-template-message-input">{renderArray}</CapRow>;
|
|
2370
|
+
};
|
|
2371
|
+
|
|
1027
2372
|
const textAreaValueChange = (e, type) => {
|
|
1028
2373
|
const value = e?.target?.value ?? '';
|
|
1029
2374
|
const id = e?.target?.id || e?.currentTarget?.id || '';
|
|
@@ -1043,7 +2388,9 @@ const splitTemplateVarString = (str) => {
|
|
|
1043
2388
|
};
|
|
1044
2389
|
|
|
1045
2390
|
const setTextAreaId = (e, type) => {
|
|
1046
|
-
|
|
2391
|
+
// VarSegmentMessageEditor calls onFocus(id) with a plain string; DOM events
|
|
2392
|
+
// have an `.target.id` shape. Support both.
|
|
2393
|
+
const id = typeof e === 'string' ? e : (e?.target?.id || e?.currentTarget?.id || '');
|
|
1047
2394
|
if (!id) return;
|
|
1048
2395
|
if (type === TITLE_TEXT) setTitleTextAreaId(id);
|
|
1049
2396
|
else setDescTextAreaId(id);
|
|
@@ -1074,44 +2421,71 @@ const splitTemplateVarString = (str) => {
|
|
|
1074
2421
|
isEditFlow={isEditFlow}
|
|
1075
2422
|
isFullMode={isFullMode}
|
|
1076
2423
|
maxButtons={MAX_BUTTONS}
|
|
1077
|
-
|
|
2424
|
+
host={hostName}
|
|
2425
|
+
/>
|
|
1078
2426
|
</>
|
|
1079
2427
|
);
|
|
1080
2428
|
};
|
|
1081
2429
|
|
|
1082
|
-
const
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
2430
|
+
const getRcsValueMap = (fieldTemplateString, fieldType) => {
|
|
2431
|
+
if (!fieldTemplateString) return {};
|
|
2432
|
+
const titleVarTokenMatches = templateTitle?.match(rcsVarRegex) ?? [];
|
|
2433
|
+
const slotOffset = fieldType === TITLE_TEXT ? 0 : titleVarTokenMatches.length;
|
|
2434
|
+
const templateSegments = splitTemplateVarStringRcs(fieldTemplateString);
|
|
2435
|
+
const segmentIdToResolvedValue = {};
|
|
2436
|
+
let varOrdinal = 0;
|
|
2437
|
+
templateSegments.forEach((segmentToken, segmentIndexInField) => {
|
|
2438
|
+
if (rcsVarTestRegex.test(segmentToken)) {
|
|
2439
|
+
const varSegmentCompositeId = `${segmentToken}_${segmentIndexInField}`;
|
|
2440
|
+
const varName = getVarNameFromToken(segmentToken);
|
|
2441
|
+
const globalSlot = slotOffset + varOrdinal;
|
|
2442
|
+
varOrdinal += 1;
|
|
2443
|
+
segmentIdToResolvedValue[varSegmentCompositeId] = resolveCardVarMappedSlotValue(
|
|
2444
|
+
cardVarMapped,
|
|
2445
|
+
varName,
|
|
2446
|
+
globalSlot,
|
|
2447
|
+
isEditLike,
|
|
2448
|
+
rcsSpanningSemanticVarNames.has(varName),
|
|
2449
|
+
);
|
|
2450
|
+
}
|
|
2451
|
+
});
|
|
2452
|
+
return segmentIdToResolvedValue;
|
|
2453
|
+
};
|
|
2454
|
+
|
|
2455
|
+
const titleVarSegmentValueMapById = useMemo(
|
|
2456
|
+
() => getRcsValueMap(templateTitle, TITLE_TEXT),
|
|
2457
|
+
[templateTitle, cardVarMapped, isEditFlow, isFullMode, rcsSpanningSemanticVarNames],
|
|
2458
|
+
);
|
|
2459
|
+
const descriptionVarSegmentValueMapById = useMemo(
|
|
2460
|
+
() => getRcsValueMap(templateDesc, MESSAGE_TEXT),
|
|
2461
|
+
[templateDesc, templateTitle, cardVarMapped, isEditFlow, isFullMode, rcsSpanningSemanticVarNames],
|
|
2462
|
+
);
|
|
2463
|
+
|
|
2464
|
+
const handleRcsVarChange = (varSegmentCompositeDomId, value, type) => {
|
|
2465
|
+
const underscoreIndexInCompositeId = varSegmentCompositeDomId.lastIndexOf('_');
|
|
2466
|
+
if (underscoreIndexInCompositeId === -1) return;
|
|
2467
|
+
const mustacheTokenFromCompositeId = varSegmentCompositeDomId.slice(0, underscoreIndexInCompositeId);
|
|
2468
|
+
const variableName = getVarNameFromToken(mustacheTokenFromCompositeId);
|
|
2469
|
+
if (variableName === undefined || variableName === null || variableName === '') return;
|
|
2470
|
+
const isInvalidValue = value?.trim() === '';
|
|
2471
|
+
const coercedSlotValue = isInvalidValue ? '' : value;
|
|
2472
|
+
const templateStringForField = type === TITLE_TEXT ? templateTitle : templateDesc;
|
|
2473
|
+
const globalVarSlotIndexZeroBased = getGlobalSlotIndexForRcsFieldId(
|
|
2474
|
+
varSegmentCompositeDomId,
|
|
2475
|
+
templateStringForField,
|
|
2476
|
+
type,
|
|
2477
|
+
);
|
|
2478
|
+
setCardVarMapped((previousCardVarMapped) => {
|
|
2479
|
+
const updatedCardVarMapped = { ...previousCardVarMapped };
|
|
2480
|
+
// Remove stale semantic key: keeping it causes every other slot sharing the same
|
|
2481
|
+
// variable name (e.g. {{adv}} in both title and description) to read the same value
|
|
2482
|
+
// via the semantic-key fallback in resolveCardVarMappedSlotValue.
|
|
2483
|
+
delete updatedCardVarMapped[variableName];
|
|
2484
|
+
if (globalVarSlotIndexZeroBased !== null && globalVarSlotIndexZeroBased !== undefined) {
|
|
2485
|
+
updatedCardVarMapped[String(globalVarSlotIndexZeroBased + 1)] = coercedSlotValue;
|
|
2486
|
+
}
|
|
2487
|
+
return updatedCardVarMapped;
|
|
2488
|
+
});
|
|
1115
2489
|
};
|
|
1116
2490
|
|
|
1117
2491
|
const renderTextComponent = () => {
|
|
@@ -1131,6 +2505,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1131
2505
|
}
|
|
1132
2506
|
suffix={
|
|
1133
2507
|
<>
|
|
2508
|
+
|
|
1134
2509
|
{(isEditFlow || !isFullMode) ? (
|
|
1135
2510
|
<TagList
|
|
1136
2511
|
label={formatMessage(globalMessages.addLabels)}
|
|
@@ -1147,18 +2522,28 @@ const splitTemplateVarString = (str) => {
|
|
|
1147
2522
|
type="flat"
|
|
1148
2523
|
isAddBtn
|
|
1149
2524
|
onClick={onTitleAddVar}
|
|
1150
|
-
disabled={
|
|
2525
|
+
disabled={templateTitleError}
|
|
1151
2526
|
>
|
|
1152
2527
|
{formatMessage(messages.addVar)}
|
|
1153
2528
|
</CapButton>
|
|
1154
|
-
|
|
2529
|
+
)}
|
|
1155
2530
|
</>
|
|
1156
|
-
}
|
|
2531
|
+
}
|
|
2532
|
+
/>
|
|
2533
|
+
|
|
2534
|
+
{(isEditFlow || !isFullMode) ? (
|
|
2535
|
+
<VarSegmentMessageEditor
|
|
2536
|
+
key={`rcs-title-vars-${rcsVarSegmentEditorRemountKey}`}
|
|
2537
|
+
templateString={templateTitle}
|
|
2538
|
+
valueMap={titleVarSegmentValueMapById}
|
|
2539
|
+
onChange={(id, value) => handleRcsVarChange(id, value, TITLE_TEXT)}
|
|
2540
|
+
onFocus={(id) => setTitleTextAreaId(id)}
|
|
2541
|
+
varRegex={rcsVarRegex}
|
|
2542
|
+
placeholderPrefix=""
|
|
2543
|
+
getPlaceholder={() => formatMessage(messages.rcsVarSlotPlaceholder)}
|
|
1157
2544
|
/>
|
|
1158
|
-
<div className="rcs_text_area_wrapper">
|
|
1159
|
-
{(isEditFlow || !isFullMode) ? (
|
|
1160
|
-
renderedRCSEditMessage(splitTemplateVarString(templateTitle), TITLE_TEXT)
|
|
1161
2545
|
) : (
|
|
2546
|
+
<div className="rcs_text_area_wrapper">
|
|
1162
2547
|
<CapInput
|
|
1163
2548
|
className={`rcs-template-title-input ${
|
|
1164
2549
|
!isTemplateApproved ? "rcs-edit-disabled" : ""
|
|
@@ -1171,8 +2556,8 @@ const splitTemplateVarString = (str) => {
|
|
|
1171
2556
|
errorMessage={templateTitleError}
|
|
1172
2557
|
disabled={isEditFlow || !isFullMode}
|
|
1173
2558
|
/>
|
|
2559
|
+
</div>
|
|
1174
2560
|
)}
|
|
1175
|
-
</div>
|
|
1176
2561
|
{(isEditFlow || !isFullMode) && templateTitleError && (
|
|
1177
2562
|
<CapError className="rcs-template-title-error">
|
|
1178
2563
|
{templateTitleError}
|
|
@@ -1180,7 +2565,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1180
2565
|
)}
|
|
1181
2566
|
{!isEditFlow && isFullMode && renderTitleCharacterCount()}
|
|
1182
2567
|
</>
|
|
1183
|
-
|
|
2568
|
+
)}
|
|
1184
2569
|
|
|
1185
2570
|
{/* Template Message */}
|
|
1186
2571
|
<CapRow id="rcs-template-message-label">
|
|
@@ -1218,9 +2603,21 @@ const splitTemplateVarString = (str) => {
|
|
|
1218
2603
|
/>
|
|
1219
2604
|
</CapRow>
|
|
1220
2605
|
<CapRow className="rcs-create-template-message-input">
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
2606
|
+
{/* Edit/library: segmented inputs (split on {{…}}). Full-mode create: single TextArea below — manual entry there never hits segment split. TagList replaces {{n}} in template string here. */}
|
|
2607
|
+
<CapRow className="rcs_text_area_wrapper">
|
|
2608
|
+
{(isEditFlow || !isFullMode)?
|
|
2609
|
+
(
|
|
2610
|
+
<VarSegmentMessageEditor
|
|
2611
|
+
key={`rcs-desc-vars-${rcsVarSegmentEditorRemountKey}`}
|
|
2612
|
+
templateString={templateDesc}
|
|
2613
|
+
valueMap={descriptionVarSegmentValueMapById}
|
|
2614
|
+
onChange={(id, value) => handleRcsVarChange(id, value, MESSAGE_TEXT)}
|
|
2615
|
+
onFocus={(id) => setDescTextAreaId(id)}
|
|
2616
|
+
varRegex={rcsVarRegex}
|
|
2617
|
+
placeholderPrefix=""
|
|
2618
|
+
getPlaceholder={() => formatMessage(messages.rcsVarSlotPlaceholder)}
|
|
2619
|
+
/>
|
|
2620
|
+
)
|
|
1224
2621
|
: (
|
|
1225
2622
|
<>
|
|
1226
2623
|
<TextArea
|
|
@@ -1258,13 +2655,15 @@ const splitTemplateVarString = (str) => {
|
|
|
1258
2655
|
</>
|
|
1259
2656
|
)
|
|
1260
2657
|
}
|
|
1261
|
-
</
|
|
2658
|
+
</CapRow>
|
|
1262
2659
|
{(isEditFlow || !isFullMode) && templateDescError && (
|
|
1263
2660
|
<CapError className="rcs-template-message-error">
|
|
1264
2661
|
{templateDescError}
|
|
1265
2662
|
</CapError>
|
|
1266
2663
|
)}
|
|
1267
|
-
{
|
|
2664
|
+
{(isEditFlow || !isFullMode)
|
|
2665
|
+
? renderDescriptionCharacterCount('rcs-character-count rcs-character-count--compact')
|
|
2666
|
+
: (!isEditFlow && isFullMode && renderDescriptionCharacterCount())}
|
|
1268
2667
|
{!isFullMode && hasTag() && (
|
|
1269
2668
|
<CapAlert
|
|
1270
2669
|
message={
|
|
@@ -1278,24 +2677,13 @@ const splitTemplateVarString = (str) => {
|
|
|
1278
2677
|
/>
|
|
1279
2678
|
)}
|
|
1280
2679
|
</CapRow>
|
|
1281
|
-
{
|
|
2680
|
+
{((!isEditFlow && isFullMode) || (isEditFlow && (suggestions?.length ?? 0) > 0)) &&
|
|
2681
|
+
renderButtonComponent()}
|
|
1282
2682
|
</>
|
|
1283
2683
|
|
|
1284
2684
|
);
|
|
1285
2685
|
};
|
|
1286
2686
|
|
|
1287
|
-
|
|
1288
|
-
const fallbackSmsLength = () => (
|
|
1289
|
-
<CapLabel type="label1" className="fallback-sms-length">
|
|
1290
|
-
{formatMessage(messages.totalCharacters, {
|
|
1291
|
-
smsCount: Math.ceil(
|
|
1292
|
-
fallbackMessage?.length / FALLBACK_MESSAGE_MAX_LENGTH,
|
|
1293
|
-
),
|
|
1294
|
-
number: fallbackMessage?.length,
|
|
1295
|
-
})}
|
|
1296
|
-
</CapLabel>
|
|
1297
|
-
);
|
|
1298
|
-
|
|
1299
2687
|
// Get character count for title (rich card only)
|
|
1300
2688
|
const getTitleCharacterCount = () => {
|
|
1301
2689
|
if (templateType === contentType.text_message) return 0;
|
|
@@ -1310,7 +2698,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1310
2698
|
// Get max length for description based on template type
|
|
1311
2699
|
const getDescriptionMaxLength = () => {
|
|
1312
2700
|
return templateType === contentType.text_message
|
|
1313
|
-
? RCS_TEXT_MESSAGE_MAX_LENGTH // 160 for text message
|
|
2701
|
+
? (isHostInfoBip ? RCS_TEXT_MESSAGE_MAX_LENGTH_INFOBIP : RCS_TEXT_MESSAGE_MAX_LENGTH) // 160 for text message
|
|
1314
2702
|
: RCS_RICH_CARD_MAX_LENGTH; // 2000 for rich card description
|
|
1315
2703
|
};
|
|
1316
2704
|
|
|
@@ -1336,6 +2724,63 @@ const splitTemplateVarString = (str) => {
|
|
|
1336
2724
|
);
|
|
1337
2725
|
};
|
|
1338
2726
|
|
|
2727
|
+
const rcsDltCardDeleteHandler = () => {
|
|
2728
|
+
closeDltContainerHandler();
|
|
2729
|
+
setDltEditData({});
|
|
2730
|
+
// setFallbackMessage('');
|
|
2731
|
+
// setFallbackMessageError(false);
|
|
2732
|
+
setShowDltCard(false);
|
|
2733
|
+
};
|
|
2734
|
+
|
|
2735
|
+
const dltFallbackListingPreviewhandler = (data) => {
|
|
2736
|
+
const {
|
|
2737
|
+
'updated-sms-editor': updatedSmsEditor = [],
|
|
2738
|
+
'sms-editor': smsEditor = '',
|
|
2739
|
+
} = data.versions.base || {};
|
|
2740
|
+
setFallbackPreviewmode(true);
|
|
2741
|
+
setDltPreviewData(
|
|
2742
|
+
updatedSmsEditor === '' ? smsEditor : updatedSmsEditor.join(''),
|
|
2743
|
+
);
|
|
2744
|
+
};
|
|
2745
|
+
|
|
2746
|
+
const getDltContentCardList = (content, channel) => {
|
|
2747
|
+
const extra = [
|
|
2748
|
+
<CapIcon
|
|
2749
|
+
type="edit"
|
|
2750
|
+
style={{ marginRight: '8px' }}
|
|
2751
|
+
onClick={() => rcsDltEditSelectHandler(dltEditData)}
|
|
2752
|
+
/>,
|
|
2753
|
+
<CapDropdown
|
|
2754
|
+
overlay={(
|
|
2755
|
+
<CapMenu>
|
|
2756
|
+
<>
|
|
2757
|
+
<CapMenu.Item
|
|
2758
|
+
className="ant-dropdown-menu-item"
|
|
2759
|
+
onClick={() => setFallbackPreviewmode(true)}
|
|
2760
|
+
>
|
|
2761
|
+
{formatMessage(globalMessages.preview)}
|
|
2762
|
+
</CapMenu.Item>
|
|
2763
|
+
<CapMenu.Item
|
|
2764
|
+
className="ant-dropdown-menu-item"
|
|
2765
|
+
onClick={rcsDltCardDeleteHandler}
|
|
2766
|
+
>
|
|
2767
|
+
{formatMessage(globalMessages.delete)}
|
|
2768
|
+
</CapMenu.Item>
|
|
2769
|
+
</>
|
|
2770
|
+
</CapMenu>
|
|
2771
|
+
)}
|
|
2772
|
+
>
|
|
2773
|
+
<CapIcon type="more" />
|
|
2774
|
+
</CapDropdown>,
|
|
2775
|
+
];
|
|
2776
|
+
return {
|
|
2777
|
+
title: channel,
|
|
2778
|
+
content,
|
|
2779
|
+
cardType: channel,
|
|
2780
|
+
extra,
|
|
2781
|
+
};
|
|
2782
|
+
};
|
|
2783
|
+
|
|
1339
2784
|
// Render character count for description/message
|
|
1340
2785
|
const renderDescriptionCharacterCount = (className = "rcs-character-count") => {
|
|
1341
2786
|
const currentLength = getDescriptionCharacterCount();
|
|
@@ -1351,6 +2796,26 @@ const splitTemplateVarString = (str) => {
|
|
|
1351
2796
|
);
|
|
1352
2797
|
};
|
|
1353
2798
|
|
|
2799
|
+
// Carousel: per-card character counts (same limits as rich card)
|
|
2800
|
+
const getCarouselTitleCharacterCount = (cardIndex) => {
|
|
2801
|
+
const t = carouselData?.[cardIndex]?.title || '';
|
|
2802
|
+
return t ? t.length : 0;
|
|
2803
|
+
};
|
|
2804
|
+
|
|
2805
|
+
const getCarouselDescriptionCharacterCount = (cardIndex) => {
|
|
2806
|
+
const d = carouselData?.[cardIndex]?.description || '';
|
|
2807
|
+
return d ? d.length : 0;
|
|
2808
|
+
};
|
|
2809
|
+
|
|
2810
|
+
const renderCarouselCharacterCount = (currentLength, maxLength, className = "rcs-character-count") => (
|
|
2811
|
+
<CapLabel type="label1" className={className}>
|
|
2812
|
+
{formatMessage(messages.templateMessageLength, {
|
|
2813
|
+
currentLength,
|
|
2814
|
+
maxLength,
|
|
2815
|
+
})}
|
|
2816
|
+
</CapLabel>
|
|
2817
|
+
);
|
|
2818
|
+
|
|
1354
2819
|
// Check if any RCS variables contain tags (similar to Zalo hasTag logic)
|
|
1355
2820
|
const hasTag = () => {
|
|
1356
2821
|
// Check cardVarMapped values for tags
|
|
@@ -1403,68 +2868,17 @@ const splitTemplateVarString = (str) => {
|
|
|
1403
2868
|
const fallMsg = get(tempData, `versions.base.updated-sms-editor`, []).join(
|
|
1404
2869
|
'',
|
|
1405
2870
|
);
|
|
2871
|
+
const templateNameFromDlt = get(dltEditData, 'name', '')
|
|
2872
|
+
|| get(tempData, 'versions.base.name', '')
|
|
2873
|
+
|| '';
|
|
1406
2874
|
closeDltContainerHandler();
|
|
1407
2875
|
setDltEditData(tempData);
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
closeDltContainerHandler();
|
|
1415
|
-
setDltEditData({});
|
|
1416
|
-
setFallbackMessage('');
|
|
1417
|
-
setFallbackMessageError(false);
|
|
1418
|
-
setShowDltCard(false);
|
|
1419
|
-
};
|
|
1420
|
-
|
|
1421
|
-
const dltFallbackListingPreviewhandler = (data) => {
|
|
1422
|
-
const {
|
|
1423
|
-
'updated-sms-editor': updatedSmsEditor = [],
|
|
1424
|
-
'sms-editor': smsEditor = '',
|
|
1425
|
-
} = data.versions.base || {};
|
|
1426
|
-
setFallbackPreviewmode(true);
|
|
1427
|
-
setDltPreviewData(
|
|
1428
|
-
updatedSmsEditor === '' ? smsEditor : updatedSmsEditor.join(''),
|
|
1429
|
-
);
|
|
1430
|
-
};
|
|
1431
|
-
|
|
1432
|
-
const getDltContentCardList = (content, channel) => {
|
|
1433
|
-
const extra = [
|
|
1434
|
-
<CapIcon
|
|
1435
|
-
type="edit"
|
|
1436
|
-
style={{ marginRight: '8px' }}
|
|
1437
|
-
onClick={() => rcsDltEditSelectHandler(dltEditData)}
|
|
1438
|
-
/>,
|
|
1439
|
-
<CapDropdown
|
|
1440
|
-
overlay={(
|
|
1441
|
-
<CapMenu>
|
|
1442
|
-
<>
|
|
1443
|
-
<CapMenu.Item
|
|
1444
|
-
className="ant-dropdown-menu-item"
|
|
1445
|
-
onClick={() => setFallbackPreviewmode(true)}
|
|
1446
|
-
>
|
|
1447
|
-
{formatMessage(globalMessages.preview)}
|
|
1448
|
-
</CapMenu.Item>
|
|
1449
|
-
<CapMenu.Item
|
|
1450
|
-
className="ant-dropdown-menu-item"
|
|
1451
|
-
onClick={rcsDltCardDeleteHandler}
|
|
1452
|
-
>
|
|
1453
|
-
{formatMessage(globalMessages.delete)}
|
|
1454
|
-
</CapMenu.Item>
|
|
1455
|
-
</>
|
|
1456
|
-
</CapMenu>
|
|
1457
|
-
)}
|
|
1458
|
-
>
|
|
1459
|
-
<CapIcon type="more" />
|
|
1460
|
-
</CapDropdown>,
|
|
1461
|
-
];
|
|
1462
|
-
return {
|
|
1463
|
-
title: channel,
|
|
1464
|
-
content,
|
|
1465
|
-
cardType: channel,
|
|
1466
|
-
extra,
|
|
1467
|
-
};
|
|
2876
|
+
const unicodeFromDlt = get(tempData, 'versions.base.unicode-validity');
|
|
2877
|
+
setSmsFallbackData({
|
|
2878
|
+
templateName: templateNameFromDlt,
|
|
2879
|
+
content: fallMsg,
|
|
2880
|
+
...(typeof unicodeFromDlt === 'boolean' ? { unicodeValidity: unicodeFromDlt } : {}),
|
|
2881
|
+
});
|
|
1468
2882
|
};
|
|
1469
2883
|
|
|
1470
2884
|
const getDltSlideBoxContent = () => {
|
|
@@ -1512,148 +2926,34 @@ const splitTemplateVarString = (str) => {
|
|
|
1512
2926
|
return { dltHeader, dltContent };
|
|
1513
2927
|
};
|
|
1514
2928
|
|
|
1515
|
-
const renderFallBackSmsComponent = () =>
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
// style: { marginLeft: '4px', marginTop: '3px' },
|
|
1540
|
-
// }}
|
|
1541
|
-
// title={formatMessage(messages.fallbackToolTip)}
|
|
1542
|
-
// />
|
|
1543
|
-
// </CapRow>
|
|
1544
|
-
// )}
|
|
1545
|
-
// description={formatMessage(messages.fallbackDesc)}
|
|
1546
|
-
// suffix={
|
|
1547
|
-
// isDltEnabled ? null : (
|
|
1548
|
-
// <CapButton
|
|
1549
|
-
// type="flat"
|
|
1550
|
-
// className="fallback-preview-btn"
|
|
1551
|
-
// prefix={<CapIcon type="eye" />}
|
|
1552
|
-
// style={{ color: CAP_SECONDARY.base }}
|
|
1553
|
-
// onClick={() => setFallbackPreviewmode(true)}
|
|
1554
|
-
// disabled={fallbackMessage === '' || fallbackMessageError}
|
|
1555
|
-
// >
|
|
1556
|
-
// {formatMessage(globalMessages.preview)}
|
|
1557
|
-
// </CapButton>
|
|
1558
|
-
// )
|
|
1559
|
-
// }
|
|
1560
|
-
// />
|
|
1561
|
-
// </CapRow>,
|
|
1562
|
-
// );
|
|
1563
|
-
|
|
1564
|
-
//dlt is enabled, and dlt content is not yet added, show button to add dlt creative
|
|
1565
|
-
// showAddCreativeBtnForDlt
|
|
1566
|
-
// && contentArr.push(
|
|
1567
|
-
// <CapCard className="rcs-dlt-fallback-card">
|
|
1568
|
-
// <CapRow type="flex" justify="center" align="middle">
|
|
1569
|
-
// <CapColumn span={10}>
|
|
1570
|
-
// <CapImage src={addCreativesIcon} />
|
|
1571
|
-
// </CapColumn>
|
|
1572
|
-
// <CapColumn span={14}>
|
|
1573
|
-
// <CapButton
|
|
1574
|
-
// className="add-dlt-btn"
|
|
1575
|
-
// type="secondary"
|
|
1576
|
-
// onClick={addDltMsgHandler}
|
|
1577
|
-
// >
|
|
1578
|
-
// {formatMessage(messages.addSmsCreative)}
|
|
1579
|
-
// </CapButton>
|
|
1580
|
-
// </CapColumn>
|
|
1581
|
-
// </CapRow>
|
|
1582
|
-
// </CapCard>,
|
|
1583
|
-
// );
|
|
1584
|
-
|
|
1585
|
-
// //dlt is enabled and dlt content is added, show it in a card
|
|
1586
|
-
// showCardForDlt
|
|
1587
|
-
// && contentArr.push(
|
|
1588
|
-
// <CapCustomCardList
|
|
1589
|
-
// cardList={[getDltContentCardList(fallbackMessage, SMS)]}
|
|
1590
|
-
// className="rcs-dlt-card"
|
|
1591
|
-
// />,
|
|
1592
|
-
// fallbackMessageError && (
|
|
1593
|
-
// <CapError className="rcs-fallback-len-error">
|
|
1594
|
-
// {formatMessage(messages.fallbackMsgLenError)}
|
|
1595
|
-
// </CapError>
|
|
1596
|
-
// ),
|
|
1597
|
-
// );
|
|
1598
|
-
|
|
1599
|
-
// //dlt is not enabled, show non dlt text area
|
|
1600
|
-
// showNonDltFallbackComp
|
|
1601
|
-
// && contentArr.push(
|
|
1602
|
-
// <>
|
|
1603
|
-
// <CapRow>
|
|
1604
|
-
// <CapHeader
|
|
1605
|
-
// title={(
|
|
1606
|
-
// <CapHeading type="h4">
|
|
1607
|
-
// {formatMessage(messages.fallbackTextAreaLabel)}
|
|
1608
|
-
// </CapHeading>
|
|
1609
|
-
// )}
|
|
1610
|
-
// suffix={(
|
|
1611
|
-
// <TagList
|
|
1612
|
-
// label={formatMessage(globalMessages.addLabels)}
|
|
1613
|
-
// onTagSelect={onTagSelectFallback}
|
|
1614
|
-
// location={location}
|
|
1615
|
-
// tags={tags || []}
|
|
1616
|
-
// onContextChange={handleOnTagsContextChange}
|
|
1617
|
-
// injectedTags={injectedTags || {}}
|
|
1618
|
-
// selectedOfferDetails={selectedOfferDetails}
|
|
1619
|
-
// />
|
|
1620
|
-
// )}
|
|
1621
|
-
// />
|
|
1622
|
-
// </CapRow>
|
|
1623
|
-
// <div className="rcs_fallback_msg_textarea_wrapper">
|
|
1624
|
-
// <TextArea
|
|
1625
|
-
// id="rcs_fallback_message_textarea"
|
|
1626
|
-
// autosize={{ minRows: 3, maxRows: 5 }}
|
|
1627
|
-
// placeholder={formatMessage(messages.fallbackMsgPlaceholder)}
|
|
1628
|
-
// onChange={onFallbackMessageChange}
|
|
1629
|
-
// errorMessage={fallbackMessageError}
|
|
1630
|
-
// value={fallbackMessage || ""}
|
|
1631
|
-
// />
|
|
1632
|
-
// {!aiContentBotDisabled && (
|
|
1633
|
-
// <CapAskAira.ContentGenerationBot
|
|
1634
|
-
// text={fallbackMessage || ""}
|
|
1635
|
-
// setText={(text) => {
|
|
1636
|
-
// onFallbackMessageChange({ target: { value: text } });
|
|
1637
|
-
// }}
|
|
1638
|
-
// iconPlacement="float-br"
|
|
1639
|
-
// rootStyle={{
|
|
1640
|
-
// bottom: "0.5rem",
|
|
1641
|
-
// right: "0.5rem",
|
|
1642
|
-
// position: "absolute",
|
|
1643
|
-
// }}
|
|
1644
|
-
// />
|
|
1645
|
-
// )}
|
|
1646
|
-
// </div>
|
|
1647
|
-
// <CapRow>{fallbackSmsLength()}</CapRow>
|
|
1648
|
-
// </>
|
|
1649
|
-
// );
|
|
1650
|
-
|
|
1651
|
-
// return <>{contentArr}</>;
|
|
1652
|
-
};
|
|
2929
|
+
const renderFallBackSmsComponent = () => (
|
|
2930
|
+
<SmsFallback
|
|
2931
|
+
value={smsFallbackData}
|
|
2932
|
+
onChange={setSmsFallbackData}
|
|
2933
|
+
parentLocation={location}
|
|
2934
|
+
smsRegister={smsRegister}
|
|
2935
|
+
isFullMode={isFullMode}
|
|
2936
|
+
selectedOfferDetails={selectedOfferDetails}
|
|
2937
|
+
channelsToHide={CHANNELS_TO_HIDE_FOR_SMS_ONLY}
|
|
2938
|
+
sectionTitle={
|
|
2939
|
+
smsFallbackData
|
|
2940
|
+
? formatMessage(messages.fallbackLabel)
|
|
2941
|
+
: formatMessage(messages.smsFallbackOptional)
|
|
2942
|
+
}
|
|
2943
|
+
templateListTitle={formatMessage(creativesMessages.creativeTemplates)}
|
|
2944
|
+
templateListDescription={formatMessage(creativesMessages.creativeTemplatesDesc)}
|
|
2945
|
+
/* Full-mode: card layout only while drafting a new template; after send for approval or when a template is loaded, use inline layout. */
|
|
2946
|
+
showAsCard={isFullMode && !isEditFlow && templateStatus === ''}
|
|
2947
|
+
disableSelectTemplate={isEditFlow}
|
|
2948
|
+
eventContextTags={eventContextTags}
|
|
2949
|
+
onRcsFallbackEditorStateChange={handleSmsFallbackEditorStateChange}
|
|
2950
|
+
isRcsEditFlow={isEditFlow}
|
|
2951
|
+
/>
|
|
2952
|
+
);
|
|
1653
2953
|
|
|
1654
2954
|
const uploadRcsImage = useCallback((file, type, fileParams, index) => {
|
|
1655
2955
|
setImageError(null);
|
|
1656
|
-
const isRcsThumbnail = index
|
|
2956
|
+
const isRcsThumbnail = isThumbnailAssetIndex(index);
|
|
1657
2957
|
actions.uploadRcsAsset(file, type, {
|
|
1658
2958
|
isRcsThumbnail,
|
|
1659
2959
|
...fileParams,
|
|
@@ -1691,10 +2991,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1691
2991
|
const updateOnRcsImageReUpload = useCallback(() => {
|
|
1692
2992
|
setUpdateRcsImageSrc('');
|
|
1693
2993
|
}, []);
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
2994
|
const uploadRcsVideo = (file, type, fileParams) => {
|
|
1697
|
-
setImageError(null);
|
|
1698
2995
|
actions.uploadRcsAsset(file, type, {
|
|
1699
2996
|
...fileParams,
|
|
1700
2997
|
type: 'video',
|
|
@@ -1703,9 +3000,6 @@ const splitTemplateVarString = (str) => {
|
|
|
1703
3000
|
});
|
|
1704
3001
|
};
|
|
1705
3002
|
|
|
1706
|
-
const updateRcsVideoSrc = (val) => {
|
|
1707
|
-
setRcsVideoSrc(val);
|
|
1708
|
-
};
|
|
1709
3003
|
const setUpdateRcsVideoSrc = useCallback((index, val) => {
|
|
1710
3004
|
setRcsVideoSrc(val);
|
|
1711
3005
|
setAssetList(val);
|
|
@@ -1728,7 +3022,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1728
3022
|
updateRcsThumbnailSrc('');
|
|
1729
3023
|
};
|
|
1730
3024
|
|
|
1731
|
-
|
|
3025
|
+
const renderThumbnailComponent = () => {
|
|
1732
3026
|
const currentDimension = selectedDimension || Object.keys(RCS_VIDEO_THUMBNAIL_DIMENSIONS)[0];
|
|
1733
3027
|
return !isEditFlow && (
|
|
1734
3028
|
<>
|
|
@@ -1752,6 +3046,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1752
3046
|
channel={RCS}
|
|
1753
3047
|
channelSpecificStyle={!isFullMode}
|
|
1754
3048
|
skipDimensionValidation={true}
|
|
3049
|
+
showReUploadButton={!isEditFlow && isFullMode}
|
|
1755
3050
|
/>
|
|
1756
3051
|
</>
|
|
1757
3052
|
)
|
|
@@ -1777,7 +3072,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1777
3072
|
value: dim.type,
|
|
1778
3073
|
label: `${dim.label}`
|
|
1779
3074
|
}))}
|
|
1780
|
-
|
|
3075
|
+
className="rcs-dimension-select--bottom-spacing"
|
|
1781
3076
|
/>
|
|
1782
3077
|
</>
|
|
1783
3078
|
)}
|
|
@@ -1791,7 +3086,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1791
3086
|
</div>
|
|
1792
3087
|
) : (
|
|
1793
3088
|
<CapImageUpload
|
|
1794
|
-
|
|
3089
|
+
style={{ paddingTop: '20px' }}
|
|
1795
3090
|
allowedExtensionsRegex={ALLOWED_IMAGE_EXTENSIONS_REGEX}
|
|
1796
3091
|
imgWidth={RCS_IMAGE_DIMENSIONS[selectedDimension].width}
|
|
1797
3092
|
imgHeight={RCS_IMAGE_DIMENSIONS[selectedDimension].height}
|
|
@@ -1802,7 +3097,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1802
3097
|
updateImageSrc={setUpdateRcsImageSrc}
|
|
1803
3098
|
updateOnReUpload={updateOnRcsImageReUpload}
|
|
1804
3099
|
index={0}
|
|
1805
|
-
className="cap-custom-image-upload"
|
|
3100
|
+
className="cap-custom-image-upload rcs-image-upload--top-spacing"
|
|
1806
3101
|
key={`rcs-uploaded-image-${selectedDimension}`}
|
|
1807
3102
|
imageData={rcsData}
|
|
1808
3103
|
channel={RCS}
|
|
@@ -1813,7 +3108,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1813
3108
|
|
|
1814
3109
|
</>
|
|
1815
3110
|
);
|
|
1816
|
-
|
|
3111
|
+
}
|
|
1817
3112
|
|
|
1818
3113
|
const renderVideoComponent = () => {
|
|
1819
3114
|
const currentDimension =selectedDimension || Object.keys(RCS_VIDEO_THUMBNAIL_DIMENSIONS)[0];
|
|
@@ -1832,7 +3127,7 @@ const splitTemplateVarString = (str) => {
|
|
|
1832
3127
|
value: dim.type,
|
|
1833
3128
|
label: `${dim.label}`
|
|
1834
3129
|
}))}
|
|
1835
|
-
|
|
3130
|
+
className="rcs-dimension-select--bottom-spacing"
|
|
1836
3131
|
/>
|
|
1837
3132
|
)}
|
|
1838
3133
|
{(isEditFlow || !isFullMode) ? (
|
|
@@ -1890,10 +3185,48 @@ const splitTemplateVarString = (str) => {
|
|
|
1890
3185
|
};
|
|
1891
3186
|
|
|
1892
3187
|
const getRcsPreview = () => {
|
|
3188
|
+
|
|
3189
|
+
if (templateType === contentType.carousel) {
|
|
3190
|
+
const cardsForPreview = buildCarouselCardsForPreview(carouselData);
|
|
3191
|
+
const carouselDimKey = getCarouselDimensionKey();
|
|
3192
|
+
const carouselImgDims =
|
|
3193
|
+
RCS_CAROUSEL_IMAGE_DIMENSIONS[carouselDimKey] || RCS_CAROUSEL_IMAGE_DIMENSIONS.MEDIUM_MEDIUM;
|
|
3194
|
+
const carouselVidDims =
|
|
3195
|
+
RCS_CAROUSEL_VIDEO_THUMBNAIL_DIMENSIONS[carouselDimKey]
|
|
3196
|
+
|| RCS_CAROUSEL_VIDEO_THUMBNAIL_DIMENSIONS.MEDIUM_MEDIUM;
|
|
3197
|
+
// Debug log for embedded/library mode preview payload (carousel)
|
|
3198
|
+
// eslint-disable-next-line no-console
|
|
3199
|
+
return (
|
|
3200
|
+
<UnifiedPreview
|
|
3201
|
+
channel={RCS}
|
|
3202
|
+
content={{
|
|
3203
|
+
carouselData: cardsForPreview,
|
|
3204
|
+
carouselPreviewDimensions: {
|
|
3205
|
+
imageWidth: carouselImgDims.width,
|
|
3206
|
+
imageHeight: carouselImgDims.height,
|
|
3207
|
+
videoThumbWidth: carouselVidDims.width,
|
|
3208
|
+
videoThumbHeight: carouselVidDims.height,
|
|
3209
|
+
},
|
|
3210
|
+
}}
|
|
3211
|
+
device={ANDROID}
|
|
3212
|
+
showDeviceToggle={false}
|
|
3213
|
+
showHeader={false}
|
|
3214
|
+
formatMessage={formatMessage}
|
|
3215
|
+
/>
|
|
3216
|
+
);
|
|
3217
|
+
}
|
|
1893
3218
|
|
|
1894
3219
|
const dimensionObj = RCS_IMAGE_DIMENSIONS[selectedDimension];
|
|
1895
|
-
const
|
|
1896
|
-
const
|
|
3220
|
+
const isSlotMappingMode = isEditFlow || !isFullMode;
|
|
3221
|
+
const titleVarCountForResolve = isMediaTypeText
|
|
3222
|
+
? 0
|
|
3223
|
+
: ((templateTitle ? (templateTitle.match(rcsVarRegex) || []) : []).length);
|
|
3224
|
+
const resolvedTitle = isMediaTypeText
|
|
3225
|
+
? ''
|
|
3226
|
+
: (isSlotMappingMode ? resolveTemplateWithMap(templateTitle, 0) : templateTitle);
|
|
3227
|
+
const resolvedDesc = isSlotMappingMode
|
|
3228
|
+
? resolveTemplateWithMap(templateDesc, titleVarCountForResolve)
|
|
3229
|
+
: templateDesc;
|
|
1897
3230
|
return (
|
|
1898
3231
|
<UnifiedPreview
|
|
1899
3232
|
channel={RCS}
|
|
@@ -1916,51 +3249,95 @@ const splitTemplateVarString = (str) => {
|
|
|
1916
3249
|
);
|
|
1917
3250
|
};
|
|
1918
3251
|
|
|
1919
|
-
const getUnmappedDesc = (str, mapping) => {
|
|
1920
|
-
if (!str) return '';
|
|
1921
|
-
if (!mapping || Object.keys(mapping).length === 0) return str;
|
|
1922
|
-
let result = str;
|
|
1923
|
-
const replacements = [];
|
|
1924
|
-
Object.entries(mapping).forEach(([key, value]) => {
|
|
1925
|
-
const raw = (value ?? '').toString();
|
|
1926
|
-
if (!raw || raw?.trim?.() === '') return;
|
|
1927
|
-
const braced = /^\{\{[\s\S]*\}\}$/.test(raw) ? raw : `{{${raw}}}`;
|
|
1928
|
-
replacements.push({ key, needle: raw });
|
|
1929
|
-
if (braced !== raw) replacements.push({ key, needle: braced });
|
|
1930
|
-
});
|
|
1931
|
-
const seen = new Set();
|
|
1932
|
-
const uniq = replacements
|
|
1933
|
-
.filter(({ key, needle }) => {
|
|
1934
|
-
const id = `${key}::${needle}`;
|
|
1935
|
-
if (seen.has(id)) return false;
|
|
1936
|
-
seen.add(id);
|
|
1937
|
-
return true;
|
|
1938
|
-
})
|
|
1939
|
-
.sort((a, b) => (b.needle.length - a.needle.length));
|
|
1940
|
-
|
|
1941
|
-
uniq.forEach(({ key, needle }) => {
|
|
1942
|
-
if (!needle) return;
|
|
1943
|
-
const escaped = needle.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
1944
|
-
const regex = new RegExp(escaped, 'g');
|
|
1945
|
-
result = result.replace(regex, `{{${key}}}`);
|
|
1946
|
-
});
|
|
1947
|
-
return result;
|
|
1948
|
-
};
|
|
1949
|
-
|
|
1950
3252
|
const createPayload = () => {
|
|
1951
|
-
const
|
|
1952
|
-
const {
|
|
1953
|
-
template_id: templateId = '',
|
|
1954
|
-
template_name = '',
|
|
1955
|
-
'sms-editor': template = '',
|
|
1956
|
-
header: registeredSenderIds = [],
|
|
1957
|
-
} = base;
|
|
1958
|
-
const resolvedTitle = !isFullMode ? resolveTemplateWithMap(templateTitle) : templateTitle;
|
|
1959
|
-
const resolvedDesc = !isFullMode ? resolveTemplateWithMap(templateDesc) : templateDesc;
|
|
3253
|
+
const isSlotMappingMode = isEditFlow || !isFullMode;
|
|
1960
3254
|
const alignment = isMediaTypeImage
|
|
1961
3255
|
? RCS_IMAGE_DIMENSIONS[selectedDimension]?.alignment
|
|
1962
3256
|
: RCS_VIDEO_THUMBNAIL_DIMENSIONS[selectedDimension]?.alignment;
|
|
1963
3257
|
|
|
3258
|
+
const heightTypeForCardWidth = isMediaTypeText
|
|
3259
|
+
? undefined
|
|
3260
|
+
: isMediaTypeImage
|
|
3261
|
+
? RCS_IMAGE_DIMENSIONS[selectedDimension]?.heightType
|
|
3262
|
+
: isMediaTypeVideo
|
|
3263
|
+
? RCS_VIDEO_THUMBNAIL_DIMENSIONS[selectedDimension]?.heightType
|
|
3264
|
+
: undefined;
|
|
3265
|
+
const cardWidthFromSelection =
|
|
3266
|
+
heightTypeForCardWidth === MEDIUM ? MEDIUM : SMALL;
|
|
3267
|
+
|
|
3268
|
+
/** Library: merge props + state so SMS fallback is not dropped when local state is empty but templateData has consumer data. */
|
|
3269
|
+
const smsFromApiShape = getLibrarySmsFallbackApiBaselineFromTemplateData(templateData);
|
|
3270
|
+
const smsFallbackMerged = !isFullMode
|
|
3271
|
+
? (() => {
|
|
3272
|
+
const local =
|
|
3273
|
+
smsFallbackData && typeof smsFallbackData === 'object' ? smsFallbackData : {};
|
|
3274
|
+
return {
|
|
3275
|
+
...smsFromApiShape,
|
|
3276
|
+
...local,
|
|
3277
|
+
rcsSmsFallbackVarMapped: mergeRcsSmsFallbackVarMapLayers(smsFromApiShape, local),
|
|
3278
|
+
};
|
|
3279
|
+
})()
|
|
3280
|
+
: (smsFallbackData || {});
|
|
3281
|
+
const smsFallbackForPayload = (() => {
|
|
3282
|
+
if (isFullMode) {
|
|
3283
|
+
return hasMeaningfulSmsFallbackShape(smsFallbackData) ? smsFallbackData : null;
|
|
3284
|
+
}
|
|
3285
|
+
const mapped = {
|
|
3286
|
+
templateName:
|
|
3287
|
+
smsFallbackMerged.templateName
|
|
3288
|
+
|| smsFallbackMerged.smsTemplateName
|
|
3289
|
+
|| '',
|
|
3290
|
+
// Use `||` so empty `content` does not block campaign/API `message` (common in embedded flows).
|
|
3291
|
+
content:
|
|
3292
|
+
smsFallbackMerged.content
|
|
3293
|
+
|| smsFallbackMerged.smsContent
|
|
3294
|
+
|| smsFallbackMerged.smsTemplateContent
|
|
3295
|
+
|| smsFallbackMerged.message
|
|
3296
|
+
|| '',
|
|
3297
|
+
templateContent:
|
|
3298
|
+
pickFirstSmsFallbackTemplateString(smsFallbackMerged)
|
|
3299
|
+
|| '',
|
|
3300
|
+
...(typeof smsFallbackMerged.unicodeValidity === 'boolean'
|
|
3301
|
+
&& { unicodeValidity: smsFallbackMerged.unicodeValidity }),
|
|
3302
|
+
...(smsFallbackMerged[RCS_SMS_FALLBACK_VAR_MAPPED_PROP]
|
|
3303
|
+
&& Object.keys(smsFallbackMerged[RCS_SMS_FALLBACK_VAR_MAPPED_PROP]).length > 0 && {
|
|
3304
|
+
[RCS_SMS_FALLBACK_VAR_MAPPED_PROP]:
|
|
3305
|
+
smsFallbackMerged[RCS_SMS_FALLBACK_VAR_MAPPED_PROP],
|
|
3306
|
+
}),
|
|
3307
|
+
};
|
|
3308
|
+
return hasMeaningfulSmsFallbackShape(mapped) ? mapped : null;
|
|
3309
|
+
})();
|
|
3310
|
+
|
|
3311
|
+
const carouselCardContent = isCarouselType
|
|
3312
|
+
? (carouselData || []).map((card = {}) => {
|
|
3313
|
+
const cardMediaType = card.mediaType;
|
|
3314
|
+
const isCardVideo = cardMediaType === RCS_MEDIA_TYPES.VIDEO;
|
|
3315
|
+
const isCardImage = cardMediaType === RCS_MEDIA_TYPES.IMAGE;
|
|
3316
|
+
const mediaUrl = isCardVideo
|
|
3317
|
+
? (card.videoAsset?.videoSrc || '')
|
|
3318
|
+
: (card.imageSrc || '');
|
|
3319
|
+
const thumbnailUrl = isCardVideo
|
|
3320
|
+
? (card.thumbnailSrc || card.videoAsset?.videoThumbnail || '')
|
|
3321
|
+
: '';
|
|
3322
|
+
return {
|
|
3323
|
+
title: card.title || '',
|
|
3324
|
+
description: card.description || '',
|
|
3325
|
+
mediaType: cardMediaType,
|
|
3326
|
+
...((isCardImage || isCardVideo) && {
|
|
3327
|
+
media: {
|
|
3328
|
+
mediaUrl,
|
|
3329
|
+
thumbnailUrl,
|
|
3330
|
+
height: selectedCarouselHeight || MEDIUM,
|
|
3331
|
+
...(isCardVideo && card.videoAsset?.videoName && { videoName: card.videoAsset.videoName }),
|
|
3332
|
+
},
|
|
3333
|
+
}),
|
|
3334
|
+
...(Array.isArray(card.suggestions) && card.suggestions.length > 0 && {
|
|
3335
|
+
suggestions: card.suggestions,
|
|
3336
|
+
}),
|
|
3337
|
+
};
|
|
3338
|
+
})
|
|
3339
|
+
: null;
|
|
3340
|
+
|
|
1964
3341
|
const payload = {
|
|
1965
3342
|
name: templateName,
|
|
1966
3343
|
versions: {
|
|
@@ -1969,16 +3346,22 @@ const splitTemplateVarString = (str) => {
|
|
|
1969
3346
|
RCS: {
|
|
1970
3347
|
rcsContent: {
|
|
1971
3348
|
...(rcsAccount && !isFullMode && { accountId: rcsAccount }),
|
|
1972
|
-
cardType: STANDALONE,
|
|
1973
|
-
cardSettings:
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
3349
|
+
cardType: isCarouselType ? contentType.carousel : STANDALONE,
|
|
3350
|
+
cardSettings: isCarouselType
|
|
3351
|
+
? { cardWidth: selectedCarouselWidth || SMALL }
|
|
3352
|
+
: {
|
|
3353
|
+
cardOrientation: isMediaTypeImage ? RCS_IMAGE_DIMENSIONS[selectedDimension]?.orientation || VERTICAL : RCS_VIDEO_THUMBNAIL_DIMENSIONS[selectedDimension]?.orientation || VERTICAL,
|
|
3354
|
+
...(alignment && { mediaAlignment: alignment }),
|
|
3355
|
+
cardWidth: cardWidthFromSelection,
|
|
3356
|
+
},
|
|
3357
|
+
cardContent: isCarouselType
|
|
3358
|
+
? carouselCardContent
|
|
3359
|
+
: [
|
|
1979
3360
|
{
|
|
1980
|
-
|
|
1981
|
-
|
|
3361
|
+
// Persist raw template copy + cardVarMapped — not resolveTemplateWithMap output — so library
|
|
3362
|
+
// / getFormData round-trip keeps {{…}} and slot values (resolved strings broke reopen hydration).
|
|
3363
|
+
title: templateTitle,
|
|
3364
|
+
description: templateDesc,
|
|
1982
3365
|
mediaType: templateMediaType,
|
|
1983
3366
|
...(!isMediaTypeText && {media: {
|
|
1984
3367
|
mediaUrl: rcsImageSrc || rcsVideoSrc.videoSrc || '',
|
|
@@ -1987,23 +3370,32 @@ const splitTemplateVarString = (str) => {
|
|
|
1987
3370
|
? RCS_IMAGE_DIMENSIONS[selectedDimension]?.heightType || MEDIUM
|
|
1988
3371
|
: RCS_VIDEO_THUMBNAIL_DIMENSIONS[selectedDimension]?.heightType || MEDIUM,
|
|
1989
3372
|
}}),
|
|
1990
|
-
...(
|
|
1991
|
-
const
|
|
1992
|
-
...(templateTitle
|
|
1993
|
-
...(templateDesc
|
|
3373
|
+
...(isSlotMappingMode && (() => {
|
|
3374
|
+
const templateVarTokens = [
|
|
3375
|
+
...(templateTitle?.match(rcsVarRegex) ?? []),
|
|
3376
|
+
...(templateDesc?.match(rcsVarRegex) ?? []),
|
|
1994
3377
|
];
|
|
1995
|
-
const
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
3378
|
+
const cardVarMappedForRcsCardOnly = pickRcsCardVarMappedEntries(
|
|
3379
|
+
cardVarMapped,
|
|
3380
|
+
);
|
|
3381
|
+
// Persist numeric slot keys only ("1","2",…) — avoids duplicating the same value under
|
|
3382
|
+
// semantic names (e.g. both "1" and dynamic_expiry_date_after_3_days.FORMAT_1). Hydration
|
|
3383
|
+
// and coalesceCardVarMappedToTemplate still resolve from numeric keys + template tokens.
|
|
3384
|
+
const persistedSlotVarMap = {};
|
|
3385
|
+
templateVarTokens.forEach((token, slotIndexZeroBased) => {
|
|
3386
|
+
const varName = getVarNameFromToken(token);
|
|
3387
|
+
if (!varName) return;
|
|
3388
|
+
const resolvedRawValue = resolveCardVarMappedSlotValue(
|
|
3389
|
+
cardVarMappedForRcsCardOnly,
|
|
3390
|
+
varName,
|
|
3391
|
+
slotIndexZeroBased,
|
|
3392
|
+
isSlotMappingMode,
|
|
3393
|
+
rcsSpanningSemanticVarNames.has(varName),
|
|
3394
|
+
);
|
|
3395
|
+
const sanitizedSlotValue = sanitizeCardVarMappedValue(resolvedRawValue);
|
|
3396
|
+
persistedSlotVarMap[String(slotIndexZeroBased + 1)] = sanitizedSlotValue;
|
|
2005
3397
|
});
|
|
2006
|
-
return { cardVarMapped:
|
|
3398
|
+
return { cardVarMapped: persistedSlotVarMap };
|
|
2007
3399
|
})()),
|
|
2008
3400
|
...(suggestions.length > 0 && { suggestions }),
|
|
2009
3401
|
}
|
|
@@ -2011,17 +3403,109 @@ const splitTemplateVarString = (str) => {
|
|
|
2011
3403
|
contentType: isFullMode ? templateType : RICHCARD,
|
|
2012
3404
|
...(isFullMode && {accountId:accountId, accessToken: accessToken, accountName: accountName, hostName: hostName}),
|
|
2013
3405
|
},
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
3406
|
+
...(smsFallbackForPayload && (() => {
|
|
3407
|
+
const smsBodyText =
|
|
3408
|
+
smsFallbackForPayload.content
|
|
3409
|
+
|| smsFallbackForPayload.templateContent
|
|
3410
|
+
|| smsFallbackForPayload.message
|
|
3411
|
+
|| smsFallbackForPayload.smsContent
|
|
3412
|
+
|| '';
|
|
3413
|
+
/**
|
|
3414
|
+
* Campaigns `getTraiSenderIds` / Iris read `smsFallBackContent.templateConfigs.registeredSenderIds`.
|
|
3415
|
+
* Library `smsFallbackForPayload` omits ids — use merged state (`smsFallbackMerged`) like test preview.
|
|
3416
|
+
*/
|
|
3417
|
+
const m = smsFallbackMerged || {};
|
|
3418
|
+
const tcSibling = m.templateConfigs && typeof m.templateConfigs === 'object'
|
|
3419
|
+
? m.templateConfigs
|
|
3420
|
+
: {};
|
|
3421
|
+
const smsFallbackTemplateId =
|
|
3422
|
+
(m.smsTemplateId != null && String(m.smsTemplateId).trim() !== ''
|
|
3423
|
+
? String(m.smsTemplateId)
|
|
3424
|
+
: '')
|
|
3425
|
+
|| (tcSibling.templateId != null && String(tcSibling.templateId).trim() !== ''
|
|
3426
|
+
? String(tcSibling.templateId)
|
|
3427
|
+
: '');
|
|
3428
|
+
const smsFallbackTemplateStr =
|
|
3429
|
+
pickFirstSmsFallbackTemplateString(m)
|
|
3430
|
+
|| (typeof m.templateContent === 'string' ? m.templateContent : '')
|
|
3431
|
+
|| (typeof tcSibling.template === 'string' ? tcSibling.template : '')
|
|
3432
|
+
|| '';
|
|
3433
|
+
const smsFallbackTemplateName =
|
|
3434
|
+
m.templateName
|
|
3435
|
+
|| m.smsTemplateName
|
|
3436
|
+
|| tcSibling.templateName
|
|
3437
|
+
|| tcSibling.name
|
|
3438
|
+
|| '';
|
|
3439
|
+
const registeredSenderIdsForPayload = Array.isArray(m.registeredSenderIds)
|
|
3440
|
+
? m.registeredSenderIds
|
|
3441
|
+
: Array.isArray(tcSibling.registeredSenderIds)
|
|
3442
|
+
? tcSibling.registeredSenderIds
|
|
3443
|
+
: Array.isArray(tcSibling.header)
|
|
3444
|
+
? tcSibling.header
|
|
3445
|
+
: null;
|
|
3446
|
+
const hasRegisteredSenderIds = Array.isArray(registeredSenderIdsForPayload);
|
|
3447
|
+
const smsFallbackTemplateConfigs =
|
|
3448
|
+
smsFallbackTemplateId || hasRegisteredSenderIds
|
|
3449
|
+
? {
|
|
3450
|
+
...(smsFallbackTemplateId && { templateId: smsFallbackTemplateId }),
|
|
3451
|
+
...(smsFallbackTemplateStr && { template: smsFallbackTemplateStr }),
|
|
3452
|
+
...(smsFallbackTemplateName && {
|
|
3453
|
+
templateName: smsFallbackTemplateName,
|
|
3454
|
+
}),
|
|
3455
|
+
...(hasRegisteredSenderIds && {
|
|
3456
|
+
registeredSenderIds: registeredSenderIdsForPayload,
|
|
3457
|
+
}),
|
|
3458
|
+
}
|
|
3459
|
+
: null;
|
|
3460
|
+
const isDltCampaign = !isFullMode && isTraiDLTEnable(isFullMode, smsRegister);
|
|
3461
|
+
return {
|
|
3462
|
+
smsFallBackContent: isFullMode
|
|
3463
|
+
? {
|
|
3464
|
+
smsTemplateName: smsFallbackForPayload.templateName || '',
|
|
3465
|
+
smsContent: smsBodyText,
|
|
3466
|
+
// cap-campaigns-v2 `normalizeRcsMessageContentForApi` only serializes `message` (+ templateConfigs); without this key SMS fallback is dropped on send.
|
|
3467
|
+
message: smsBodyText,
|
|
3468
|
+
...(typeof smsFallbackForPayload.unicodeValidity === 'boolean' && {
|
|
3469
|
+
unicodeValidity: smsFallbackForPayload.unicodeValidity,
|
|
3470
|
+
}),
|
|
3471
|
+
...(smsFallbackForPayload.rcsSmsFallbackVarMapped
|
|
3472
|
+
&& Object.keys(smsFallbackForPayload.rcsSmsFallbackVarMapped).length > 0 && {
|
|
3473
|
+
[RCS_SMS_FALLBACK_VAR_MAPPED_PROP]: smsFallbackForPayload.rcsSmsFallbackVarMapped,
|
|
3474
|
+
}),
|
|
3475
|
+
...(smsFallbackTemplateConfigs && {
|
|
3476
|
+
templateConfigs: smsFallbackTemplateConfigs,
|
|
3477
|
+
}),
|
|
3478
|
+
}
|
|
3479
|
+
: {
|
|
3480
|
+
// Round-trip storage: full shape so reopening the editor restores template
|
|
3481
|
+
// name, sender IDs, and var mappings. normalizeRcsMessageContentForApi
|
|
3482
|
+
// (called in CreativesContainer getCreativesData) strips this to
|
|
3483
|
+
// { message, templateConfigs } before the API call — the extra fields here
|
|
3484
|
+
// are only used for re-hydration, never sent to the API.
|
|
3485
|
+
message: smsBodyText,
|
|
3486
|
+
...(smsFallbackForPayload.templateName && {
|
|
3487
|
+
smsTemplateName: smsFallbackForPayload.templateName,
|
|
3488
|
+
}),
|
|
3489
|
+
...(smsFallbackForPayload.templateContent && {
|
|
3490
|
+
templateContent: smsFallbackForPayload.templateContent,
|
|
3491
|
+
}),
|
|
3492
|
+
...(typeof smsFallbackForPayload.unicodeValidity === 'boolean' && {
|
|
3493
|
+
unicodeValidity: smsFallbackForPayload.unicodeValidity,
|
|
3494
|
+
}),
|
|
3495
|
+
...(Array.isArray(registeredSenderIdsForPayload) && {
|
|
3496
|
+
registeredSenderIds: registeredSenderIdsForPayload,
|
|
3497
|
+
}),
|
|
3498
|
+
...(smsFallbackForPayload[RCS_SMS_FALLBACK_VAR_MAPPED_PROP]
|
|
3499
|
+
&& Object.keys(smsFallbackForPayload[RCS_SMS_FALLBACK_VAR_MAPPED_PROP]).length > 0 && {
|
|
3500
|
+
[RCS_SMS_FALLBACK_VAR_MAPPED_PROP]:
|
|
3501
|
+
smsFallbackForPayload[RCS_SMS_FALLBACK_VAR_MAPPED_PROP],
|
|
3502
|
+
}),
|
|
3503
|
+
...(isDltCampaign && smsFallbackTemplateConfigs && {
|
|
3504
|
+
templateConfigs: smsFallbackTemplateConfigs,
|
|
3505
|
+
}),
|
|
3506
|
+
},
|
|
3507
|
+
};
|
|
3508
|
+
})()),
|
|
2025
3509
|
},
|
|
2026
3510
|
},
|
|
2027
3511
|
},
|
|
@@ -2031,6 +3515,109 @@ const splitTemplateVarString = (str) => {
|
|
|
2031
3515
|
return payload;
|
|
2032
3516
|
};
|
|
2033
3517
|
|
|
3518
|
+
/** Shape expected by CommonTestAndPreview buildRcsTestMessagePayload (versions.base.content.RCS). */
|
|
3519
|
+
const testPreviewFormData = useMemo(() => {
|
|
3520
|
+
const payload = createPayload();
|
|
3521
|
+
const rcs = payload?.versions?.base?.content?.RCS;
|
|
3522
|
+
if (!rcs) return null;
|
|
3523
|
+
// createMessageMeta uses WeCRM `id` when present; else template API account id (sourceAccountIdentifier).
|
|
3524
|
+
const accountIdForCreateMessageMeta =
|
|
3525
|
+
(wecrmAccountId != null && String(wecrmAccountId).trim() !== '')
|
|
3526
|
+
? String(wecrmAccountId)
|
|
3527
|
+
: accountId;
|
|
3528
|
+
const isSlotMappingModeForPreview = isEditFlow || !isFullMode;
|
|
3529
|
+
let rcsForTest = {
|
|
3530
|
+
...rcs,
|
|
3531
|
+
rcsContent: {
|
|
3532
|
+
...rcs.rcsContent,
|
|
3533
|
+
...(accountIdForCreateMessageMeta ? { accountId: accountIdForCreateMessageMeta } : {}),
|
|
3534
|
+
},
|
|
3535
|
+
};
|
|
3536
|
+
/** Approval payload keeps numeric-only `cardVarMapped`; preview APIs still need semantic keys. */
|
|
3537
|
+
if (isSlotMappingModeForPreview) {
|
|
3538
|
+
const cardContent = rcsForTest.rcsContent?.cardContent;
|
|
3539
|
+
if (Array.isArray(cardContent) && cardContent[0]) {
|
|
3540
|
+
const fullCardVarMapped = coalesceCardVarMappedToTemplate(
|
|
3541
|
+
pickRcsCardVarMappedEntries(cardVarMapped),
|
|
3542
|
+
templateTitle,
|
|
3543
|
+
templateDesc,
|
|
3544
|
+
rcsVarRegex,
|
|
3545
|
+
);
|
|
3546
|
+
rcsForTest = {
|
|
3547
|
+
...rcsForTest,
|
|
3548
|
+
rcsContent: {
|
|
3549
|
+
...rcsForTest.rcsContent,
|
|
3550
|
+
cardContent: [
|
|
3551
|
+
{ ...cardContent[0], cardVarMapped: fullCardVarMapped },
|
|
3552
|
+
...cardContent.slice(1),
|
|
3553
|
+
],
|
|
3554
|
+
},
|
|
3555
|
+
};
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
const out = {
|
|
3559
|
+
versions: {
|
|
3560
|
+
base: {
|
|
3561
|
+
content: {
|
|
3562
|
+
RCS: rcsForTest,
|
|
3563
|
+
},
|
|
3564
|
+
},
|
|
3565
|
+
},
|
|
3566
|
+
};
|
|
3567
|
+
const fb = smsFallbackData;
|
|
3568
|
+
if (fb && (fb.smsTemplateId || fb.templateContent || fb.content)) {
|
|
3569
|
+
out.templateConfigs = {
|
|
3570
|
+
templateId: fb.smsTemplateId || '',
|
|
3571
|
+
template: fb.templateContent || fb.content || '',
|
|
3572
|
+
traiDltEnabled: isTraiDLTEnable(isFullMode, smsRegister),
|
|
3573
|
+
registeredSenderIds: Array.isArray(fb.registeredSenderIds) ? fb.registeredSenderIds : [],
|
|
3574
|
+
};
|
|
3575
|
+
}
|
|
3576
|
+
return out;
|
|
3577
|
+
}, [
|
|
3578
|
+
templateName,
|
|
3579
|
+
templateTitle,
|
|
3580
|
+
templateDesc,
|
|
3581
|
+
templateMediaType,
|
|
3582
|
+
cardVarMapped,
|
|
3583
|
+
suggestions,
|
|
3584
|
+
rcsImageSrc,
|
|
3585
|
+
rcsVideoSrc,
|
|
3586
|
+
rcsThumbnailSrc,
|
|
3587
|
+
selectedDimension,
|
|
3588
|
+
smsFallbackData,
|
|
3589
|
+
isFullMode,
|
|
3590
|
+
isEditFlow,
|
|
3591
|
+
templateType,
|
|
3592
|
+
accountId,
|
|
3593
|
+
wecrmAccountId,
|
|
3594
|
+
accessToken,
|
|
3595
|
+
accountName,
|
|
3596
|
+
hostName,
|
|
3597
|
+
smsRegister,
|
|
3598
|
+
]);
|
|
3599
|
+
|
|
3600
|
+
/**
|
|
3601
|
+
* Library/campaign: `createPayload` merges root + nested `smsFallBackContent` from `templateData`
|
|
3602
|
+
* with `smsFallbackData`. Done/slot validation must use the same merge — otherwise local state can
|
|
3603
|
+
* miss `templateContent` / var map while the parent payload still has them (DLT campaigns).
|
|
3604
|
+
*/
|
|
3605
|
+
const librarySmsFallbackMergedForValidation = useMemo(() => {
|
|
3606
|
+
if (isFullMode) {
|
|
3607
|
+
return smsFallbackData;
|
|
3608
|
+
}
|
|
3609
|
+
const smsFromApiShape = getLibrarySmsFallbackApiBaselineFromTemplateData(templateData);
|
|
3610
|
+
const local =
|
|
3611
|
+
smsFallbackData && typeof smsFallbackData === 'object' ? smsFallbackData : {};
|
|
3612
|
+
return {
|
|
3613
|
+
...smsFromApiShape,
|
|
3614
|
+
...local,
|
|
3615
|
+
rcsSmsFallbackVarMapped: mergeRcsSmsFallbackVarMapLayers(smsFromApiShape, local),
|
|
3616
|
+
};
|
|
3617
|
+
}, [isFullMode, templateData, smsFallbackData]);
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
2034
3621
|
const actionCallback = ({ errorMessage, resp }, isEdit) => {
|
|
2035
3622
|
// eslint-disable-next-line no-undef
|
|
2036
3623
|
const error = errorMessage?.message || errorMessage;
|
|
@@ -2060,6 +3647,9 @@ const splitTemplateVarString = (str) => {
|
|
|
2060
3647
|
_id: params?.id,
|
|
2061
3648
|
validity: true,
|
|
2062
3649
|
type: RCS,
|
|
3650
|
+
// CreativesContainer closes the slide box *after* getCreativesData runs so the parent receives
|
|
3651
|
+
// the RCS payload first (closing immediately used to skip getCreativesData → empty "Add creative").
|
|
3652
|
+
closeSlideBoxAfterSubmit: !isFullMode,
|
|
2063
3653
|
};
|
|
2064
3654
|
getFormData(formDataParams);
|
|
2065
3655
|
};
|
|
@@ -2073,6 +3663,7 @@ const splitTemplateVarString = (str) => {
|
|
|
2073
3663
|
actionCallback({ resp, errorMessage });
|
|
2074
3664
|
setSpin(false); // Always turn off spinner
|
|
2075
3665
|
if (!errorMessage) {
|
|
3666
|
+
setTemplateStatus(RCS_STATUSES.pending);
|
|
2076
3667
|
onCreateComplete();
|
|
2077
3668
|
}
|
|
2078
3669
|
});
|
|
@@ -2084,6 +3675,86 @@ const splitTemplateVarString = (str) => {
|
|
|
2084
3675
|
}
|
|
2085
3676
|
};
|
|
2086
3677
|
|
|
3678
|
+
/** When a fallback SMS row exists, require non-empty body (trimmed) and filled var slots (DLT). */
|
|
3679
|
+
const smsFallbackBlocksDone = () => {
|
|
3680
|
+
// Non-DLT library: user removed SMS fallback (local null) but template still carries fallback — block Done.
|
|
3681
|
+
if (
|
|
3682
|
+
!isFullMode
|
|
3683
|
+
&& !isTraiDLTEnable(isFullMode, smsRegister)
|
|
3684
|
+
&& smsFallbackData == null
|
|
3685
|
+
&& hasMeaningfulSmsFallbackShape(
|
|
3686
|
+
getLibrarySmsFallbackApiBaselineFromTemplateData(templateData),
|
|
3687
|
+
)
|
|
3688
|
+
) {
|
|
3689
|
+
return true;
|
|
3690
|
+
}
|
|
3691
|
+
if (!smsFallbackData) return false;
|
|
3692
|
+
// Full-mode (Send for approval): SMS fallback is optional. Tag-slot mapping is a display/preview
|
|
3693
|
+
// concern, not a structural requirement for approval — the registered SMS template body stands on
|
|
3694
|
+
// its own. Never block the Send for approval button due to missing or unfilled fallback var slots.
|
|
3695
|
+
if (isFullMode) return false;
|
|
3696
|
+
const merged = librarySmsFallbackMergedForValidation;
|
|
3697
|
+
const templateText = pickFirstSmsFallbackTemplateString(merged);
|
|
3698
|
+
if (!templateText) {
|
|
3699
|
+
return true;
|
|
3700
|
+
}
|
|
3701
|
+
const rawVarMap =
|
|
3702
|
+
merged.rcsSmsFallbackVarMapped
|
|
3703
|
+
|| merged['rcs-sms-fallback-var-mapped'];
|
|
3704
|
+
const varMap =
|
|
3705
|
+
rawVarMap != null && typeof rawVarMap === 'object' ? rawVarMap : {};
|
|
3706
|
+
return !areAllRcsSmsFallbackVarSlotsFilled(templateText, varMap);
|
|
3707
|
+
};
|
|
3708
|
+
|
|
3709
|
+
/**
|
|
3710
|
+
* Library / campaigns (`!isFullMode`): card slots are often stored on numeric keys (`1`,`2`,…) while
|
|
3711
|
+
* semantic keys stay `""` from API round-trip. `resolveCardVarMappedSlotValue` matches createPayload
|
|
3712
|
+
* / preview — naive `cardVarMapped[name]` wrongly kept Done disabled for DLT.
|
|
3713
|
+
*/
|
|
3714
|
+
const isLibraryCampaignCardVarMappingIncomplete = () => {
|
|
3715
|
+
if (isFullMode) return false;
|
|
3716
|
+
const titleTokens = splitTemplateVarStringRcs(templateTitle).filter((elem) =>
|
|
3717
|
+
rcsVarTestRegex.test(elem),
|
|
3718
|
+
);
|
|
3719
|
+
const descTokens = splitTemplateVarStringRcs(templateDesc).filter((elem) =>
|
|
3720
|
+
rcsVarTestRegex.test(elem),
|
|
3721
|
+
);
|
|
3722
|
+
const orderedVarNames = [
|
|
3723
|
+
...titleTokens.map((t) => t.replace(/^\{\{|\}\}$/g, '')),
|
|
3724
|
+
...descTokens.map((t) => t.replace(/^\{\{|\}\}$/g, '')),
|
|
3725
|
+
];
|
|
3726
|
+
if (orderedVarNames.length > 0 && isEmpty(cardVarMapped)) {
|
|
3727
|
+
return true;
|
|
3728
|
+
}
|
|
3729
|
+
return orderedVarNames.some((name, globalIdx) => {
|
|
3730
|
+
const v = resolveCardVarMappedSlotValue(
|
|
3731
|
+
cardVarMapped,
|
|
3732
|
+
name,
|
|
3733
|
+
globalIdx,
|
|
3734
|
+
true,
|
|
3735
|
+
rcsSpanningSemanticVarNames.has(name),
|
|
3736
|
+
);
|
|
3737
|
+
const s = v == null ? '' : String(v);
|
|
3738
|
+
return s.trim() === '';
|
|
3739
|
+
});
|
|
3740
|
+
};
|
|
3741
|
+
|
|
3742
|
+
const isCarouselLibraryIncomplete = () => {
|
|
3743
|
+
if (!isCarouselType || isFullMode) return false;
|
|
3744
|
+
if ((carouselErrors || []).some((err) => err?.title || err?.description)) return true;
|
|
3745
|
+
const unfilledVar = (carouselData || []).some((card) =>
|
|
3746
|
+
['title', 'description'].some((field) => {
|
|
3747
|
+
const tokens = splitTemplateVarStringRcs(card?.[field] || '').filter((t) => rcsVarTestRegex.test(t));
|
|
3748
|
+
return tokens.some((t) => {
|
|
3749
|
+
const name = t.replace(/^\{\{|\}\}$/g, '');
|
|
3750
|
+
const v = cardVarMapped?.[name];
|
|
3751
|
+
return v == null || String(v).trim() === '';
|
|
3752
|
+
});
|
|
3753
|
+
})
|
|
3754
|
+
);
|
|
3755
|
+
return unfilledVar;
|
|
3756
|
+
};
|
|
3757
|
+
|
|
2087
3758
|
const isDisableDone = () => {
|
|
2088
3759
|
if(isEditFlow){
|
|
2089
3760
|
return false;
|
|
@@ -2094,46 +3765,26 @@ const splitTemplateVarString = (str) => {
|
|
|
2094
3765
|
}
|
|
2095
3766
|
}
|
|
2096
3767
|
|
|
2097
|
-
if(
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
const allVars = Array.from(new Set([ ...titleVars, ...descVars ]));
|
|
2101
|
-
|
|
2102
|
-
if (allVars.length > 0 && isEmpty(cardVarMapped)) {
|
|
2103
|
-
return true;
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
|
-
const hasEmptyMapping =
|
|
2107
|
-
cardVarMapped &&
|
|
2108
|
-
Object.keys(cardVarMapped).length > 0 &&
|
|
2109
|
-
Object.entries(cardVarMapped).some(([_, v]) => {
|
|
2110
|
-
if (typeof v !== 'string') return !v; // null/undefined
|
|
2111
|
-
return v.trim() === ''; // empty string
|
|
2112
|
-
});
|
|
2113
|
-
|
|
2114
|
-
if (hasEmptyMapping) {
|
|
2115
|
-
return true;
|
|
2116
|
-
}
|
|
3768
|
+
if (isCarouselLibraryIncomplete()) {
|
|
3769
|
+
return true;
|
|
3770
|
+
}
|
|
2117
3771
|
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
if (typeof v !== 'string') return !v;
|
|
2121
|
-
return v.trim() === '';
|
|
2122
|
-
});
|
|
2123
|
-
if (anyMissing) {
|
|
2124
|
-
return true;
|
|
2125
|
-
}
|
|
3772
|
+
if (isLibraryCampaignCardVarMappingIncomplete()) {
|
|
3773
|
+
return true;
|
|
2126
3774
|
}
|
|
2127
3775
|
|
|
2128
|
-
|
|
3776
|
+
if (smsFallbackBlocksDone()) {
|
|
2129
3777
|
return true;
|
|
3778
|
+
}
|
|
2130
3779
|
|
|
3780
|
+
if (!isCarouselType && isMediaTypeText && templateDesc.trim() === '') {
|
|
3781
|
+
return true;
|
|
2131
3782
|
}
|
|
2132
|
-
if (isMediaTypeImage && (rcsImageSrc === '' || templateTitle === '' || templateDesc === '' )) {
|
|
3783
|
+
if (!isCarouselType && isMediaTypeImage && (rcsImageSrc === '' || templateTitle === '' || templateDesc === '' )) {
|
|
2133
3784
|
return true;
|
|
2134
3785
|
}
|
|
2135
3786
|
|
|
2136
|
-
if (isMediaTypeVideo && (rcsVideoSrc.videoSrc
|
|
3787
|
+
if (!isCarouselType && isMediaTypeVideo && (!rcsVideoSrc.videoSrc || rcsThumbnailSrc === '' || templateTitle === '' || templateDesc === '' )) {
|
|
2137
3788
|
return true;
|
|
2138
3789
|
}
|
|
2139
3790
|
if (buttonType.includes(CTA)) {
|
|
@@ -2145,72 +3796,61 @@ const splitTemplateVarString = (str) => {
|
|
|
2145
3796
|
return true;
|
|
2146
3797
|
}
|
|
2147
3798
|
}
|
|
2148
|
-
if (templateDescError || templateTitleError
|
|
3799
|
+
if (templateDescError || templateTitleError) {
|
|
3800
|
+
return true;
|
|
3801
|
+
}
|
|
3802
|
+
if (
|
|
3803
|
+
smsFallbackData?.content
|
|
3804
|
+
&& smsFallbackData.content.length > FALLBACK_MESSAGE_MAX_LENGTH
|
|
3805
|
+
) {
|
|
2149
3806
|
return true;
|
|
2150
3807
|
}
|
|
2151
3808
|
return false;
|
|
2152
3809
|
};
|
|
2153
3810
|
|
|
2154
3811
|
const isEditDisableDone = () => {
|
|
2155
|
-
|
|
2156
|
-
if (templateStatus !== RCS_STATUSES.approved) {
|
|
3812
|
+
if (isFullMode && !isHostInfoBip && templateStatus !== RCS_STATUSES.approved) {
|
|
2157
3813
|
return true;
|
|
2158
3814
|
}
|
|
2159
3815
|
|
|
2160
|
-
if (!isFullMode) {
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
3816
|
+
// if (!isFullMode) {
|
|
3817
|
+
// if (templateName.trim() === '' || templateNameError) {
|
|
3818
|
+
// return true;
|
|
3819
|
+
// }
|
|
3820
|
+
// }
|
|
3821
|
+
if (isLibraryCampaignCardVarMappingIncomplete()) {
|
|
3822
|
+
return true;
|
|
2164
3823
|
}
|
|
2165
|
-
if(!isFullMode){
|
|
2166
|
-
const titleVars = splitTemplateVarString(templateTitle).filter(elem => rcsVarTestRegex.test(elem)).map(v => v.replace(/^\{\{|\}\}$/g, ''));
|
|
2167
|
-
const descVars = splitTemplateVarString(templateDesc).filter(elem => rcsVarTestRegex.test(elem)).map(v => v.replace(/^\{\{|\}\}$/g, ''));
|
|
2168
|
-
const allVars = Array.from(new Set([ ...titleVars, ...descVars ]));
|
|
2169
|
-
|
|
2170
|
-
if (allVars.length > 0 && isEmpty(cardVarMapped)) {
|
|
2171
|
-
return true;
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
const hasEmptyMapping =
|
|
2175
|
-
cardVarMapped &&
|
|
2176
|
-
Object.keys(cardVarMapped).length > 0 &&
|
|
2177
|
-
Object.entries(cardVarMapped).some(([_, v]) => {
|
|
2178
|
-
if (typeof v !== 'string') return !v; // null/undefined
|
|
2179
|
-
return v.trim() === ''; // empty string
|
|
2180
|
-
});
|
|
2181
|
-
|
|
2182
|
-
if (hasEmptyMapping) {
|
|
2183
|
-
return true;
|
|
2184
|
-
}
|
|
2185
3824
|
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
if (typeof v !== 'string') return !v;
|
|
2189
|
-
return v.trim() === '';
|
|
2190
|
-
});
|
|
2191
|
-
if (anyMissing) {
|
|
2192
|
-
return true;
|
|
2193
|
-
}
|
|
3825
|
+
if (smsFallbackBlocksDone()) {
|
|
3826
|
+
return true;
|
|
2194
3827
|
}
|
|
2195
|
-
|
|
3828
|
+
|
|
3829
|
+
if (!isCarouselType && isMediaTypeText && templateDesc.trim() === '') {
|
|
2196
3830
|
return true;
|
|
2197
3831
|
}
|
|
2198
|
-
if (isMediaTypeImage && rcsImageSrc === '') {
|
|
3832
|
+
if (!isCarouselType && isMediaTypeImage && rcsImageSrc === '') {
|
|
2199
3833
|
return true;
|
|
2200
3834
|
}
|
|
2201
|
-
if(isMediaTypeVideo && (rcsThumbnailSrc === '' || rcsVideoSrc.videoSrc === '')) {
|
|
3835
|
+
if (!isCarouselType && isMediaTypeVideo && (rcsThumbnailSrc === '' || rcsVideoSrc.videoSrc === '')) {
|
|
2202
3836
|
return true;
|
|
2203
3837
|
}
|
|
2204
3838
|
|
|
2205
3839
|
if (buttonType.includes(CTA)) {
|
|
2206
|
-
const hasValidButtons = suggestions.every(suggestion =>
|
|
3840
|
+
const hasValidButtons = suggestions.every(suggestion =>
|
|
2207
3841
|
suggestion.text && suggestion.url && !suggestionError && !forbiddenCharactersValidation(suggestion.text)
|
|
2208
3842
|
);
|
|
2209
3843
|
if (!hasValidButtons) {
|
|
2210
3844
|
return true;
|
|
2211
3845
|
}
|
|
2212
3846
|
}
|
|
2213
|
-
if (templateTitleError || templateDescError
|
|
3847
|
+
if (templateTitleError || templateDescError) {
|
|
3848
|
+
return true;
|
|
3849
|
+
}
|
|
3850
|
+
if (
|
|
3851
|
+
smsFallbackData?.content
|
|
3852
|
+
&& smsFallbackData.content.length > FALLBACK_MESSAGE_MAX_LENGTH
|
|
3853
|
+
) {
|
|
2214
3854
|
return true;
|
|
2215
3855
|
}
|
|
2216
3856
|
return false;
|
|
@@ -2260,54 +3900,58 @@ const splitTemplateVarString = (str) => {
|
|
|
2260
3900
|
};
|
|
2261
3901
|
|
|
2262
3902
|
const getMainContent = () => {
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
return (
|
|
2267
|
-
<CapSlideBox
|
|
2268
|
-
show={showDltContainer}
|
|
2269
|
-
header={dltHeader}
|
|
2270
|
-
content={dltContent}
|
|
2271
|
-
handleClose={closeDltContainerHandler}
|
|
2272
|
-
size="size-xl"
|
|
2273
|
-
/>
|
|
2274
|
-
);
|
|
2275
|
-
}
|
|
2276
|
-
|
|
3903
|
+
// Slideboxes are rendered outside the page-level spinner to avoid
|
|
3904
|
+
// stacking/blur issues during initial loads.
|
|
3905
|
+
if (showDltContainer) return null;
|
|
2277
3906
|
return (
|
|
2278
3907
|
<>
|
|
2279
|
-
{templateStatus !== '' && (
|
|
2280
|
-
<
|
|
2281
|
-
{
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
3908
|
+
{templateStatus !== '' && (
|
|
3909
|
+
<CapRow className="template-status-container">
|
|
3910
|
+
<CapColumn span={14}>
|
|
3911
|
+
<CapLabel type="label2">
|
|
3912
|
+
{formatMessage(messages.templateStatusLabel)}
|
|
3913
|
+
</CapLabel>
|
|
3914
|
+
|
|
3915
|
+
{!isHostInfoBip && templateStatus && (
|
|
3916
|
+
<CapAlert
|
|
3917
|
+
message={getTemplateStatusMessage()}
|
|
3918
|
+
type={getTemplateStatusType(templateStatus)}
|
|
3919
|
+
/>
|
|
3920
|
+
)}
|
|
3921
|
+
</CapColumn>
|
|
3922
|
+
</CapRow>
|
|
2291
3923
|
)}
|
|
2292
|
-
<CapRow className=
|
|
3924
|
+
<CapRow className={`cap-rcs-creatives ${isEditLike ? 'rcs-edit-mode' : ''}`}>
|
|
2293
3925
|
<CapColumn span={14}>
|
|
2294
3926
|
{/* template name */}
|
|
2295
3927
|
{isFullMode && (
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
3928
|
+
isEditFlow ? (
|
|
3929
|
+
<div className="rcs-creative-name-readonly">
|
|
3930
|
+
<CapHeading type="h4">
|
|
3931
|
+
{formatMessage(globalMessages.creativeNameLabel)}
|
|
3932
|
+
</CapHeading>
|
|
3933
|
+
<CapHeading type="h5" className="rcs-creative-name-value">
|
|
3934
|
+
{templateName || '-'}
|
|
3935
|
+
</CapHeading>
|
|
3936
|
+
</div>
|
|
3937
|
+
) : (
|
|
3938
|
+
<CapInput
|
|
3939
|
+
id="rcs_template_name_input"
|
|
3940
|
+
data-testid="template_name"
|
|
3941
|
+
onChange={onTemplateNameChange}
|
|
3942
|
+
errorMessage={templateNameError}
|
|
3943
|
+
placeholder={formatMessage(
|
|
3944
|
+
globalMessages.templateNamePlaceholder,
|
|
3945
|
+
)}
|
|
3946
|
+
value={templateName || ''}
|
|
3947
|
+
size="default"
|
|
3948
|
+
label={formatMessage(globalMessages.creativeNameLabel)}
|
|
3949
|
+
disabled={(isEditFlow || !isFullMode)}
|
|
3950
|
+
/>
|
|
3951
|
+
)
|
|
2309
3952
|
)}
|
|
2310
3953
|
{renderLabel('templateTypeLabel')}
|
|
3954
|
+
|
|
2311
3955
|
<CapRadioGroup
|
|
2312
3956
|
id="select-rcs-template-type"
|
|
2313
3957
|
options={TEMPLATE_TYPE_OPTIONS}
|
|
@@ -2316,24 +3960,30 @@ const splitTemplateVarString = (str) => {
|
|
|
2316
3960
|
disabled={(isEditFlow || !isFullMode)}
|
|
2317
3961
|
/>
|
|
2318
3962
|
|
|
2319
|
-
{
|
|
2320
|
-
|
|
3963
|
+
{templateType === contentType.carousel ? (
|
|
3964
|
+
renderCarouselSection()
|
|
3965
|
+
) : (
|
|
2321
3966
|
<>
|
|
2322
|
-
{
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
3967
|
+
{/* Show media only for rich_card */}
|
|
3968
|
+
{templateType === contentType.rich_card && (
|
|
3969
|
+
<>
|
|
3970
|
+
{renderLabel('mediaLabel')}
|
|
3971
|
+
<CapRadioGroup
|
|
3972
|
+
options={mediaRadioOptions || []}
|
|
3973
|
+
value={templateMediaType}
|
|
3974
|
+
onChange={onTemplateMediaTypeChange}
|
|
3975
|
+
disabled={(isEditFlow || !isFullMode)}
|
|
3976
|
+
className="rcs-radio"
|
|
3977
|
+
/>
|
|
3978
|
+
<div className="rcs-container-image">
|
|
3979
|
+
{getMediaBasedComponent()}
|
|
3980
|
+
</div>
|
|
3981
|
+
</>
|
|
3982
|
+
)}
|
|
3983
|
+
{renderTextComponent()}
|
|
2333
3984
|
</>
|
|
2334
3985
|
)}
|
|
2335
|
-
|
|
2336
|
-
<CapDivider style={{ margin: `${CAP_SPACE_28} 0` }} />
|
|
3986
|
+
<CapDivider className="rcs-fallback-section-divider" />
|
|
2337
3987
|
{renderFallBackSmsComponent()}
|
|
2338
3988
|
<div className="rcs-scroll-div" />
|
|
2339
3989
|
</CapColumn>
|
|
@@ -2345,7 +3995,8 @@ const splitTemplateVarString = (str) => {
|
|
|
2345
3995
|
|
|
2346
3996
|
|
|
2347
3997
|
<div className="rcs-footer">
|
|
2348
|
-
{!
|
|
3998
|
+
{/* Full-mode create only: send-for-approval + disabled test/preview. Library mode uses Done below — onDoneCallback() is undefined when !isFullMode, so do not render this row (avoids a no-op primary button). */}
|
|
3999
|
+
{!isEditFlow && isFullMode && (
|
|
2349
4000
|
<>
|
|
2350
4001
|
<div className="button-disabled-tooltip-wrapper">
|
|
2351
4002
|
<CapButton
|
|
@@ -2353,7 +4004,9 @@ const splitTemplateVarString = (str) => {
|
|
|
2353
4004
|
disabled={isDisableDone()}
|
|
2354
4005
|
className="rcs-done-btn"
|
|
2355
4006
|
>
|
|
2356
|
-
<FormattedMessage
|
|
4007
|
+
<FormattedMessage
|
|
4008
|
+
{...(isHostInfoBip ? messages.doneButtonLabel : messages.sendForApprovalButtonLabel)}
|
|
4009
|
+
/>
|
|
2357
4010
|
</CapButton>
|
|
2358
4011
|
</div>
|
|
2359
4012
|
<CapTooltip
|
|
@@ -2366,7 +4019,6 @@ const splitTemplateVarString = (str) => {
|
|
|
2366
4019
|
className="rcs-test-preview-btn"
|
|
2367
4020
|
type="secondary"
|
|
2368
4021
|
disabled={true}
|
|
2369
|
-
style={{ marginLeft: "8px" }}
|
|
2370
4022
|
>
|
|
2371
4023
|
<FormattedMessage {...creativesMessages.testAndPreview} />
|
|
2372
4024
|
</CapButton>
|
|
@@ -2387,7 +4039,7 @@ const splitTemplateVarString = (str) => {
|
|
|
2387
4039
|
</div>
|
|
2388
4040
|
</>
|
|
2389
4041
|
)}
|
|
2390
|
-
{isEditFlow && templateStatus === RCS_STATUSES.approved && (
|
|
4042
|
+
{isEditFlow && (isHostInfoBip || templateStatus === RCS_STATUSES.approved) && (
|
|
2391
4043
|
<>
|
|
2392
4044
|
<CapButton
|
|
2393
4045
|
onClick={handleTestAndPreview}
|
|
@@ -2399,51 +4051,6 @@ const splitTemplateVarString = (str) => {
|
|
|
2399
4051
|
</>
|
|
2400
4052
|
)}
|
|
2401
4053
|
</div>
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
{fallbackPreviewmode && (
|
|
2405
|
-
<CapSlideBox
|
|
2406
|
-
className="rcs-fallback-preview"
|
|
2407
|
-
show={fallbackPreviewmode}
|
|
2408
|
-
header={(
|
|
2409
|
-
<CapHeading type="h7" style={{ color: CAP_G01 }}>
|
|
2410
|
-
{formatMessage(messages.fallbackPreviewtitle)}
|
|
2411
|
-
</CapHeading>
|
|
2412
|
-
)}
|
|
2413
|
-
content={(
|
|
2414
|
-
<>
|
|
2415
|
-
<UnifiedPreview
|
|
2416
|
-
channel={RCS}
|
|
2417
|
-
content={{
|
|
2418
|
-
rcsPreviewContent: {
|
|
2419
|
-
rcsDesc: tempMsg,
|
|
2420
|
-
},
|
|
2421
|
-
}}
|
|
2422
|
-
device={ANDROID}
|
|
2423
|
-
showDeviceToggle={false}
|
|
2424
|
-
showHeader={false}
|
|
2425
|
-
formatMessage={formatMessage}
|
|
2426
|
-
/>
|
|
2427
|
-
<CapHeading
|
|
2428
|
-
type="h3"
|
|
2429
|
-
style={{ textAlign: 'center' }}
|
|
2430
|
-
className="margin-t-16"
|
|
2431
|
-
>
|
|
2432
|
-
{formatMessage(messages.totalCharacters, {
|
|
2433
|
-
smsCount: Math.ceil(
|
|
2434
|
-
tempMsg?.length / FALLBACK_MESSAGE_MAX_LENGTH,
|
|
2435
|
-
),
|
|
2436
|
-
number: tempMsg.length,
|
|
2437
|
-
})}
|
|
2438
|
-
</CapHeading>
|
|
2439
|
-
</>
|
|
2440
|
-
)}
|
|
2441
|
-
handleClose={() => {
|
|
2442
|
-
setFallbackPreviewmode(false);
|
|
2443
|
-
setDltPreviewData('');
|
|
2444
|
-
}}
|
|
2445
|
-
/>
|
|
2446
|
-
)}
|
|
2447
4054
|
</>
|
|
2448
4055
|
);
|
|
2449
4056
|
};
|
|
@@ -2452,23 +4059,57 @@ const splitTemplateVarString = (str) => {
|
|
|
2452
4059
|
<CapSpin spinning={loadingTags || spin}>
|
|
2453
4060
|
{getMainContent()}
|
|
2454
4061
|
</CapSpin>
|
|
4062
|
+
|
|
4063
|
+
{showDltContainer && (() => {
|
|
4064
|
+
const { dltHeader = '', dltContent = '' } = getDltSlideBoxContent() || {};
|
|
4065
|
+
return (
|
|
4066
|
+
<CapSlideBox
|
|
4067
|
+
show={showDltContainer}
|
|
4068
|
+
header={dltHeader}
|
|
4069
|
+
content={dltContent}
|
|
4070
|
+
handleClose={closeDltContainerHandler}
|
|
4071
|
+
size="size-xl"
|
|
4072
|
+
/>
|
|
4073
|
+
);
|
|
4074
|
+
})()}
|
|
4075
|
+
|
|
2455
4076
|
<TestAndPreviewSlidebox
|
|
2456
4077
|
show={propsShowTestAndPreviewSlidebox || showTestAndPreviewSlidebox}
|
|
2457
4078
|
onClose={handleCloseTestAndPreview}
|
|
2458
|
-
formData={
|
|
2459
|
-
content={
|
|
4079
|
+
formData={testPreviewFormData}
|
|
4080
|
+
content={testAndPreviewContent}
|
|
2460
4081
|
currentChannel={RCS}
|
|
4082
|
+
orgUnitId={orgUnitId}
|
|
4083
|
+
rcsTestPreviewOptions={{ isLibraryMode: !isFullMode }}
|
|
4084
|
+
smsFallbackContent={
|
|
4085
|
+
smsFallbackData && (smsFallbackData.templateContent || smsFallbackData.content)
|
|
4086
|
+
? {
|
|
4087
|
+
templateContent:
|
|
4088
|
+
smsFallbackData.templateContent || smsFallbackData.content || '',
|
|
4089
|
+
templateName: smsFallbackData.templateName || '',
|
|
4090
|
+
[RCS_SMS_FALLBACK_VAR_MAPPED_PROP]: !isFullMode
|
|
4091
|
+
? mergeRcsSmsFallbackVarMapLayers(
|
|
4092
|
+
getLibrarySmsFallbackApiBaselineFromTemplateData(templateData),
|
|
4093
|
+
smsFallbackData,
|
|
4094
|
+
)
|
|
4095
|
+
: mergeRcsSmsFallbackVarMapLayers({}, smsFallbackData),
|
|
4096
|
+
}
|
|
4097
|
+
: null
|
|
4098
|
+
}
|
|
4099
|
+
smsRegister={smsRegister}
|
|
2461
4100
|
/>
|
|
2462
4101
|
</>
|
|
2463
4102
|
);
|
|
2464
4103
|
};
|
|
2465
4104
|
|
|
4105
|
+
|
|
2466
4106
|
const mapStateToProps = createStructuredSelector({
|
|
2467
4107
|
rcsData: makeSelectRcs(),
|
|
2468
4108
|
accountData: makeSelectAccount(),
|
|
2469
4109
|
metaEntities: makeSelectMetaEntities(),
|
|
2470
4110
|
loadingTags: isLoadingMetaEntities(),
|
|
2471
4111
|
injectedTags: setInjectedTags(),
|
|
4112
|
+
currentOrgDetails: selectCurrentOrgDetails(),
|
|
2472
4113
|
});
|
|
2473
4114
|
|
|
2474
4115
|
const mapDispatchToProps = (dispatch) => ({
|