@capillarytech/creatives-library 7.10.49 → 7.10.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/v2common.js +13 -0
- package/v2Components/TemplatePreview/assets/images/whatsapp_mobile_android.svg +2041 -1
- package/v2Components/TemplatePreview/index.js +27 -38
- package/v2Components/TemplatePreview/messages.js +0 -4
- package/v2Containers/CreativesContainer/SlideBoxContent.js +3 -2
- package/v2Containers/CreativesContainer/index.js +46 -7
- package/v2Containers/Templates/_templates.scss +14 -0
- package/v2Containers/Templates/index.js +74 -42
- package/v2Containers/Templates/messages.js +4 -8
- package/v2Containers/TemplatesV2/index.js +11 -4
- package/v2Containers/Whatsapp/index.js +84 -16
- package/v2Containers/Whatsapp/messages.js +9 -0
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +5932 -33286
- package/v2Containers/Whatsapp/tests/index.test.js +9 -49
- package/v2Containers/Whatsapp/tests/mockData.js +1 -120
|
@@ -51,9 +51,11 @@ import withCreatives from '../../hoc/withCreatives';
|
|
|
51
51
|
import TemplatePreview from '../../v2Components/TemplatePreview';
|
|
52
52
|
import TagList from '../TagList';
|
|
53
53
|
import { makeSelectMetaEntities, setInjectedTags } from '../Cap/selectors';
|
|
54
|
+
import { validateTags } from '../../utils/tagValidations';
|
|
54
55
|
|
|
55
56
|
let varMap = {};
|
|
56
57
|
let editContent = {};
|
|
58
|
+
let tagValidationResponse = {};
|
|
57
59
|
|
|
58
60
|
export const Whatsapp = (props) => {
|
|
59
61
|
const {
|
|
@@ -73,6 +75,7 @@ export const Whatsapp = (props) => {
|
|
|
73
75
|
metaEntities,
|
|
74
76
|
injectedTags,
|
|
75
77
|
loadingTags,
|
|
78
|
+
getFormData
|
|
76
79
|
} = props || {};
|
|
77
80
|
const { formatMessage } = intl;
|
|
78
81
|
const { TextArea } = CapInput;
|
|
@@ -91,13 +94,16 @@ export const Whatsapp = (props) => {
|
|
|
91
94
|
//for edit only
|
|
92
95
|
const [isEditFlow, setEditFlow] = useState(false);
|
|
93
96
|
const [templateDate, setTemplateDate] = useState('');
|
|
94
|
-
const [templateStatus, setTemplateStatus] = useState(
|
|
97
|
+
const [templateStatus, setTemplateStatus] = useState(
|
|
98
|
+
WHATSAPP_STATUSES.unsubmitted,
|
|
99
|
+
);
|
|
95
100
|
const [templateRejectionReason, setTemplateRejectionReason] = useState(null);
|
|
96
101
|
const [tempMsgArray, updateTempMsgArray] = useState([]);
|
|
97
102
|
const [updatedSmsEditor, setUpdatedSmsEditor] = useState([]);
|
|
98
103
|
//for tag only
|
|
99
104
|
const [tags, updateTags] = useState([]);
|
|
100
105
|
const [textAreaId, updateTextAreaId] = useState();
|
|
106
|
+
const [isTagValidationError, updateIsTagValidationError] = useState(false);
|
|
101
107
|
|
|
102
108
|
const validVarRegex = /{{([1-9]|1[0-9])}}/g;
|
|
103
109
|
|
|
@@ -108,7 +114,8 @@ export const Whatsapp = (props) => {
|
|
|
108
114
|
width: 100%;
|
|
109
115
|
margin-left: -32px;
|
|
110
116
|
padding: ${CAP_SPACE_32} ${CAP_SPACE_24};
|
|
111
|
-
|
|
117
|
+
z-index: 1;
|
|
118
|
+
|
|
112
119
|
.ant-btn {
|
|
113
120
|
margin-right: ${CAP_SPACE_16};
|
|
114
121
|
}
|
|
@@ -140,7 +147,6 @@ export const Whatsapp = (props) => {
|
|
|
140
147
|
setSpin(true);
|
|
141
148
|
actions.getTemplateDetails(id);
|
|
142
149
|
}
|
|
143
|
-
setEditFlow(true);
|
|
144
150
|
}
|
|
145
151
|
//cleanup code
|
|
146
152
|
return () => {
|
|
@@ -154,9 +160,10 @@ export const Whatsapp = (props) => {
|
|
|
154
160
|
name = '',
|
|
155
161
|
versions = {},
|
|
156
162
|
createdAt = '',
|
|
157
|
-
} = editData.templateDetails || templateData || {};
|
|
163
|
+
} = isFullMode ? editData.templateDetails || {} : templateData || {};
|
|
158
164
|
editContent = get(versions, `base.content.whatsapp`, {});
|
|
159
165
|
if (editContent && !isEmpty(editContent)) {
|
|
166
|
+
setEditFlow(true);
|
|
160
167
|
setTemplateName(name);
|
|
161
168
|
setTemplateDate(createdAt);
|
|
162
169
|
const {
|
|
@@ -260,6 +267,27 @@ export const Whatsapp = (props) => {
|
|
|
260
267
|
}
|
|
261
268
|
}, [metaEntities, isEditFlow]);
|
|
262
269
|
|
|
270
|
+
//performs tag validation
|
|
271
|
+
useEffect(() => {
|
|
272
|
+
if (
|
|
273
|
+
!isFullMode &&
|
|
274
|
+
updatedSmsEditor?.length > 0 &&
|
|
275
|
+
!updatedSmsEditor.join('').match(validVarRegex)
|
|
276
|
+
) {
|
|
277
|
+
tagValidationResponse =
|
|
278
|
+
validateTags({
|
|
279
|
+
content: updatedSmsEditor.join(''),
|
|
280
|
+
tagsParam: tags,
|
|
281
|
+
injectedTagsParams: injectedTags,
|
|
282
|
+
location,
|
|
283
|
+
tagModule: getDefaultTags,
|
|
284
|
+
}) || {};
|
|
285
|
+
updateIsTagValidationError(
|
|
286
|
+
tagValidationResponse.unsupportedTags.length > 0,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}, [updatedSmsEditor, tags]);
|
|
290
|
+
|
|
263
291
|
const handleOnTagsContextChange = (data) => {
|
|
264
292
|
const { type } = location.query || {};
|
|
265
293
|
const isEmbedded = type === EMBEDDED;
|
|
@@ -467,13 +495,16 @@ export const Whatsapp = (props) => {
|
|
|
467
495
|
languages: [
|
|
468
496
|
{
|
|
469
497
|
language: 'en',
|
|
470
|
-
content:
|
|
471
|
-
|
|
472
|
-
|
|
498
|
+
content:
|
|
499
|
+
isEditFlow
|
|
500
|
+
? `${updatedSmsEditor.join('')} ${formatMessage(messages.templateMessageUnsubscribeText)}`
|
|
501
|
+
: `$'${templateMessage}\nClick {{${
|
|
502
|
+
addedVarCount + 1 }}} to unsubscribe'`,
|
|
473
503
|
},
|
|
474
504
|
],
|
|
475
|
-
mediaType: '
|
|
476
|
-
varMapped:
|
|
505
|
+
mediaType: 'TEXT',
|
|
506
|
+
varMapped: varMap,
|
|
507
|
+
templateEditor: templateMessage,
|
|
477
508
|
accountId,
|
|
478
509
|
accessToken,
|
|
479
510
|
accountName,
|
|
@@ -518,6 +549,15 @@ export const Whatsapp = (props) => {
|
|
|
518
549
|
}
|
|
519
550
|
};
|
|
520
551
|
|
|
552
|
+
const saveToMessage = () => {
|
|
553
|
+
getFormData({
|
|
554
|
+
value: createPayload(),
|
|
555
|
+
_id: params?.paramObj?.id,
|
|
556
|
+
validity: true,
|
|
557
|
+
type: 'WHATSAPP',
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
521
561
|
const isDisableDone = () => {
|
|
522
562
|
//if template name is not entered
|
|
523
563
|
if (templateName.trim() === '' || templateNameError) {
|
|
@@ -773,14 +813,23 @@ export const Whatsapp = (props) => {
|
|
|
773
813
|
}
|
|
774
814
|
};
|
|
775
815
|
|
|
816
|
+
const tagValidationErrorMessage = () => {
|
|
817
|
+
const { unsupportedTags = [] } = tagValidationResponse;
|
|
818
|
+
let tagError = '';
|
|
819
|
+
if (unsupportedTags.length > 0) {
|
|
820
|
+
tagError = formatMessage(messages.unsupportedTagsValidationError, {
|
|
821
|
+
unsupportedTags,
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
return <CapError>{tagError}</CapError>;
|
|
825
|
+
};
|
|
826
|
+
|
|
776
827
|
const editModeContent = (
|
|
777
828
|
<>
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
/>
|
|
783
|
-
)}
|
|
829
|
+
<CapAlert
|
|
830
|
+
message={getTemplateStatusMessage()}
|
|
831
|
+
type={getTemplateStatusType()}
|
|
832
|
+
/>
|
|
784
833
|
<CapRow className="whatsapp-render-heading">
|
|
785
834
|
<CapHeader
|
|
786
835
|
title={
|
|
@@ -814,6 +863,7 @@ export const Whatsapp = (props) => {
|
|
|
814
863
|
</CapTooltip>
|
|
815
864
|
|
|
816
865
|
{renderMessageLength()}
|
|
866
|
+
{isTagValidationError && tagValidationErrorMessage()}
|
|
817
867
|
</>
|
|
818
868
|
);
|
|
819
869
|
//edit methods end
|
|
@@ -834,12 +884,19 @@ export const Whatsapp = (props) => {
|
|
|
834
884
|
<TemplatePreview
|
|
835
885
|
channel={WHATSAPP}
|
|
836
886
|
content={{ templateMsg }}
|
|
837
|
-
whatsappContentLen={isEditFlow ? updatedSmsEditor.join('').length : templateMessage.length}
|
|
838
887
|
whatsappAccountName={accountName}
|
|
839
888
|
/>
|
|
840
889
|
);
|
|
841
890
|
};
|
|
842
891
|
|
|
892
|
+
const isEditDoneDisabled = () => {
|
|
893
|
+
return isTagValidationError || Object.values(varMap).some( (inputValue) => {
|
|
894
|
+
if (inputValue === '') {
|
|
895
|
+
return true;
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
|
|
843
900
|
return (
|
|
844
901
|
<CapSpin spinning={spin}>
|
|
845
902
|
<CapRow>
|
|
@@ -874,6 +931,17 @@ export const Whatsapp = (props) => {
|
|
|
874
931
|
</CapButton>
|
|
875
932
|
</>
|
|
876
933
|
)}
|
|
934
|
+
{!isFullMode && isEditFlow && (
|
|
935
|
+
<>
|
|
936
|
+
<CapButton
|
|
937
|
+
onClick={saveToMessage}
|
|
938
|
+
disabled={isEditDoneDisabled()}
|
|
939
|
+
className="whatsapp-create-btn"
|
|
940
|
+
>
|
|
941
|
+
<FormattedMessage {...messages.done} />
|
|
942
|
+
</CapButton>
|
|
943
|
+
</>
|
|
944
|
+
)}
|
|
877
945
|
</WhatsappFooter>
|
|
878
946
|
</CapSpin>
|
|
879
947
|
);
|
|
@@ -232,4 +232,13 @@ export default defineMessages({
|
|
|
232
232
|
id: `${prefix}.disabledEditTooltipStatus`,
|
|
233
233
|
defaultMessage: 'awaiting for approval',
|
|
234
234
|
},
|
|
235
|
+
done: {
|
|
236
|
+
id: `${prefix}.done`,
|
|
237
|
+
defaultMessage: 'Done',
|
|
238
|
+
},
|
|
239
|
+
unsupportedTagsValidationError: {
|
|
240
|
+
id: `${prefix}.unsupportedTagsValidationError`,
|
|
241
|
+
defaultMessage:
|
|
242
|
+
'Unsupported tags: {unsupportedTags}. Please remove them from this message.',
|
|
243
|
+
},
|
|
235
244
|
});
|