@capillarytech/creatives-library 8.0.241 → 8.0.242-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/package.json +1 -1
  2. package/sagas/__tests__/assetPolling.test.js +607 -0
  3. package/sagas/assetPolling.js +156 -0
  4. package/services/api.js +16 -0
  5. package/services/tests/api.test.js +124 -0
  6. package/translations/en.json +1 -0
  7. package/utils/assetStatusConstants.js +12 -0
  8. package/utils/asyncAssetUpload.js +161 -0
  9. package/utils/tests/asyncAssetUpload.test.js +292 -0
  10. package/utils/transformerUtils.js +42 -0
  11. package/v2Components/CapImageUpload/constants.js +2 -0
  12. package/v2Components/CapImageUpload/index.js +54 -14
  13. package/v2Components/CapImageUpload/index.scss +4 -1
  14. package/v2Components/CapImageUpload/messages.js +4 -0
  15. package/v2Components/CapImageUrlUpload/constants.js +19 -0
  16. package/v2Components/CapImageUrlUpload/index.js +455 -0
  17. package/v2Components/CapImageUrlUpload/index.scss +35 -0
  18. package/v2Components/CapImageUrlUpload/messages.js +47 -0
  19. package/v2Containers/App/constants.js +5 -0
  20. package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +1 -0
  21. package/v2Containers/CreativesContainer/SlideBoxContent.js +57 -2
  22. package/v2Containers/CreativesContainer/SlideBoxHeader.js +1 -0
  23. package/v2Containers/CreativesContainer/constants.js +2 -0
  24. package/v2Containers/CreativesContainer/index.js +152 -0
  25. package/v2Containers/CreativesContainer/messages.js +4 -0
  26. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +3 -0
  27. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +2 -0
  28. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +25 -0
  29. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +18 -0
  30. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +46 -0
  31. package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +4 -0
  32. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +8 -0
  33. package/v2Containers/Templates/ChannelTypeIllustration.js +13 -1
  34. package/v2Containers/Templates/_templates.scss +203 -0
  35. package/v2Containers/Templates/actions.js +2 -1
  36. package/v2Containers/Templates/constants.js +1 -0
  37. package/v2Containers/Templates/index.js +273 -30
  38. package/v2Containers/Templates/messages.js +24 -0
  39. package/v2Containers/Templates/reducer.js +2 -0
  40. package/v2Containers/Templates/tests/index.test.js +10 -0
  41. package/v2Containers/TemplatesV2/index.js +3 -2
  42. package/v2Containers/TemplatesV2/messages.js +4 -0
  43. package/v2Containers/WebPush/Create/components/ButtonForm.js +175 -0
  44. package/v2Containers/WebPush/Create/components/ButtonItem.js +101 -0
  45. package/v2Containers/WebPush/Create/components/ButtonList.js +144 -0
  46. package/v2Containers/WebPush/Create/components/_buttons.scss +246 -0
  47. package/v2Containers/WebPush/Create/components/tests/ButtonForm.test.js +554 -0
  48. package/v2Containers/WebPush/Create/components/tests/ButtonItem.test.js +607 -0
  49. package/v2Containers/WebPush/Create/components/tests/ButtonList.test.js +633 -0
  50. package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonForm.test.js.snap +666 -0
  51. package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonItem.test.js.snap +74 -0
  52. package/v2Containers/WebPush/Create/components/tests/__snapshots__/ButtonList.test.js.snap +80 -0
  53. package/v2Containers/WebPush/Create/index.js +1755 -0
  54. package/v2Containers/WebPush/Create/index.scss +123 -0
  55. package/v2Containers/WebPush/Create/messages.js +199 -0
  56. package/v2Containers/WebPush/Create/preview/DevicePreviewContent.js +241 -0
  57. package/v2Containers/WebPush/Create/preview/NotificationContainer.js +290 -0
  58. package/v2Containers/WebPush/Create/preview/PreviewContent.js +81 -0
  59. package/v2Containers/WebPush/Create/preview/PreviewControls.js +240 -0
  60. package/v2Containers/WebPush/Create/preview/PreviewDisclaimer.js +23 -0
  61. package/v2Containers/WebPush/Create/preview/WebPushPreview.js +144 -0
  62. package/v2Containers/WebPush/Create/preview/assets/Light.svg +53 -0
  63. package/v2Containers/WebPush/Create/preview/assets/Top.svg +5 -0
  64. package/v2Containers/WebPush/Create/preview/assets/chrome-icon.png +0 -0
  65. package/v2Containers/WebPush/Create/preview/assets/edge-icon.png +0 -0
  66. package/v2Containers/WebPush/Create/preview/assets/firefox-icon.svg +106 -0
  67. package/v2Containers/WebPush/Create/preview/assets/iOS.svg +26 -0
  68. package/v2Containers/WebPush/Create/preview/assets/opera-icon.svg +18 -0
  69. package/v2Containers/WebPush/Create/preview/assets/safari-icon.svg +29 -0
  70. package/v2Containers/WebPush/Create/preview/components/AndroidMobileChromeHeader.js +44 -0
  71. package/v2Containers/WebPush/Create/preview/components/AndroidMobileExpanded.js +110 -0
  72. package/v2Containers/WebPush/Create/preview/components/IOSHeader.js +45 -0
  73. package/v2Containers/WebPush/Create/preview/components/NotificationExpandedContent.js +72 -0
  74. package/v2Containers/WebPush/Create/preview/components/NotificationHeader.js +55 -0
  75. package/v2Containers/WebPush/Create/preview/components/WindowsChromeExpanded.js +70 -0
  76. package/v2Containers/WebPush/Create/preview/components/tests/AndroidMobileExpanded.test.js +512 -0
  77. package/v2Containers/WebPush/Create/preview/components/tests/__snapshots__/AndroidMobileExpanded.test.js.snap +77 -0
  78. package/v2Containers/WebPush/Create/preview/config/notificationMappings.js +527 -0
  79. package/v2Containers/WebPush/Create/preview/constants.js +162 -0
  80. package/v2Containers/WebPush/Create/preview/notification-container.scss +104 -0
  81. package/v2Containers/WebPush/Create/preview/preview.scss +409 -0
  82. package/v2Containers/WebPush/Create/preview/styles/_android-mobile-chrome.scss +300 -0
  83. package/v2Containers/WebPush/Create/preview/styles/_android-mobile-edge.scss +12 -0
  84. package/v2Containers/WebPush/Create/preview/styles/_android-mobile-firefox.scss +12 -0
  85. package/v2Containers/WebPush/Create/preview/styles/_android-mobile-opera.scss +12 -0
  86. package/v2Containers/WebPush/Create/preview/styles/_android-tablet-chrome.scss +303 -0
  87. package/v2Containers/WebPush/Create/preview/styles/_android-tablet-edge.scss +11 -0
  88. package/v2Containers/WebPush/Create/preview/styles/_android-tablet-firefox.scss +11 -0
  89. package/v2Containers/WebPush/Create/preview/styles/_android-tablet-opera.scss +11 -0
  90. package/v2Containers/WebPush/Create/preview/styles/_base.scss +188 -0
  91. package/v2Containers/WebPush/Create/preview/styles/_ios.scss +106 -0
  92. package/v2Containers/WebPush/Create/preview/styles/_ipados.scss +107 -0
  93. package/v2Containers/WebPush/Create/preview/styles/_macos-chrome.scss +75 -0
  94. package/v2Containers/WebPush/Create/preview/styles/_windows-chrome.scss +174 -0
  95. package/v2Containers/WebPush/Create/preview/tests/DevicePreviewContent.test.js +909 -0
  96. package/v2Containers/WebPush/Create/preview/tests/NotificationContainer.test.js +1077 -0
  97. package/v2Containers/WebPush/Create/preview/tests/PreviewControls.test.js +723 -0
  98. package/v2Containers/WebPush/Create/preview/tests/WebPushPreview.test.js +943 -0
  99. package/v2Containers/WebPush/Create/preview/tests/__snapshots__/DevicePreviewContent.test.js.snap +128 -0
  100. package/v2Containers/WebPush/Create/preview/tests/__snapshots__/NotificationContainer.test.js.snap +121 -0
  101. package/v2Containers/WebPush/Create/preview/tests/__snapshots__/PreviewControls.test.js.snap +144 -0
  102. package/v2Containers/WebPush/Create/preview/tests/__snapshots__/WebPushPreview.test.js.snap +127 -0
  103. package/v2Containers/WebPush/Create/utils/urlValidation.js +116 -0
  104. package/v2Containers/WebPush/Create/utils/urlValidation.test.js +449 -0
  105. package/v2Containers/WebPush/actions.js +60 -0
  106. package/v2Containers/WebPush/constants.js +108 -0
  107. package/v2Containers/WebPush/index.js +2 -0
  108. package/v2Containers/WebPush/reducer.js +104 -0
  109. package/v2Containers/WebPush/sagas.js +119 -0
  110. package/v2Containers/WebPush/selectors.js +65 -0
  111. package/v2Containers/WebPush/tests/reducer.test.js +863 -0
  112. package/v2Containers/WebPush/tests/sagas.test.js +566 -0
  113. package/v2Containers/WebPush/tests/selectors.test.js +960 -0
  114. package/v2Containers/Whatsapp/constants.js +9 -0
  115. package/v2Containers/Whatsapp/reducer.js +34 -5
  116. package/v2Containers/Whatsapp/sagas.js +61 -10
  117. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +132 -0
  118. package/v2Containers/Whatsapp/tests/reducer.test.js +188 -0
  119. package/v2Containers/Whatsapp/tests/saga.test.js +420 -7
