@capillarytech/creatives-library 7.1.11 → 7.2.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.
Files changed (62) hide show
  1. package/assets/viber.png +0 -0
  2. package/index.js +8 -1
  3. package/package.json +2 -1
  4. package/reducers.js +2 -0
  5. package/routes.js +7 -1
  6. package/services/api.js +5 -0
  7. package/v2Components/TemplatePreview/_templatePreview.scss +8 -2
  8. package/v2Components/TemplatePreview/assets/images/viberMobile.svg +135 -0
  9. package/v2Components/TemplatePreview/index.js +108 -18
  10. package/v2Containers/App/constants.js +1 -1
  11. package/v2Containers/CreativesContainer/SlideBoxContent.js +67 -2
  12. package/v2Containers/CreativesContainer/constants.js +2 -0
  13. package/v2Containers/CreativesContainer/index.js +40 -5
  14. package/v2Containers/FTP/_FTP.scss +103 -0
  15. package/v2Containers/FTP/actions.js +7 -0
  16. package/v2Containers/FTP/constants.js +3 -0
  17. package/v2Containers/FTP/index.js +534 -0
  18. package/v2Containers/FTP/messages.js +60 -0
  19. package/v2Containers/FTP/reducer.js +32 -0
  20. package/v2Containers/FTP/sagas.js +26 -0
  21. package/v2Containers/FTP/selectors.js +20 -0
  22. package/v2Containers/Templates/_templates.scss +57 -0
  23. package/v2Containers/Templates/actions.js +117 -110
  24. package/v2Containers/Templates/constants.js +2 -0
  25. package/v2Containers/Templates/index.js +88 -7
  26. package/v2Containers/Templates/messages.js +4 -0
  27. package/v2Containers/Templates/reducer.js +2 -0
  28. package/v2Containers/TemplatesV2/index.js +9 -1
  29. package/v2Containers/TemplatesV2/messages.js +4 -0
  30. package/v2Containers/Viber/actions.js +74 -0
  31. package/v2Containers/Viber/constants.js +30 -0
  32. package/v2Containers/Viber/index.js +727 -0
  33. package/v2Containers/Viber/messages.js +145 -0
  34. package/v2Containers/Viber/reducer.js +84 -0
  35. package/v2Containers/Viber/sagas.js +107 -0
  36. package/v2Containers/Viber/selectors.js +21 -0
  37. package/v2Components/TemplatePreview/assets/images/mobile.svg +0 -24
  38. package/v2Containers/Line/Create/_lineCreate.scss +0 -64
  39. package/v2Containers/Line/Create/actions.js +0 -94
  40. package/v2Containers/Line/Create/constants.js +0 -43
  41. package/v2Containers/Line/Create/index.js +0 -1132
  42. package/v2Containers/Line/Create/initialSchema.js +0 -378
  43. package/v2Containers/Line/Create/messages.js +0 -229
  44. package/v2Containers/Line/Create/reducer.js +0 -99
  45. package/v2Containers/Line/Create/sagas.js +0 -113
  46. package/v2Containers/Line/Create/selectors.js +0 -30
  47. package/v2Containers/Line/CreateWrapper/constants.js +0 -2
  48. package/v2Containers/Line/CreateWrapper/index.js +0 -117
  49. package/v2Containers/Line/CreateWrapper/messages.js +0 -55
  50. package/v2Containers/Line/Edit/_lineEdit.scss +0 -23
  51. package/v2Containers/Line/Edit/actions.js +0 -79
  52. package/v2Containers/Line/Edit/constants.js +0 -27
  53. package/v2Containers/Line/Edit/index.js +0 -1051
  54. package/v2Containers/Line/Edit/messages.js +0 -173
  55. package/v2Containers/Line/Edit/reducer.js +0 -83
  56. package/v2Containers/Line/Edit/sagas.js +0 -81
  57. package/v2Containers/Line/Edit/selectors.js +0 -29
  58. package/v2Containers/Line/Edit/tests/actions.test.js +0 -18
  59. package/v2Containers/Line/Edit/tests/index.test.js +0 -10
  60. package/v2Containers/Line/Edit/tests/reducer.test.js +0 -9
  61. package/v2Containers/Line/Edit/tests/sagas.test.js +0 -15
  62. package/v2Containers/Line/Edit/tests/selectors.test.js +0 -10
