@capillarytech/creatives-library 7.17.118-alpha.0 → 7.17.118

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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/tests/integration/TemplateCreation/TemplateCreation.integration.test.js +12 -16
  3. package/v2Components/CapImageUpload/index.js +16 -15
  4. package/v2Components/CapImageUpload/messages.js +5 -1
  5. package/v2Components/CapVideoUpload/constants.js +0 -5
  6. package/v2Components/CapVideoUpload/index.js +8 -28
  7. package/v2Components/CapVideoUpload/index.scss +1 -4
  8. package/v2Components/CapVideoUpload/messages.js +4 -4
  9. package/v2Components/FormBuilder/constants.js +1 -0
  10. package/v2Components/FormBuilder/index.js +2 -2
  11. package/v2Components/TemplatePreview/_templatePreview.scss +0 -21
  12. package/v2Components/TemplatePreview/index.js +45 -56
  13. package/v2Containers/CreativesContainer/SlideBoxContent.js +8 -10
  14. package/v2Containers/CreativesContainer/SlideBoxHeader.js +0 -1
  15. package/v2Containers/CreativesContainer/index.js +1 -0
  16. package/v2Containers/CreativesContainer/messages.js +0 -4
  17. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -11
  18. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +0 -225
  19. package/v2Containers/Email/index.js +3 -1
  20. package/v2Containers/EmailWrapper/index.js +3 -0
  21. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +20 -35
  22. package/v2Containers/Templates/_templates.scss +4 -9
  23. package/v2Containers/Templates/index.js +8 -29
  24. package/v2Containers/Viber/constants.js +0 -58
  25. package/v2Containers/Viber/index.js +421 -409
  26. package/v2Containers/Viber/messages.js +0 -68
  27. package/v2Components/CapImageUpload/constants.js +0 -6
  28. package/v2Containers/Viber/index.scss +0 -113
  29. package/v2Containers/Viber/style.js +0 -20
  30. package/v2Containers/Viber/tests/index.test.js +0 -297
  31. package/v2Containers/Viber/tests/mockData.js +0 -134
@@ -1,59 +1,69 @@
1
- import React, { useState, useEffect, useCallback } from 'react';
1
+ import React, { useState, useEffect } from 'react';
2
2
  import { bindActionCreators } from 'redux';
3
3
  import { createStructuredSelector } from 'reselect';
4
4
  import { injectIntl, FormattedMessage } from 'react-intl';
5
- import isEmpty from 'lodash/isEmpty';
6
- import get from 'lodash/get';
7
- import CapHeader from '@capillarytech/cap-ui-library/CapHeader';
8
- import CapRow from '@capillarytech/cap-ui-library/CapRow';
9
- import CapColumn from '@capillarytech/cap-ui-library/CapColumn';
10
- import CapSpin from '@capillarytech/cap-ui-library/CapSpin';
11
- import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
12
- import CapInput from '@capillarytech/cap-ui-library/CapInput';
13
- import CapHeading from '@capillarytech/cap-ui-library/CapHeading';
14
- import CapButton from '@capillarytech/cap-ui-library/CapButton';
15
- import CapNotification from '@capillarytech/cap-ui-library/CapNotification';
16
- import CapTooltip from '@capillarytech/cap-ui-library/CapTooltip';
17
- import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
18
- import CapRadioGroup from '@capillarytech/cap-ui-library/CapRadioGroup';
19
- import { GA } from '@capillarytech/cap-ui-utils';
5
+ import { isUrl } from '../Line/Container/Wrapper/utils';
6
+ import { get } from 'lodash';
7
+ import withCreatives from '../../hoc/withCreatives';
8
+ import {
9
+ CapHeader,
10
+ CapRow,
11
+ CapColumn,
12
+ CapSpin,
13
+ CapLabel,
14
+ CapInput,
15
+ CapHeading,
16
+ CapDivider,
17
+ CapIcon,
18
+ CapButton,
19
+ CapUploader,
20
+ CapDrawer,
21
+ CapNotification,
22
+ CapImage,
23
+ } from '@capillarytech/cap-ui-library';
20
24
  import { makeSelectViber, makeSelectCreateViber } from './selectors';
21
25
  import * as viberActions from './actions';
22
26
  import { validateTags } from '../../utils/tagValidations';
23
27
  import TemplatePreview from '../../v2Components/TemplatePreview';
24
- import { isUrl } from '../Line/Container/Wrapper/utils';
28
+ import {
29
+ CAP_G09,
30
+ CAP_SPACE_08,
31
+ CAP_SPACE_12,
32
+ FONT_COLOR_05,
33
+ CAP_SPACE_32,
34
+ CAP_SPACE_24,
35
+ CAP_WHITE,
36
+ CAP_SPACE_16,
37
+ CAP_G07,
38
+ } from '@capillarytech/cap-ui-library/styled/variables';
39
+ import LabelHOC from '@capillarytech/cap-ui-library/assets/HOCs/ComponentWithLabelHOC';
40
+ import styled from 'styled-components';
25
41
  import messages from './messages';
26
42
  import TagList from '../TagList';
27
43
  import { makeSelectMetaEntities, setInjectedTags } from '../Cap/selectors';
44
+ import Gallery from '../Assets/Gallery';
28
45
  import {
29
- ALLOWED_IMAGE_EXTENSIONS_REGEX_VIBER,
30
- ALLOWED_EXTENSIONS_VIDEO_REGEX_VIBER,
46
+ ALLOWED_EXTENSIONS_REGEX,
31
47
  VIBER_IMG_HEIGHT,
32
48
  VIBER_IMG_WIDTH,
33
49
  VIBER_IMG_SIZE,
34
- VIBER_VIDEO_SIZE,
35
50
  charLimit,
36
- VIBER_MEDIA_TYPES,
37
- VIBER_BUTTON_TYPES,
38
- NONE,
39
- mediaRadioOptions,
40
- buttonRadioOptions,
41
51
  } from './constants';
