@capillarytech/creatives-library 8.0.345-alpha.14 → 8.0.345-alpha.15
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/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/RcsPreviewContent.js.rej +18 -0
- 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 +49 -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 +300 -103
- 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 -11
- package/v2Containers/Email/sagas.js +5 -9
- package/v2Containers/Email/tests/__snapshots__/reducer.test.js.snap +0 -4
- package/v2Containers/Email/tests/sagas.test.js +3 -21
- package/v2Containers/Rcs/constants.js +119 -8
- package/v2Containers/Rcs/index.js +2379 -807
- package/v2Containers/Rcs/index.js.rej +1336 -0
- package/v2Containers/Rcs/index.scss +276 -6
- package/v2Containers/Rcs/index.scss.rej +74 -0
- package/v2Containers/Rcs/messages.js +38 -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/__snapshots__/utils.test.js.snap.rej +128 -0
- 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
|
@@ -33,6 +33,10 @@ import injectReducer from '../../../utils/injectReducer';
|
|
|
33
33
|
import v2SmsCreateReducer from './reducer';
|
|
34
34
|
import * as globalActions from '../../Cap/actions';
|
|
35
35
|
import TestAndPreviewSlidebox from '../../../v2Components/TestAndPreviewSlidebox';
|
|
36
|
+
import {
|
|
37
|
+
getSmsEmbeddedFooterValidity,
|
|
38
|
+
getSmsMessageFromFormData,
|
|
39
|
+
} from '../smsFormDataHelpers';
|
|
36
40
|
|
|
37
41
|
export class Create extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
38
42
|
constructor(props) {
|
|
@@ -53,6 +57,11 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
53
57
|
isTestAndPreviewMode: false,
|
|
54
58
|
pendingGetFormData: false,
|
|
55
59
|
};
|
|
60
|
+
// Tracks the last validity value reported to SmsFallback so componentDidUpdate
|
|
61
|
+
// does not dispatch on every render and create an infinite update loop.
|
|
62
|
+
// Intentionally undefined (not true) so the first render always reports the
|
|
63
|
+
// real validity rather than assuming the form starts invalid.
|
|
64
|
+
this._lastReportedSmsFooterInvalid = undefined;
|
|
56
65
|
this.saveFormData = this.saveFormData.bind(this);
|
|
57
66
|
this.onFormDataChange = this.onFormDataChange.bind(this);
|
|
58
67
|
this.onTemplateNameChange = this.onTemplateNameChange.bind(this);
|
|
@@ -159,7 +168,9 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
159
168
|
layout: 'SMS',
|
|
160
169
|
type: 'TAG',
|
|
161
170
|
context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
|
|
162
|
-
embedded: this.props.
|
|
171
|
+
embedded: this.props.forceFullTagContext
|
|
172
|
+
? 'full'
|
|
173
|
+
: (this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full'),
|
|
163
174
|
};
|
|
164
175
|
if (this.props.getDefaultTags) {
|
|
165
176
|
query.context = this.props.getDefaultTags;
|
|
@@ -172,6 +183,22 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
172
183
|
}
|
|
173
184
|
}
|
|
174
185
|
|
|
186
|
+
componentDidUpdate() {
|
|
187
|
+
if (!this.props.embeddedSmsFallback || typeof this.props.onEmbeddedSmsFooterValidity !== 'function') {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const validity = getSmsEmbeddedFooterValidity(this.state.formData, this.state.tabCount);
|
|
191
|
+
const isInvalid = !!validity.isTemplateNameEmpty || !!validity.isMessageEmpty;
|
|
192
|
+
// Only dispatch when the validity value changes. Dispatching unconditionally caused
|
|
193
|
+
// an infinite loop: componentDidUpdate → dispatch → SmsFallback re-render →
|
|
194
|
+
// SmsCreate re-render → componentDidUpdate → ... even when state was unchanged.
|
|
195
|
+
// The instance variable handles both reference-based and mutation-based FormBuilder
|
|
196
|
+
// updates: validity is recomputed from current formData content, not by reference.
|
|
197
|
+
if (this._lastReportedSmsFooterInvalid === isInvalid) return;
|
|
198
|
+
this._lastReportedSmsFooterInvalid = isInvalid;
|
|
199
|
+
this.props.onEmbeddedSmsFooterValidity(validity);
|
|
200
|
+
}
|
|
201
|
+
|
|
175
202
|
componentWillUnmount() {
|
|
176
203
|
if (this.pendingGetFormDataTimeout) {
|
|
177
204
|
clearTimeout(this.pendingGetFormDataTimeout);
|
|
@@ -275,6 +302,10 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
275
302
|
}
|
|
276
303
|
const result = {};
|
|
277
304
|
result.base = baseData;
|
|
305
|
+
/* Root field used by FormBuilder; embedded getFormSubscriptionData reads value.base */
|
|
306
|
+
if (formData['template-name'] !== undefined) {
|
|
307
|
+
result.base['template-name'] = formData['template-name'];
|
|
308
|
+
}
|
|
278
309
|
if (this.state.isValid) {
|
|
279
310
|
const msgObj = charCount.updateCharCount(baseData['sms-editor']);
|
|
280
311
|
result.base.msg_count = msgObj.msgCount;
|
|
@@ -881,7 +912,9 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
881
912
|
layout: 'SMS',
|
|
882
913
|
type: 'TAG',
|
|
883
914
|
context: (data && data.toLowerCase() === 'all') ? 'default' : (data && data.toLowerCase()),
|
|
884
|
-
embedded: this.props.
|
|
915
|
+
embedded: this.props.forceFullTagContext
|
|
916
|
+
? 'full'
|
|
917
|
+
: (this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full'),
|
|
885
918
|
};
|
|
886
919
|
this.props.globalActions.fetchSchemaForEntity(query);
|
|
887
920
|
}
|
|
@@ -889,11 +922,29 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
889
922
|
removeStandAlone() {
|
|
890
923
|
const schema = _.cloneDeep(this.state.schema);
|
|
891
924
|
const childSections = _.get(schema, 'standalone.sections[0].childSections');
|
|
892
|
-
childSections
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
925
|
+
if (childSections) {
|
|
926
|
+
/* In-form Save / Test row (index 2) only exists when the schema has > 2 sections. */
|
|
927
|
+
if (childSections.length > 2) {
|
|
928
|
+
childSections.splice(2, 1);
|
|
929
|
+
}
|
|
930
|
+
/*
|
|
931
|
+
* Creatives library drops the standalone template-name block because `SlideBoxHeader`
|
|
932
|
+
* shows the name. This is independent of the section count — guard it separately so
|
|
933
|
+
* it still runs even when childSections.length <= 2 (e.g. schema arrives pre-trimmed).
|
|
934
|
+
* RCS SMS fallback uses the same slidebox footer but keeps the name in the form.
|
|
935
|
+
*/
|
|
936
|
+
if (!this.props.embeddedSmsFallback) {
|
|
937
|
+
const fields = _.get(childSections, '[1].childSections[0].childSections');
|
|
938
|
+
if (fields && fields.length > 0) {
|
|
939
|
+
fields.splice(0, 1);
|
|
940
|
+
_.set(childSections, '[1].childSections[0].childSections', fields);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
_.set(schema, 'standalone.sections[0].childSections', childSections);
|
|
944
|
+
}
|
|
945
|
+
// Always increment loadingStatus — isSmsLoading() requires >= 2 in library mode
|
|
946
|
+
// (isFullMode=false). The early return previously skipped this, leaving the
|
|
947
|
+
// spinner stuck forever when the schema had <= 2 childSections.
|
|
897
948
|
this.setState({ schema, loadingStatus: this.state.loadingStatus + 1 });
|
|
898
949
|
}
|
|
899
950
|
|
|
@@ -938,37 +989,8 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
938
989
|
this.setState({startValidation: false});
|
|
939
990
|
}
|
|
940
991
|
|
|
941
|
-
getTemplateContent = () =>
|
|
942
|
-
|
|
943
|
-
if (!this.state.formData || !Array.isArray(this.state.formData) || this.state.formData.length === 0) {
|
|
944
|
-
return '';
|
|
945
|
-
}
|
|
946
|
-
const currentTabData = this.state.formData[this.state.currentTab - 1];
|
|
947
|
-
if (!currentTabData) {
|
|
948
|
-
return '';
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
// PRIORITY 1: Check direct path first (most common for SMS)
|
|
952
|
-
// This handles: formData[0]['sms-editor']
|
|
953
|
-
if (currentTabData['sms-editor']) {
|
|
954
|
-
return currentTabData['sms-editor'];
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
// PRIORITY 2: Check activeTab structure (for versioned templates)
|
|
958
|
-
// This handles: formData[0][activeTab]['sms-editor']
|
|
959
|
-
const activeTab = currentTabData?.activeTab || 'base';
|
|
960
|
-
if (currentTabData[activeTab]?.['sms-editor']) {
|
|
961
|
-
return currentTabData[activeTab]['sms-editor'];
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
// PRIORITY 3: Check base explicitly (fallback)
|
|
965
|
-
// This handles: formData[0]['base']['sms-editor']
|
|
966
|
-
if (currentTabData['base']?.['sms-editor']) {
|
|
967
|
-
return currentTabData['base']['sms-editor'];
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
return '';
|
|
971
|
-
}
|
|
992
|
+
getTemplateContent = () =>
|
|
993
|
+
getSmsMessageFromFormData(this.state.formData, this.state.currentTab);
|
|
972
994
|
|
|
973
995
|
handleTestAndPreview = () => {
|
|
974
996
|
// If parent is managing state (props exist), call parent handler
|
|
@@ -997,6 +1019,35 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
997
1019
|
}
|
|
998
1020
|
|
|
999
1021
|
saveFormData() {
|
|
1022
|
+
/*
|
|
1023
|
+
* RCS SMS fallback slidebox (embeddedSmsFallback): parent passes isFullMode from RCS, but we must not
|
|
1024
|
+
* call createTemplate — that spins CapSpin on createTemplateInProgress and is not the embedded contract.
|
|
1025
|
+
* Same as library: hand off form payload via getFormSubscriptionData.
|
|
1026
|
+
*/
|
|
1027
|
+
if (this.props.embeddedSmsFallback && this.props.getFormSubscriptionData) {
|
|
1028
|
+
const { isTemplateNameEmpty, isMessageEmpty } = getSmsEmbeddedFooterValidity(
|
|
1029
|
+
this.state.formData,
|
|
1030
|
+
this.state.tabCount,
|
|
1031
|
+
);
|
|
1032
|
+
if (isTemplateNameEmpty || isMessageEmpty) {
|
|
1033
|
+
this.setState({ startValidation: true, pendingGetFormData: false });
|
|
1034
|
+
if (this.props.onValidationFail) {
|
|
1035
|
+
this.props.onValidationFail();
|
|
1036
|
+
}
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
const payload = this.getFormData();
|
|
1040
|
+
if (!payload.validity) {
|
|
1041
|
+
if (this.props.onValidationFail) {
|
|
1042
|
+
this.props.onValidationFail();
|
|
1043
|
+
}
|
|
1044
|
+
this.setState({ pendingGetFormData: false, startValidation: false });
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
this.props.getFormSubscriptionData(payload);
|
|
1048
|
+
this.setState({ pendingGetFormData: false, startValidation: false });
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1000
1051
|
// In library mode: FormBuilder calls onSubmit only after liquid validation succeeds.
|
|
1001
1052
|
// Submit to parent here so the slidebox can close with valid data.
|
|
1002
1053
|
if (!this.props.isFullMode) {
|
|
@@ -1096,7 +1147,9 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
1096
1147
|
onTestContentClicked={this.props.onTestContentClicked}
|
|
1097
1148
|
onPreviewContentClicked={this.props.onPreviewContentClicked}
|
|
1098
1149
|
eventContextTags={this.props?.eventContextTags}
|
|
1099
|
-
|
|
1150
|
+
tagListGetPopupContainer={this.props.tagListGetPopupContainer}
|
|
1151
|
+
tagListPopoverOverlayStyle={this.props.tagListPopoverOverlayStyle}
|
|
1152
|
+
tagListPopoverOverlayClassName={this.props.tagListPopoverOverlayClassName}
|
|
1100
1153
|
/>
|
|
1101
1154
|
</CapColumn>
|
|
1102
1155
|
</CapRow>
|
|
@@ -1109,6 +1162,7 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
|
|
|
1109
1162
|
formData={this.state.formData}
|
|
1110
1163
|
content={this.getTemplateContent()}
|
|
1111
1164
|
currentChannel={SMS}
|
|
1165
|
+
smsRegister={this.props.smsRegister}
|
|
1112
1166
|
/>
|
|
1113
1167
|
</div>
|
|
1114
1168
|
);
|
|
@@ -1133,11 +1187,17 @@ Create.propTypes = {
|
|
|
1133
1187
|
isLoadingMetaEntities: PropTypes.bool,
|
|
1134
1188
|
selectedOfferDetails: PropTypes.array,
|
|
1135
1189
|
eventContextTags: PropTypes.array,
|
|
1136
|
-
waitEventContextTags: PropTypes.object,
|
|
1137
1190
|
showTestAndPreviewSlidebox: PropTypes.bool,
|
|
1138
1191
|
handleTestAndPreview: PropTypes.func,
|
|
1139
1192
|
handleCloseTestAndPreview: PropTypes.func,
|
|
1140
1193
|
isTestAndPreviewMode: PropTypes.bool,
|
|
1194
|
+
smsRegister: PropTypes.any,
|
|
1195
|
+
forceFullTagContext: PropTypes.bool,
|
|
1196
|
+
embeddedSmsFallback: PropTypes.bool,
|
|
1197
|
+
onEmbeddedSmsFooterValidity: PropTypes.func,
|
|
1198
|
+
tagListGetPopupContainer: PropTypes.func,
|
|
1199
|
+
tagListPopoverOverlayStyle: PropTypes.object,
|
|
1200
|
+
tagListPopoverOverlayClassName: PropTypes.string,
|
|
1141
1201
|
};
|
|
1142
1202
|
|
|
1143
1203
|
const mapStateToProps = createStructuredSelector({
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared SMS FormBuilder formData helpers for Sms/Create (and any embedded host).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {object} formData FormBuilder state (same shape as Sms/Create `this.state.formData`)
|
|
7
|
+
* @param {number} currentTab 1-based tab index
|
|
8
|
+
* @returns {string} Raw message body or ''
|
|
9
|
+
*/
|
|
10
|
+
export function getSmsMessageFromFormData(formData, currentTab) {
|
|
11
|
+
if (formData == null || typeof formData !== 'object') {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
const tab = currentTab != null && currentTab > 0 ? currentTab : 1;
|
|
15
|
+
const currentTabData = formData[tab - 1];
|
|
16
|
+
if (currentTabData && typeof currentTabData === 'object') {
|
|
17
|
+
const versionedKey = tab > 1 ? `sms-editor${tab}` : 'sms-editor';
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(currentTabData, versionedKey)) {
|
|
19
|
+
const v = currentTabData[versionedKey];
|
|
20
|
+
// Key exists — commit to this version's value rather than falling through to base.
|
|
21
|
+
// Treat null/undefined as empty so a cleared version correctly reports as empty.
|
|
22
|
+
return (v != null && v !== '') ? String(v) : '';
|
|
23
|
+
}
|
|
24
|
+
if (currentTabData['sms-editor'] != null) {
|
|
25
|
+
return String(currentTabData['sms-editor']);
|
|
26
|
+
}
|
|
27
|
+
const activeTab = currentTabData.activeTab || 'base';
|
|
28
|
+
if (currentTabData[activeTab]?.['sms-editor'] != null) {
|
|
29
|
+
return String(currentTabData[activeTab]['sms-editor']);
|
|
30
|
+
}
|
|
31
|
+
if (currentTabData.base?.['sms-editor'] != null) {
|
|
32
|
+
return String(currentTabData.base['sms-editor']);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const rootBase = formData.base;
|
|
36
|
+
if (rootBase && typeof rootBase === 'object' && rootBase['sms-editor'] != null) {
|
|
37
|
+
return String(rootBase['sms-editor']);
|
|
38
|
+
}
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {number} [tabCount] Total number of versions/tabs. When >1 all versions are checked.
|
|
44
|
+
* @returns {{ isTemplateNameEmpty: boolean, isMessageEmpty: boolean }}
|
|
45
|
+
*/
|
|
46
|
+
export function getSmsEmbeddedFooterValidity(formData, tabCount) {
|
|
47
|
+
const rawName = formData?.['template-name'];
|
|
48
|
+
const name = rawName != null && rawName !== '' ? String(rawName).trim() : '';
|
|
49
|
+
|
|
50
|
+
// Check ALL versions: if any version's message is empty, Done should be disabled.
|
|
51
|
+
// With a single version this is equivalent to the previous single-tab check.
|
|
52
|
+
const count = tabCount != null && tabCount > 1 ? tabCount : 1;
|
|
53
|
+
let isMessageEmpty = false;
|
|
54
|
+
for (let i = 1; i <= count; i++) {
|
|
55
|
+
const content = getSmsMessageFromFormData(formData, i);
|
|
56
|
+
const msg = content != null && content !== '' ? String(content).trim() : '';
|
|
57
|
+
if (!msg) {
|
|
58
|
+
isMessageEmpty = true;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
isTemplateNameEmpty: !name,
|
|
65
|
+
isMessageEmpty,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSmsMessageFromFormData,
|
|
3
|
+
getSmsEmbeddedFooterValidity,
|
|
4
|
+
} from '../smsFormDataHelpers';
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// getSmsMessageFromFormData
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
describe('getSmsMessageFromFormData', () => {
|
|
11
|
+
describe('null / invalid formData guard', () => {
|
|
12
|
+
it('returns empty string when formData is null', () => {
|
|
13
|
+
expect(getSmsMessageFromFormData(null, 1)).toBe('');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('returns empty string when formData is undefined', () => {
|
|
17
|
+
expect(getSmsMessageFromFormData(undefined, 1)).toBe('');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('returns empty string when formData is a string (not an object)', () => {
|
|
21
|
+
expect(getSmsMessageFromFormData('bad', 1)).toBe('');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('returns empty string when formData is a number', () => {
|
|
25
|
+
expect(getSmsMessageFromFormData(42, 1)).toBe('');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('currentTab normalisation', () => {
|
|
30
|
+
it('defaults to tab 1 when currentTab is null', () => {
|
|
31
|
+
const formData = { 0: { 'sms-editor': 'hello' } };
|
|
32
|
+
expect(getSmsMessageFromFormData(formData, null)).toBe('hello');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('defaults to tab 1 when currentTab is undefined', () => {
|
|
36
|
+
const formData = { 0: { 'sms-editor': 'hello' } };
|
|
37
|
+
expect(getSmsMessageFromFormData(formData, undefined)).toBe('hello');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('defaults to tab 1 when currentTab is 0', () => {
|
|
41
|
+
const formData = { 0: { 'sms-editor': 'hello' } };
|
|
42
|
+
expect(getSmsMessageFromFormData(formData, 0)).toBe('hello');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('defaults to tab 1 when currentTab is negative', () => {
|
|
46
|
+
const formData = { 0: { 'sms-editor': 'hello' } };
|
|
47
|
+
expect(getSmsMessageFromFormData(formData, -5)).toBe('hello');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('versioned key lookup', () => {
|
|
52
|
+
it('uses "sms-editor" key for tab 1', () => {
|
|
53
|
+
const formData = { 0: { 'sms-editor': 'tab1 msg' } };
|
|
54
|
+
expect(getSmsMessageFromFormData(formData, 1)).toBe('tab1 msg');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('uses "sms-editor2" versioned key for tab 2', () => {
|
|
58
|
+
const formData = { 1: { 'sms-editor2': 'tab2 msg', 'sms-editor': 'fallback' } };
|
|
59
|
+
expect(getSmsMessageFromFormData(formData, 2)).toBe('tab2 msg');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('uses "sms-editor3" versioned key for tab 3', () => {
|
|
63
|
+
const formData = { 2: { 'sms-editor3': 'tab3 msg' } };
|
|
64
|
+
expect(getSmsMessageFromFormData(formData, 3)).toBe('tab3 msg');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('returns empty string when versioned key exists but is null (cleared version)', () => {
|
|
68
|
+
const formData = { 1: { 'sms-editor2': null } };
|
|
69
|
+
expect(getSmsMessageFromFormData(formData, 2)).toBe('');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('returns empty string when versioned key exists but is empty string', () => {
|
|
73
|
+
const formData = { 1: { 'sms-editor2': '' } };
|
|
74
|
+
expect(getSmsMessageFromFormData(formData, 2)).toBe('');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('coerces a numeric value in versioned key to string', () => {
|
|
78
|
+
const formData = { 1: { 'sms-editor2': 12345 } };
|
|
79
|
+
expect(getSmsMessageFromFormData(formData, 2)).toBe('12345');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('"sms-editor" flat key fallback (versioned key absent)', () => {
|
|
84
|
+
it('falls back to "sms-editor" when versioned key is absent for tab 2', () => {
|
|
85
|
+
const formData = { 1: { 'sms-editor': 'flat fallback' } };
|
|
86
|
+
expect(getSmsMessageFromFormData(formData, 2)).toBe('flat fallback');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('activeTab nested fallback', () => {
|
|
91
|
+
it('falls back to activeTab["sms-editor"] when neither versioned key nor flat "sms-editor" is present', () => {
|
|
92
|
+
// The versioned key must be absent entirely for the activeTab fallback to be reached.
|
|
93
|
+
// (If 'sms-editor' exists but is null, the function commits to '' without falling through.)
|
|
94
|
+
const formData = {
|
|
95
|
+
0: {
|
|
96
|
+
activeTab: 'variant1',
|
|
97
|
+
variant1: { 'sms-editor': 'variant msg' },
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
expect(getSmsMessageFromFormData(formData, 1)).toBe('variant msg');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('falls back to base["sms-editor"] when activeTab entry lacks "sms-editor" and flat key is absent', () => {
|
|
104
|
+
const formData = {
|
|
105
|
+
0: {
|
|
106
|
+
activeTab: 'variant1',
|
|
107
|
+
variant1: {},
|
|
108
|
+
base: { 'sms-editor': 'base msg' },
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
expect(getSmsMessageFromFormData(formData, 1)).toBe('base msg');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('defaults activeTab to "base" when activeTab prop is not set and flat key is absent', () => {
|
|
115
|
+
const formData = {
|
|
116
|
+
0: {
|
|
117
|
+
base: { 'sms-editor': 'default base msg' },
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
expect(getSmsMessageFromFormData(formData, 1)).toBe('default base msg');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('root formData.base fallback', () => {
|
|
125
|
+
it('falls back to formData.base["sms-editor"] when tab slot is missing', () => {
|
|
126
|
+
const formData = {
|
|
127
|
+
base: { 'sms-editor': 'root base msg' },
|
|
128
|
+
};
|
|
129
|
+
expect(getSmsMessageFromFormData(formData, 1)).toBe('root base msg');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('returns empty string when even root base has no "sms-editor"', () => {
|
|
133
|
+
const formData = { base: {} };
|
|
134
|
+
expect(getSmsMessageFromFormData(formData, 1)).toBe('');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('returns empty string when formData has no relevant keys at all', () => {
|
|
138
|
+
expect(getSmsMessageFromFormData({}, 1)).toBe('');
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// getSmsEmbeddedFooterValidity
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
describe('getSmsEmbeddedFooterValidity', () => {
|
|
148
|
+
describe('isTemplateNameEmpty', () => {
|
|
149
|
+
it('is true when template-name is absent', () => {
|
|
150
|
+
const formData = { 0: { 'sms-editor': 'msg' } };
|
|
151
|
+
const { isTemplateNameEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
|
|
152
|
+
expect(isTemplateNameEmpty).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('is true when template-name is empty string', () => {
|
|
156
|
+
const formData = { 'template-name': '', 0: { 'sms-editor': 'msg' } };
|
|
157
|
+
const { isTemplateNameEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
|
|
158
|
+
expect(isTemplateNameEmpty).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('is true when template-name is whitespace only', () => {
|
|
162
|
+
const formData = { 'template-name': ' ', 0: { 'sms-editor': 'msg' } };
|
|
163
|
+
const { isTemplateNameEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
|
|
164
|
+
expect(isTemplateNameEmpty).toBe(true);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('is false when template-name is a non-empty string', () => {
|
|
168
|
+
const formData = { 'template-name': 'My Template', 0: { 'sms-editor': 'msg' } };
|
|
169
|
+
const { isTemplateNameEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
|
|
170
|
+
expect(isTemplateNameEmpty).toBe(false);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('isMessageEmpty — single tab', () => {
|
|
175
|
+
it('is true when message is empty string', () => {
|
|
176
|
+
const formData = { 'template-name': 'T', 0: { 'sms-editor': '' } };
|
|
177
|
+
const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
|
|
178
|
+
expect(isMessageEmpty).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('is true when message is whitespace only', () => {
|
|
182
|
+
const formData = { 'template-name': 'T', 0: { 'sms-editor': ' ' } };
|
|
183
|
+
const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
|
|
184
|
+
expect(isMessageEmpty).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('is true when no sms-editor key at all', () => {
|
|
188
|
+
const formData = { 'template-name': 'T', 0: {} };
|
|
189
|
+
const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
|
|
190
|
+
expect(isMessageEmpty).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('is false when message is non-empty', () => {
|
|
194
|
+
const formData = { 'template-name': 'T', 0: { 'sms-editor': 'Hello world' } };
|
|
195
|
+
const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 1);
|
|
196
|
+
expect(isMessageEmpty).toBe(false);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('isMessageEmpty — multiple tabs', () => {
|
|
201
|
+
it('is false when all tabs have non-empty messages', () => {
|
|
202
|
+
const formData = {
|
|
203
|
+
'template-name': 'T',
|
|
204
|
+
0: { 'sms-editor': 'Tab 1 message' },
|
|
205
|
+
1: { 'sms-editor2': 'Tab 2 message' },
|
|
206
|
+
2: { 'sms-editor3': 'Tab 3 message' },
|
|
207
|
+
};
|
|
208
|
+
const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 3);
|
|
209
|
+
expect(isMessageEmpty).toBe(false);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('is true when the second tab has an empty message', () => {
|
|
213
|
+
const formData = {
|
|
214
|
+
'template-name': 'T',
|
|
215
|
+
0: { 'sms-editor': 'Tab 1 message' },
|
|
216
|
+
1: { 'sms-editor2': '' },
|
|
217
|
+
};
|
|
218
|
+
const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 2);
|
|
219
|
+
expect(isMessageEmpty).toBe(true);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('is true when the third tab has no message', () => {
|
|
223
|
+
const formData = {
|
|
224
|
+
'template-name': 'T',
|
|
225
|
+
0: { 'sms-editor': 'msg1' },
|
|
226
|
+
1: { 'sms-editor2': 'msg2' },
|
|
227
|
+
2: {},
|
|
228
|
+
};
|
|
229
|
+
const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData, 3);
|
|
230
|
+
expect(isMessageEmpty).toBe(true);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('treats tabCount=1 as single-tab check even when not explicitly provided', () => {
|
|
234
|
+
const formData = { 'template-name': 'T', 0: { 'sms-editor': 'msg' } };
|
|
235
|
+
const { isMessageEmpty } = getSmsEmbeddedFooterValidity(formData);
|
|
236
|
+
expect(isMessageEmpty).toBe(false);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe('both fields together', () => {
|
|
241
|
+
it('returns both empty when template name absent and message empty', () => {
|
|
242
|
+
const formData = { 0: { 'sms-editor': '' } };
|
|
243
|
+
const result = getSmsEmbeddedFooterValidity(formData, 1);
|
|
244
|
+
expect(result).toEqual({ isTemplateNameEmpty: true, isMessageEmpty: true });
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('returns both non-empty when template name and message are present', () => {
|
|
248
|
+
const formData = { 'template-name': 'My Template', 0: { 'sms-editor': 'Hello!' } };
|
|
249
|
+
const result = getSmsEmbeddedFooterValidity(formData, 1);
|
|
250
|
+
expect(result).toEqual({ isTemplateNameEmpty: false, isMessageEmpty: false });
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -70,6 +70,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
70
70
|
onCreateComplete,
|
|
71
71
|
isFullMode,
|
|
72
72
|
onShowTemplates,
|
|
73
|
+
embeddedSmsFallback,
|
|
73
74
|
traiSms: {
|
|
74
75
|
duplicateDetails = {},
|
|
75
76
|
duplicateDetailsError = '',
|
|
@@ -659,9 +660,11 @@ export const SmsTraiCreate = (props) => {
|
|
|
659
660
|
|
|
660
661
|
const createCallback = ({ errorMessage }) => {
|
|
661
662
|
if (!errorMessage) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
663
|
+
if (!embeddedSmsFallback) {
|
|
664
|
+
CapNotification.success({
|
|
665
|
+
message: formatMessage(messages.smsCreateNotification),
|
|
666
|
+
});
|
|
667
|
+
}
|
|
665
668
|
actions.clearCreateResponse();
|
|
666
669
|
} else {
|
|
667
670
|
CapNotification.error({
|
|
@@ -741,7 +744,9 @@ export const SmsTraiCreate = (props) => {
|
|
|
741
744
|
{ templates: savedData },
|
|
742
745
|
(resp, errorMessage) => {
|
|
743
746
|
createCallback({ errorMessage });
|
|
744
|
-
if (
|
|
747
|
+
if (embeddedSmsFallback) {
|
|
748
|
+
if (!errorMessage) onCreateComplete(savedData[0]);
|
|
749
|
+
} else if (isFullMode) {
|
|
745
750
|
onCreateComplete();
|
|
746
751
|
} else {
|
|
747
752
|
onShowTemplates();
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
export const CHARLIMIT = 40;
|
|
8
|
+
/** Display / soft cap label for DLT SMS body length (matches product UI). */
|
|
9
|
+
export const SMS_TRAI_CONTENT_MAX_LENGTH = 1024;
|
|
8
10
|
export const SMS = 'SMS';
|
|
9
11
|
export const SMS_TRAI_VAR = '{#var#}';
|
|
10
12
|
export const TAG = 'TAG';
|