@capillarytech/creatives-library 8.0.248 → 8.0.250

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.
@@ -98,9 +98,9 @@ describe('ButtonsLinksSection', () => {
98
98
  });
99
99
 
100
100
  const defaultProps = {
101
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE,
101
+ onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL,
102
102
  onClickBehaviourOptions: [
103
- { value: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE, label: 'Open Site' },
103
+ { value: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL, label: 'Open Site' },
104
104
  { value: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL, label: 'Redirect to URL' },
105
105
  ],
106
106
  onClickBehaviourChange: mockOnClickBehaviourChange,
@@ -151,7 +151,7 @@ describe('ButtonsLinksSection', () => {
151
151
  const radioGroup = wrapper.find(CapRadioGroup);
152
152
  expect(radioGroup.exists()).toBe(true);
153
153
  expect(radioGroup.prop('options')).toEqual(defaultProps.onClickBehaviourOptions);
154
- expect(radioGroup.prop('value')).toBe(ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE);
154
+ expect(radioGroup.prop('value')).toBe(ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL);
155
155
  });
156
156
  });
157
157
 
@@ -175,7 +175,7 @@ describe('ButtonsLinksSection', () => {
175
175
  expect(input.exists()).toBe(true);
176
176
  });
177
177
 
178
- it('should not render redirect URL input when OPEN_SITE is selected', () => {
178
+ it('should not render redirect URL input when SITE_URL is selected', () => {
179
179
  const wrapper = mountWithIntl(<ButtonsLinksSection {...defaultProps} />);
180
180
  const input = wrapper.find(CapInput).find('#webpush-redirect-url-input');
181
181
  expect(input.exists()).toBe(false);
@@ -32,7 +32,7 @@ exports[`ButtonsLinksSection Rendering should render correctly with default prop
32
32
  Array [
33
33
  Object {
34
34
  "label": "Open Site",
35
- "value": "OPEN_SITE",
35
+ "value": "SITE_URL",
36
36
  },
37
37
  Object {
38
38
  "label": "Redirect to URL",
@@ -40,7 +40,7 @@ exports[`ButtonsLinksSection Rendering should render correctly with default prop
40
40
  },
41
41
  ]
42
42
  }
43
- value="OPEN_SITE"
43
+ value="SITE_URL"
44
44
  />
45
45
  </CapRow>
46
46
  <CapRow
@@ -32,6 +32,9 @@ import { useImageUpload } from './hooks/useImageUpload';
32
32
  import { useTagManagement } from './hooks/useTagManagement';
33
33
  import isEmpty from 'lodash/isEmpty';
34
34
  import get from 'lodash/get';
35
+ import * as templateActions from '../../Templates/actions';
36
+ import { makeSelectTemplates } from '../../Templates/selectors';
37
+
35
38
  import {
36
39
  WEBPUSH_MEDIA_TYPES,
37
40
  BRAND_ICON_OPTIONS,
@@ -53,6 +56,7 @@ import {
53
56
  } from '../selectors';
54
57
  import webPushReducer from '../reducer';
55
58
  import webPushSagas from '../sagas';
59
+ import { v2TemplateSaga } from '../../Templates/sagas';
56
60
  import withCreatives from '../../../hoc/withCreatives';
57
61
  import messages from './messages';
58
62
  import { createWebPushPayload } from './utils/payloadBuilder';
@@ -67,6 +71,7 @@ import {
67
71
  setInjectedTags,
68
72
  } from '../../Cap/selectors';
69
73
  import './index.scss';
74
+ import { WEBPUSH } from '../../CreativesContainer/constants';
70
75
 
71
76
  // Memoized TagList wrapper components for better performance
72
77
  const MemoizedTagList = memo(({
@@ -123,6 +128,8 @@ const WebPushCreate = ({
123
128
  accountData,
124
129
  webPush,
125
130
  onCreateComplete,
131
+ getFormData,
132
+ isGetFormData,
126
133
  templateData,
127
134
  creativesMode,
128
135
  params,
@@ -135,6 +142,8 @@ const WebPushCreate = ({
135
142
  forwardedTags,
136
143
  selectedOfferDetails = [],
137
144
  eventContextTags = [],
145
+ templateActions: templateActionsProps,
146
+ Templates,
138
147
  }) => {
139
148
  const { formatMessage } = intl;
140
149
 
@@ -152,7 +161,7 @@ const WebPushCreate = ({
152
161
  message: false,
153
162
  });
154
163
  const [brandIconOption, setBrandIconOption] = useState(BRAND_ICON_OPTIONS.DONT_SHOW);
155
- const [onClickBehaviour, setOnClickBehaviour] = useState(ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE);
164
+ const [onClickBehaviour, setOnClickBehaviour] = useState(ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL);
156
165
  const [redirectUrl, setRedirectUrl] = useState('');
157
166
  const [redirectUrlError, setRedirectUrlError] = useState('');
158
167
  const [activeUploadField, setActiveUploadField] = useState(null);
@@ -213,6 +222,7 @@ const WebPushCreate = ({
213
222
  eventContextTags,
214
223
  });
215
224
  const { tags, handleOnTagsContextChange, validationConfig } = tagState;
225
+ const { weCrmAccounts } = Templates;
216
226
 
217
227
  // Edit mode detection: check creativesMode or presence of template ID
218
228
  const isEditMode = useMemo(
@@ -239,11 +249,22 @@ const WebPushCreate = ({
239
249
  templateData,
240
250
  ]);
241
251
 
252
+ const selectedWebPushAccount = useMemo(() =>
253
+ weCrmAccounts?.find(account => account?.id === accountId),
254
+ [weCrmAccounts, accountId]);
255
+
242
256
  const websiteLink = useMemo(
243
- () => accountData?.configs?.websiteLink || '',
244
- [accountData?.configs?.websiteLink],
257
+ () => accountData?.configs?.websiteLink || selectedWebPushAccount?.configs?.websiteLink || '',
258
+ [accountData?.configs?.websiteLink, selectedWebPushAccount?.configs?.websiteLink],
245
259
  );
246
260
 
261
+ // Fetch account details when websiteLink is missing but accountId exists
262
+ useEffect(() => {
263
+ if (!websiteLink && accountId && templateActionsProps?.getWeCrmAccounts) {
264
+ templateActionsProps.getWeCrmAccounts('WebPush');
265
+ }
266
+ }, [websiteLink, accountId, templateActionsProps?.getWeCrmAccounts]);
267
+
247
268
  const previewUrl = useMemo(
248
269
  () => (
249
270
  onClickBehaviour === ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL
@@ -255,7 +276,7 @@ const WebPushCreate = ({
255
276
 
256
277
  const onClickBehaviourOptions = useMemo(
257
278
  () => ([
258
- { value: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE, label: formatMessage(messages.openSite) },
279
+ { value: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL, label: formatMessage(messages.openSite) },
259
280
  { value: ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL, label: formatMessage(messages.redirectToSpecificUrl) },
260
281
  ]),
261
282
  [formatMessage],
@@ -349,13 +370,13 @@ const WebPushCreate = ({
349
370
  setOnClickBehaviour(ON_CLICK_BEHAVIOUR_OPTIONS.REDIRECT_TO_URL);
350
371
  setRedirectUrl(onClickAction?.url || '');
351
372
  setRedirectUrlError('');
352
- } else if (onClickAction?.type === ACTION_TYPES.OPEN_SITE) {
353
- setOnClickBehaviour(ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE);
354
- setRedirectUrl('');
373
+ } else if (onClickAction?.type === ACTION_TYPES.SITE_URL) {
374
+ setOnClickBehaviour(ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL);
375
+ setRedirectUrl(websiteLink);
355
376
  setRedirectUrlError('');
356
377
  } else {
357
- setOnClickBehaviour(ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE);
358
- setRedirectUrl('');
378
+ setOnClickBehaviour(ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL);
379
+ setRedirectUrl(websiteLink);
359
380
  setRedirectUrlError('');
360
381
  }
361
382
 
@@ -522,6 +543,15 @@ const WebPushCreate = ({
522
543
  });
523
544
  }, [isFullMode, templateName]);
524
545
 
546
+ // Pure validator that returns boolean without setting error state
547
+ const validateFormSilent = () => {
548
+ const templateNameInvalid = isFullMode && validateTemplateName(templateName);
549
+ const titleValidation = validateTitle(notificationTitle);
550
+ const messageValidation = validateMessageContent(message);
551
+
552
+ return !(templateNameInvalid || titleValidation || messageValidation);
553
+ };
554
+
525
555
  const isFormValid = () => {
526
556
  const templateNameInvalid = isFullMode && validateTemplateName(templateName);
527
557
  const titleValidation = validateTitle(notificationTitle);
@@ -558,8 +588,24 @@ const WebPushCreate = ({
558
588
  buttons,
559
589
  onClickBehaviour,
560
590
  redirectUrl,
591
+ websiteLink,
561
592
  });
562
593
 
594
+ // In library mode (not full mode), use getFormData to communicate with parent
595
+ if (!isFullMode && getFormData) {
596
+ const formDataForLibrary = {
597
+ validity: true,
598
+ value: payload,
599
+ type: WEBPUSH,
600
+ };
601
+ getFormData(formDataForLibrary);
602
+ if (handleClose) {
603
+ handleClose();
604
+ }
605
+ return;
606
+ }
607
+
608
+ // Full mode: proceed with API calls
563
609
  if (isEditMode) {
564
610
  // Get template ID from params or templateData
565
611
  const templateId = params?.id || templateData?._id;
@@ -649,6 +695,37 @@ const WebPushCreate = ({
649
695
  }
650
696
  }, [webPush?.editResponse, onCreateComplete, handleClose, isEditMode]);
651
697
 
698
+ // Handle getFormData request from parent (library mode)
699
+ useEffect(() => {
700
+ if (isGetFormData && getFormData && validateFormSilent()) {
701
+ const payload = createWebPushPayload({
702
+ templateName,
703
+ notificationTitle,
704
+ message,
705
+ mediaType,
706
+ accountId,
707
+ isFullMode,
708
+ imageSrc,
709
+ imageUrl,
710
+ imageUploadMethod: imageUpload?.uploadMethod,
711
+ brandIconOption,
712
+ brandIconSrc,
713
+ brandIconUrl,
714
+ buttons,
715
+ onClickBehaviour,
716
+ redirectUrl,
717
+ websiteLink,
718
+ });
719
+ const formDataForLibrary = {
720
+ validity: true,
721
+ value: payload,
722
+ type: WEBPUSH,
723
+ };
724
+ getFormData(formDataForLibrary);
725
+ }
726
+ // eslint-disable-next-line react-hooks/exhaustive-deps
727
+ }, [isGetFormData, getFormData]);
728
+
652
729
  const isUploadingAsset = useMemo(
653
730
  () => webPush?.assetUploading || false,
654
731
  [webPush?.assetUploading],
@@ -872,7 +949,7 @@ const WebPushCreate = ({
872
949
  () => (!accountId ? formatMessage(messages.accountRequired) : ''),
873
950
  [accountId, formatMessage],
874
951
  );
875
-
952
+
876
953
  return (
877
954
  <CapRow className="webpush-container">
878
955
  <CapColumn className="content-section" span={14}>
@@ -972,6 +1049,8 @@ WebPushCreate.propTypes = {
972
1049
  accountData: PropTypes.object,
973
1050
  webPush: PropTypes.object,
974
1051
  onCreateComplete: PropTypes.func,
1052
+ getFormData: PropTypes.func,
1053
+ isGetFormData: PropTypes.bool,
975
1054
  templateData: PropTypes.object,
976
1055
  creativesMode: PropTypes.string,
977
1056
  params: PropTypes.object,
@@ -984,6 +1063,7 @@ WebPushCreate.propTypes = {
984
1063
  forwardedTags: PropTypes.object,
985
1064
  selectedOfferDetails: PropTypes.array,
986
1065
  eventContextTags: PropTypes.array,
1066
+ templateActions: PropTypes.object,
987
1067
  };
988
1068
 
989
1069
  WebPushCreate.defaultProps = {
@@ -996,6 +1076,8 @@ WebPushCreate.defaultProps = {
996
1076
  accountData: {},
997
1077
  webPush: {},
998
1078
  onCreateComplete: () => { },
1079
+ getFormData: null,
1080
+ isGetFormData: false,
999
1081
  templateData: null,
1000
1082
  creativesMode: 'createTemplate',
1001
1083
  params: null,
@@ -1008,6 +1090,8 @@ WebPushCreate.defaultProps = {
1008
1090
  forwardedTags: {},
1009
1091
  selectedOfferDetails: [],
1010
1092
  eventContextTags: [],
1093
+ templateActions: {},
1094
+ Templates: {},
1011
1095
  };
1012
1096
 
1013
1097
  const mapStateToProps = createStructuredSelector({
@@ -1018,6 +1102,7 @@ const mapStateToProps = createStructuredSelector({
1018
1102
  editTemplateError: makeSelectEditError(),
1019
1103
  metaEntities: makeSelectMetaEntities(),
1020
1104
  injectedTags: setInjectedTags(),
1105
+ Templates: makeSelectTemplates(),
1021
1106
  accountData: createSelector(
1022
1107
  (state) => state.get('templates'),
1023
1108
  (templatesState) => {
@@ -1032,14 +1117,21 @@ const mapStateToProps = createStructuredSelector({
1032
1117
 
1033
1118
  const mapDispatchToProps = (dispatch) => ({
1034
1119
  webPushActions: bindActionCreators(actions, dispatch),
1120
+ templateActions: bindActionCreators(templateActions, dispatch),
1035
1121
  });
1036
1122
 
1037
- const withSaga = injectSaga({
1123
+ const withWebPushSaga = injectSaga({
1038
1124
  key: 'webPush',
1039
1125
  saga: webPushSagas,
1040
1126
  mode: DAEMON,
1041
1127
  });
1042
1128
 
1129
+ const withTemplateSaga = injectSaga({
1130
+ key: 'webPushTemplates',
1131
+ saga: v2TemplateSaga,
1132
+ mode: DAEMON,
1133
+ });
1134
+
1043
1135
  const withReducer = injectReducer({
1044
1136
  key: 'webPush',
1045
1137
  reducer: webPushReducer,
@@ -1050,7 +1142,7 @@ export default withCreatives({
1050
1142
  mapStateToProps,
1051
1143
  mapDispatchToProps,
1052
1144
  userAuth: true,
1053
- sagas: [withSaga],
1145
+ sagas: [withWebPushSaga, withTemplateSaga],
1054
1146
  reducers: [withReducer],
1055
1147
  });
1056
1148
 
@@ -32,6 +32,7 @@ const WebPushPreview = ({
32
32
  imageSrc,
33
33
  brandIconSrc,
34
34
  buttons,
35
+ onClickShowInAllDevices,
35
36
  }) => {
36
37
  const [selectedOS, setSelectedOS] = useState(DEFAULT_OS);
37
38
  const [selectedBrowser, setSelectedBrowser] = useState(DEFAULT_BROWSER);
@@ -56,7 +57,11 @@ const WebPushPreview = ({
56
57
  }, [browserOptionsForOS, selectedBrowser]);
57
58
 
58
59
  const handleOpenPreviewSlideBox = () => {
59
- setShowPreviewSlideBox(true);
60
+ if (onClickShowInAllDevices) {
61
+ onClickShowInAllDevices();
62
+ } else {
63
+ setShowPreviewSlideBox(true);
64
+ }
60
65
  };
61
66
 
62
67
  const handleClosePreviewSlideBox = () => {