@capillarytech/creatives-library 8.0.311 → 8.0.312-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2643,7 +2643,7 @@ const MobilePushNew = ({
|
|
|
2643
2643
|
const onSuccess = () => handleSave();
|
|
2644
2644
|
|
|
2645
2645
|
// When liquid is enabled and isFullMode is true, skip liquid validation and proceed directly
|
|
2646
|
-
if (
|
|
2646
|
+
if (isFullMode) {
|
|
2647
2647
|
onSuccess();
|
|
2648
2648
|
return;
|
|
2649
2649
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-syntax */
|
|
2
2
|
/* eslint-disable no-undef */
|
|
3
|
-
import React, { useState, useEffect } from 'react';
|
|
3
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
4
4
|
import { createStructuredSelector } from 'reselect';
|
|
5
5
|
import { bindActionCreators } from 'redux';
|
|
6
6
|
import { FormattedMessage } from 'react-intl';
|
|
@@ -82,6 +82,7 @@ export const SmsTraiEdit = (props) => {
|
|
|
82
82
|
eventContextTags,
|
|
83
83
|
fetchingLiquidTags,
|
|
84
84
|
getLiquidTags,
|
|
85
|
+
showLiquidErrorInFooter,
|
|
85
86
|
} = props || {};
|
|
86
87
|
|
|
87
88
|
const { formatMessage } = intl;
|
|
@@ -96,7 +97,15 @@ export const SmsTraiEdit = (props) => {
|
|
|
96
97
|
const [showMsgLengthNote, updateshowMsgLengthNote] = useState(false);
|
|
97
98
|
const [liquidErrorMessages, setLiquidErrorMessages] = useState({});
|
|
98
99
|
const [isLiquidValidationError, setIsLiquidValidationError] = useState(false);
|
|
100
|
+
/** After user closes the validation panel, keep it hidden until Save is clicked again (even if ErrorInfoNote remounts). */
|
|
101
|
+
const [liquidErrorPanelDismissed, setLiquidErrorPanelDismissed] = useState(false);
|
|
99
102
|
const [showTestAndPreviewSlidebox, setShowTestAndPreviewSlidebox] = useState(false);
|
|
103
|
+
const routeTemplateId = (params && params.id) || '';
|
|
104
|
+
const traitSource = isFullMode ? templateDetails : templateData;
|
|
105
|
+
const smsEditorSource = get(traitSource, 'versions.base.sms-editor', '') || '';
|
|
106
|
+
const baseTemplateId = get(traitSource, 'versions.base.template_id', '') || '';
|
|
107
|
+
/** Avoid reparsing props into tempMsgArray when only object identity changes (fixes cleared text snapping back). */
|
|
108
|
+
const lastHydratedSignatureRef = useRef(null);
|
|
100
109
|
const SMSTraiFooter = styled.div`
|
|
101
110
|
background-color: ${CAP_WHITE};
|
|
102
111
|
padding: ${CAP_SPACE_32} ${CAP_SPACE_24};
|
|
@@ -144,29 +153,43 @@ export const SmsTraiEdit = (props) => {
|
|
|
144
153
|
//computing placeholder array for mapping values and rendering dynamic form
|
|
145
154
|
useEffect(() => {
|
|
146
155
|
traiData = isFullMode ? templateDetails : templateData;
|
|
147
|
-
if (traiData
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
if (!traiData || isEmpty(traiData)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const hydrateSignature = `${String(isFullMode)}|${routeTemplateId}|${baseTemplateId}|${smsEditorSource}`;
|
|
160
|
+
if (lastHydratedSignatureRef.current === hydrateSignature) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
lastHydratedSignatureRef.current = hydrateSignature;
|
|
164
|
+
|
|
165
|
+
let msg = smsEditorSource;
|
|
166
|
+
const templateMessageArray = [];
|
|
167
|
+
//converting sms-editor string to an array split at '{#var#}'
|
|
168
|
+
//split and push string before '{#var#}[0 to index]', push '{#var#}',
|
|
169
|
+
//split and repeat for remaining string[index+7 to length]
|
|
170
|
+
while (msg.length !== 0) {
|
|
171
|
+
const index = msg.search(SMS_TRAI_VAR);
|
|
172
|
+
if (index !== -1) {
|
|
173
|
+
templateMessageArray.push(msg.substring(0, index));
|
|
174
|
+
templateMessageArray.push(SMS_TRAI_VAR);
|
|
175
|
+
msg = msg.substring(index + 7, msg.length);
|
|
176
|
+
} else {
|
|
177
|
+
templateMessageArray.push(msg);
|
|
178
|
+
break;
|
|
163
179
|
}
|
|
164
|
-
const filteredTemplateMessageArray = templateMessageArray.filter((i) => i === 0 || i);
|
|
165
|
-
updateTempMsgArray(filteredTemplateMessageArray);
|
|
166
|
-
//stop spinner
|
|
167
|
-
updateLoading(false);
|
|
168
180
|
}
|
|
169
|
-
|
|
181
|
+
const filteredTemplateMessageArray = templateMessageArray.filter((i) => i === 0 || i);
|
|
182
|
+
updateTempMsgArray(filteredTemplateMessageArray);
|
|
183
|
+
//stop spinner
|
|
184
|
+
updateLoading(false);
|
|
185
|
+
}, [
|
|
186
|
+
isFullMode,
|
|
187
|
+
routeTemplateId,
|
|
188
|
+
baseTemplateId,
|
|
189
|
+
smsEditorSource,
|
|
190
|
+
templateDetails,
|
|
191
|
+
templateData,
|
|
192
|
+
]);
|
|
170
193
|
|
|
171
194
|
//compute/get varMapped and updated-sms-editor
|
|
172
195
|
useEffect(() => {
|
|
@@ -263,6 +286,7 @@ export const SmsTraiEdit = (props) => {
|
|
|
263
286
|
const onSubmitWrapper = () => {
|
|
264
287
|
setIsLiquidValidationError(false);
|
|
265
288
|
setLiquidErrorMessages({});
|
|
289
|
+
setLiquidErrorPanelDismissed(false);
|
|
266
290
|
// Liquid validation (extractTags) only in library mode
|
|
267
291
|
if (isFullMode) {
|
|
268
292
|
onDoneCallback();
|
|
@@ -658,8 +682,20 @@ export const SmsTraiEdit = (props) => {
|
|
|
658
682
|
</CapColumn>
|
|
659
683
|
</CapRow>
|
|
660
684
|
<SMSTraiFooter>
|
|
661
|
-
{isLiquidValidationError && (
|
|
662
|
-
<ErrorInfoNote
|
|
685
|
+
{isLiquidValidationError && !liquidErrorPanelDismissed && (
|
|
686
|
+
<ErrorInfoNote
|
|
687
|
+
errorMessages={liquidErrorMessages}
|
|
688
|
+
intl={intl}
|
|
689
|
+
onClose={() => {
|
|
690
|
+
setLiquidErrorPanelDismissed(true);
|
|
691
|
+
if (typeof showLiquidErrorInFooter === 'function') {
|
|
692
|
+
showLiquidErrorInFooter({
|
|
693
|
+
STANDARD_ERROR_MSG: [],
|
|
694
|
+
LIQUID_ERROR_MSG: [],
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}}
|
|
698
|
+
/>
|
|
663
699
|
)}
|
|
664
700
|
<CapButton
|
|
665
701
|
onClick={handleTestAndPreview}
|