@@ -0,0 +1,727 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { bindActionCreators } from 'redux';
3
+ import { createStructuredSelector } from 'reselect';
4
+ import { injectIntl, FormattedMessage } from 'react-intl';
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';
24
+ import { makeSelectViber, makeSelectCreateViber } from './selectors';
25
+ import * as viberActions from './actions';
26
+ import { validateTags } from '../../utils/tagValidations';
27
+ import TemplatePreview from '../../v2Components/TemplatePreview';
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';
41
+ import messages from './messages';
42
+ import TagList from '../TagList';
43
+ import { makeSelectMetaEntities, setInjectedTags } from '../Cap/selectors';
44
+ import Gallery from '../Assets/Gallery';
45
+ import {
46
+ ALLOWED_EXTENSIONS_REGEX,
47
+ VIBER_IMG_HEIGHT,
48
+ VIBER_IMG_WIDTH,
49
+ VIBER_IMG_SIZE,
50
+ charLimit,
51
+ } from './constants';
52
+ const { CapHeadingSpan } = CapHeading;
53
+ const { TextArea } = CapInput;
54
+
55
+ const Viber = (props) => {
56
+ const {
57
+ intl,
58
+ supportedExtensions,
59
+ isFullMode,
60
+ injectedTags,
61
+ location,
62
+ metaEntities,
63
+ globalActions,
64
+ handleClose,
65
+ onCreateComplete,
66
+ params,
67
+ templateData = {},
68
+ actions,
69
+ viber = {},
70
+ getFormSubscriptionData,
71
+ viberData = {},
72
+ } = props || {};
73
+
74
+ const { formatMessage } = intl;
75
+ const [isImageError, updateImageErrorMessage] = useState(false);
76
+ const [isImage, updateImageStatus] = useState(false);
77
+ const [imageSrc, updateImageSrc] = useState();
78
+ const [isDrawerRequired, updateDrawerRequirement] = useState(false);
79
+ const [messageContent, updateTextMessageContent] = useState('');
80
+ const [buttonText, updateButtonText] = useState('');
81
+ const [buttonURL, updateButtonUrl] = useState('');
82
+ const [errorMessageTextarea, updateErrorMessageTextArea] = useState(false);
83
+ const [imagePreview, updateImagePreview] = useState();
84
+ const [isEditLoading, updateEditLoading] = useState(false);
85
+ const [isEditFlow, checkEditFlow] = useState(false);
86
+ const [messageTitle, updateTextMessageTitle] = useState('');
87
+ const [errorMessageTitle, updateErrorMessageTitle] = useState(false);
88
+ const [buttonURLErrorMessage, updateButtonURLErrorMessage] = useState(false);
89
+ const [accountName, updateAccountName] = useState("");
90
+
91
+ const StyledHeader = styled(CapHeader)`
92
+ margin-bottom: 14px;
93
+ `;
94
+ const ViberFooter = styled.div`
95
+ background-color: ${CAP_WHITE};
96
+ position: fixed;
97
+ bottom: 0;
98
+ width: 100%;
99
+ margin-left: -32px;
100
+ padding: ${CAP_SPACE_32} ${CAP_SPACE_24};
101
+
102
+ .ant-btn {
103
+ margin-right: ${CAP_SPACE_16};
104
+ }
105
+ }
106
+ `;
107
+
108
+ const paramObj = params || {};
109
+
110
+ useEffect(() => {
111
+ const { id } = paramObj;
112
+ if (id && !get(templateData, `versions.base.content`)) {
113
+ updateEditLoading(true);
114
+ actions.getTemplateDetails(id, updateEditLoading);
115
+ checkEditFlow(true);
116
+ }
117
+ }, [paramObj.id]);
118
+
119
+ useEffect(() => {
120
+ const { name = '' } = viberData.selectedViberAccount || {};
121
+ updateAccountName(name);
122
+ }, [viberData.selectedViberAccount]);
123
+
124
+ useEffect(() => {
125
+ if ((params && params.id) || templateData.edit) {
126
+ const { viber: editViberContent = {} } = get(templateData, `versions.base.content`) || get(viber, `templateDetails.versions.base.content`) || {};
127
+ const editMessageTitle = (templateData || {}).name || get(viber, 'templateDetails.name');
128
+ updateTextMessageTitle(editMessageTitle);
129
+ updateTextMessageContent(editViberContent.text || '');
130
+ updateButtonText(editViberContent.buttonText || '');
131
+ updateButtonUrl(editViberContent.buttonURL || '');
132
+ if (editViberContent.imageURL) {
133
+ updateImageSrc(editViberContent.imageURL);
134
+ updateImagePreview(editViberContent.imageURL);
135
+ updateImageStatus(true);
136
+ }
137
+ }
138
+ }, [viber[`templateDetails`] || templateData]);
139
+
140
+ // Common container for TEXT, IMAGE and Button
141
+ const container = (icon, message, data, showOptional) => (<CapRow
142
+ style={{
143
+ border: `solid 1px ${CAP_G07}`,
144
+ marginBottom: '20px',
145
+ }}>
146
+ <CapRow style={{ padding: `${CAP_SPACE_12} ${CAP_SPACE_24} 0px` }}>
147
+ <CapIcon type={icon}/>
148
+ <CapHeading type="h4" style={{position: 'absolute', display: 'inline-block', top: '13px', paddingLeft: '10px'}}>
149
+ {message} {" "}
150
+ {showOptional && <CapLabel.CapLabelInline type="label14">{formatMessage(messages.optional)}</CapLabel.CapLabelInline>}
151
+ </CapHeading>
152
+ </CapRow>
153
+ <CapDivider className="cap-divider-margin"/>
154
+ <CapRow style={{ padding: `0 ${CAP_SPACE_24} 22px` }}>
155
+ {data}
156
+ </CapRow>
157
+ </CapRow>);
158
+
159
+ // ******************** Text area Code start here ******************************
160
+
161
+ // Tags Code start from here
162
+ useEffect(() => {
163
+ const type = location && location.query && location.query.type;
164
+ const getTagsQuery = {
165
+ layout: 'LINE',
166
+ type: 'TAG',
167
+ context: type ? 'outbound' : 'default',
168
+ embedded: type || 'full',
169
+ };
170
+ globalActions.fetchSchemaForEntity(getTagsQuery);
171
+ }, []);
172
+
173
+ const onTagSelect = (data) => {
174
+ const messageData = `${messageContent}{{${data}}}`;
175
+ updateTextMessageContent(messageData);
176
+ updateTextContentError(messageData);
177
+ };
178
+
179
+ const handleOnTagsContextChange = (data) => {
180
+ const query = {
181
+ layout: 'LINE',
182
+ type: 'TAG',
183
+ context:
184
+ (data || '').toLowerCase() === 'all' ? 'default' : (data || '').toLowerCase(),
185
+ embedded:
186
+ location.query.type === 'embedded'
187
+ ? location.query.type
188
+ : 'full',
189
+ };
190
+ globalActions.fetchSchemaForEntity(query);
191
+ };
192
+
193
+ const tags = metaEntities && metaEntities.tags
194
+ ? metaEntities.tags.standard
195
+ : [];
196
+
197
+ // tags Code end here
198
+
199
+ // validation on Text area and tags validation
200
+ const updateTextContentError = (value) => {
201
+ let errorMessage = false;
202
+ const { valid } = validateTags({
203
+ content: value,
204
+ tagsParam: tags,
205
+ injectedTagsParams: injectedTags,
206
+ location,
207
+ tagModule: 'outbound',
208
+ }) || {};
209
+ if (value.trim() === '') {
210
+ errorMessage = formatMessage(messages.emptyContentErrorMessage);
211
+ } else if (value.length > charLimit) {
212
+ errorMessage = formatMessage(messages.limitExceededContentErrorMessage);
213
+ } else if (!valid) {
214
+ errorMessage = formatMessage(messages.invalidTagError);
215
+ }
216
+ updateErrorMessageTextArea(errorMessage);
217
+ };
218
+
219
+ // on change event of Text Area
220
+ const onTextContentChange = ({ target: { value } }) => {
221
+ updateTextMessageContent(value);
222
+ updateTextContentError(value);
223
+ };
224
+
225
+ const onTextTitleChange = ({ target: { value } }) => {
226
+ updateTextMessageTitle(value);
227
+ updateTextTitleError(value);
228
+ };
229
+
230
+ const updateTextTitleError = (value) => {
231
+ let errorMessage = false;
232
+ if (value === '') {
233
+ errorMessage = formatMessage(messages.emptyTitleErrorMessage);
234
+ }
235
+ updateErrorMessageTitle(errorMessage);
236
+ };
237
+ // Text Area container
238
+ const TextAreaViber = (<>
239
+ <TextArea
240
+ id={'viber_textarea'}
241
+ label={(
242
+ <>
243
+ <FormattedMessage {...messages.textMessage} />
244
+ <CapLabel
245
+ type="label2" style={{display: 'inline-block',
246
+ float: 'right'}}>
247
+ {(messageContent || '').length}/{charLimit} {" "}
248
+ <FormattedMessage {...messages.characters} />
249
+
250
+ </CapLabel>
251
+ </>
252
+ )}
253
+ autosize={false}
254
+ onChange={onTextContentChange}
255
+ className={`${errorMessageTextarea ? 'error' : ''}`}
256
+ errorMessage={errorMessageTextarea}
257
+ defaultValue={messageContent || ''}
258
+ value={messageContent || ''}
259
+ rows={5}
260
+ cols={2}
261
+ />
262
+ <TagList
263
+ key={'viber_tags'}
264
+ moduleFilterEnabled={location && location.query && location.query.type !== 'embedded'}
265
+ label={formatMessage(messages.addLabels)}
266
+ onTagSelect={onTagSelect}
267
+ onContextChange={handleOnTagsContextChange}
268
+ location={location}
269
+ tags={tags}
270
+ injectedTags={injectedTags || {}}
271
+ id={'viber_tags'}
272
+ userLocale={localStorage.getItem('jlocale') || 'en'}
273
+ />
274
+ </>);
275
+
276
+ // ******************** Text area Code End here ******************************
277
+
278
+ // ******************** Image section Code start here ******************************
279
+ useEffect(() => {
280
+ if (viber[`uploadedAssetData0`] && Object.keys(viber[`uploadedAssetData0`]).length) {
281
+ const imgSrc = get(viber, `uploadedAssetData0.metaInfo.secure_file_path`, '');
282
+ actions.clearViberAsset(0);
283
+ if (imgSrc) {
284
+ updateImageSrc(imgSrc);
285
+ updateImageStatus(true);
286
+ }
287
+ }
288
+ }, [viber[`uploadedAssetData0`]]);
289
+
290
+ const submitAction = (data, incorrectFile) => {
291
+ const {
292
+ file: {size},
293
+ fileParams: {
294
+ height,
295
+ width,
296
+ },
297
+ } = data;
298
+ if (incorrectFile || size > VIBER_IMG_SIZE || height > VIBER_IMG_HEIGHT || width > VIBER_IMG_WIDTH) {
299
+ updateImageErrorMessage(formatMessage(messages.viberImageIncorrectSize));
300
+ } else {
301
+ updateImageErrorMessage('');
302
+ actions.uploadViberAsset(
303
+ data.file,
304
+ data.type,
305
+ data.fileParams,
306
+ 0,
307
+ );
308
+ }
309
+ };
310
+
311
+ const uploadImages = (e, {files}) => {
312
+ if (e) {
313
+ e.preventDefault();
314
+ }
315
+ const _URL = window.URL || window.webkitURL;
316
+ let incorrectFile = false;
317
+ const file = files[0];
318
+ if (!ALLOWED_EXTENSIONS_REGEX.test(file.name)) {
319
+ incorrectFile = true;
320
+ }
321
+ const img = new Image();
322
+ img.src = _URL.createObjectURL(file);
323
+ img.onload = () => {
324
+ const fileParams = {
325
+ width: img.width,
326
+ height: img.height,
327
+ error: file && (file.size / (1e+6) > 3),
328
+ };
329
+ submitAction({file, type: 'image', fileParams}, incorrectFile);
330
+ };
331
+ if (e) {
332
+ const event = e;
333
+ event.target.value = null;
334
+ }
335
+ };
336
+
337
+ const ImageComponent = () => (<>
338
+ <CapHeader
339
+ title={formatMessage(messages.uploadImage)}
340
+ description={formatMessage(messages.imageDesc)}
341
+ size="regular"
342
+ />
343
+ <div
344
+ className={`image-container ${props.ifError ? 'error' : ''}`}
345
+ style={{
346
+ marginTop: 20,
347
+ backgroundColor: CAP_G09,
348
+ }}
349
+ >
350
+ {isImage && (<CapImage src={imageSrc} alt="viber-image-src" height="400" />)}
351
+ </div></>
352
+ );
353
+
354
+ const setDrawerVisibility = (drawervisibleFlag) => updateDrawerRequirement(drawervisibleFlag);
355
+
356
+ const onGalleryClick = (event) => {
357
+ event.stopPropagation();
358
+ setDrawerVisibility(true);
359
+ };
360
+
361
+ const capUploaderCustomRequest = (uploadData) => {
362
+ uploadImages(undefined, {files: [uploadData.file]});
363
+ };
364
+ const onReUpload = () => {
365
+ updateImageStatus(false);
366
+ // deleteUploadedImgList(index);
367
+ updateImageSrc('');
368
+ updateImagePreview('');
369
+ };
370
+ const getViberImageSection = () => {
371
+ if (!isImage) {
372
+ return (<>
373
+ <CapUploader.CapDragger
374
+ customRequest={capUploaderCustomRequest}
375
+ className="form-builder-dragger"
376
+ >
377
+ <CapHeading className="dragger-title" type="h7">
378
+ <FormattedMessage {...messages.dragAndDrop} />
379
+ </CapHeading>
380
+ <CapHeading className="dragger-or" type="label6">
381
+ <FormattedMessage {...messages.or} />
382
+ </CapHeading>
383
+ <CapButton className="dragger-button" type="secondary" style={{marginRight: CAP_SPACE_08}}>
384
+ <FormattedMessage {...messages.uploadComputer} />
385
+ </CapButton>
386
+ <CapButton
387
+ className="dragger-button"
388
+ type="secondary"
389
+ style={{marginLeft: CAP_SPACE_08}}
390
+ onClick={onGalleryClick}
391
+ >
392
+ <FormattedMessage {...messages.uploadGallery} />
393
+ </CapButton>
394
+ </CapUploader.CapDragger>
395
+ <div style={{marginTop: '15px' }}>
396
+ <CapHeadingSpan type="label2" style={{marginTop: CAP_SPACE_12, marginRight: '46px' }}>
397
+ <FormattedMessage {...messages.imageDimenstionDescription} />
398
+ </CapHeadingSpan>
399
+ <CapHeadingSpan type="label2" style={{marginTop: CAP_SPACE_12 }}>
400
+ <FormattedMessage {...messages.imageSizeDescription} />
401
+ </CapHeadingSpan>
402
+ </div>
403
+
404
+ </>
405
+ );
406
+ }
407
+ return (
408
+ <CapButton
409
+ className="dragger-button"
410
+ type="flat"
411
+ style={{
412
+ top: 0,
413
+ position: 'absolute',
414
+ right: 0,
415
+ color: FONT_COLOR_05,
416
+ }}
417
+ onClick={onReUpload}
418
+ >
419
+ <FormattedMessage {...messages.imageReUpload} />
420
+ </CapButton>
421
+ );
422
+ };
423
+
424
+ const getGalleryDrawerContent = () => {
425
+ const locationGallery = {
426
+ pathname: `/assets`,
427
+ search: '',
428
+ query: !isFullMode ? {type: 'embedded', module: 'library'} : {},
429
+ };
430
+ return (
431
+ <>
432
+ <CapHeading type="h3">
433
+ {formatMessage(messages.imageGallery)}
434
+ </CapHeading>
435
+ <Gallery
436
+ location={locationGallery}
437
+ isFullMode={isFullMode}
438
+ isLineAsset
439
+ onGalleryImageSelect={onGalleryImageSelect}
440
+ />
441
+ </>
442
+ );
443
+ };
444
+
445
+ const onGalleryImageSelect = (imageTemplate) => {
446
+ const image = get(imageTemplate, 'metaInfo.secure_file_path');
447
+ const imageURL = get(imageTemplate, 'metaInfo.secure_file_path_preview');
448
+ updateDrawerRequirement(false);
449
+ if (!ALLOWED_EXTENSIONS_REGEX.test(image)) {
450
+ updateImageErrorMessage(formatMessage(messages.viberImageIncorrectSize));
451
+ } else {
452
+ updateImageErrorMessage('');
453
+ updateImageStatus(true);
454
+ updateImageSrc(image);
455
+ updateImagePreview(imageURL);
456
+ }
457
+ };
458
+
459
+ const WithLabel = LabelHOC(ImageComponent);
460
+ const ImageViber = <>
461
+ <WithLabel
462
+ key={`viber-with-label`}
463
+ errorMessage={isImageError} ifError={!!isImageError}
464
+ />
465
+ <form encType="multipart/form-data" id={`viber_form`}>
466
+ <input
467
+ key={`viber_imgFile`}
468
+ style={{ display: 'none' }}
469
+ id="fileName"
470
+ type="file"
471
+ onChange={(e) => uploadImages(e, { files: e.target.files })}
472
+ accept={supportedExtensions || "image/*"}
473
+ />
474
+ {getViberImageSection()}
475
+ <CapDrawer
476
+ content={getGalleryDrawerContent()}
477
+ visible={isDrawerRequired}
478
+ width={430}
479
+ onClose={() => updateDrawerRequirement(false)}
480
+ />
481
+ </form>
482
+ </>;
483
+ // ******************** Image section End here ******************************
484
+
485
+
486
+ // ******************** Button Code start here ******************************
487
+
488
+ const onChangeButtonText = ({ target: { value } }) => {
489
+ updateButtonText(value);
490
+ };
491
+
492
+ const onChangeButtonUrl = ({ target: { value } }) => {
493
+ let errorMessage = false;
494
+ updateButtonUrl(value);
495
+ if (!isUrl(value)) {
496
+ errorMessage = formatMessage(messages.inValidUrliErrorMessage);
497
+ }
498
+ updateButtonURLErrorMessage(errorMessage);
499
+ };
500
+ const getPreviewSection = () =>
501
+ // const accountName = get(lineData, 'selectedLineAccount.name', '');
502
+ (
503
+ <TemplatePreview
504
+ channel="VIBER"
505
+ content={{imageURL: imagePreview, buttonText, messageContent}}
506
+ viberAccountName={((accountName[0] || "")).toUpperCase()}
507
+ viberBrandName={accountName}
508
+ />
509
+ );
510
+
511
+ const ButtonViber = (<>
512
+ <CapInput
513
+ id="viber-button-text"
514
+ type="input" onChange={onChangeButtonText}
515
+ label={formatMessage(messages.buttonText)}
516
+ defaultValue={buttonText}
517
+ value={buttonText}
518
+ style={{paddingBottom: '11px'}}
519
+ maxLength={20}
520
+ />
521
+ <CapInput
522
+ id="viber-button-url"
523
+ type="input"
524
+ onChange={onChangeButtonUrl}
525
+ defaultValue={buttonURL}
526
+ value={buttonURL}
527
+ label={formatMessage(messages.buttonUrl)}
528
+ errorMessage={buttonURLErrorMessage}
529
+ />
530
+ </>);
531
+
532
+ // ******************** Button Code End here ******************************
533
+ const formatSubmitPayload = () => {
534
+ const messageData = {
535
+ text: messageContent,
536
+ };
537
+ if (imageSrc) {
538
+ messageData.imageURL = imageSrc;
539
+ }
540
+ if (buttonText && buttonURL) {
541
+ messageData.buttonText = buttonText;
542
+ messageData.buttonURL = buttonURL;
543
+ }
544
+ return {
545
+ versions: {
546
+ base: {
547
+ content: {
548
+ destinations: [
549
+ {
550
+ to: {
551
+ phoneNumber: "{{viber_user_id}}",
552
+ },
553
+ },
554
+ ],
555
+ viber: {...messageData},
556
+ },
557
+ },
558
+ },
559
+ type: "VIBER",
560
+ name: messageTitle,
561
+ };
562
+ };
563
+
564
+ const createCallback = (errorMessage, isEdit) => {
565
+ if (!errorMessage) {
566
+ CapNotification.success({
567
+ message: isEdit ? formatMessage(messages.viberEditNotification) : formatMessage(messages.viberCreateNotification),
568
+ });
569
+ if (isEdit) {
570
+ actions.clearEditResponse();
571
+ } else {
572
+ actions.clearCreateResponse();
573
+ }
574
+ } else {
575
+ CapNotification.error({
576
+ message: errorMessage,
577
+ });
578
+ }
579
+ };
580
+
581
+ const onCreateViber = () => {
582
+ actions.createTemplate(
583
+ formatSubmitPayload(),
584
+ (resp, errorMessage) => {
585
+ createCallback(errorMessage);
586
+ onCreateComplete();
587
+ }
588
+ );
589
+ };
590
+
591
+ const onEditViber = () => {
592
+ actions.editTemplate(
593
+ {
594
+ ...formatSubmitPayload(),
595
+ _id: params.id,
596
+ },
597
+ (resp, errorMessage) => {
598
+ createCallback(errorMessage, true);
599
+ onCreateComplete();
600
+ });
601
+ };
602
+
603
+ const onDoneCallback = () => {
604
+ if (isFullMode) {
605
+ if (isEditFlow) {
606
+ return onEditViber;
607
+ }
608
+ return onCreateViber;
609
+ }
610
+ return () => getFormSubscriptionData({
611
+ value: formatSubmitPayload(),
612
+ _id: params && params.id,
613
+ validity: true,
614
+ type: 'VIBER',
615
+ });
616
+ };
617
+
618
+ const isDisableDone = () => {
619
+ // textbox area should not empty and should have max 1000 charactor
620
+ if (messageContent.trim() === '' || errorMessageTextarea) {
621
+ return true;
622
+ }
623
+ // cannot send text + image only messages, Need to add button details or remove one of the components in order to proceed
624
+ const trimedButtonText = buttonText.trim();
625
+ const trimedButtonUrl = buttonURL.trim();
626
+ if (messageContent !== '' && imageSrc && (trimedButtonUrl === '' && trimedButtonUrl === '')) {
627
+ return true;
628
+ }
629
+ // if button is being added than button url and button Text both are mandatory
630
+ if (( trimedButtonText === '' && trimedButtonUrl !== '') || ( trimedButtonText !== '' && trimedButtonUrl === '')) {
631
+ return true;
632
+ }
633
+ // if button url is not valid url
634
+ if (buttonURLErrorMessage) {
635
+ return true;
636
+ }
637
+ return false;
638
+ };
639
+
640
+ return (
641
+ <>
642
+ <CapSpin spinning={isEditLoading}>
643
+ <CapRow>
644
+ <CapColumn span={14}>
645
+ <StyledHeader
646
+ title={formatMessage(messages.viberCreativeTitle)}
647
+ size="regular"
648
+ />
649
+ {
650
+ isFullMode
651
+ ? (
652
+ <CapInput
653
+ id={`viber_input`}
654
+ onChange={onTextTitleChange}
655
+ errorMessage={errorMessageTitle}
656
+ className="text-template-title"
657
+ placeholder={formatMessage(messages.textMessageTitlePlaceholder)}
658
+ defaultValue={messageTitle || ''}
659
+ value={messageTitle || ''}
660
+ size="default"
661
+ label={formatMessage(messages.textMessageTitleLabel)}
662
+ style={{marginBottom: 20}}
663
+ />
664
+ )
665
+ : null
666
+ }
667
+ {container("message", <FormattedMessage {...messages.message} />, TextAreaViber, false)}
668
+ {container("image", <FormattedMessage {...messages.image} />, ImageViber, true)}
669
+ {container("button", <FormattedMessage {...messages.button} />, ButtonViber, true)}
670
+ <div style={{marginBottom: '100px'}}/>
671
+ </CapColumn>
672
+ <CapColumn span={6}>
673
+ <CapRow>
674
+ <CapColumn span={23} offset={6}>
675
+ {getPreviewSection()}
676
+ <CapHeading
677
+ type="h3"
678
+ style={{margin: '24px 0px 0px 28px'}}
679
+ >
680
+ <FormattedMessage {...messages.message} />: {" "}
681
+ ({(messageContent || '').length}/{charLimit} {" "}
682
+ <FormattedMessage {...messages.characters} />)
683
+ </CapHeading>
684
+ </CapColumn>
685
+ </CapRow>
686
+ </CapColumn>
687
+ </CapRow>
688
+ <ViberFooter>
689
+ <CapButton
690
+ onClick={onDoneCallback()}
691
+ disabled={isDisableDone()}
692
+ className="create-msg"
693
+ >
694
+ <FormattedMessage {...messages.doneButtonLabel} />
695
+ </CapButton>
696
+ <CapButton
697
+ onClick={handleClose}
698
+ className="cancel-msg"
699
+ type="secondary"
700
+ >
701
+ <FormattedMessage {...messages.cancelButtonLabel} />
702
+ </CapButton>
703
+ </ViberFooter>
704
+ </CapSpin>
705
+
706
+ </>
707
+ );
708
+ };
709
+
710
+ const mapStateToProps = createStructuredSelector({
711
+ metaEntities: makeSelectMetaEntities(),
712
+ injectedTags: setInjectedTags(),
713
+ viberData: makeSelectViber(),
714
+ viber: makeSelectCreateViber(),
715
+ });
716
+
717
+ const mapDispatchToProps = (dispatch) => ({
718
+ actions: bindActionCreators(viberActions, dispatch),
719
+ });
720
+
721
+
722
+ export default withCreatives({
723
+ WrappedComponent: injectIntl(Viber),
724
+ mapStateToProps,
725
+ mapDispatchToProps,
726
+ userAuth: true,
727
+ });