@capillarytech/creatives-library 7.10.40 → 7.10.41

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.
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable no-undef */
2
- import React, { useState } from 'react';
2
+ import React, { useState, useEffect } from 'react';
3
3
  import { bindActionCreators } from 'redux';
4
4
  import { createStructuredSelector } from 'reselect';
5
5
  import { injectIntl, FormattedMessage } from 'react-intl';
6
+ import { get, isEmpty, cloneDeep } from 'lodash';
6
7
  import styled from 'styled-components';
7
8
  import CapSpin from '@capillarytech/cap-ui-library/CapSpin';
8
9
  import CapRow from '@capillarytech/cap-ui-library/CapRow';
@@ -15,8 +16,11 @@ import CapHeading from '@capillarytech/cap-ui-library/CapHeading';
15
16
  import CapRadioGroup from '@capillarytech/cap-ui-library/CapRadioGroup';
16
17
  import CapTooltip from '@capillarytech/cap-ui-library/CapTooltip';
17
18
  import CapError from '@capillarytech/cap-ui-library/CapError';
19
+ import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
18
20
  import CapButton from '@capillarytech/cap-ui-library/CapButton';
19
21
  import CapNotification from '@capillarytech/cap-ui-library/CapNotification';
22
+ import CapAlert from '@capillarytech/cap-ui-library/CapAlert';
23
+ import moment from 'moment';
20
24
  import {
21
25
  CAP_SPACE_04,
22
26
  CAP_SPACE_16,
@@ -24,7 +28,7 @@ import {
24
28
  CAP_SPACE_32,
25
29
  CAP_WHITE,
26
30
  } from '@capillarytech/cap-ui-library/styled/variables';
27
- import {} from './selectors';
31
+ import { makeSelectWhatsapp, makeSelectAccount } from './selectors';
28
32
  import * as WhatsappActions from './actions';
29
33
  import './index.scss';
30
34
  import {
@@ -32,28 +36,42 @@ import {
32
36
  TEMPLATE_MESSAGE_MAX_LENGTH,
33
37
  WHATSAPP,
34
38
  CATEGORY_OPTIONS,
39
+ WHATSAPP_STATUSES,
40
+ TAG,
41
+ EMBEDDED,
42
+ DEFAULT,
43
+ FULL,
44
+ ALL,
45
+ LIBRARY,
35
46
  } from './constants';
36
47
  import messages from './messages';
37
48
  import withCreatives from '../../hoc/withCreatives';
38
49
  import TemplatePreview from '../../v2Components/TemplatePreview';
50
+ import TagList from '../TagList';
51
+ import { makeSelectMetaEntities, setInjectedTags } from '../Cap/selectors';
52
+
53
+ let varMap = {};
54
+ let editContent = {};
39
55
 
40
56
  export const Whatsapp = (props) => {
41
57
  const {
42
58
  intl,
59
+ actions,
43
60
  isFullMode,
61
+ onCreateComplete,
44
62
  handleClose,
63
+ params,
64
+ templateData = {},
65
+ editData = {},
66
+ accountData = {},
67
+ globalActions,
45
68
  location,
46
- actions,
47
- onCreateComplete,
48
- selectedWeChatAccount = {},
69
+ getDefaultTags,
70
+ supportedTags,
71
+ metaEntities,
72
+ injectedTags,
49
73
  } = props || {};
50
74
  const { formatMessage } = intl;
51
- const {
52
- name: accountName = '',
53
- configs: accountConfigs = {},
54
- sourceAccountIdentifier: accountId = '',
55
- } = selectedWeChatAccount;
56
- const { accessToken = '' } = accountConfigs;
57
75
  const { TextArea } = CapInput;
58
76
  const [templateName, setTemplateName] = useState('');
59
77
  const [templateNameError, setTemplateNameError] = useState(false);
@@ -63,11 +81,23 @@ export const Whatsapp = (props) => {
63
81
  const [templateMessage, setTemplateMessage] = useState('');
64
82
  const [templateMessageError, setTemplateMessageError] = useState(false);
65
83
  const [addedVarCount, setAddedVarCount] = useState(0);
84
+ const [accountId, setAccountId] = useState('');
85
+ const [accessToken, setAccessToken] = useState('');
86
+ const [accountName, setAccountName] = useState('');
66
87
  const [spin, setSpin] = useState(false);
88
+ //for edit only
89
+ const [isEditFlow, setEditFlow] = useState(false);
90
+ const [templateDate, setTemplateDate] = useState('');
91
+ const [templateStatus, setTemplateStatus] = useState(
92
+ WHATSAPP_STATUSES.unsubmitted,
93
+ );
94
+ const [tempMsgArray, updateTempMsgArray] = useState([]);
95
+ const [updatedSmsEditor, setUpdatedSmsEditor] = useState([]);
96
+ //for tag only
97
+ const [tags, updateTags] = useState([]);
98
+ const [textAreaId, updateTextAreaId] = useState();
67
99
 
68
- const StyledSelect = styled(CapSelect)`
69
- margin-top: ${CAP_SPACE_16};
70
- `;
100
+ const validVarRegex = /{{([1-9]|1[0-9])}}/g;
71
101
 
72
102
  const WhatsappFooter = styled.div`
73
103
  background-color: ${CAP_WHITE};
@@ -82,7 +112,171 @@ export const Whatsapp = (props) => {
82
112
  }
83
113
  }
84
114
  `;
115
+ //edit
116
+ //gets account details
117
+ useEffect(() => {
118
+ const accountObj = accountData.selectedWhatsappAccount || {};
119
+ if (!isEmpty(accountObj)) {
120
+ setAccountId(get(accountObj, `sourceAccountIdentifier`, ''));
121
+ setAccessToken(get(accountObj, `configs.accessToken`, ''));
122
+ setAccountName(get(accountObj, `name`, ''));
123
+ }
124
+ }, [accountData.selectedWhatsappAccount]);
125
+
126
+ //gets template details
127
+ const paramObj = params || {};
128
+ useEffect(() => {
129
+ const { id } = paramObj;
130
+ if (id && !get(templateData, `versions.base.content`)) {
131
+ setSpin(true);
132
+ actions.getTemplateDetails(id);
133
+ setEditFlow(true);
134
+ }
135
+ //cleanup code
136
+ return () => {
137
+ actions.resetEditTemplate();
138
+ varMap = {};
139
+ };
140
+ }, [paramObj.id]);
141
+
142
+ useEffect(() => {
143
+ editContent =
144
+ get(templateData, `versions.base.content.whatsapp`) ||
145
+ get(editData, `templateDetails.versions.base.content.whatsapp`) ||
146
+ {};
147
+ if (editContent && !isEmpty(editContent)) {
148
+ const editMessageTitle =
149
+ (templateData || {}).name || get(editData, 'templateDetails.name');
150
+ const createdAt =
151
+ (templateData || {}).createdAt ||
152
+ get(editData, 'templateDetails.createdAt');
153
+ setTemplateName(editMessageTitle);
154
+ setTemplateDate(createdAt);
155
+ setTemplateCategory(get(editContent, `category`, ''));
156
+ setTemplateStatus(
157
+ get(editContent, `status`, WHATSAPP_STATUSES.unsubmitted),
158
+ );
159
+ computeTempMsgArray();
160
+ }
161
+ }, [editData.templateDetails || templateData]);
85
162
 
163
+ const computeTempMsgArray = () => {
164
+ let msg = get(editContent, `languages[0].content`, '');
165
+ const validVarArr = msg.match(validVarRegex) || [];
166
+ const templateMessageArray = [];
167
+ msg = msg.slice(2, -1);
168
+ msg = msg.replace(
169
+ `Click ${validVarArr[validVarArr.length - 1]} to unsubscribe`,
170
+ '',
171
+ );
172
+ validVarArr.pop();
173
+ while (msg.length !== 0) {
174
+ const index = msg.indexOf(validVarArr[0]);
175
+ if (index !== -1) {
176
+ templateMessageArray.push(msg.substring(0, index));
177
+ templateMessageArray.push(validVarArr[0]);
178
+ msg = msg.substring(index + validVarArr[0].length, msg.length);
179
+ validVarArr.shift();
180
+ } else {
181
+ templateMessageArray.push(msg);
182
+ break;
183
+ }
184
+ }
185
+ updateTempMsgArray(templateMessageArray.filter((i) => i === 0 || i));
186
+ //stop spinner
187
+ setSpin(false);
188
+ };
189
+
190
+ useEffect(() => {
191
+ if (tempMsgArray.length !== 0) {
192
+ const { varMapped = {} } = editContent;
193
+ if (!isEmpty(varMapped)) {
194
+ varMap = cloneDeep(varMapped);
195
+ } else {
196
+ //computing and setting varMap for first edit
197
+ for (let i = 0; i < tempMsgArray.length; i += 1) {
198
+ if (tempMsgArray[i].match(validVarRegex)?.length > 0) {
199
+ varMap[`${tempMsgArray[i]}_${i}`] = '';
200
+ }
201
+ }
202
+ }
203
+ //setting updatedSmsEditor based on varMap
204
+ const arr = [...tempMsgArray];
205
+ for (const key in varMap) {
206
+ if (varMap[key] !== '') {
207
+ arr[key.slice(key.indexOf('_') + 1)] = varMap[key];
208
+ }
209
+ }
210
+ setUpdatedSmsEditor(arr);
211
+ }
212
+ }, [tempMsgArray]);
213
+
214
+ // tag Code start from here
215
+ useEffect(() => {
216
+ //fetching tags
217
+ const { type, module } = location.query || {};
218
+ const isEmbedded = type === EMBEDDED;
219
+ const query = {
220
+ layout: 'SMS',
221
+ type: TAG,
222
+ context: isEmbedded ? module : DEFAULT,
223
+ embedded: isEmbedded ? type : FULL,
224
+ };
225
+ if (getDefaultTags) {
226
+ query.context = getDefaultTags;
227
+ }
228
+ globalActions.fetchSchemaForEntity(query);
229
+ }, []);
230
+
231
+ useEffect(() => {
232
+ let tag =
233
+ metaEntities && metaEntities.tags ? metaEntities.tags.standard : [];
234
+ const { type, module } = location.query || {};
235
+ if (type === EMBEDDED && module === LIBRARY && !getDefaultTags) {
236
+ tag = supportedTags;
237
+ }
238
+ updateTags(tag);
239
+ }, [metaEntities]);
240
+
241
+ const handleOnTagsContextChange = (data) => {
242
+ const { type } = location.query || {};
243
+ const isEmbedded = type === EMBEDDED;
244
+ const query = {
245
+ layout: 'SMS',
246
+ type: TAG,
247
+ context:
248
+ (data || '').toLowerCase() === ALL
249
+ ? DEFAULT
250
+ : (data || '').toLowerCase(),
251
+ embedded: isEmbedded ? type : FULL,
252
+ };
253
+ globalActions.fetchSchemaForEntity(query);
254
+ };
255
+
256
+ const onTagSelect = (data) => {
257
+ if (varMap && updatedSmsEditor) {
258
+ let numId = Number(textAreaId?.slice(textAreaId?.indexOf('_') + 1));
259
+ if (numId !== NaN) {
260
+ const arr = [...updatedSmsEditor];
261
+ //when trying to insert tag in empty textarea,{#var#} is replaced with "" and then tag is added
262
+ if (arr[numId]?.match(validVarRegex)?.length > 0) {
263
+ arr[numId] = '';
264
+ }
265
+ const messageData = `${arr[numId]}{{${data}}}`;
266
+ arr[numId] = messageData;
267
+ varMap[textAreaId] = messageData;
268
+ setUpdatedSmsEditor(arr);
269
+ }
270
+ }
271
+ };
272
+
273
+ //setting the id of currently selected text area, is used onTagSelect
274
+ const setTextAreaId = ({ target: { id } }) => {
275
+ updateTextAreaId(id);
276
+ };
277
+ // tag Code end
278
+
279
+ //create methods start
86
280
  const renderTemplateCategoryLabel = (tooltipLabel, title) => (
87
281
  <CapRow>
88
282
  <CapColumn span={23}>{title}</CapColumn>
@@ -129,6 +323,43 @@ export const Whatsapp = (props) => {
129
323
  },
130
324
  ];
131
325
 
326
+ const renderLabel = (value) => (
327
+ <CapHeading type="h4" className="whatsapp-render-heading">
328
+ {formatMessage(messages[value])}
329
+ </CapHeading>
330
+ );
331
+
332
+ const renderUnsubscribeText = () => (
333
+ <>
334
+ <CapColumn span={12}>
335
+ <CapTooltip
336
+ placement="bottom"
337
+ title={formatMessage(messages.unsubscribeTextTooltip)}
338
+ >
339
+ <CapHeading
340
+ className={
341
+ !isEditFlow
342
+ ? 'whatsapp-create-render-unsubscribe-text'
343
+ : 'whatsapp-edit-render-unsubscribe-text'
344
+ }
345
+ >
346
+ {formatMessage(messages.templateMessageUnsubscribeText)}
347
+ </CapHeading>
348
+ </CapTooltip>
349
+ </CapColumn>
350
+ <CapColumn span={12}></CapColumn>
351
+ </>
352
+ );
353
+
354
+ const renderMessageLength = () => (
355
+ <CapHeading type="h6" className="whatsapp-render-message-length">
356
+ {formatMessage(messages.templateMessageLength, {
357
+ currentLength: UNSUBSCRIBE_TEXT_LENGTH + templateMessage?.length,
358
+ maxLength: TEMPLATE_MESSAGE_MAX_LENGTH,
359
+ })}
360
+ </CapHeading>
361
+ );
362
+
132
363
  const onTemplateNameChange = ({ target: { value } }) => {
133
364
  setTemplateName(value);
134
365
  templateNameErrorHandler(value);
@@ -149,11 +380,6 @@ export const Whatsapp = (props) => {
149
380
  const onTemplateCategoryChange = (value) => {
150
381
  setTemplateCategory(value);
151
382
  };
152
- const renderHeading = (value) => (
153
- <CapHeading type="h4" className="whatsapp-render-heading">
154
- {formatMessage(messages[value])}
155
- </CapHeading>
156
- );
157
383
 
158
384
  const onTemplateMessageChange = ({ target: { value } }) => {
159
385
  const error = templateMessageErrorHandler(value);
@@ -171,7 +397,6 @@ export const Whatsapp = (props) => {
171
397
  ) {
172
398
  errorMessage = formatMessage(messages.templateMessageLengthError);
173
399
  } else {
174
- const validVarRegex = /{{([1-9]|1[0-9])}}/g;
175
400
  const validVarArr = value.match(validVarRegex) || [];
176
401
  const validVarSet = [...new Set(validVarArr)];
177
402
 
@@ -179,7 +404,7 @@ export const Whatsapp = (props) => {
179
404
  const invalidVarArr = value.match(invalidVarRegex) || [];
180
405
  const invalidVarSet = [...new Set(invalidVarArr)];
181
406
 
182
- const spamVar = /}}[^a-zA-Z]*{{/g;
407
+ const noContentBetweenVars = /}}[^a-zA-Z]*{{/g;
183
408
 
184
409
  if (validVarArr?.length > 0 || invalidVarArr?.length > 0) {
185
410
  if (validVarArr?.length !== validVarSet?.length) {
@@ -188,7 +413,7 @@ export const Whatsapp = (props) => {
188
413
  } else if (invalidVarSet?.length !== validVarSet?.length) {
189
414
  //checks for invalid vars like Hi {{abcd}}, offer for you {{^_^}}
190
415
  errorMessage = formatMessage(messages.unknownVars);
191
- } else if (value.match(spamVar)?.length > 0) {
416
+ } else if (value.match(noContentBetweenVars)?.length > 0) {
192
417
  //checks for text between vars like Hi {{1}}{{2}}
193
418
  errorMessage = formatMessage(messages.noContentBetweenVars);
194
419
  } else {
@@ -207,44 +432,6 @@ export const Whatsapp = (props) => {
207
432
  return errorMessage;
208
433
  };
209
434
 
210
- const renderUnsubscribeText = () => (
211
- <>
212
- <CapColumn span={12}>
213
- <CapTooltip
214
- placement="bottom"
215
- title={formatMessage(messages.unsubscribeTextTooltip)}
216
- >
217
- <CapHeading className="whatsapp-render-unsubscribe-text">
218
- {formatMessage(messages.templateMessageUnsubscribeText)}
219
- </CapHeading>
220
- </CapTooltip>
221
- </CapColumn>
222
- <CapColumn span={12}></CapColumn>
223
- </>
224
- );
225
-
226
- const renderMessageLength = () => (
227
- <CapHeading type="h6" className="whatsapp-render-message-length">
228
- {formatMessage(messages.templateMessageLength, {
229
- currentLength: UNSUBSCRIBE_TEXT_LENGTH + templateMessage?.length,
230
- maxLength: TEMPLATE_MESSAGE_MAX_LENGTH,
231
- })}
232
- </CapHeading>
233
- );
234
-
235
- const generateVarMapped = () => {
236
- const varMappedObj = {};
237
- const finalIndex = addedVarCount + 1;
238
- for (let i = 1; i <= finalIndex; i += 1) {
239
- if (i === addedVarCount + 1) {
240
- varMappedObj[i] = '{{unsubscribe}}';
241
- } else {
242
- varMappedObj[i] = '';
243
- }
244
- }
245
- return varMappedObj;
246
- };
247
-
248
435
  const createPayload = () => ({
249
436
  name: templateName,
250
437
  versions: {
@@ -261,7 +448,7 @@ export const Whatsapp = (props) => {
261
448
  },
262
449
  ],
263
450
  mediaType: 'text',
264
- 'var-mapped': generateVarMapped(),
451
+ varMapped: {},
265
452
  accountId,
266
453
  accessToken,
267
454
  accountName,
@@ -322,10 +509,261 @@ export const Whatsapp = (props) => {
322
509
  return false;
323
510
  };
324
511
 
512
+ const createModeContent = (
513
+ <>
514
+ {/* template name */}
515
+ <CapHeader
516
+ title={
517
+ <CapHeading type="h4">
518
+ {formatMessage(messages.templateNameLabel)}
519
+ <CapTooltipWithInfo
520
+ infoIconProps={{
521
+ style: { marginLeft: CAP_SPACE_04 },
522
+ }}
523
+ autoAdjustOverflow
524
+ title={<FormattedMessage {...messages.templateNameTooltip} />}
525
+ />
526
+ </CapHeading>
527
+ }
528
+ description={
529
+ <CapLabel className="whatsapp-template-name-desc">
530
+ {formatMessage(messages.templateNameDesc)}
531
+ </CapLabel>
532
+ }
533
+ />
534
+ <CapInput
535
+ id={`whatsapp_template_name_input`}
536
+ onChange={onTemplateNameChange}
537
+ errorMessage={templateNameError}
538
+ placeholder={formatMessage(messages.templateNamePlaceholder)}
539
+ defaultValue={templateName || ''}
540
+ value={templateName || ''}
541
+ size="default"
542
+ />
543
+ {/* template category */}
544
+ {renderLabel('templateCategoryLabel')}
545
+ <CapSelect
546
+ id={'select-whatsapp-category'}
547
+ options={templateCategoryOptions || []}
548
+ onChange={onTemplateCategoryChange}
549
+ value={templateCategory}
550
+ />
551
+ {/* template language */}
552
+ {renderLabel('messageLanguageLabel')}
553
+ <CapInput
554
+ id={`whatsapp_template_language_input`}
555
+ defaultValue={'English'}
556
+ size="default"
557
+ disabled={true}
558
+ />
559
+ {/* template mdeia type */}
560
+ {renderLabel('mediaLabel')}
561
+ <CapRadioGroup options={mediaRadioOptions || []} defaultValue={'text'} />
562
+ {/* template message create flow */}
563
+ <CapHeading type="h4" className="whatsapp-render-heading">
564
+ {formatMessage(messages.templateMessageLabel)}
565
+ <CapTooltipWithInfo
566
+ placement="right"
567
+ infoIconProps={{
568
+ style: { marginLeft: CAP_SPACE_04 },
569
+ }}
570
+ autoAdjustOverflow
571
+ title={
572
+ <FormattedMessage
573
+ {...messages.templateMessageTooltip}
574
+ values={{
575
+ br: <br />,
576
+ var: '{{1}}',
577
+ }}
578
+ />
579
+ }
580
+ />
581
+ </CapHeading>
582
+ <CapRow className="whatsapp-create-template-message-input">
583
+ <TextArea
584
+ id={`whatsapp-create-template-message-input`}
585
+ autosize={{ minRows: 3, maxRows: 5 }}
586
+ placeholder={formatMessage(messages.templateMessagePlaceholder)}
587
+ onChange={onTemplateMessageChange}
588
+ errorMessage={
589
+ templateMessageError && (
590
+ <CapError className="whatsapp-template-message-error">
591
+ {templateMessageError}
592
+ </CapError>
593
+ )
594
+ }
595
+ value={templateMessage || ''}
596
+ />
597
+ {renderUnsubscribeText()}
598
+ </CapRow>
599
+ {renderMessageLength()}
600
+ </>
601
+ );
602
+ //create methods end
603
+
604
+ //edit methods start
605
+ const getAlertType = () => {
606
+ if (templateStatus === WHATSAPP_STATUSES.approved) {
607
+ return 'success';
608
+ } else if (templateStatus === WHATSAPP_STATUSES.rejected) {
609
+ return 'error';
610
+ }
611
+ return 'warning';
612
+ };
613
+
614
+ const getAlertMessage = () => {
615
+ if (templateStatus === WHATSAPP_STATUSES.approved) {
616
+ return (
617
+ <CapLabel type="label2">
618
+ {formatMessage(messages.approvedStatusMsg)}
619
+ </CapLabel>
620
+ );
621
+ } else if (templateStatus === WHATSAPP_STATUSES.rejected) {
622
+ return (
623
+ <CapLabel type="label2">
624
+ {formatMessage(messages.rejectedStatusMsg)}
625
+ </CapLabel>
626
+ );
627
+ }
628
+ return (
629
+ <>
630
+ <CapLabel type="label2" style={{ fontWeight: 500 }}>
631
+ {formatMessage(messages.awaitingStatusMsg)}
632
+ </CapLabel>
633
+ <CapLabel
634
+ type="label2"
635
+ style={{ marginTop: CAP_SPACE_04, marginBottom: CAP_SPACE_04 }}
636
+ >
637
+ {formatMessage(messages.awaitingStatusDesc, {
638
+ date: moment(templateDate).format('D MMM YYYY'),
639
+ time: moment(templateDate).format('hh:mm A'),
640
+ })}
641
+ </CapLabel>
642
+ </>
643
+ );
644
+ };
645
+
646
+ // on change event of Text Area
647
+ const textAreaValueChange = ({ target: { value, id } }) => {
648
+ const numId = Number(id.slice(id.indexOf('_') + 1));
649
+ const arr = [...updatedSmsEditor];
650
+
651
+ //assign entered value to varMap
652
+ varMap[id] = value;
653
+ //based on entered value update updatedSmsEditor
654
+ if (value === '') {
655
+ arr[numId] = id.slice(0, id.indexOf('_'));
656
+ } else {
657
+ arr[numId] = value;
658
+ }
659
+ setUpdatedSmsEditor(arr);
660
+ };
661
+
662
+ const textAreaValue = (idValue) => {
663
+ if (idValue >= 0 && updatedSmsEditor) {
664
+ const value = updatedSmsEditor[idValue];
665
+ if (value && (value.match(validVarRegex) || []).length === 0) {
666
+ return value;
667
+ }
668
+ return '';
669
+ }
670
+ return '';
671
+ };
672
+
673
+ const renderedEditMessage = () => {
674
+ const renderArray = [];
675
+ if (tempMsgArray?.length !== 0) {
676
+ let varCount = 0;
677
+ tempMsgArray.forEach((elem, index) => {
678
+ if (elem.match(validVarRegex)?.length > 0) {
679
+ varCount += 1;
680
+ renderArray.push(
681
+ <TextArea
682
+ id={`${elem}_${index}`}
683
+ key={`${elem}_${index}`}
684
+ placeholder={formatMessage(messages.inputplaceHolderText, {
685
+ value: `{{${varCount}}}`,
686
+ })}
687
+ autosize={{ minRows: 1, maxRows: 3 }}
688
+ onChange={textAreaValueChange}
689
+ value={textAreaValue(index)}
690
+ onFocus={setTextAreaId}
691
+ disabled={templateStatus !== WHATSAPP_STATUSES.approved}
692
+ />,
693
+ );
694
+ } else {
695
+ renderArray.push(
696
+ <CapHeading
697
+ key={`${elem}_${index}`}
698
+ type="h4"
699
+ className="whatsapp-edit-template-message-heading"
700
+ >
701
+ {elem}
702
+ </CapHeading>,
703
+ );
704
+ }
705
+ });
706
+ }
707
+ renderArray.push(renderUnsubscribeText());
708
+ return renderArray;
709
+ };
710
+
711
+ const editModeContent = (
712
+ <>
713
+ <CapAlert message={getAlertMessage()} type={getAlertType()} />
714
+ <CapRow className="whatsapp-render-heading">
715
+ <CapHeader
716
+ title={
717
+ <CapHeading type="h4">
718
+ {formatMessage(messages.templateMessageLabel)}
719
+ </CapHeading>
720
+ }
721
+ suffix={
722
+ templateStatus === WHATSAPP_STATUSES.approved && (
723
+ <TagList
724
+ label={formatMessage(messages.addLabels)}
725
+ onTagSelect={onTagSelect}
726
+ location={location}
727
+ tags={tags || []}
728
+ onContextChange={handleOnTagsContextChange}
729
+ injectedTags={injectedTags || {}}
730
+ />
731
+ )
732
+ }
733
+ />
734
+ </CapRow>
735
+ <CapTooltip
736
+ title={
737
+ templateStatus === WHATSAPP_STATUSES.approved
738
+ ? ''
739
+ : templateStatus === WHATSAPP_STATUSES.rejected
740
+ ? formatMessage(messages.disabledEditTooltip, {
741
+ status: templateStatus,
742
+ })
743
+ : formatMessage(messages.disabledEditTooltip, {
744
+ status: 'awaiting for approval',
745
+ })
746
+ }
747
+ >
748
+ <CapRow
749
+ className={`whatsapp-edit-template-message-input ${
750
+ templateStatus !== WHATSAPP_STATUSES.approved &&
751
+ 'whatsapp-edit-disabled'
752
+ }`}
753
+ >
754
+ {renderedEditMessage()}
755
+ </CapRow>
756
+ </CapTooltip>
757
+
758
+ {renderMessageLength()}
759
+ </>
760
+ );
761
+ //edit methods end
762
+
325
763
  const getPreviewSection = () => {
326
- const templateMsg = `${templateMessage}\n${formatMessage(
327
- messages.templateMessageUnsubscribeText,
328
- )}`;
764
+ const templateMsg = `${
765
+ isEditFlow ? updatedSmsEditor.join('') : templateMessage
766
+ }\n${formatMessage(messages.templateMessageUnsubscribeText)}`;
329
767
  return (
330
768
  <TemplatePreview
331
769
  channel={WHATSAPP}
@@ -334,101 +772,16 @@ export const Whatsapp = (props) => {
334
772
  />
335
773
  );
336
774
  };
775
+
337
776
  return (
338
777
  <CapSpin spinning={spin}>
339
778
  <CapRow>
340
779
  <CapColumn span={14}>
341
- <CapInput
342
- id={`whatsapp_template_name_input`}
343
- onChange={onTemplateNameChange}
344
- errorMessage={templateNameError}
345
- placeholder={formatMessage(messages.templateNamePlaceholder)}
346
- defaultValue={templateName || ''}
347
- value={templateName || ''}
348
- size="default"
349
- label={
350
- <CapHeader
351
- title={
352
- <>
353
- {formatMessage(messages.templateNameLabel)}
354
- <CapTooltipWithInfo
355
- infoIconProps={{
356
- style: { marginLeft: CAP_SPACE_04 },
357
- }}
358
- autoAdjustOverflow
359
- title={
360
- <FormattedMessage {...messages.templateNameTooltip} />
361
- }
362
- />
363
- </>
364
- }
365
- description={formatMessage(messages.templateNameDesc)}
366
- size="regular"
367
- />
368
- }
369
- />
370
- <StyledSelect
371
- id={'select-whatsapp-category'}
372
- label={formatMessage(messages.templateCategoryLabel)}
373
- options={templateCategoryOptions || []}
374
- onChange={onTemplateCategoryChange}
375
- value={templateCategory}
376
- />
377
- {renderHeading('messageLanguageLabel')}
378
- <CapInput
379
- id={`whatsapp_template_language_input`}
380
- defaultValue={'English'}
381
- size="default"
382
- disabled={true}
383
- />
384
- {renderHeading('mediaLabel')}
385
- <CapRadioGroup
386
- options={mediaRadioOptions || []}
387
- defaultValue={'text'}
388
- />
389
- <CapHeading type="h4" className="whatsapp-render-heading">
390
- <>
391
- {formatMessage(messages.templateMessageLabel)}
392
- <CapTooltipWithInfo
393
- placement="right"
394
- infoIconProps={{
395
- style: { marginLeft: CAP_SPACE_04 },
396
- }}
397
- autoAdjustOverflow
398
- title={
399
- <FormattedMessage
400
- {...messages.templateMessageTooltip}
401
- values={{
402
- br: <br />,
403
- var: '{{1}}',
404
- }}
405
- />
406
- }
407
- />
408
- </>
409
- </CapHeading>
410
- <CapRow className="whatsapp-template-message-input">
411
- <TextArea
412
- id={`whatsapp-template-message-input`}
413
- autosize={{ minRows: 3, maxRows: 5 }}
414
- placeholder={formatMessage(messages.templateMessagePlaceholder)}
415
- onChange={onTemplateMessageChange}
416
- errorMessage={
417
- templateMessageError && (
418
- <CapError className="whatsapp-template-message-error">
419
- {templateMessageError}
420
- </CapError>
421
- )
422
- }
423
- value={templateMessage || ''}
424
- />
425
- {renderUnsubscribeText()}
426
- </CapRow>
427
- {renderMessageLength()}
780
+ {isEditFlow ? editModeContent : createModeContent}
428
781
  <div className="whatsapp-scroll-div" />
429
782
  </CapColumn>
430
783
  <CapColumn span={6}>
431
- <CapRow>
784
+ <CapRow className={isEditFlow ? 'whatsapp-edit-alert-margin' : ''}>
432
785
  <CapColumn span={24} offset={9}>
433
786
  {getPreviewSection()}
434
787
  </CapColumn>
@@ -436,26 +789,35 @@ export const Whatsapp = (props) => {
436
789
  </CapColumn>
437
790
  </CapRow>
438
791
  <WhatsappFooter>
439
- <CapButton
440
- onClick={onDoneCallback()}
441
- disabled={isDisableDone()}
442
- className="whatsapp-create-btn"
443
- >
444
- <FormattedMessage {...messages.sendForApprovalButtonLabel} />
445
- </CapButton>
446
- <CapButton
447
- onClick={handleClose}
448
- className="whatsapp-cancel-btn"
449
- type="secondary"
450
- >
451
- <FormattedMessage {...messages.cancelButtonLabel} />
452
- </CapButton>
792
+ {!isEditFlow && (
793
+ <>
794
+ <CapButton
795
+ onClick={onDoneCallback()}
796
+ disabled={isDisableDone()}
797
+ className="whatsapp-create-btn"
798
+ >
799
+ <FormattedMessage {...messages.sendForApprovalButtonLabel} />
800
+ </CapButton>
801
+ <CapButton
802
+ onClick={handleClose}
803
+ className="whatsapp-cancel-btn"
804
+ type="secondary"
805
+ >
806
+ <FormattedMessage {...messages.cancelButtonLabel} />
807
+ </CapButton>
808
+ </>
809
+ )}
453
810
  </WhatsappFooter>
454
811
  </CapSpin>
455
812
  );
456
813
  };
457
814
 
458
- const mapStateToProps = createStructuredSelector({});
815
+ const mapStateToProps = createStructuredSelector({
816
+ editData: makeSelectWhatsapp(),
817
+ accountData: makeSelectAccount(),
818
+ metaEntities: makeSelectMetaEntities(),
819
+ injectedTags: setInjectedTags(),
820
+ });
459
821
 
460
822
  const mapDispatchToProps = (dispatch) => ({
461
823
  actions: bindActionCreators(WhatsappActions, dispatch),