@capillarytech/creatives-library 7.0.1 → 7.0.4

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