42
- import withCreatives from '../../hoc/withCreatives';
52
+ import { GA } from '@capillarytech/cap-ui-utils';
43
53
  import { CREATE, EDIT, TRACK_CREATE_VIBER, TRACK_EDIT_VIBER } from '../App/constants';
44
54
  import { gtmPush } from '../../utils/gtmTrackers';
45
55
  import { VIBER } from '../CreativesContainer/constants';
46
56
  import { getCdnUrl } from '../../utils/cdnTransformation';
47
57
  import globalMessages from '../Cap/messages';
48
- import CapImageUpload from '../../v2Components/CapImageUpload';
49
- import CapVideoUpload from '../../v2Components/CapVideoUpload';
50
- import './index.scss';
51
- import { ViberFooter } from './style';
58
+
59
+ const { CapHeadingSpan } = CapHeading;
52
60
  const { TextArea } = CapInput;
53
61
 
54
- export const Viber = (props) => {
62
+
63
+ const Viber = (props) => {
55
64
  const {
56
65
  intl,
66
+ supportedExtensions,
57
67
  isFullMode,
58
68
  injectedTags,
59
69
  location,
@@ -71,37 +81,47 @@ export const Viber = (props) => {
71
81
  } = props || {};
72
82
 
73
83
  const { formatMessage } = intl;
74
- const [imageSrc, setImageSrc] = useState('');
84
+ const [isImageError, updateImageErrorMessage] = useState(false);
85
+ const [isImage, updateImageStatus] = useState(false);
86
+ const [imageSrc, setImageSrc] = useState();
87
+ const [isDrawerRequired, updateDrawerRequirement] = useState(false);
75
88
  const [messageContent, updateTextMessageContent] = useState('');
76
89
  const [buttonText, updateButtonText] = useState('');
77
90
  const [buttonURL, updateButtonUrl] = useState('');
78
91
  const [errorMessageTextarea, updateErrorMessageTextArea] = useState(false);
92
+ const [imagePreview, updateImagePreview] = useState();
79
93
  const [isEditLoading, updateEditLoading] = useState(false);
80
94
  const [isEditFlow, checkEditFlow] = useState(false);
81
- const [messageTitle, updateTextMessageTitle] = useState("");
95
+ const [messageTitle, updateTextMessageTitle] = useState('');
82
96
  const [errorMessageTitle, updateErrorMessageTitle] = useState(false);
83
97
  const [buttonURLErrorMessage, updateButtonURLErrorMessage] = useState(false);
84
98
  const [accountName, updateAccountName] = useState("");
85
- const [templateMediaType, setTemplateMediaType] = useState(
86
- VIBER_MEDIA_TYPES.TEXT
87
- );
88
- const [assetList, updateAssetList] = useState([]);
89
- const [viberVideoSrcAndPreview, setViberVideoSrcAndPreview] = useState({
90
- viberVideoSrc: '',
91
- viberVideoPreviewImg: '',
92
- duration: 0,
93
- });
94
- // cta button
95
- const [buttonType, setButtonType] = useState(NONE);
96
- const [ctaData, setCtadata] = useState({});
97
- const [isCtaSaved, setIsCtaSaved] = useState(false);
98
-
99
- const updateImageSrc = React.useCallback((url) => {
99
+
100
+
101
+ const updateImageSrc = React.useCallback((url)=>{
100
102
  const newUrl = getCdnUrl({url, channelName: 'VIBER'});
101
103
  setImageSrc(newUrl);
102
- }, []);
104
+ },[]);
105
+
106
+ const StyledHeader = styled(CapHeader)`
107
+ margin-bottom: 14px;
108
+ `;
109
+ const ViberFooter = styled.div`
110
+ background-color: ${CAP_WHITE};
111
+ position: fixed;
112
+ bottom: 0;
113
+ width: 100%;
114
+ margin-left: -32px;
115
+ padding: ${CAP_SPACE_32} ${CAP_SPACE_24};
116
+
117
+ .ant-btn {
118
+ margin-right: ${CAP_SPACE_16};
119
+ }
120
+ }
121
+ `;
103
122
 
104
123
  const paramObj = params || {};
124
+
105
125
  useEffect(() => {
106
126
  const { id } = paramObj;
107
127
  if (id && !get(templateData, `versions.base.content`)) {
@@ -118,51 +138,42 @@ export const Viber = (props) => {
118
138
 
119
139
  useEffect(() => {
120
140
  if ((params && params.id) || (templateData || {}).edit) {
121
- const { content: editViberContent = {} } =
122
- get(templateData, `versions.base.content`) ||
123
- get(viber, `templateDetails.versions.base.content`) ||
124
- {};
125
- const editMessageTitle =
126
- (templateData || {}).name || get(viber, "templateDetails.name");
127
- const {
128
- text = "",
129
- button = {},
130
- image = {},
131
- video = {},
132
- } = editViberContent || {};
133
- const { text: ctaBtnText = "", url = "" } = button || {};
141
+ const { viber: editViberContent = {} } = get(templateData, `versions.base.content`) || get(viber, `templateDetails.versions.base.content`) || {};
142
+ const editMessageTitle = (templateData || {}).name || get(viber, 'templateDetails.name');
134
143
  updateTextMessageTitle(editMessageTitle);
135
- updateTextMessageContent(text || "");
136
- updateButtonText(ctaBtnText);
137
- updateButtonUrl(url);
138
- setIsCtaSaved(true);
139
- setButtonType(button?.text ? VIBER_BUTTON_TYPES.CTA : NONE);
140
- setCtadata({ buttonText: button?.text, buttonURL: button?.url });
141
- if (!isEmpty(image)) {
142
- setTemplateMediaType(VIBER_MEDIA_TYPES.IMAGE);
143
- updateImageSrc(image?.url);
144
- } else if (!isEmpty(video)) {
145
- setTemplateMediaType(VIBER_MEDIA_TYPES.VIDEO);
146
- setViberVideoSrcAndPreview({
147
- viberVideoSrc: video?.thumbnailUrl,
148
- viberVideoPreviewImg: video?.thumbnailUrl,
149
- duration: video?.duration,
150
- });
151
- updateAssetList({
152
- ...assetList,
153
- previewUrl: video?.thumbnailUrl,
154
- videoSrc: video?.url,
155
- videoDuration: video?.duration,
156
- });
157
- } else {
158
- setTemplateMediaType(VIBER_MEDIA_TYPES.TEXT);
144
+ updateTextMessageContent(editViberContent.text || '');
145
+ updateButtonText(editViberContent.buttonText || '');
146
+ updateButtonUrl(editViberContent.buttonURL || '');
147
+ if (editViberContent.imageURL) {
148
+ updateImageSrc(editViberContent.imageURL);
149
+ updateImagePreview(editViberContent.imageURL);
150
+ updateImageStatus(true);
159
151
  }
160
152
  }
161
153
  }, [viber[`templateDetails`] || templateData]);
162
154
 
163
- // Text area Code start here
155
+ // Common container for TEXT, IMAGE and Button
156
+ const container = (icon, message, data, showOptional) => (<CapRow
157
+ style={{
158
+ border: `solid 1px ${CAP_G07}`,
159
+ marginBottom: '20px',
160
+ }}>
161
+ <CapRow style={{ padding: `${CAP_SPACE_12} ${CAP_SPACE_24} 0px` }}>
162
+ <CapIcon type={icon}/>
163
+ <CapHeading type="h4" style={{position: 'absolute', display: 'inline-block', top: '13px', paddingLeft: '10px'}}>
164
+ {message} {" "}
165
+ {showOptional && <CapLabel.CapLabelInline type="label14">{formatMessage(messages.optional)}</CapLabel.CapLabelInline>}
166
+ </CapHeading>
167
+ </CapRow>
168
+ <CapDivider className="cap-divider-margin"/>
169
+ <CapRow style={{ padding: `0 ${CAP_SPACE_24} 22px` }}>
170
+ {data}
171
+ </CapRow>
172
+ </CapRow>);
173
+
174
+ // ******************** Text area Code start here ******************************
164
175
 
165
- // Tags Code start from here
176
+ // Tags Code start from here
166
177
  useEffect(() => {
167
178
  const type = location && location.query && location.query.type;
168
179
  const getTagsQuery = {
@@ -197,9 +208,10 @@ export const Viber = (props) => {
197
208
  const tags = metaEntities && metaEntities.tags
198
209
  ? metaEntities.tags.standard
199
210
  : [];
211
+
200
212
  // tags Code end here
201
213
 
202
- // validation on Text area and tags validation
214
+ // validation on Text area and tags validation
203
215
  const updateTextContentError = (value) => {
204
216
  let errorMessage = false;
205
217
  const { valid, isBraceError } = validateTags({
@@ -213,11 +225,12 @@ export const Viber = (props) => {
213
225
  errorMessage = formatMessage(messages.emptyContentErrorMessage);
214
226
  } else if (value.length > charLimit) {
215
227
  errorMessage = formatMessage(messages.limitExceededContentErrorMessage);
216
- } else if (isBraceError) {
228
+ } else if (isBraceError){
217
229
  errorMessage = formatMessage(globalMessages.unbalanacedCurlyBraces);
218
230
  } else if (!valid) {
219
231
  errorMessage = formatMessage(messages.invalidTagError);
220
232
  }
233
+
221
234
  updateErrorMessageTextArea(errorMessage);
222
235
  };
223
236
 
@@ -240,152 +253,257 @@ export const Viber = (props) => {
240
253
  updateErrorMessageTitle(errorMessage);
241
254
  };
242
255
  // Text Area container
243
- const renderTextAreaViber = () => (
244
- <>
245
- <CapColumn className="viber-message-header">
246
- <CapHeading type="h5" className="viber-message-header-style">
247
- {formatMessage(messages.message)}
248
- </CapHeading>
249
- <TagList
250
- key={"viber_tags"}
251
- className="tag-list-viber"
252
- moduleFilterEnabled={
253
- location && location.query && location.query.type !== "embedded"
254
- }
255
- label={formatMessage(messages.addLabels)}
256
- onTagSelect={onTagSelect}
257
- onContextChange={handleOnTagsContextChange}
258
- location={location}
259
- tags={tags}
260
- injectedTags={injectedTags || {}}
261
- id={"viber_tags"}
262
- userLocale={localStorage.getItem("jlocale") || "en"}
263
- selectedOfferDetails={selectedOfferDetails}
264
- />
265
- </CapColumn>
266
- <TextArea
267
- id={"viber_textarea"}
268
- autosize={false}
269
- onChange={onTextContentChange}
270
- className={`${errorMessageTextarea ? "error" : ""}`}
271
- errorMessage={errorMessageTextarea}
272
- defaultValue={messageContent || ""}
273
- value={messageContent || ""}
274
- rows={5}
275
- cols={2}
276
- placeholder={formatMessage(messages.enterMessage)}
277
- />
278
- <CapLabel type="label1" className="char-count-viber">
279
- <FormattedMessage {...messages.charCount} />
280
- {(messageContent || "").length}/{charLimit}{" "}
281
- </CapLabel>
282
- </>
283
- );
284
- // Text area Code End here
285
-
286
- // template media code start here
256
+ const TextAreaViber = (<>
257
+ <TextArea
258
+ id={'viber_textarea'}
259
+ label={(
260
+ <>
261
+ <FormattedMessage {...messages.textMessage} />
262
+ <CapLabel
263
+ type="label2" style={{display: 'inline-block',
264
+ float: 'right'}}>
265
+ {(messageContent || '').length}/{charLimit} {" "}
266
+ <FormattedMessage {...messages.characters} />
267
+
268
+ </CapLabel>
269
+ </>
270
+ )}
271
+ autosize={false}
272
+ onChange={onTextContentChange}
273
+ className={`${errorMessageTextarea ? 'error' : ''}`}
274
+ errorMessage={errorMessageTextarea}
275
+ defaultValue={messageContent || ''}
276
+ value={messageContent || ''}
277
+ rows={5}
278
+ cols={2}
279
+ />
280
+ <TagList
281
+ key={'viber_tags'}
282
+ moduleFilterEnabled={location && location.query && location.query.type !== 'embedded'}
283
+ label={formatMessage(messages.addLabels)}
284
+ onTagSelect={onTagSelect}
285
+ onContextChange={handleOnTagsContextChange}
286
+ location={location}
287
+ tags={tags}
288
+ injectedTags={injectedTags || {}}
289
+ id={'viber_tags'}
290
+ userLocale={localStorage.getItem('jlocale') || 'en'}
291
+ selectedOfferDetails={selectedOfferDetails}
292
+ />
293
+ </>);
287
294
 
288
- const isMediaTypeImage = templateMediaType === VIBER_MEDIA_TYPES.IMAGE;
289
- const isMediaTypeVideo = templateMediaType === VIBER_MEDIA_TYPES.VIDEO;
295
+ // ******************** Text area Code End here ******************************
290
296
 
291
- const onTemplateMediaTypeChange = ({ target: { value } }) => {
292
- setTemplateMediaType(value);
297
+ // ******************** Image section Code start here ******************************
298
+ useEffect(() => {
299
+ if (viber[`uploadedAssetData0`] && Object.keys(viber[`uploadedAssetData0`]).length) {
300
+ const imgSrc = get(viber, `uploadedAssetData0.metaInfo.secure_file_path`, '');
301
+ actions.clearViberAsset(0);
302
+ if (imgSrc) {
303
+ updateImageSrc(imgSrc);
304
+ updateImageStatus(true);
305
+ }
306
+ }
307
+ }, [viber[`uploadedAssetData0`]]);
308
+
309
+ const submitAction = (data, incorrectFile) => {
310
+ const {
311
+ file: {size},
312
+ fileParams: {
313
+ height,
314
+ width,
315
+ },
316
+ } = data;
317
+ if (incorrectFile || size > VIBER_IMG_SIZE || height > VIBER_IMG_HEIGHT || width > VIBER_IMG_WIDTH) {
318
+ updateImageErrorMessage(formatMessage(messages.viberImageIncorrectSize));
319
+ } else {
320
+ updateImageErrorMessage('');
321
+ actions.uploadViberAsset(
322
+ data.file,
323
+ data.type,
324
+ data.fileParams,
325
+ 0,
326
+ );
327
+ }
293
328
  };
294
329
 
295
- const uploadViberAsset = (file, type, fileParams) => {
296
- actions.uploadViberAsset(file, type, fileParams, 0);
330
+ const uploadImages = (e, {files}) => {
331
+ if (e) {
332
+ e.preventDefault();
333
+ }
334
+ const _URL = window.URL || window.webkitURL;
335
+ let incorrectFile = false;
336
+ const file = files[0];
337
+ if (!ALLOWED_EXTENSIONS_REGEX.test(file.name)) {
338
+ incorrectFile = true;
339
+ }
340
+ const img = new Image();
341
+ img.src = _URL.createObjectURL(file);
342
+ img.onload = () => {
343
+ const fileParams = {
344
+ width: img.width,
345
+ height: img.height,
346
+ error: file && (file.size / (1e+6) > 3),
347
+ };
348
+ submitAction({file, type: 'image', fileParams}, incorrectFile);
349
+ };
350
+ if (e) {
351
+ const event = e;
352
+ event.target.value = null;
353
+ }
297
354
  };
298
355
 
299
- const updateOnViberImageReUpload = useCallback(() => {
300
- setImageSrc("");
301
- }, [imageSrc]);
356
+ const ImageComponent = () => (<>
357
+ <CapHeader
358
+ title={formatMessage(messages.uploadImage)}
359
+ description={formatMessage(messages.imageDesc)}
360
+ size="regular"
361
+ />
362
+ <div
363
+ className={`image-container ${props.ifError ? 'error' : ''}`}
364
+ style={{
365
+ marginTop: 20,
366
+ backgroundColor: CAP_G09,
367
+ }}
368
+ >
369
+ {isImage && (<CapImage src={imageSrc} alt="viber-image-src" height="400" />)}
370
+ </div></>
371
+ );
302
372
 
303
- const setUpdateViberImageSrc = useCallback(
304
- (val) => {
305
- setImageSrc(val);
306
- actions.clearViberAsset(0);
307
- },
308
- [imageSrc]
309
- );
373
+ const setDrawerVisibility = (drawervisibleFlag) => updateDrawerRequirement(drawervisibleFlag);
310
374
 
311
- const setUpdateViberVideoSrc = useCallback(
312
- (index, data) => {
313
- const { videoSrc = "", previewUrl = "", videoDuration } = data;
314
- setViberVideoSrcAndPreview({
315
- viberVideoSrc: videoSrc,
316
- viberVideoPreviewImg: previewUrl,
317
- duration: videoDuration,
318
- });
319
- updateAssetList(data);
320
- actions.clearViberAsset(0);
321
- },
322
- [viberVideoSrcAndPreview?.viberVideoSrc]
323
- );
375
+ const onGalleryClick = (event) => {
376
+ event.stopPropagation();
377
+ setDrawerVisibility(true);
378
+ };
324
379
 
325
- const renderMediaSection = () => (
326
- <>
327
- <CapHeading type="h4" className="viber-render-heading">
328
- {formatMessage(messages.mediaLabel)}
329
- </CapHeading>
330
- <CapRadioGroup
331
- id="viber-media-radio"
332
- options={mediaRadioOptions}
333
- value={templateMediaType}
334
- onChange={onTemplateMediaTypeChange}
335
- className="viber-media-radio"
336
- />
337
- </>
338
- );
380
+ const capUploaderCustomRequest = (uploadData) => {
381
+ uploadImages(undefined, {files: [uploadData.file]});
382
+ };
383
+ const onReUpload = () => {
384
+ updateImageStatus(false);
385
+ // deleteUploadedImgList(index);
386
+ updateImageSrc('');
387
+ updateImagePreview('');
388
+ };
389
+ const getViberImageSection = () => {
390
+ if (!isImage) {
391
+ return (<>
392
+ <CapUploader.CapDragger
393
+ customRequest={capUploaderCustomRequest}
394
+ className="form-builder-dragger"
395
+ >
396
+ <CapHeading className="dragger-title" type="h7">
397
+ <FormattedMessage {...messages.dragAndDrop} />
398
+ </CapHeading>
399
+ <CapHeading className="dragger-or" type="label6">
400
+ <FormattedMessage {...messages.or} />
401
+ </CapHeading>
402
+ <CapButton className="dragger-button" type="secondary" style={{marginRight: CAP_SPACE_08}}>
403
+ <FormattedMessage {...messages.uploadComputer} />
404
+ </CapButton>
405
+ <CapButton
406
+ className="dragger-button"
407
+ type="secondary"
408
+ style={{marginLeft: CAP_SPACE_08}}
409
+ onClick={onGalleryClick}
410
+ >
411
+ <FormattedMessage {...messages.uploadGallery} />
412
+ </CapButton>
413
+ </CapUploader.CapDragger>
414
+ <div style={{marginTop: '15px' }}>
415
+ <CapHeadingSpan type="label2" style={{marginTop: CAP_SPACE_12, marginRight: '46px' }}>
416
+ <FormattedMessage {...messages.imageDimenstionDescription} />
417
+ </CapHeadingSpan>
418
+ <CapHeadingSpan type="label2" style={{marginTop: CAP_SPACE_12 }}>
419
+ <FormattedMessage {...messages.imageSizeDescription} />
420
+ </CapHeadingSpan>
421
+ </div>
422
+
423
+ </>
424
+ );
425
+ }
426
+ return (
427
+ <CapButton
428
+ className="dragger-button"
429
+ type="flat"
430
+ style={{
431
+ top: 0,
432
+ position: 'absolute',
433
+ right: 0,
434
+ color: FONT_COLOR_05,
435
+ }}
436
+ onClick={onReUpload}
437
+ >
438
+ <FormattedMessage {...messages.imageReUpload} />
439
+ </CapButton>
440
+ );
441
+ };
339
442
 
340
- const renderImageComponent = () => (
341
- <CapImageUpload
342
- allowedExtensionsRegex={ALLOWED_IMAGE_EXTENSIONS_REGEX_VIBER}
343
- imgSize={VIBER_IMG_SIZE}
344
- imgWidth={VIBER_IMG_WIDTH}
345
- imgHeight={VIBER_IMG_HEIGHT}
346
- uploadAsset={uploadViberAsset}
347
- isFullMode={isFullMode}
348
- imageSrc={imageSrc}
349
- updateImageSrc={setUpdateViberImageSrc}
350
- updateOnReUpload={updateOnViberImageReUpload}
351
- index={0}
352
- className="cap-custom-image-upload"
353
- key="viber-uploaded-image"
354
- imageData={viber}
355
- channel={VIBER}
356
- />
357
- );
443
+ const getGalleryDrawerContent = () => {
444
+ const locationGallery = {
445
+ pathname: `/assets`,
446
+ search: '',
447
+ query: !isFullMode ? {type: 'embedded', module: 'library'} : {},
448
+ };
449
+ return (
450
+ <>
451
+ <CapHeading type="h3">
452
+ {formatMessage(messages.imageGallery)}
453
+ </CapHeading>
454
+ <Gallery
455
+ location={locationGallery}
456
+ isFullMode={isFullMode}
457
+ isLineAsset
458
+ onGalleryImageSelect={onGalleryImageSelect}
459
+ />
460
+ </>
461
+ );
462
+ };
358
463
 
359
- const renderVideoComonent = () => (
360
- <CapVideoUpload
361
- index={0}
362
- allowedExtensionsRegex={ALLOWED_EXTENSIONS_VIDEO_REGEX_VIBER}
363
- videoSize={VIBER_VIDEO_SIZE}
364
- isFullMode={isFullMode}
365
- uploadAsset={uploadViberAsset}
366
- uploadedAssetList={assetList}
367
- onVideoUploadUpdateAssestList={setUpdateViberVideoSrc}
368
- videoData={viber}
369
- className="cap-custom-video-upload"
370
- formClassName={"viber-video-upload"}
371
- channel={VIBER}
372
- errorMessage={formatMessage(messages.videoErrorMessage)}
373
- showVideoNameAndDuration={false}
374
- />
375
- );
464
+ const onGalleryImageSelect = (imageTemplate) => {
465
+ const image = get(imageTemplate, 'metaInfo.secure_file_path');
466
+ const imageURL = get(imageTemplate, 'metaInfo.secure_file_path_preview');
467
+ updateDrawerRequirement(false);
468
+ if (!ALLOWED_EXTENSIONS_REGEX.test(image)) {
469
+ updateImageErrorMessage(formatMessage(messages.viberImageIncorrectSize));
470
+ } else {
471
+ updateImageErrorMessage('');
472
+ updateImageStatus(true);
473
+ updateImageSrc(image);
474
+ updateImagePreview(imageURL);
475
+ }
476
+ };
376
477
 
377
- const renderMediaComponent = () => (
378
- <>
379
- {isMediaTypeImage && renderImageComponent()}
380
- {isMediaTypeVideo && renderVideoComonent()}
381
- </>
382
- );
478
+ const WithLabel = LabelHOC(ImageComponent);
479
+ const ImageViber = <>
480
+ <WithLabel
481
+ key={`viber-with-label`}
482
+ errorMessage={isImageError} ifError={!!isImageError}
483
+ />
484
+ <form encType="multipart/form-data" id={`viber_form`}>
485
+ <input
486
+ key={`viber_imgFile`}
487
+ style={{ display: 'none' }}
488
+ id="fileName"
489
+ type="file"
490
+ onChange={(e) => uploadImages(e, { files: e.target.files })}
491
+ accept={supportedExtensions || "image/*"}
492
+ />
493
+ {getViberImageSection()}
494
+ <CapDrawer
495
+ content={getGalleryDrawerContent()}
496
+ visible={isDrawerRequired}
497
+ width={430}
498
+ onClose={() => updateDrawerRequirement(false)}
499
+ />
500
+ </form>
501
+ </>;
502
+ // ******************** Image section End here ******************************
383
503
 
384
- // template media code end here
385
504
 
386
- // Button Code start here
505
+ // ******************** Button Code start here ******************************
387
506
 
388
- const isBtnTypeCta = buttonType === VIBER_BUTTON_TYPES.CTA;
389
507
  const onChangeButtonText = ({ target: { value } }) => {
390
508
  updateButtonText(value);
391
509
  };
@@ -398,159 +516,50 @@ export const Viber = (props) => {
398
516
  }
399
517
  updateButtonURLErrorMessage(errorMessage);
400
518
  };
401
- const getPreviewSection = () => (
519
+ const getPreviewSection = () =>
402
520
  // const accountName = get(lineData, 'selectedLineAccount.name', '');
403
- <TemplatePreview
404
- channel={VIBER}
405
- content={{
406
- viberPreviewContent: {
407
- ...(isMediaTypeImage && { imageURL: imageSrc }),
408
- ...(isMediaTypeVideo && { videoParams: viberVideoSrcAndPreview }),
409
- buttonText,
410
- messageContent,
411
- },
412
- }}
413
- viberAccountName={(accountName[0] || "").toUpperCase()}
414
- viberBrandName={accountName}
415
- />
416
- );
417
-
418
- const handleSaveCta = () => {
419
- setCtadata({ buttonText, buttonURL });
420
- setIsCtaSaved(true);
421
- };
422
-
423
- const handleEditCta = () => {
424
- setIsCtaSaved(false);
425
- updateButtonText(ctaData?.buttonText);
426
- updateButtonUrl(ctaData?.buttonURL);
427
- };
428
-
429
- const handleCancelCta = () => {
430
- if (isEmpty(ctaData)) {
431
- setButtonType(NONE);
432
- } else {
433
- setIsCtaSaved(true);
434
- }
435
- };
436
-
437
- const isCtaSaveDisabled =
438
- isEmpty(buttonText.trim()) ||
439
- isEmpty(buttonURL.trim()) ||
440
- buttonURLErrorMessage;
441
-
442
- const ButtonViber = !isCtaSaved ? (
443
- <div className="cta-section">
444
- <CapHeading type="h4" className="button-text">
445
- {formatMessage(messages.buttonText)}{" "}
446
- <CapTooltip title={formatMessage(messages.buttonTextTooltip)}>
447
- <CapIcon type="info" size="s" />
448
- </CapTooltip>
449
- </CapHeading>
450
- <CapInput
451
- id="viber-button-text"
452
- className="cta-text-input"
453
- type="input"
454
- onChange={onChangeButtonText}
455
- defaultValue={buttonText}
456
- value={buttonText}
457
- maxLength={20}
458
- placeholder={formatMessage(messages.enterButtonText)}
459
- />
460
- <CapInput
461
- id="viber-button-url"
462
- type="input"
463
- onChange={onChangeButtonUrl}
464
- defaultValue={buttonURL}
465
- value={buttonURL}
466
- label={formatMessage(messages.buttonUrl)}
467
- errorMessage={buttonURLErrorMessage}
468
- placeholder={formatMessage(messages.enterButtonUrl)}
469
- />
470
- <CapColumn className="cta-actions">
471
- <CapButton
472
- disabled={isCtaSaveDisabled}
473
- className="cta-btn-action"
474
- onClick={handleSaveCta}
475
- >
476
- {formatMessage(messages.save)}
477
- </CapButton>
478
- <CapButton className="cta-btn-action" onClick={handleCancelCta}>
479
- {formatMessage(messages.cancel)}
480
- </CapButton>
481
- </CapColumn>
482
- </div>
483
- ) : (
484
- <CapRow className="cta-section-saved">
485
- <CapLabel type="label4" className="cta-text">
486
- {ctaData?.buttonText}
487
- </CapLabel>
488
- <CapLabel type="label2" className="button-url">
489
- {ctaData?.buttonURL}
490
- </CapLabel>
491
- <CapColumn className="button-edit-icon" onClick={handleEditCta}>
492
- <CapIcon type="edit" size="s" aria-label="edit-cta-icon"></CapIcon>
493
- </CapColumn>
494
- </CapRow>
495
- );
496
-
497
- const onChangeButtonType = ({ target: { value } }) => {
498
- setButtonType(value);
499
- setCtadata({});
500
- updateButtonText("");
501
- updateButtonUrl("");
502
- setIsCtaSaved(false);
503
- };
521
+ (
522
+ <TemplatePreview
523
+ channel="VIBER"
524
+ content={{imageURL: imagePreview, buttonText, messageContent}}
525
+ viberAccountName={((accountName[0] || "")).toUpperCase()}
526
+ viberBrandName={accountName}
527
+ />
528
+ );
504
529
 
505
- const renderButtonsSection = () => (
506
- <div className="button-section">
507
- <CapHeader
508
- className="viber-render-heading"
509
- title={
510
- <CapRow type="flex">
511
- <CapHeading type="h4">
512
- {formatMessage(messages.btnLabel)}
513
- </CapHeading>
514
- <CapHeading className="viber-optional-label">
515
- {formatMessage(messages.optional)}
516
- </CapHeading>
517
- </CapRow>
518
- }
519
- description={
520
- <CapLabel type="label3">{formatMessage(messages.btnDesc)}</CapLabel>
521
- }
522
- />
523
- <CapRadioGroup
524
- options={buttonRadioOptions}
525
- value={buttonType}
526
- onChange={onChangeButtonType}
527
- className="viber-btn-radio-group"
530
+ const ButtonViber = (<>
531
+ <CapInput
532
+ id="viber-button-text"
533
+ type="input"
534
+ onChange={onChangeButtonText}
535
+ label={formatMessage(messages.buttonText)}
536
+ defaultValue={buttonText}
537
+ value={buttonText}
538
+ style={{paddingBottom: '11px'}}
539
+ maxLength={20}
540
+ />
541
+ <CapInput
542
+ id="viber-button-url"
543
+ type="input"
544
+ onChange={onChangeButtonUrl}
545
+ defaultValue={buttonURL}
546
+ value={buttonURL}
547
+ label={formatMessage(messages.buttonUrl)}
548
+ errorMessage={buttonURLErrorMessage}
528
549
  />
529
- {isBtnTypeCta && ButtonViber}
530
- </div>
531
- );
532
- // Button Code End here
550
+ </>);
533
551
 
552
+ // ******************** Button Code End here ******************************
534
553
  const formatSubmitPayload = () => {
535
554
  const messageData = {
536
555
  text: messageContent,
537
556
  };
538
- if (isMediaTypeImage) {
539
- messageData.image = {};
540
- messageData.image.url = imageSrc;
557
+ if (imageSrc) {
558
+ messageData.imageURL = imageSrc;
541
559
  }
542
- if (isMediaTypeVideo) {
543
- const { viberVideoSrc, duration, viberVideoPreviewImg } =
544
- viberVideoSrcAndPreview;
545
- messageData.video = {};
546
- messageData.video.url = viberVideoSrc;
547
- messageData.video.thumbnailUrl = viberVideoPreviewImg;
548
- messageData.video.duration = duration; // integer value in seconds
549
- }
550
- if (!isEmpty(ctaData)) {
551
- messageData.button = {};
552
- messageData.button.text = ctaData?.buttonText;
553
- messageData.button.url = ctaData?.buttonURL;
560
+ if (buttonText && buttonURL) {
561
+ messageData.buttonText = buttonText;
562
+ messageData.buttonURL = buttonURL;
554
563
  }
555
564
  return {
556
565
  versions: {
@@ -563,7 +572,7 @@ export const Viber = (props) => {
563
572
  },
564
573
  },
565
574
  ],
566
- content: {...messageData},
575
+ viber: {...messageData},
567
576
  },
568
577
  },
569
578
  },
@@ -572,7 +581,7 @@ export const Viber = (props) => {
572
581
  };
573
582
  };
574
583
 
575
- const createCallback = ({ errorMessage, resp }, isEdit) => {
584
+ const createCallback = ({errorMessage, resp}, isEdit) => {
576
585
  if (!errorMessage) {
577
586
  CapNotification.success({
578
587
  message: isEdit ? formatMessage(messages.viberEditNotification) : formatMessage(messages.viberCreateNotification),
@@ -592,7 +601,7 @@ export const Viber = (props) => {
592
601
  channel: VIBER,
593
602
  timeTaken,
594
603
  content: messageContent,
595
- mode: isEdit ? EDIT : CREATE,
604
+ mode: isEdit ? EDIT : CREATE
596
605
  });
597
606
  } else {
598
607
  CapNotification.error({
@@ -606,9 +615,7 @@ export const Viber = (props) => {
606
615
  formatSubmitPayload(),
607
616
  (resp, errorMessage) => {
608
617
  createCallback({resp, errorMessage});
609
- if (!errorMessage) {
610
- onCreateComplete();
611
- }
618
+ onCreateComplete();
612
619
  }
613
620
  );
614
621
  };
@@ -621,9 +628,7 @@ export const Viber = (props) => {
621
628
  },
622
629
  (resp, errorMessage) => {
623
630
  createCallback({resp, errorMessage}, true);
624
- if (!errorMessage) {
625
- onCreateComplete();
626
- }
631
+ onCreateComplete();
627
632
  });
628
633
  };
629
634
 
@@ -647,24 +652,22 @@ export const Viber = (props) => {
647
652
  if (messageContent?.trim() === '' || errorMessageTextarea) {
648
653
  return true;
649
654
  }
650
- // // cannot send text + image only messages, Need to add button details or remove one of the components in order to proceed
651
- // const trimedButtonText = buttonText.trim();
652
- // const trimedButtonUrl = buttonURL.trim();
653
- // if (messageContent !== '' && (trimedButtonText === '' && trimedButtonUrl === '')) {
654
- // return true;
655
- // }
656
- //if template title is empty
657
- if (messageTitle?.trim() === '') {
655
+ // cannot send text + image only messages, Need to add button details or remove one of the components in order to proceed
656
+ const trimedButtonText = buttonText.trim();
657
+ const trimedButtonUrl = buttonURL.trim();
658
+ if (messageContent !== '' && imageSrc && (trimedButtonUrl === '' && trimedButtonUrl === '')) {
658
659
  return true;
659
660
  }
660
- // if media type is image/video than image/video should be uploaded
661
- if (
662
- (isMediaTypeImage && !imageSrc) ||
663
- (isMediaTypeVideo && !viberVideoSrcAndPreview.viberVideoSrc)
664
- ) {
661
+ // if button is being added than button url and button Text both are mandatory
662
+ if (( trimedButtonText === '' && trimedButtonUrl !== '') || ( trimedButtonText !== '' && trimedButtonUrl === '')) {
665
663
  return true;
666
664
  }
667
- if (isBtnTypeCta && !isCtaSaved) {
665
+ // if button url is not valid url
666
+ if (buttonURLErrorMessage) {
667
+ return true;
668
+ }
669
+ //if template title is empty
670
+ if (messageTitle?.trim() === '') {
668
671
  return true;
669
672
  }
670
673
  return false;
@@ -675,25 +678,32 @@ export const Viber = (props) => {
675
678
  <CapSpin spinning={isEditLoading}>
676
679
  <CapRow>
677
680
  <CapColumn span={14}>
678
- {isFullMode ? (
679
- <CapInput
680
- id={`viber_input`}
681
- onChange={onTextTitleChange}
682
- errorMessage={errorMessageTitle}
683
- placeholder={formatMessage(
684
- messages.textMessageTitlePlaceholder
685
- )}
686
- defaultValue={messageTitle || ""}
687
- value={messageTitle || ""}
688
- size="default"
689
- label={formatMessage(messages.textMessageTitleLabel)}
690
- data-testid="template_name"
691
- />
692
- ) : null}
693
- {renderMediaSection()}
694
- {renderMediaComponent()}
695
- {renderTextAreaViber()}
696
- {renderButtonsSection()}
681
+ <StyledHeader
682
+ title={formatMessage(messages.viberCreativeTitle)}
683
+ size="regular"
684
+ />
685
+ {
686
+ isFullMode
687
+ ? (
688
+ <CapInput
689
+ id={`viber_input`}
690
+ onChange={onTextTitleChange}
691
+ errorMessage={errorMessageTitle}
692
+ className="text-template-title"
693
+ placeholder={formatMessage(messages.textMessageTitlePlaceholder)}
694
+ defaultValue={messageTitle || ''}
695
+ value={messageTitle || ''}
696
+ size="default"
697
+ label={formatMessage(messages.textMessageTitleLabel)}
698
+ style={{marginBottom: 20}}
699
+ data-testid="template_name"
700
+ />
701
+ )
702
+ : null
703
+ }
704
+ {container("message", <FormattedMessage {...messages.message} />, TextAreaViber, false)}
705
+ {container("image", <FormattedMessage {...messages.image} />, ImageViber, true)}
706
+ {container("button", <FormattedMessage {...messages.button} />, ButtonViber, true)}
697
707
  <div style={{marginBottom: '100px'}}/>
698
708
  </CapColumn>
699
709
  <CapColumn span={6}>
@@ -724,11 +734,12 @@ export const Viber = (props) => {
724
734
  onClick={handleClose}
725
735
  className="cancel-msg"
726
736
  type="secondary"
727
- >
737
+ >
728
738
  <FormattedMessage {...messages.cancelButtonLabel} />
729
739
  </CapButton>
730
740
  </ViberFooter>
731
741
  </CapSpin>
742
+
732
743
  </>
733
744
  );
734
745
  };
@@ -744,9 +755,10 @@ const mapDispatchToProps = (dispatch) => ({
744
755
  actions: bindActionCreators(viberActions, dispatch),
745
756
  });
746
757
 
758
+
747
759
  export default withCreatives({
748
760
  WrappedComponent: injectIntl(Viber),
749
761
  mapStateToProps,
750
762
  mapDispatchToProps,
751
763
  userAuth: true,
752
- });
764
+ });