@@ -0,0 +1,123 @@
1
+ @import '~@capillarytech/cap-ui-library/styles/_variables';
2
+ @import './components/buttons';
3
+
4
+ .webpush-container {
5
+ .creatives-webpush-title,
6
+ .creatives-webpush-message,
7
+ .creatives-webpush-media {
8
+ display: flex;
9
+ flex-direction: column;
10
+ gap: $CAP_SPACE_08;
11
+ position: relative;
12
+ }
13
+
14
+ .creatives-webpush-title {
15
+ margin-bottom: $CAP_SPACE_12;
16
+ }
17
+
18
+ .webpush-title,
19
+ .webpush-message,
20
+ .webpush-media-type {
21
+ font-weight: $FONT_WEIGHT_MEDIUM;
22
+ color: $CAP_G16;
23
+ margin: 0;
24
+ font-size: 14px;
25
+ }
26
+
27
+ .creatives-webpush-brand-icon {
28
+ display: flex;
29
+ flex-direction: column;
30
+ gap: $CAP_SPACE_08;
31
+
32
+ .webpush-brand-icon {
33
+ font-weight: $FONT_WEIGHT_MEDIUM;
34
+ color: $CAP_G16;
35
+ margin: 0;
36
+ font-size: 14px;
37
+ }
38
+ }
39
+
40
+ .creatives-webpush-buttons-links {
41
+ display: flex;
42
+ flex-direction: column;
43
+ gap: 0.65rem;
44
+
45
+ .webpush-buttons-links {
46
+ font-weight: $FONT_WEIGHT_MEDIUM;
47
+ color: $CAP_G16;
48
+ margin: 0;
49
+ font-size: 16px;
50
+
51
+ .optional-text {
52
+ color: $CAP_G05;
53
+ font-size: $FONT_SIZE_M;
54
+ font-weight: normal;
55
+ padding: 0;
56
+ margin: 0.1rem;
57
+ }
58
+ }
59
+
60
+ .webpush-on-click-behaviour {
61
+ font-weight: $FONT_WEIGHT_MEDIUM;
62
+ color: $CAP_G16;
63
+ margin: 0;
64
+ font-size: 14px;
65
+ }
66
+ }
67
+
68
+ .creatives-webpush-actions {
69
+ margin-bottom: $CAP_SPACE_24;
70
+ }
71
+
72
+ .webpush-character-count {
73
+ position: absolute;
74
+ bottom: -0.8rem;
75
+ right: 0;
76
+ color: $CAP_G05;
77
+ pointer-events: none;
78
+ }
79
+
80
+ .webpush-message-divider {
81
+ margin-top: $CAP_SPACE_36;
82
+ }
83
+
84
+ .webpush-title-taglist,
85
+ .webpush-message-taglist {
86
+ margin-bottom: -2.5625rem; // approx -41px
87
+ }
88
+
89
+ .webpush-buttons-section-heading {
90
+ font-weight: $FONT_WEIGHT_MEDIUM;
91
+ color: $CAP_G16;
92
+ margin: 0;
93
+ margin-bottom: 0.6rem;
94
+ font-size: 14px;
95
+ }
96
+
97
+ .webpush-image-upload-method {
98
+ margin-top: $CAP_SPACE_16;
99
+ margin-bottom: $CAP_SPACE_16;
100
+ }
101
+
102
+ .webpush-image-upload-section,
103
+ .webpush-image-url-section {
104
+ display: flex;
105
+ flex-direction: column;
106
+ gap: $CAP_SPACE_12;
107
+ margin-top: $CAP_SPACE_16;
108
+ }
109
+
110
+ .webpush-image-specs {
111
+ display: flex;
112
+ justify-content: space-between;
113
+ margin-top: $CAP_SPACE_08;
114
+
115
+ .image-dimension,
116
+ .image-size,
117
+ .image-format {
118
+ color: $CAP_WHITE;
119
+ font-size: $FONT_SIZE_S;
120
+ }
121
+ }
122
+ }
123
+
@@ -0,0 +1,199 @@
1
+ import { defineMessages } from 'react-intl';
2
+
3
+ const scope = 'creatives.containersV2.WebPush';
4
+
5
+ export default defineMessages({
6
+ creativeName: {
7
+ id: `${scope}.creativeName`,
8
+ defaultMessage: 'Creative name',
9
+ },
10
+ creativeNamePlaceholder: {
11
+ id: `${scope}.creativeNamePlaceholder`,
12
+ defaultMessage: 'Enter creative name',
13
+ },
14
+ notificationTitle: {
15
+ id: `${scope}.notificationTitle`,
16
+ defaultMessage: 'Notification Title',
17
+ },
18
+ notificationTitlePlaceholder: {
19
+ id: `${scope}.notificationTitlePlaceholder`,
20
+ defaultMessage: 'Enter notification title',
21
+ },
22
+ message: {
23
+ id: `${scope}.message`,
24
+ defaultMessage: 'Message',
25
+ },
26
+ messagePlaceholder: {
27
+ id: `${scope}.messagePlaceholder`,
28
+ defaultMessage: 'Enter message',
29
+ },
30
+ mediaType: {
31
+ id: `${scope}.mediaType`,
32
+ defaultMessage: 'Media Type',
33
+ },
34
+ emptyTemplateErrorMessage: {
35
+ id: `${scope}.emptyTemplateErrorMessage`,
36
+ defaultMessage: 'Template name cannot be empty',
37
+ },
38
+ titleRequired: {
39
+ id: `${scope}.titleRequired`,
40
+ defaultMessage: 'Title is required',
41
+ },
42
+ messageRequired: {
43
+ id: `${scope}.messageRequired`,
44
+ defaultMessage: 'Message is required',
45
+ },
46
+ saveTemplate: {
47
+ id: `${scope}.saveTemplate`,
48
+ defaultMessage: 'Save Template',
49
+ },
50
+ accountRequired: {
51
+ id: `${scope}.accountRequired`,
52
+ defaultMessage: 'Select an account to create a template',
53
+ },
54
+ brandIconLogo: {
55
+ id: `${scope}.brandIconLogo`,
56
+ defaultMessage: 'Brand icon/logo',
57
+ },
58
+ dontShow: {
59
+ id: `${scope}.dontShow`,
60
+ defaultMessage: "Don't show",
61
+ },
62
+ uploadImage: {
63
+ id: `${scope}.uploadImage`,
64
+ defaultMessage: 'Upload image',
65
+ },
66
+ addImageUrl: {
67
+ id: `${scope}.addImageUrl`,
68
+ defaultMessage: 'Add image URL',
69
+ },
70
+ buttonsAndLinks: {
71
+ id: `${scope}.buttonsAndLinks`,
72
+ defaultMessage: 'Buttons and links',
73
+ },
74
+ optional: {
75
+ id: `${scope}.optional`,
76
+ defaultMessage: '(Optional)',
77
+ },
78
+ onClickBehaviour: {
79
+ id: `${scope}.onClickBehaviour`,
80
+ defaultMessage: 'On-click behaviour',
81
+ },
82
+ openSite: {
83
+ id: `${scope}.openSite`,
84
+ defaultMessage: 'Open site',
85
+ },
86
+ redirectToSpecificUrl: {
87
+ id: `${scope}.redirectToSpecificUrl`,
88
+ defaultMessage: 'Redirect to specific URL',
89
+ },
90
+ characterCount: {
91
+ id: `${scope}.characterCount`,
92
+ defaultMessage: 'Character count: {currentLength}/{maxLength}',
93
+ },
94
+ sizeLimit: {
95
+ id: `${scope}.sizeLimit`,
96
+ defaultMessage: 'Size upto: 5MB',
97
+ },
98
+ sizeLimitBrandIcon: {
99
+ id: `${scope}.sizeLimitBrandIcon`,
100
+ defaultMessage: 'Size upto: 1MB',
101
+ },
102
+ formatTypes: {
103
+ id: `${scope}.formatTypes`,
104
+ defaultMessage: 'Format: JPEG, JPG, PNG',
105
+ },
106
+ enterUrl: {
107
+ id: `${scope}.enterUrl`,
108
+ defaultMessage: 'Enter URL',
109
+ },
110
+ urlRequired: {
111
+ id: `${scope}.urlRequired`,
112
+ defaultMessage: 'URL is required',
113
+ },
114
+ urlInvalid: {
115
+ id: `${scope}.urlInvalid`,
116
+ defaultMessage: 'Please enter a valid URL',
117
+ },
118
+ buttons: {
119
+ id: `${scope}.buttons`,
120
+ defaultMessage: 'Buttons',
121
+ },
122
+ addPrimaryButton: {
123
+ id: `${scope}.addPrimaryButton`,
124
+ defaultMessage: 'Add primary button',
125
+ },
126
+ addSecondaryButton: {
127
+ id: `${scope}.addSecondaryButton`,
128
+ defaultMessage: 'Add secondary button',
129
+ },
130
+ addButton: {
131
+ id: `${scope}.addButton`,
132
+ defaultMessage: 'Add button',
133
+ },
134
+ buttonText: {
135
+ id: `${scope}.buttonText`,
136
+ defaultMessage: 'Button text',
137
+ },
138
+ buttonTextPlaceholder: {
139
+ id: `${scope}.buttonTextPlaceholder`,
140
+ defaultMessage: 'Enter button text',
141
+ },
142
+ buttonUrlLabel: {
143
+ id: `${scope}.buttonUrlLabel`,
144
+ defaultMessage: 'URL',
145
+ },
146
+ buttonUrlPlaceholder: {
147
+ id: `${scope}.buttonUrlPlaceholder`,
148
+ defaultMessage: 'Enter URL',
149
+ },
150
+ saveButton: {
151
+ id: `${scope}.saveButton`,
152
+ defaultMessage: 'Save',
153
+ },
154
+ deleteButton: {
155
+ id: `${scope}.deleteButton`,
156
+ defaultMessage: 'Delete',
157
+ },
158
+ cancelButton: {
159
+ id: `${scope}.cancelButton`,
160
+ defaultMessage: 'Cancel',
161
+ },
162
+ buttonTextRequired: {
163
+ id: `${scope}.buttonTextRequired`,
164
+ defaultMessage: 'Button text is required',
165
+ },
166
+ buttonUrlRequired: {
167
+ id: `${scope}.buttonUrlRequired`,
168
+ defaultMessage: 'Button URL is required',
169
+ },
170
+ buttonUrlInvalid: {
171
+ id: `${scope}.buttonUrlInvalid`,
172
+ defaultMessage: 'Please enter a valid URL',
173
+ },
174
+ addLabels: {
175
+ id: `${scope}.addLabels`,
176
+ defaultMessage: 'Add labels',
177
+ },
178
+ previewInAllDevices: {
179
+ id: `${scope}.previewInAllDevices`,
180
+ defaultMessage: 'Preview in all devices',
181
+ },
182
+ webPushNotificationPreview: {
183
+ id: `${scope}.webPushNotificationPreview`,
184
+ defaultMessage: 'Web push notification preview',
185
+ },
186
+ operatingSystem: {
187
+ id: `${scope}.operatingSystem`,
188
+ defaultMessage: 'Operating system',
189
+ },
190
+ browser: {
191
+ id: `${scope}.browser`,
192
+ defaultMessage: 'Browser',
193
+ },
194
+ state: {
195
+ id: `${scope}.state`,
196
+ defaultMessage: 'State',
197
+ },
198
+ });
199
+
@@ -0,0 +1,241 @@
1
+ import React, { useState, useMemo, useRef, useEffect } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import CapRow from '@capillarytech/cap-ui-library/CapRow';
4
+ import CapColumn from '@capillarytech/cap-ui-library/CapColumn';
5
+ import PreviewControls from './PreviewControls';
6
+ import NotificationContainer from './NotificationContainer';
7
+ import {
8
+ OS_OPTIONS,
9
+ STATE_OPTIONS,
10
+ DEFAULT_OS,
11
+ DEFAULT_BROWSER,
12
+ DEFAULT_STATE,
13
+ LAYOUT_MODE,
14
+ } from './constants';
15
+ import {
16
+ getBrowserOptionsForOS,
17
+ getResolvedVariant,
18
+ coerceStateForVariant,
19
+ getSupportedStates,
20
+ } from './config/notificationMappings';
21
+ // Device frame SVG assets
22
+ import topSvg from './assets/Top.svg';
23
+ import iosSvg from './assets/iOS.svg';
24
+ import lightSvg from './assets/Light.svg';
25
+ import './preview.scss';
26
+
27
+ /**
28
+ * Device-to-Asset Mapping
29
+ * Maps OS/Device types to their corresponding device frame SVG assets
30
+ */
31
+ const DEVICE_ASSET_MAP = {
32
+ 'macOS': topSvg,
33
+ 'Windows': topSvg,
34
+ 'iOS': iosSvg,
35
+ 'Android (Mobile)': iosSvg,
36
+ 'iPadOS': lightSvg,
37
+ 'Android (Tablet)': lightSvg,
38
+ };
39
+
40
+ /**
41
+ * DevicePreviewContent Component
42
+ *
43
+ * Displays device frame previews with web push notifications positioned
44
+ * relative to device frames. This component will be used inside the
45
+ * "Preview in all devices" SlideBox.
46
+ *
47
+ * The component renders:
48
+ * - Dropdown controls for OS, Browser, and State selection
49
+ * - A background container (100% width, height determined by device frame, #F4F5F7 background)
50
+ * - Device frames centered within the container
51
+ * - Notification previews positioned relative to device frames (Phase 4)
52
+ *
53
+ * NOTIFICATION POSITIONING SYSTEM:
54
+ *
55
+ * The notification position is configured using x, y coordinates relative to the device frame.
56
+ * Position is calculated relative to device frame boundaries, not background container.
57
+ *
58
+ * @param {string} notificationTitle - Title of the notification
59
+ * @param {string} notificationBody - Body text of the notification
60
+ * @param {string} url - URL for the notification
61
+ * @param {string} layoutMode - Layout mode for controls: LAYOUT_MODE.COMPACT, LAYOUT_MODE.INLINE, or LAYOUT_MODE.NEW_ROW (default: LAYOUT_MODE.COMPACT)
62
+ */
63
+ const DevicePreviewContent = ({
64
+ notificationTitle,
65
+ notificationBody,
66
+ url,
67
+ imageSrc,
68
+ brandIconSrc,
69
+ layoutMode = LAYOUT_MODE.COMPACT,
70
+ }) => {
71
+ // State for device selection
72
+ const [selectedOS, setSelectedOS] = useState(DEFAULT_OS);
73
+ const [selectedBrowser, setSelectedBrowser] = useState(DEFAULT_BROWSER);
74
+ const [selectedState, setSelectedState] = useState(DEFAULT_STATE);
75
+
76
+ // Filtered browser options per OS
77
+ const browserOptionsForOS = useMemo(() => getBrowserOptionsForOS(selectedOS), [selectedOS]);
78
+
79
+ // Coerce browser when OS changes and current browser is unsupported
80
+ useEffect(() => {
81
+ const hasBrowser = browserOptionsForOS.some((option) => option.value === selectedBrowser);
82
+ if (!hasBrowser && browserOptionsForOS.length) {
83
+ setSelectedBrowser(browserOptionsForOS[0].value);
84
+ }
85
+ }, [browserOptionsForOS, selectedBrowser]);
86
+
87
+ // Coerce state when OS/Browser changes and current state is unsupported
88
+ useEffect(() => {
89
+ const coercedState = coerceStateForVariant(selectedOS, selectedBrowser, selectedState);
90
+ if (coercedState && coercedState !== selectedState) {
91
+ setSelectedState(coercedState);
92
+ }
93
+ }, [selectedOS, selectedBrowser, selectedState]);
94
+
95
+ const stateOptionsForVariant = useMemo(() => {
96
+ const supportedStates = getSupportedStates(selectedOS, selectedBrowser);
97
+ if (!supportedStates.length) return STATE_OPTIONS;
98
+ return supportedStates.map((state) => ({ value: state, label: state }));
99
+ }, [selectedOS, selectedBrowser]);
100
+
101
+ // Refs for measuring device frame and notification dimensions
102
+ const deviceFrameRef = useRef(null);
103
+ const notificationRef = useRef(null);
104
+
105
+ // Get the device frame asset for the selected OS
106
+ const deviceFrameAsset = useMemo(() => {
107
+ return DEVICE_ASSET_MAP[selectedOS] || topSvg;
108
+ }, [selectedOS]);
109
+
110
+ const resolvedVariant = useMemo(() => {
111
+ return getResolvedVariant(selectedOS, selectedBrowser, selectedState);
112
+ }, [selectedOS, selectedBrowser, selectedState]);
113
+
114
+ // Notification position using x, y coordinates from variant configuration
115
+ const notificationPosition = useMemo(() => {
116
+ if (resolvedVariant?.stateConfig?.position?.custom) {
117
+ return resolvedVariant.stateConfig.position.custom;
118
+ }
119
+ // Fallback to origin (0, 0) if no position configured
120
+ return { x: 0, y: 0 };
121
+ }, [resolvedVariant]);
122
+
123
+ // Store position in state for Phase 5 (when we'll apply it to notification element)
124
+ const [calculatedPosition, setCalculatedPosition] = useState(notificationPosition);
125
+
126
+ // Update calculated position when dependencies change
127
+ useEffect(() => {
128
+ setCalculatedPosition(notificationPosition);
129
+ }, [notificationPosition]);
130
+
131
+ const handleOSChange = (value) => {
132
+ setSelectedOS(value);
133
+ };
134
+
135
+ const handleBrowserChange = (value) => {
136
+ setSelectedBrowser(value);
137
+ };
138
+
139
+ const handleStateChange = (value) => {
140
+ setSelectedState(value);
141
+ };
142
+
143
+ return (
144
+ <CapRow>
145
+ <CapColumn span={24}>
146
+ {/* Dropdown Controls */}
147
+ <PreviewControls
148
+ selectedOS={selectedOS}
149
+ selectedBrowser={selectedBrowser}
150
+ selectedState={selectedState}
151
+ osOptions={OS_OPTIONS}
152
+ browserOptions={browserOptionsForOS}
153
+ stateOptions={stateOptionsForVariant}
154
+ onOSChange={handleOSChange}
155
+ onBrowserChange={handleBrowserChange}
156
+ onStateChange={handleStateChange}
157
+ layoutMode={layoutMode}
158
+ showStateDropdown={true}
159
+ />
160
+
161
+ {/* Background Container - Preview Section */}
162
+ {/*
163
+ Background: #F4F5F7
164
+ Padding: 24px 16px 16px 16px
165
+ Width: 100% (responsive)
166
+ Height: Determined by device frame content
167
+ */}
168
+ <div className="device-preview-container">
169
+ {/* Device Frame Display */}
170
+ {/* Device frames are centered horizontally and vertically within the container */}
171
+ <div className="device-frame-wrapper">
172
+ <div className="device-frame-asset">
173
+ <img
174
+ ref={deviceFrameRef}
175
+ src={deviceFrameAsset}
176
+ alt={`${selectedOS} device frame`}
177
+ className="device-frame"
178
+ />
179
+ {/* Notification preview positioned relative to the device frame image */}
180
+ {/* Inline styles kept: Dynamic positioning calculated at runtime based on OS/browser/state selection.
181
+ These values change with user interaction and cannot be moved to static SCSS.
182
+ calculatedPosition is computed from variant configuration and device frame measurements. */}
183
+ <div
184
+ ref={notificationRef}
185
+ className={`device-notification-wrapper ${resolvedVariant ? '' : 'preview-unavailable'}`.trim()}
186
+ style={{
187
+ position: 'absolute',
188
+ left: `${calculatedPosition?.x || 0}px`,
189
+ ...(calculatedPosition?.bottom !== undefined
190
+ ? { bottom: `${calculatedPosition.bottom}px` }
191
+ : { top: `${calculatedPosition?.y || 0}px` }),
192
+ zIndex: 10,
193
+ }}
194
+ >
195
+ {resolvedVariant && (
196
+ <NotificationContainer
197
+ notificationTitle={notificationTitle}
198
+ notificationBody={notificationBody}
199
+ url={url}
200
+ selectedOS={selectedOS}
201
+ selectedBrowser={selectedBrowser}
202
+ notificationState={resolvedVariant.stateKey}
203
+ icon={resolvedVariant.variant.icon}
204
+ supportsExpanded={resolvedVariant.stateConfig.supportsExpanded}
205
+ enableMedia={resolvedVariant.stateConfig.showMedia}
206
+ // CTA buttons intentionally disabled per requirement change; do not enable unless confirmed.
207
+ enableCtas={false}
208
+ className={resolvedVariant.variant.notificationClassName}
209
+ imageSrc={imageSrc}
210
+ brandIconSrc={brandIconSrc}
211
+ />
212
+ )}
213
+ </div>
214
+ </div>
215
+ </div>
216
+ </div>
217
+ </CapColumn>
218
+ </CapRow>
219
+ );
220
+ };
221
+
222
+ DevicePreviewContent.propTypes = {
223
+ notificationTitle: PropTypes.string,
224
+ notificationBody: PropTypes.string,
225
+ url: PropTypes.string,
226
+ imageSrc: PropTypes.string,
227
+ brandIconSrc: PropTypes.string,
228
+ layoutMode: PropTypes.oneOf([LAYOUT_MODE.COMPACT, LAYOUT_MODE.INLINE, LAYOUT_MODE.NEW_ROW]),
229
+ };
230
+
231
+ DevicePreviewContent.defaultProps = {
232
+ notificationTitle: '',
233
+ notificationBody: '',
234
+ url: '',
235
+ imageSrc: '',
236
+ brandIconSrc: '',
237
+ layoutMode: LAYOUT_MODE.COMPACT,
238
+ };
239
+
240
+ export default DevicePreviewContent;
241
+