@capillarytech/creatives-library 7.10.41 → 7.10.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "7.10.41",
4
+ "version": "7.10.43",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -47,6 +47,7 @@ export const PREVIEW = 'preview';
47
47
 
48
48
  export const VIBER = 'viber';
49
49
  export const FACEBOOK = 'facebook';
50
+ export const WHATSAPP = 'whatsapp';
50
51
 
51
52
  export const TRACK_EDIT_SMS = 'editSms';
52
53
  export const TRACK_EDIT_EMAIL = 'editEmail';
@@ -107,4 +108,6 @@ export const FB_AD_CALL_TO_ACTION = {
107
108
  export const CREATIVES = 'creatives';
108
109
  export const LOYALTY = 'loyalty';
109
110
 
110
- export const FAILURE = 'FAILURE';
111
+ export const FAILURE = 'FAILURE';
112
+ export const DATE_DISPLAY_FORMAT = 'D MMM YYYY';
113
+ export const TIME_DISPLAY_FORMAT = 'hh:mm A';
@@ -1,13 +1,14 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
  import { FormattedMessage } from 'react-intl';
4
+ import get from 'lodash/get';
4
5
  import { CapHeader, CapIcons, CapLabel, CapSteps } from '@capillarytech/cap-ui-library';
5
6
  import moment from 'moment';
6
7
  import PropTypes from 'prop-types';
7
8
  import messages from './messages';
8
9
  import whatsppMsg from '../Whatsapp/messages';
9
10
  import { MAP_TEMPLATE } from '../WeChat/Wrapper/constants';
10
- import { NO_COMMUNICATION, FTP } from '../App/constants';
11
+ import { NO_COMMUNICATION, FTP, WHATSAPP } from '../App/constants';
11
12
  import { isTraiDLTEnable } from '../../utils/common';
12
13
  import { formatString } from '../../utils/Formatter';
13
14
  import {
@@ -43,8 +44,10 @@ function SlideBoxHeader(props) {
43
44
  const mapTemplateCreate = !showTemplateNameHeader && slidBoxContent === 'createTemplate' && weChatTemplateType === MAP_TEMPLATE && templateStep !== 'modeSelection';
44
45
  const isTraiDlt = isTraiDLTEnable(isFullMode, smsRegister);
45
46
  const showCreateTraiSMSHeader = isTraiDlt && channel.toLowerCase() === "sms";
46
- const isWhatsappEdit = channel.toLowerCase() === 'whatsapp' && slidBoxContent === 'editTemplate';
47
+ const isWhatsappEdit = channel.toLowerCase() === WHATSAPP && slidBoxContent === 'editTemplate';
47
48
  const whatsappOverview = isWhatsappEdit && isFullMode;
49
+ const headerMessage = whatsappOverview ? messages.whatsappOverview : messages.editMessageContent;
50
+ const whatsappTemplateCategory = get(templateData, `versions.base.content.whatsapp.category`, '');
48
51
 
49
52
  return (
50
53
  <div key="creatives-container-slidebox-header-content">
@@ -72,15 +75,15 @@ function SlideBoxHeader(props) {
72
75
  )}
73
76
  {!showTemplateNameHeader && slidBoxContent === 'editTemplate' && (
74
77
  <CapHeader
75
- title={<FormattedMessage {...(whatsappOverview ? messages.whatsappOverview : messages.editMessageContent)} values={{channel: getChannelLabel(channel)}}/>}
78
+ title={<FormattedMessage {...headerMessage} values={{channel: getChannelLabel(channel)}}/>}
76
79
  description={
77
80
  isWhatsappEdit && (
78
81
  <>
79
82
  {renderWhatsappData("label1", <FormattedMessage {...whatsppMsg.templateNameLabel} />)}
80
- {renderWhatsappData("label2", templateData?.whatsappTemplateName)}
83
+ {renderWhatsappData("label2", templateData?.name)}
81
84
  {renderWhatsappData("label3", <FormattedMessage {...whatsppMsg.labelSeperator} />)}
82
85
  {renderWhatsappData("label1", <FormattedMessage {...whatsppMsg.templateCategoryLabel} />)}
83
- {renderWhatsappData("label2", formatString(templateData?.whatsappTemplateCategory))}
86
+ {renderWhatsappData("label2", formatString(whatsappTemplateCategory))}
84
87
  {renderWhatsappData("label3", <FormattedMessage {...whatsppMsg.labelSeperator} />)}
85
88
  {renderWhatsappData("label1", <FormattedMessage {...whatsppMsg.languageLabel} />)}
86
89
  {renderWhatsappData("label2", <FormattedMessage {...whatsppMsg.templateLanguageEnglish} />)}
@@ -542,3 +542,21 @@
542
542
  margin: 8px 0;
543
543
  white-space: pre-wrap;
544
544
  }
545
+
546
+ .delete-template-confirm {
547
+ .ant-modal-footer {
548
+ padding: $CAP_SPACE_16 $CAP_SPACE_24 $CAP_SPACE_24 $CAP_SPACE_24;
549
+ }
550
+
551
+ .ant-modal-header {
552
+ padding: $CAP_SPACE_24 $CAP_SPACE_24 $CAP_SPACE_08 $CAP_SPACE_24;
553
+ }
554
+
555
+ .ant-modal-body {
556
+ padding: 0 $CAP_SPACE_24;
557
+ }
558
+
559
+ .ant-modal-close-x {
560
+ padding: $CAP_SPACE_12;
561
+ }
562
+ }
@@ -22,7 +22,7 @@ import find from 'lodash/find';
22
22
  import map from 'lodash/map';
23
23
  import { bindActionCreators } from 'redux';
24
24
  import { Modal, Form} from 'antd';
25
- import {CapMenu, CapDropdown, CapButton, CapInput, CapIcon, CapRadioCard, CapPopover, CapSpin, CapCustomCard, CapRow, CapSlideBox, CapLink, CapHeading, CapNotification, CapIllustration, CapHeader, CapLabel, CapRadio, CapSelectFilter, CapTag, CapTooltip, CapAlert } from '@capillarytech/cap-ui-library';
25
+ import {CapMenu, CapDropdown, CapButton, CapInput, CapIcon, CapRadioCard, CapPopover, CapSpin, CapCustomCard, CapRow, CapSlideBox, CapLink, CapHeading, CapNotification, CapIllustration, CapHeader, CapLabel, CapRadio, CapSelectFilter, CapTag, CapTooltip, CapAlert, CapModal } from '@capillarytech/cap-ui-library';
26
26
  import { makeSelectTemplates, makeSelectTemplatesResponse } from './selectors';
27
27
  import { makeSelectCreate as makeSelectCreateSms} from '../Sms/Create/selectors';
28
28
  import { makeSelectCreate as makeSelectCreateMobilePush } from '../MobilePush/Create/selectors';
@@ -116,6 +116,10 @@ const SMS_FILTERS = {
116
116
  };
117
117
 
118
118
  const WHATSAPP_LOWERCASE = WHATSAPP.toLowerCase();
119
+ const SMS_LOWERCASE = SMS.toLowerCase();
120
+ const MOBILE_PUSH_LOWERCASE = MOBILE_PUSH.toLowerCase();
121
+ const EBILL_LOWERCASE = EBILL.toLowerCase();
122
+ const LINE_LOWERCASE = LINE.toLowerCase();
119
123
  export class Templates extends React.Component { // eslint-disable-line react/prefer-stateless-function
120
124
  constructor(props) {
121
125
  super(props);
@@ -426,22 +430,31 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
426
430
  if ((this.state.channel || '').toLowerCase() !== "sms") {
427
431
  CapNotification.error({key: 'somethingWrong', message});
428
432
  }
429
- if ( this.state.channel) {
430
- if (this.state.channel.toLowerCase() === "sms") {
431
- this.props.smsActions.clearCreateResponse();
432
- } else if (this.state.channel.toLowerCase() === "mobilepush") {
433
- this.props.mobilepushActions.clearCreateResponse();
434
- } else if (this.state.channel.toLowerCase() === "ebill") {
435
- this.props.ebillActions.clearCreateResponse();
436
- } else if (this.state.channel.toLowerCase() === "line") {
437
- this.props.lineActions.clearCreateResponse();
438
- } else if (this.state.channel.toLowerCase() === VIBER_CHANNEL) {
439
- this.props.viberActions.clearCreateResponse();
440
- } else if (this.state.channel.toLowerCase() === FACEBOOK_CHANNEL) {
441
- this.props.facebookActions.clearCreateResponse();
442
- }else if (this.state.channel.toLowerCase() === WHATSAPP_LOWERCASE) {
443
- this.props.whatsappActions.clearCreateResponse();
444
- }
433
+ const { smsActions, mobilepushActions, ebillActions, lineActions, viberActions, facebookActions, whatsappActions } = this.props;
434
+ switch (selectedChannel) {
435
+ case SMS_LOWERCASE:
436
+ smsActions.clearCreateResponse();
437
+ break;
438
+ case MOBILE_PUSH_LOWERCASE:
439
+ mobilepushActions.clearCreateResponse();
440
+ break;
441
+ case EBILL_LOWERCASE:
442
+ ebillActions.clearCreateResponse();
443
+ break;
444
+ case LINE_LOWERCASE:
445
+ lineActions.clearCreateResponse();
446
+ break;
447
+ case VIBER_CHANNEL:
448
+ viberActions.clearCreateResponse();
449
+ break;
450
+ case FACEBOOK_CHANNEL:
451
+ facebookActions.clearCreateResponse();
452
+ break;
453
+ case WHATSAPP_LOWERCASE:
454
+ whatsappActions.clearCreateResponse();
455
+ break;
456
+ default:
457
+ break;
445
458
  }
446
459
  }
447
460
 
@@ -491,7 +504,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
491
504
  paramsDefault.wecrmId = nextProps.Templates.weCrmAccounts[0].configs.wecrm_app_id;
492
505
  paramsDefault.wecrmToken = nextProps.Templates.weCrmAccounts[0].configs.wecrm_token;
493
506
  paramsDefault.originalId = nextProps.Templates.weCrmAccounts[0].sourceAccountIdentifier;
494
- if (WHATSAPP_LOWERCASE === this.state.channel.toLowerCase()) {
507
+ if (this.state.channel.toLowerCase() === WHATSAPP_LOWERCASE) {
495
508
  nextProps.actions.setChannelAccount(
496
509
  WHATSAPP,
497
510
  nextProps.Templates.weCrmAccounts[0],
@@ -588,10 +601,12 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
588
601
  creativesParams._id = pathname.split('/')[3];
589
602
  creativesParams.modeType = pathname.split('/')[4];
590
603
  creativesParams.account = pathname.split('/')[5];
591
- if(this.state.channel.toLowerCase() === WHATSAPP_LOWERCASE){
604
+ if (this.state.channel.toLowerCase() === WHATSAPP_LOWERCASE){
592
605
  const whatsappSelectedTemplateData = this.selectTemplate(creativesParams._id) || {};
593
- creativesParams.whatsappTemplateName = get(whatsappSelectedTemplateData, `name`, '');
594
- creativesParams.whatsappTemplateCategory = get(whatsappSelectedTemplateData, `versions.base.content.whatsapp.category`, '');
606
+ creativesParams = {
607
+ ...creativesParams,
608
+ ...whatsappSelectedTemplateData,
609
+ };
595
610
  }
596
611
  }
597
612
  creativesParams.type = this.state.channel.toUpperCase();
@@ -786,7 +801,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
786
801
  </CapMenu.Item>}
787
802
  <CapMenu.Item
788
803
  className={this.state.channel.toUpperCase() === WECHAT && !template.definition ? `unmap-${channelLowerCase}` : `delete-${channelLowerCase}`}
789
- onClick={() => this.deleteTemplate(template)}
804
+ onClick={() => this.toggleDeleteTemplateModal(template)}
790
805
  >
791
806
  {this.state.channel.toUpperCase() === WECHAT && !template.definition ? <FormattedMessage {...messages.unMapButton} /> : <FormattedMessage {...messages.deleteButton} />}
792
807
  </CapMenu.Item>
@@ -1956,21 +1971,25 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1956
1971
  );
1957
1972
  }
1958
1973
  renderDeleteConfirmationModal = () => {
1959
- const modal =
1960
- (<Modal
1974
+ const {
1975
+ intl: {
1976
+ formatMessage,
1977
+ } = {},
1978
+ } = this.props;
1979
+
1980
+ const modal = ( <CapModal
1981
+ className="delete-template-confirm"
1982
+ title={formatMessage(messages.areYouSureText)}
1961
1983
  visible={this.state.showModal}
1962
- title={"Alert"}
1963
1984
  onOk={this.handleOk}
1964
1985
  onCancel={this.handleCancel}
1965
- footer={[
1966
- <CapButton key="back" onClick={this.handleCancel}>{this.props.intl.formatMessage(messages.cancelText)}</CapButton>,
1967
- <CapButton key="submit" type="primary" id="delete-version" onClick={this.handleOk}>
1968
- {this.props.intl.formatMessage(messages.yesText)}
1969
- </CapButton>,
1970
- ]}
1986
+ centered
1987
+ okText={formatMessage(messages.yesText)}
1988
+ closeText={formatMessage(messages.cancelText)}
1971
1989
  >
1972
- {this.props.intl.formatMessage(messages.templateDeleteConfirm)}
1973
- </Modal>);
1990
+ {formatMessage(messages.templateDeleteConfirm)}
1991
+ </CapModal>
1992
+ );
1974
1993
  return modal;
1975
1994
  };
1976
1995
 
@@ -220,7 +220,11 @@ export default defineMessages({
220
220
  },
221
221
  "templateDeleteConfirm": {
222
222
  id: `${scope}.templateDeleteConfirm`,
223
- defaultMessage: `Are you sure you want to delete this template?`,
223
+ defaultMessage: `Are you sure you wish to delete this template?`,
224
+ },
225
+ "areYouSureText": {
226
+ id: `${scope}.areYouSureText`,
227
+ defaultMessage: `Confirm delete template`,
224
228
  },
225
229
  "cancelText": {
226
230
  id: `${scope}.cancelText`,
@@ -228,7 +232,7 @@ export default defineMessages({
228
232
  },
229
233
  "yesText": {
230
234
  id: `${scope}.yesText`,
231
- defaultMessage: `Yes`,
235
+ defaultMessage: `Yes, delete`,
232
236
  },
233
237
  "templateSelection": {
234
238
  id: `${scope}.templateSelection`,
@@ -44,6 +44,7 @@ import {
44
44
  ALL,
45
45
  LIBRARY,
46
46
  } from './constants';
47
+ import { DATE_DISPLAY_FORMAT, TIME_DISPLAY_FORMAT } from '../App/constants';
47
48
  import messages from './messages';
48
49
  import withCreatives from '../../hoc/withCreatives';
49
50
  import TemplatePreview from '../../v2Components/TemplatePreview';
@@ -52,6 +53,7 @@ import { makeSelectMetaEntities, setInjectedTags } from '../Cap/selectors';
52
53
 
53
54
  let varMap = {};
54
55
  let editContent = {};
56
+ let timerid;
55
57
 
56
58
  export const Whatsapp = (props) => {
57
59
  const {
@@ -117,9 +119,15 @@ export const Whatsapp = (props) => {
117
119
  useEffect(() => {
118
120
  const accountObj = accountData.selectedWhatsappAccount || {};
119
121
  if (!isEmpty(accountObj)) {
120
- setAccountId(get(accountObj, `sourceAccountIdentifier`, ''));
121
- setAccessToken(get(accountObj, `configs.accessToken`, ''));
122
- setAccountName(get(accountObj, `name`, ''));
122
+ const {
123
+ sourceAccountIdentifier = '',
124
+ configs = {},
125
+ name = '',
126
+ } = accountObj;
127
+ const { accessToken = '' } = configs;
128
+ setAccountId(sourceAccountIdentifier);
129
+ setAccessToken(accessToken);
130
+ setAccountName(name);
123
131
  }
124
132
  }, [accountData.selectedWhatsappAccount]);
125
133
 
@@ -136,26 +144,26 @@ export const Whatsapp = (props) => {
136
144
  return () => {
137
145
  actions.resetEditTemplate();
138
146
  varMap = {};
147
+ if (timerid) {
148
+ clearTimeout(timerid);
149
+ }
139
150
  };
140
151
  }, [paramObj.id]);
141
152
 
142
153
  useEffect(() => {
143
- editContent =
144
- get(templateData, `versions.base.content.whatsapp`) ||
145
- get(editData, `templateDetails.versions.base.content.whatsapp`) ||
146
- {};
154
+ const {
155
+ name = '',
156
+ versions = {},
157
+ createdAt = '',
158
+ } = editData.templateDetails || templateData || {};
159
+ editContent = get(versions, `base.content.whatsapp`, {});
147
160
  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);
161
+ setTemplateName(name);
154
162
  setTemplateDate(createdAt);
155
- setTemplateCategory(get(editContent, `category`, ''));
156
- setTemplateStatus(
157
- get(editContent, `status`, WHATSAPP_STATUSES.unsubmitted),
158
- );
163
+ const { category = '', status = WHATSAPP_STATUSES.unsubmitted } =
164
+ editContent;
165
+ setTemplateCategory(category);
166
+ setTemplateStatus(status);
159
167
  computeTempMsgArray();
160
168
  }
161
169
  }, [editData.templateDetails || templateData]);
@@ -164,27 +172,29 @@ export const Whatsapp = (props) => {
164
172
  let msg = get(editContent, `languages[0].content`, '');
165
173
  const validVarArr = msg.match(validVarRegex) || [];
166
174
  const templateMessageArray = [];
175
+ //removing $'' which was added for twilio enter handling
167
176
  msg = msg.slice(2, -1);
177
+ //removing Click {{unsubscribe}} to unsubscribe
168
178
  msg = msg.replace(
169
179
  `Click ${validVarArr[validVarArr.length - 1]} to unsubscribe`,
170
180
  '',
171
181
  );
182
+ //removing last var added for Click {{unsubscribe}} to unsubscribe
172
183
  validVarArr.pop();
173
184
  while (msg.length !== 0) {
185
+ //converting content string to an array split at var
174
186
  const index = msg.indexOf(validVarArr[0]);
175
187
  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();
188
+ templateMessageArray.push(msg.substring(0, index)); //push string before var
189
+ templateMessageArray.push(validVarArr[0]); //push var
190
+ msg = msg.substring(index + validVarArr[0].length, msg.length); //remaining str
191
+ validVarArr.shift(); //remove considered var
180
192
  } else {
181
- templateMessageArray.push(msg);
193
+ templateMessageArray.push(msg); //remaining str
182
194
  break;
183
195
  }
184
196
  }
185
197
  updateTempMsgArray(templateMessageArray.filter((i) => i === 0 || i));
186
- //stop spinner
187
- setSpin(false);
188
198
  };
189
199
 
190
200
  useEffect(() => {
@@ -200,7 +210,7 @@ export const Whatsapp = (props) => {
200
210
  }
201
211
  }
202
212
  }
203
- //setting updatedSmsEditor based on varMap
213
+ //setting updatedSmsEditor state based on varMap
204
214
  const arr = [...tempMsgArray];
205
215
  for (const key in varMap) {
206
216
  if (varMap[key] !== '') {
@@ -208,35 +218,42 @@ export const Whatsapp = (props) => {
208
218
  }
209
219
  }
210
220
  setUpdatedSmsEditor(arr);
221
+ timerid = setTimeout(() => {
222
+ //stop spinner
223
+ setSpin(false);
224
+ }, 500);
211
225
  }
212
226
  }, [tempMsgArray]);
213
227
 
214
228
  // tag Code start from here
215
229
  useEffect(() => {
216
230
  //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;
231
+ if (isEditFlow) {
232
+ const { type, module } = location.query || {};
233
+ const isEmbedded = type === EMBEDDED;
234
+ const query = {
235
+ layout: 'SMS',
236
+ type: TAG,
237
+ context: isEmbedded ? module : DEFAULT,
238
+ embedded: isEmbedded ? type : FULL,
239
+ };
240
+ if (getDefaultTags) {
241
+ query.context = getDefaultTags;
242
+ }
243
+ globalActions.fetchSchemaForEntity(query);
227
244
  }
228
- globalActions.fetchSchemaForEntity(query);
229
- }, []);
245
+ }, [isEditFlow]);
230
246
 
231
247
  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;
248
+ if (isEditFlow) {
249
+ let tag = get(metaEntities, `tags.standard`, []);
250
+ const { type, module } = location.query || {};
251
+ if (type === EMBEDDED && module === LIBRARY && !getDefaultTags) {
252
+ tag = supportedTags;
253
+ }
254
+ updateTags(tag);
237
255
  }
238
- updateTags(tag);
239
- }, [metaEntities]);
256
+ }, [metaEntities, isEditFlow]);
240
257
 
241
258
  const handleOnTagsContextChange = (data) => {
242
259
  const { type } = location.query || {};
@@ -255,8 +272,8 @@ export const Whatsapp = (props) => {
255
272
 
256
273
  const onTagSelect = (data) => {
257
274
  if (varMap && updatedSmsEditor) {
258
- let numId = Number(textAreaId?.slice(textAreaId?.indexOf('_') + 1));
259
- if (numId !== NaN) {
275
+ const numId = Number(textAreaId?.slice(textAreaId?.indexOf('_') + 1));
276
+ if (numId != NaN) {
260
277
  const arr = [...updatedSmsEditor];
261
278
  //when trying to insert tag in empty textarea,{#var#} is replaced with "" and then tag is added
262
279
  if (arr[numId]?.match(validVarRegex)?.length > 0) {
@@ -334,7 +351,7 @@ export const Whatsapp = (props) => {
334
351
  <CapColumn span={12}>
335
352
  <CapTooltip
336
353
  placement="bottom"
337
- title={formatMessage(messages.unsubscribeTextTooltip)}
354
+ title={!isEditFlow && formatMessage(messages.unsubscribeTextTooltip)}
338
355
  >
339
356
  <CapHeading
340
357
  className={
@@ -351,10 +368,13 @@ export const Whatsapp = (props) => {
351
368
  </>
352
369
  );
353
370
 
371
+ //used by create and edit
354
372
  const renderMessageLength = () => (
355
373
  <CapHeading type="h6" className="whatsapp-render-message-length">
356
374
  {formatMessage(messages.templateMessageLength, {
357
- currentLength: UNSUBSCRIBE_TEXT_LENGTH + templateMessage?.length,
375
+ currentLength: isEditFlow
376
+ ? updatedSmsEditor?.join('')?.length + UNSUBSCRIBE_TEXT_LENGTH
377
+ : templateMessage?.length + UNSUBSCRIBE_TEXT_LENGTH,
358
378
  maxLength: TEMPLATE_MESSAGE_MAX_LENGTH,
359
379
  })}
360
380
  </CapHeading>
@@ -602,45 +622,50 @@ export const Whatsapp = (props) => {
602
622
  //create methods end
603
623
 
604
624
  //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';
625
+ const getTemplateStatusType = () => {
626
+ switch (templateStatus) {
627
+ case WHATSAPP_STATUSES.approved:
628
+ return 'success';
629
+ case WHATSAPP_STATUSES.rejected:
630
+ return 'error';
631
+ default:
632
+ return 'warning';
610
633
  }
611
- return 'warning';
612
634
  };
613
635
 
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
- );
636
+ const getTemplateStatusMessage = () => {
637
+ switch (templateStatus) {
638
+ case WHATSAPP_STATUSES.approved:
639
+ return (
640
+ <CapLabel type="label2">
641
+ {formatMessage(messages.approvedStatusMsg)}
642
+ </CapLabel>
643
+ );
644
+ case WHATSAPP_STATUSES.rejected:
645
+ return (
646
+ <CapLabel type="label2">
647
+ {formatMessage(messages.rejectedStatusMsg)}
648
+ </CapLabel>
649
+ );
650
+ default:
651
+ //all cases except approved and rejected, return awaiting approval
652
+ return (
653
+ <>
654
+ <CapLabel type="label2" style={{ fontWeight: 500 }}>
655
+ {formatMessage(messages.awaitingStatusMsg)}
656
+ </CapLabel>
657
+ <CapLabel
658
+ type="label2"
659
+ style={{ marginTop: CAP_SPACE_04, marginBottom: CAP_SPACE_04 }}
660
+ >
661
+ {formatMessage(messages.awaitingStatusDesc, {
662
+ date: moment(templateDate).format(DATE_DISPLAY_FORMAT),
663
+ time: moment(templateDate).format(TIME_DISPLAY_FORMAT),
664
+ })}
665
+ </CapLabel>
666
+ </>
667
+ );
627
668
  }
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
669
  };
645
670
 
646
671
  // on change event of Text Area
@@ -662,10 +687,10 @@ export const Whatsapp = (props) => {
662
687
  const textAreaValue = (idValue) => {
663
688
  if (idValue >= 0 && updatedSmsEditor) {
664
689
  const value = updatedSmsEditor[idValue];
690
+ //if value is there and it is not a variable return it
665
691
  if (value && (value.match(validVarRegex) || []).length === 0) {
666
692
  return value;
667
693
  }
668
- return '';
669
694
  }
670
695
  return '';
671
696
  };
@@ -675,6 +700,7 @@ export const Whatsapp = (props) => {
675
700
  if (tempMsgArray?.length !== 0) {
676
701
  let varCount = 0;
677
702
  tempMsgArray.forEach((elem, index) => {
703
+ // if var return textarea else return text
678
704
  if (elem.match(validVarRegex)?.length > 0) {
679
705
  varCount += 1;
680
706
  renderArray.push(
@@ -708,9 +734,27 @@ export const Whatsapp = (props) => {
708
734
  return renderArray;
709
735
  };
710
736
 
737
+ const disabledEditTooltipRender = () => {
738
+ switch (templateStatus) {
739
+ case WHATSAPP_STATUSES.approved:
740
+ return '';
741
+ case WHATSAPP_STATUSES.rejected:
742
+ return formatMessage(messages.disabledEditTooltip, {
743
+ status: templateStatus,
744
+ });
745
+ default:
746
+ return formatMessage(messages.disabledEditTooltip, {
747
+ status: formatMessage(messages.disabledEditTooltipStatus),
748
+ });
749
+ }
750
+ };
751
+
711
752
  const editModeContent = (
712
753
  <>
713
- <CapAlert message={getAlertMessage()} type={getAlertType()} />
754
+ <CapAlert
755
+ message={getTemplateStatusMessage()}
756
+ type={getTemplateStatusType()}
757
+ />
714
758
  <CapRow className="whatsapp-render-heading">
715
759
  <CapHeader
716
760
  title={
@@ -732,19 +776,7 @@ export const Whatsapp = (props) => {
732
776
  }
733
777
  />
734
778
  </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
- >
779
+ <CapTooltip placement="bottom" title={disabledEditTooltipRender()}>
748
780
  <CapRow
749
781
  className={`whatsapp-edit-template-message-input ${
750
782
  templateStatus !== WHATSAPP_STATUSES.approved &&
@@ -760,10 +792,18 @@ export const Whatsapp = (props) => {
760
792
  );
761
793
  //edit methods end
762
794
 
795
+ //used by create and edit
763
796
  const getPreviewSection = () => {
764
- const templateMsg = `${
765
- isEditFlow ? updatedSmsEditor.join('') : templateMessage
766
- }\n${formatMessage(messages.templateMessageUnsubscribeText)}`;
797
+ const templateMsg = (
798
+ <>
799
+ <CapLabel type="label5">
800
+ {isEditFlow ? updatedSmsEditor.join('') : templateMessage}
801
+ </CapLabel>
802
+ <CapLabel type="label11">
803
+ {formatMessage(messages.templateMessageUnsubscribeText)}
804
+ </CapLabel>
805
+ </>
806
+ );
767
807
  return (
768
808
  <TemplatePreview
769
809
  channel={WHATSAPP}
@@ -18,7 +18,7 @@
18
18
  text-align: right;
19
19
  }
20
20
  .whatsapp-create-template-message-input {
21
- background-color: #fafbfc;
21
+ background-color: $CAP_G10;
22
22
  padding-top: $CAP_SPACE_16;
23
23
  }
24
24
  .whatsapp-template-message-error {
@@ -35,7 +35,7 @@
35
35
  margin-top: 46px;
36
36
  }
37
37
  .whatsapp-edit-template-message-input {
38
- background-color: #fafbfc;
38
+ background-color: $CAP_G10;
39
39
  padding: 0 $CAP_SPACE_16;
40
40
  }
41
41
  .whatsapp-edit-template-message-heading {
@@ -218,4 +218,8 @@ export default defineMessages({
218
218
  id: `${prefix}.disabledEditTooltip`,
219
219
  defaultMessage: 'This template is non-editable as this is {status}',
220
220
  },
221
+ disabledEditTooltipStatus: {
222
+ id: `${prefix}.disabledEditTooltipStatus`,
223
+ defaultMessage: 'awaiting for approval',
224
+ },
221
225
  });