@bikdotai/bik-widgets 1.0.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 (206) hide show
  1. package/.eslintrc +22 -0
  2. package/.eslintrc.js +19 -0
  3. package/.github/workflows/main.yml +293 -0
  4. package/.prettierignore +13 -0
  5. package/.prettierrc +10 -0
  6. package/README.md +128 -0
  7. package/cypress/apiHelper/endpoints.ts +21 -0
  8. package/cypress/apiHelper/executor.ts +42 -0
  9. package/cypress/e2e/bottomDrawer.cy.ts +49 -0
  10. package/cypress/e2e/directReward.cy.ts +67 -0
  11. package/cypress/e2e/scratchTheCard.cy.ts +68 -0
  12. package/cypress/e2e/stw.cy.ts +82 -0
  13. package/cypress/e2e/waRedirection.cy.ts +46 -0
  14. package/cypress/fixtures/payloads.ts +330 -0
  15. package/cypress/support/commands.ts +37 -0
  16. package/cypress/support/e2e.ts +20 -0
  17. package/cypress.staging.config.ts +23 -0
  18. package/jsconfig.json +6 -0
  19. package/localtest.sh +10 -0
  20. package/log-server.js +86 -0
  21. package/package.json +79 -0
  22. package/postcss.config.js +8 -0
  23. package/src/Globals.d.ts +2 -0
  24. package/src/assets/lottie/santa.json +11722 -0
  25. package/src/assets/svg/CalendarClockIcon.tsx +30 -0
  26. package/src/assets/svg/CalendarIcon.tsx +24 -0
  27. package/src/assets/svg/CheckIcon.tsx +17 -0
  28. package/src/assets/svg/ChevronIcon.tsx +21 -0
  29. package/src/assets/svg/Close.tsx +39 -0
  30. package/src/assets/svg/Confetti.tsx +140 -0
  31. package/src/assets/svg/Copy.tsx +26 -0
  32. package/src/assets/svg/DropdownCheckIcon.tsx +35 -0
  33. package/src/assets/svg/ErrorIcon.tsx +27 -0
  34. package/src/assets/svg/RadioIcon.tsx +25 -0
  35. package/src/assets/svg/UncheckedCheckboxIcon.tsx +28 -0
  36. package/src/assets/svg/UncheckedRadioIcon.tsx +26 -0
  37. package/src/assets/svg/info.tsx +30 -0
  38. package/src/assets/svg/qrcode.svg +14 -0
  39. package/src/bootstrap.tsx +8 -0
  40. package/src/components/CtaCard/index.tsx +37 -0
  41. package/src/components/CtaCard/preview.module.css +32 -0
  42. package/src/components/CtaCard/style.module.css +32 -0
  43. package/src/components/EmailInput/emailInputBox.tsx +95 -0
  44. package/src/components/Fab/index.tsx +224 -0
  45. package/src/components/Fab/preview.module.css +28 -0
  46. package/src/components/Fab/style.module.css +37 -0
  47. package/src/components/Icons/Call.tsx +26 -0
  48. package/src/components/Icons/Cross.tsx +24 -0
  49. package/src/components/Icons/Gmail.tsx +61 -0
  50. package/src/components/Icons/Instagram.tsx +60 -0
  51. package/src/components/Icons/LiveChat.tsx +43 -0
  52. package/src/components/Icons/Messenger.tsx +57 -0
  53. package/src/components/Icons/Send.tsx +22 -0
  54. package/src/components/Icons/Whatsapp.tsx +24 -0
  55. package/src/components/Shimmer/index.tsx +12 -0
  56. package/src/components/Shimmer/style.module.css +37 -0
  57. package/src/components/SmsInput/smsInputBox.tsx +135 -0
  58. package/src/components/UserDetailsV2/userDetailsV2.desktop.module.css +52 -0
  59. package/src/components/UserDetailsV2/userDetailsV2.mobile.module.css +52 -0
  60. package/src/components/UserDetailsV2/userDetailsV2.module.css +81 -0
  61. package/src/components/UserDetailsV2/userDetailsV2.tsx +527 -0
  62. package/src/components/WhatsappInput/Spinner.tsx +26 -0
  63. package/src/components/WhatsappInput/whatsappInput.module.css +106 -0
  64. package/src/components/WhatsappInput/whatsappInputBox.tsx +155 -0
  65. package/src/components/WhatsappInput/whatsappInputPreviewDesktop.module.css +71 -0
  66. package/src/components/WhatsappInput/whatsappInputPreviewMobile.module.css +65 -0
  67. package/src/components/checkbox/checkbox.module.css +19 -0
  68. package/src/components/checkbox/checkbox.tsx +88 -0
  69. package/src/components/countryCodePicker/countriesDropdown.module.css +77 -0
  70. package/src/components/countryCodePicker/countriesDropdown.tsx +81 -0
  71. package/src/components/couponDetails/coupon.module.css +208 -0
  72. package/src/components/couponDetails/coupon.tsx +210 -0
  73. package/src/components/couponDetails/couponPreviewDesktop.module.css +158 -0
  74. package/src/components/couponDetails/couponPreviewMobile.module.css +164 -0
  75. package/src/components/index.ts +3 -0
  76. package/src/components/inputComponents/Checkbox.module.css +197 -0
  77. package/src/components/inputComponents/Checkbox.tsx +85 -0
  78. package/src/components/inputComponents/DatePicker.module.css +565 -0
  79. package/src/components/inputComponents/DatePicker.tsx +278 -0
  80. package/src/components/inputComponents/Dropdown.module.css +796 -0
  81. package/src/components/inputComponents/Dropdown.tsx +630 -0
  82. package/src/components/inputComponents/InputBox.module.css +401 -0
  83. package/src/components/inputComponents/InputBox.tsx +209 -0
  84. package/src/components/selectedCountry/selectedCountry.module.css +76 -0
  85. package/src/components/selectedCountry/selectedCountry.tsx +76 -0
  86. package/src/components/selectedCountry/selectedCountryPreviewDesktop.module.css +56 -0
  87. package/src/components/selectedCountry/selectedCountryPreviewMobile.module.css +57 -0
  88. package/src/components/userDetailsForm/RenderCustomFields.tsx +333 -0
  89. package/src/components/userDetailsForm/userDetailsForm.tsx +675 -0
  90. package/src/hooks/index.ts +4 -0
  91. package/src/hooks/useExitIntent.ts +452 -0
  92. package/src/hooks/useIsMobile.tsx +21 -0
  93. package/src/hooks/useMessageEvent.ts +8 -0
  94. package/src/hooks/useTriggeredIntentDetails.ts +43 -0
  95. package/src/hooks/useUrlListerner.ts +30 -0
  96. package/src/hooks/useWebSocketLogger.ts +59 -0
  97. package/src/hooks/useWindowEvent.ts +8 -0
  98. package/src/icons/copyIcon.tsx +26 -0
  99. package/src/icons/crossIconDesktop.tsx +20 -0
  100. package/src/icons/crossIconMobile.tsx +20 -0
  101. package/src/index.html +30 -0
  102. package/src/index.ts +32 -0
  103. package/src/index.tsx +1 -0
  104. package/src/repo/widgetRepo.ts +21 -0
  105. package/src/types/customFields.ts +73 -0
  106. package/src/utilities/cookie.ts +70 -0
  107. package/src/utilities/customFieldTypeMapping.ts +67 -0
  108. package/src/utilities/customFieldValidation.ts +201 -0
  109. package/src/utilities/encryption.ts +21 -0
  110. package/src/utilities/exitIntentUtils.ts +31 -0
  111. package/src/utilities/global.css +11 -0
  112. package/src/utilities/languageUtilities.ts +235 -0
  113. package/src/utilities/localRunner.js +26 -0
  114. package/src/utilities/localRunner.ts +27 -0
  115. package/src/utilities/localStorage.ts +40 -0
  116. package/src/utilities/script.tsx +15 -0
  117. package/src/utilities/stringUtils.ts +5 -0
  118. package/src/utilities/styleUtils.ts +134 -0
  119. package/src/utilities/variables.ts +11 -0
  120. package/src/utilities/widgetUtils.js +342 -0
  121. package/src/utilities/widgetUtils.ts +313 -0
  122. package/src/widgets/BottomDrawer/config.ts +41 -0
  123. package/src/widgets/BottomDrawer/index.tsx +116 -0
  124. package/src/widgets/BottomDrawer/modal.tsx +286 -0
  125. package/src/widgets/BottomDrawer/preview.module.css +122 -0
  126. package/src/widgets/BottomDrawer/previewMobile.module.css +124 -0
  127. package/src/widgets/BottomDrawer/style.module.css +279 -0
  128. package/src/widgets/CaptivateBanner/captivateBanner.tsx +200 -0
  129. package/src/widgets/CaptivateBanner/config.ts +72 -0
  130. package/src/widgets/CaptivateBanner/index.tsx +204 -0
  131. package/src/widgets/CaptivateBanner/previewDesktop.module.css +51 -0
  132. package/src/widgets/CaptivateBanner/previewMobile.module.css +51 -0
  133. package/src/widgets/CaptivateBanner/style.module.css +77 -0
  134. package/src/widgets/CaptivateBanner/utils.ts +104 -0
  135. package/src/widgets/CentrallyAlignedPopup/config.ts +42 -0
  136. package/src/widgets/CentrallyAlignedPopup/index.tsx +109 -0
  137. package/src/widgets/CentrallyAlignedPopup/modal.tsx +269 -0
  138. package/src/widgets/CentrallyAlignedPopup/preview.module.css +153 -0
  139. package/src/widgets/CentrallyAlignedPopup/previewMobile.module.css +153 -0
  140. package/src/widgets/CentrallyAlignedPopup/style.module.css +283 -0
  141. package/src/widgets/DirectReward/components/couponDetails.tsx +265 -0
  142. package/src/widgets/DirectReward/components/userDetails.tsx +117 -0
  143. package/src/widgets/DirectReward/config.ts +186 -0
  144. package/src/widgets/DirectReward/directReward.tsx +350 -0
  145. package/src/widgets/DirectReward/index.tsx +579 -0
  146. package/src/widgets/DirectReward/previewStyles/thankYouPreviewDesktop.module.css +276 -0
  147. package/src/widgets/DirectReward/previewStyles/thankYouPreviewMobile.module.css +303 -0
  148. package/src/widgets/DirectReward/previewStyles/userDetailsPreviewDesktop.module.css +511 -0
  149. package/src/widgets/DirectReward/previewStyles/userDetailsPreviewMobile.module.css +462 -0
  150. package/src/widgets/DirectReward/style.module.css +836 -0
  151. package/src/widgets/ExitIntentHook.tsx +28 -0
  152. package/src/widgets/STW/api.ts +70 -0
  153. package/src/widgets/STW/components/svgFactory.tsx +44 -0
  154. package/src/widgets/STW/config.ts +193 -0
  155. package/src/widgets/STW/context.ts +7 -0
  156. package/src/widgets/STW/couponDetails.tsx +121 -0
  157. package/src/widgets/STW/index.tsx +733 -0
  158. package/src/widgets/STW/previewStyles/thankyouPreviewDesktop.module.css +215 -0
  159. package/src/widgets/STW/previewStyles/thankyouPreviewMobile.module.css +205 -0
  160. package/src/widgets/STW/previewStyles/userInputsPreviewDesktop.module.css +732 -0
  161. package/src/widgets/STW/previewStyles/userInputsPreviewMobile.module.css +661 -0
  162. package/src/widgets/STW/previewStyles/wheelPreviewDesktop.module.css +498 -0
  163. package/src/widgets/STW/previewStyles/wheelPreviewMobile.module.css +497 -0
  164. package/src/widgets/STW/stw1.tsx +119 -0
  165. package/src/widgets/STW/stw2Components/wheelDesign.tsx +183 -0
  166. package/src/widgets/STW/stw2Pages/couponDetails.tsx +72 -0
  167. package/src/widgets/STW/stw2Pages/stw2.tsx +212 -0
  168. package/src/widgets/STW/stw2Pages/style.module.css +1226 -0
  169. package/src/widgets/STW/stw2Pages/userDetails.tsx +86 -0
  170. package/src/widgets/STW/stw2Pages/wheel.tsx +117 -0
  171. package/src/widgets/STW/stw2PreviewStyles/thankyouPreviewDesktop.module.css +835 -0
  172. package/src/widgets/STW/stw2PreviewStyles/thankyouPreviewMobile.module.css +787 -0
  173. package/src/widgets/STW/stw2PreviewStyles/userInputsPreviewDesktop.module.css +867 -0
  174. package/src/widgets/STW/stw2PreviewStyles/userInputsPreviewMobile.module.css +798 -0
  175. package/src/widgets/STW/stw2PreviewStyles/wheelPreviewDesktop.module.css +572 -0
  176. package/src/widgets/STW/stw2PreviewStyles/wheelPreviewMobile.module.css +559 -0
  177. package/src/widgets/STW/style.module.css +901 -0
  178. package/src/widgets/STW/userDetails.tsx +150 -0
  179. package/src/widgets/STW/utility.ts +664 -0
  180. package/src/widgets/STW/wheel.tsx +304 -0
  181. package/src/widgets/ScratchCard/ScratchOff/scratchOff.tsx +157 -0
  182. package/src/widgets/ScratchCard/config.ts +152 -0
  183. package/src/widgets/ScratchCard/globalStyle.module.css +931 -0
  184. package/src/widgets/ScratchCard/index.tsx +546 -0
  185. package/src/widgets/ScratchCard/modal.tsx +225 -0
  186. package/src/widgets/ScratchCard/preview.module.css +250 -0
  187. package/src/widgets/ScratchCard/previewMobile.module.css +247 -0
  188. package/src/widgets/ScratchCard/previewStyles/userDetailsPreviewDesktop.module.css +537 -0
  189. package/src/widgets/ScratchCard/previewStyles/userDetailsPreviewMobile.module.css +463 -0
  190. package/src/widgets/ScratchCard/style.module.css +220 -0
  191. package/src/widgets/ShopifyForm/config.ts +168 -0
  192. package/src/widgets/ShopifyForm/index.tsx +214 -0
  193. package/src/widgets/ShopifyForm/previewDesktop.module.css +117 -0
  194. package/src/widgets/ShopifyForm/previewMobile.module.css +131 -0
  195. package/src/widgets/ShopifyForm/shopifyForm.tsx +445 -0
  196. package/src/widgets/ShopifyForm/style.module.css +161 -0
  197. package/src/widgets/SingleButtonRedirection/config.ts +47 -0
  198. package/src/widgets/SingleButtonRedirection/index.tsx +121 -0
  199. package/src/widgets/WebStories/config.ts +105 -0
  200. package/src/widgets/WebStories/index.css +3 -0
  201. package/src/widgets/WebStories/index.tsx +282 -0
  202. package/src/widgets/WebStories/style.module.css +26 -0
  203. package/src/widgets/index.tsx +3 -0
  204. package/src/widgets/utility.ts +31 -0
  205. package/tsconfig.json +12 -0
  206. package/webpack.config.js +239 -0
@@ -0,0 +1,579 @@
1
+ import React, { useState, useEffect, useRef, LegacyRef, Suspense } from 'react';
2
+ import includeMe from 'utilities/script';
3
+ import { IPageConfigProcessed, WidgetUtils } from 'utilities/widgetUtils';
4
+ import { shouldShowExitIntent } from 'utilities/exitIntentUtils';
5
+ import {
6
+ addLead,
7
+ fetchCouponCode,
8
+ IChannelInfo,
9
+ IPayloadFetchCouponCode,
10
+ } from 'widgets/STW/api';
11
+ import { IUserInputs } from 'widgets/STW/userDetails';
12
+ import {
13
+ cookieClickHandler,
14
+ getCookie,
15
+ getScrollPercent,
16
+ setCookie,
17
+ } from '../STW/utility';
18
+ import DirectRewardTemplate from './directReward';
19
+ import DRStyle from './style.module.css';
20
+ import {
21
+ IDRWidgetCustomisation,
22
+ IDRWidgetLeadGeneration,
23
+ IDRWidgetVisibility,
24
+ ISTWWidgetLeadGeneration,
25
+ WIDGET_NAME,
26
+ WidgetInfo,
27
+ WidgetSchema,
28
+ ISO_CODES_VALUES,
29
+ } from '@bikdotai/bik-models/dm';
30
+ import {
31
+ LOCAL_STORAGE_KEYS,
32
+ storeDataInLocalStorage,
33
+ } from '../../utilities/localStorage';
34
+ import { decryptBikData } from '../../utilities/encryption';
35
+ import useIsMobile from '../../hooks/useIsMobile';
36
+ import { useTriggeredIntentDetails } from '../../hooks/useTriggeredIntentDetails';
37
+ import { getTriggeredPageFromUrl } from '../utility';
38
+ import {
39
+ EXIT_INTENT_LEVEL,
40
+ TRIGGERED_INTENT_SOURCE,
41
+ TRIGGERED_INTENT_TYPE,
42
+ } from '@bikdotai/bik-models/dm/models/analytics';
43
+ import { CUSTOM_FIELDS } from 'utilities/customFieldTypeMapping';
44
+ import { LEAD_GENERATION_CHANNELS } from '../../types/customFields';
45
+
46
+ const ExitIntentHook = React.lazy(() => import('../ExitIntentHook'));
47
+
48
+ interface IDR extends WidgetSchema {
49
+ visibility: IDRWidgetVisibility;
50
+ id: string;
51
+ storeWidgetConfig: IPageConfigProcessed;
52
+ environment: string;
53
+ preview?: boolean;
54
+ templateName?: WIDGET_NAME;
55
+ isMobile?: boolean;
56
+ previewLanguage?: ISO_CODES_VALUES;
57
+ }
58
+
59
+ export interface IDRTemplate {
60
+ id: string;
61
+ info?: WidgetInfo;
62
+ widgetCustomisation?: IDRWidgetCustomisation;
63
+ visibility: IDRWidgetVisibility;
64
+ discountCodeDetails?: {
65
+ discountCodeTitle: string;
66
+ discountCodeDescription: string;
67
+ };
68
+ claimPrizeHandle?: (userInputs: IUserInputs) => Promise<void>;
69
+ error?: string;
70
+ isLoading?: boolean;
71
+ preview?: boolean;
72
+ isMobile?: boolean;
73
+ leadGeneration?: IDRWidgetLeadGeneration;
74
+ showComponents?: {
75
+ userDetails: boolean;
76
+ couponDetails: boolean;
77
+ floatingButton: boolean;
78
+ };
79
+ setShowComponents: React.Dispatch<
80
+ React.SetStateAction<{
81
+ userDetails: boolean;
82
+ couponDetails: boolean;
83
+ floatingButton: boolean;
84
+ }>
85
+ >;
86
+ onCloseHandle?: () => void;
87
+ templateName?: WIDGET_NAME;
88
+ containerReference?: LegacyRef<HTMLDivElement>;
89
+ isMobileDevice?: boolean;
90
+ countryCode?: string;
91
+ environment: string;
92
+ widgetLanguage: ISO_CODES_VALUES;
93
+ }
94
+
95
+ let isModalOpened = false;
96
+ const DirectReward = (props: IDR) => {
97
+ const { widgetCustomisation, leadGeneration, environment, info, visibility } =
98
+ props;
99
+ const { mandatoryOption, optionalOptions } =
100
+ leadGeneration as ISTWWidgetLeadGeneration;
101
+ const { storeId, templateId, templateName } = info as WidgetInfo;
102
+ const [showComponents, setShowComponents] = useState({
103
+ userDetails: false,
104
+ couponDetails: false,
105
+ floatingButton: false,
106
+ });
107
+ const [error, setError] = useState<string>(null);
108
+ const [isLoading, setIsLoading] = useState<boolean>(false);
109
+ const [sameMobileNumberTogglers, setSameMobileNumberTogglers] = useState<{
110
+ sameSMSNo: boolean;
111
+ sameWhatsappNumber: boolean;
112
+ }>({
113
+ sameSMSNo: false,
114
+ sameWhatsappNumber: false,
115
+ });
116
+ const [couponCodeDetails, setCouponCodeDetails] = useState<{
117
+ discountCodeTitle: string;
118
+ discountCodeDescription: string;
119
+ }>({
120
+ discountCodeTitle: 'SND20OFF',
121
+ discountCodeDescription:
122
+ '20% off on entire order | Minimum purchase of ₹500.00 One time use only | Expiry date : 5th Aug, 2022',
123
+ });
124
+ const widgetUtils = new WidgetUtils();
125
+ const directRewardContainer = useRef(null);
126
+ const isMobileDevice = useIsMobile();
127
+ const { setTriggeredIntentDetails, getTriggeredIntentDetails } =
128
+ useTriggeredIntentDetails(props.id);
129
+
130
+ const triggers =
131
+ (visibility as IDRWidgetVisibility).triggers ??
132
+ ({} as IDRWidgetVisibility['triggers']);
133
+ const pageScroll = triggers?.pageScroll;
134
+ const viewLimit = (triggers?.frequency ? triggers.frequency : 0) / 24;
135
+ const timeDelay = (triggers?.timeDelay ? triggers.timeDelay : 0) * 1000;
136
+
137
+ const handleExitIntent = (exitIntentType: TRIGGERED_INTENT_TYPE) => {
138
+ if (!isModalOpened) {
139
+ setTriggeredIntentDetails({
140
+ triggerSource: TRIGGERED_INTENT_SOURCE.EXIT_INTENT,
141
+ triggerType: exitIntentType,
142
+ triggeredPage: getTriggeredPageFromUrl(window.location.href),
143
+ exitIntentLevel:
144
+ triggers?.showExitIntentOn ?? EXIT_INTENT_LEVEL.WEBPAGE,
145
+ });
146
+ launchModal();
147
+ }
148
+ };
149
+
150
+ const getExitIntentHook = () => {
151
+ if (props.preview) {
152
+ return false;
153
+ }
154
+
155
+ const pathname = window.location.pathname;
156
+ const location = window.location.href;
157
+ const visiblePages = visibility?.visiblePages ?? [];
158
+
159
+ if (
160
+ shouldShowExitIntent({
161
+ visiblePages,
162
+ currentLocation: location,
163
+ currentPathname: pathname,
164
+ isMobileDevice,
165
+ triggers,
166
+ })
167
+ ) {
168
+ return (
169
+ <Suspense fallback={null}>
170
+ <ExitIntentHook
171
+ onExitIntent={handleExitIntent}
172
+ config={{
173
+ exitIntentTimeDelay: triggers?.exitIntentTimeDelay,
174
+ exitIntentViewLimit: triggers?.exitIntentViewLimit,
175
+ exitIntentFastUpScroll: triggers?.exitIntentFastUpScroll,
176
+ showExitIntentOn: triggers?.showExitIntentOn,
177
+ }}
178
+ widgetId={props.id}
179
+ />
180
+ </Suspense>
181
+ );
182
+ } else {
183
+ return null;
184
+ }
185
+ };
186
+
187
+ useEffect(() => {
188
+ cookieClickHandler(
189
+ `bik-${props.id}-visitor`,
190
+ 'bikvisitor',
191
+ 'WIDGET_VISITED',
192
+ 1,
193
+ props.id,
194
+ environment,
195
+ );
196
+ const shouldShow = widgetUtils.showWidget(
197
+ {
198
+ currentUrl: window.location.href.replace(window.location.origin, ''),
199
+ customUrls: props.storeWidgetConfig,
200
+ currentWidgetId: props.id,
201
+ },
202
+ props.info.isAutomationTesting,
203
+ );
204
+ if (
205
+ !shouldShow ||
206
+ (getCookie(`bik-${props.id}-claimed`) &&
207
+ visibility?.triggers?.hideAfterClaimed)
208
+ ) {
209
+ return;
210
+ }
211
+ if (visibility.triggers?.fabButtonVisibility) {
212
+ setShowComponents({
213
+ ...showComponents,
214
+ floatingButton: true,
215
+ });
216
+ }
217
+ if (
218
+ getCookie(`bik-${props.id}-modalopened`) &&
219
+ visibility?.triggers?.frequency
220
+ ) {
221
+ return;
222
+ }
223
+ launchModalOnTimeDelay();
224
+ const scrollCleanup = launchModalOnScroll();
225
+
226
+ return () => {
227
+ if (scrollCleanup) {
228
+ scrollCleanup();
229
+ }
230
+ };
231
+ }, [window.location.href]);
232
+
233
+ useEffect(() => {
234
+ function handleClickOutside(event) {
235
+ if (
236
+ directRewardContainer.current &&
237
+ !directRewardContainer.current.contains(event.target)
238
+ ) {
239
+ if (!props.preview) {
240
+ onCloseHandle();
241
+ }
242
+ }
243
+ }
244
+
245
+ document.addEventListener('click', handleClickOutside);
246
+ return () => {
247
+ document.removeEventListener('click', handleClickOutside);
248
+ };
249
+ }, [directRewardContainer]);
250
+
251
+ const launchModal = () => {
252
+ isModalOpened = true;
253
+ document.body.classList.add(DRStyle.noScrollBackground);
254
+ setShowComponents(prev => ({
255
+ ...prev,
256
+ couponDetails: false,
257
+ userDetails: true,
258
+ }));
259
+ setCookie(`bik-${props.id}-modalopened`, 'bikmodalopened', viewLimit);
260
+ cookieClickHandler(
261
+ `bik-${props.id}-clicked`,
262
+ 'bikview',
263
+ 'WIDGET_CLICKED',
264
+ 1,
265
+ props.id,
266
+ environment,
267
+ );
268
+ };
269
+
270
+ const launchModalOnTimeDelay = () => {
271
+ if (timeDelay) {
272
+ setTimeout(() => {
273
+ if (!isModalOpened) {
274
+ setTriggeredIntentDetails({
275
+ triggerSource: TRIGGERED_INTENT_SOURCE.AUTO_POPULATE,
276
+ triggerType: TRIGGERED_INTENT_TYPE.TIME_DELAY,
277
+ triggeredPage: getTriggeredPageFromUrl(window.location.href),
278
+ });
279
+ launchModal();
280
+ }
281
+ }, timeDelay);
282
+ }
283
+ };
284
+
285
+ const launchModalOnScroll = () => {
286
+ const handleScroll = () => {
287
+ if (
288
+ isModalOpened ||
289
+ !pageScroll ||
290
+ (getCookie(`bik-${props.id}-claimed`) &&
291
+ visibility?.triggers?.hideAfterClaimed) ||
292
+ (getCookie(`bik-${props.id}-modalopened`) &&
293
+ visibility?.triggers?.frequency)
294
+ ) {
295
+ return;
296
+ }
297
+ if (pageScroll && getScrollPercent() >= pageScroll) {
298
+ setTriggeredIntentDetails({
299
+ triggerSource: TRIGGERED_INTENT_SOURCE.AUTO_POPULATE,
300
+ triggerType: TRIGGERED_INTENT_TYPE.PAGE_SCROLL,
301
+ triggeredPage: getTriggeredPageFromUrl(window.location.href),
302
+ });
303
+ launchModal();
304
+ }
305
+ };
306
+
307
+ window.addEventListener('scrollend', handleScroll);
308
+ return () => window.removeEventListener('scrollend', handleScroll);
309
+ };
310
+
311
+ const onCloseHandle = () => {
312
+ setError(null);
313
+ setShowComponents(prev => ({
314
+ couponDetails: false,
315
+ userDetails: false,
316
+ floatingButton: !!(prev.couponDetails === true
317
+ ? triggers?.fabButtonVisibility &&
318
+ !getCookie(`bik-${props.id}-claimed`) &&
319
+ visibility?.triggers?.hideAfterClaimed &&
320
+ !getCookie(`bik-${props.id}-modalopened`) &&
321
+ visibility?.triggers?.frequency
322
+ : triggers?.fabButtonVisibility),
323
+ }));
324
+ const bikDirectRewardParentContainer = document.getElementsByClassName(
325
+ DRStyle.bikDRParentContainer,
326
+ )[0];
327
+ const bikDirectRewardMainContainer = document.getElementsByClassName(
328
+ DRStyle.bikDRMainContainer,
329
+ )[0];
330
+ bikDirectRewardMainContainer.classList.remove(DRStyle.scaleUpEffect);
331
+ if (window.screen.width <= 768) {
332
+ bikDirectRewardParentContainer.classList.add(DRStyle.scaleDownEffect);
333
+ } else {
334
+ bikDirectRewardMainContainer.classList.add(DRStyle.scaleDownEffect);
335
+ }
336
+ document.body.classList.remove(DRStyle.noScrollBackground);
337
+ isModalOpened = !viewLimit;
338
+ };
339
+
340
+ const claimPrizeHandle = async (userInputs: IUserInputs) => {
341
+ let primaryPhoneNumber: string,
342
+ secondaryPhoneNumber: string,
343
+ emailId: string;
344
+ const primaryInfo: IChannelInfo[] = [];
345
+ const secondaryInfo: IChannelInfo[] = [];
346
+ Object.keys(mandatoryOption).map(key => {
347
+ if (mandatoryOption[key]) {
348
+ if (key === CUSTOM_FIELDS) {
349
+ const customFields = userInputs[key];
350
+ Object.keys(customFields).forEach(fieldKey => {
351
+ const fieldId = Number(fieldKey);
352
+ const fieldValue = customFields[fieldKey];
353
+ if (
354
+ mandatoryOption.customFields &&
355
+ Array.isArray(mandatoryOption.customFields) &&
356
+ mandatoryOption.customFields.some(field => field.id === fieldId)
357
+ ) {
358
+ primaryInfo.push({
359
+ channel: 'customField',
360
+ value: fieldValue,
361
+ customFieldId: fieldId,
362
+ });
363
+ }
364
+ });
365
+ } else {
366
+ const value = userInputs[key].countryCodeData
367
+ ? userInputs[key].countryCodeData.dial + userInputs[key].value
368
+ : userInputs[key].value;
369
+ let channel: LEAD_GENERATION_CHANNELS;
370
+ if (key === 'isEmail') {
371
+ channel = LEAD_GENERATION_CHANNELS.EMAIL;
372
+ emailId = value;
373
+ } else if (key === 'isSms') {
374
+ channel = LEAD_GENERATION_CHANNELS.SMS;
375
+ secondaryPhoneNumber = value;
376
+ } else if (key === 'isWhatsapp') {
377
+ channel = LEAD_GENERATION_CHANNELS.WHATSAPP;
378
+ primaryPhoneNumber = value;
379
+ }
380
+ primaryInfo.push({
381
+ channel: channel,
382
+ value: value,
383
+ });
384
+ }
385
+ }
386
+ });
387
+ sameMobileNumberTogglers.sameSMSNo
388
+ ? (userInputs['isWhatsapp'] = {
389
+ ...userInputs['isWhatsapp'],
390
+ countryCodeData: userInputs['isSms'].countryCodeData,
391
+ value: userInputs['isSms'].value,
392
+ })
393
+ : sameMobileNumberTogglers.sameWhatsappNumber
394
+ ? (userInputs['isSms'] = {
395
+ ...userInputs['isSms'],
396
+ countryCodeData: userInputs['isWhatsapp'].countryCodeData,
397
+ value: userInputs['isWhatsapp'].value,
398
+ })
399
+ : '';
400
+
401
+ Object.keys(optionalOptions).map(key => {
402
+ if (optionalOptions[key]) {
403
+ if (key === CUSTOM_FIELDS) {
404
+ const customFields = userInputs[key];
405
+ Object.keys(customFields).forEach(fieldKey => {
406
+ const fieldId = Number(fieldKey);
407
+ const fieldValue = customFields[fieldKey];
408
+ if (
409
+ optionalOptions.customFields &&
410
+ Array.isArray(optionalOptions.customFields) &&
411
+ optionalOptions.customFields.some(field => field.id === fieldId)
412
+ ) {
413
+ secondaryInfo.push({
414
+ channel: 'customField',
415
+ value: fieldValue,
416
+ customFieldId: fieldId,
417
+ });
418
+ }
419
+ });
420
+ } else {
421
+ const value = userInputs[key].countryCodeData
422
+ ? userInputs[key].countryCodeData.dial + userInputs[key].value
423
+ : userInputs[key].value;
424
+ let channel: LEAD_GENERATION_CHANNELS;
425
+ if (key === 'isEmail') {
426
+ channel = LEAD_GENERATION_CHANNELS.EMAIL;
427
+ emailId = value;
428
+ } else if (key === 'isSms') {
429
+ channel = LEAD_GENERATION_CHANNELS.SMS;
430
+ secondaryPhoneNumber = value;
431
+ } else if (key === 'isWhatsapp') {
432
+ channel = LEAD_GENERATION_CHANNELS.WHATSAPP;
433
+ primaryPhoneNumber = value;
434
+ }
435
+ secondaryInfo.push({
436
+ channel: channel,
437
+ value: value,
438
+ });
439
+ }
440
+ }
441
+ });
442
+
443
+ const triggeredIntentDetails = getTriggeredIntentDetails();
444
+
445
+ const data: IPayloadFetchCouponCode = {
446
+ storeId: storeId,
447
+ widgetId: props.id,
448
+ primaryInfo: primaryInfo,
449
+ secondaryInfo: secondaryInfo,
450
+ templateId: templateId,
451
+ quadrant: 1,
452
+ triggeredIntentDetails,
453
+ };
454
+ setIsLoading(true);
455
+ if (templateName === WIDGET_NAME.DIRECT_REWARD) {
456
+ let disbursedCoupon = undefined;
457
+ if (primaryPhoneNumber) {
458
+ disbursedCoupon = localStorage.getItem(
459
+ `${LOCAL_STORAGE_KEYS.BIK_COUPON_DISBURSED}-${props.id}-${primaryPhoneNumber}`,
460
+ );
461
+ }
462
+ if (!disbursedCoupon && secondaryPhoneNumber) {
463
+ disbursedCoupon = localStorage.getItem(
464
+ `${LOCAL_STORAGE_KEYS.BIK_COUPON_DISBURSED}-${props.id}-${secondaryPhoneNumber}`,
465
+ );
466
+ }
467
+ if (!disbursedCoupon && emailId) {
468
+ disbursedCoupon = localStorage.getItem(
469
+ `${LOCAL_STORAGE_KEYS.BIK_COUPON_DISBURSED}-${props.id}-${emailId}`,
470
+ );
471
+ }
472
+ if (disbursedCoupon) {
473
+ const decryptedData = JSON.parse(decryptBikData(disbursedCoupon));
474
+ setCouponCodeDetails({
475
+ discountCodeTitle: decryptedData.code,
476
+ discountCodeDescription: decryptedData.description,
477
+ });
478
+ setIsLoading(false);
479
+ setShowComponents({
480
+ ...showComponents,
481
+ userDetails: false,
482
+ couponDetails: true,
483
+ });
484
+ return;
485
+ }
486
+ const response: any = await fetchCouponCode(data, environment);
487
+ setIsLoading(false);
488
+ if (response.status === 404) {
489
+ if (response.error == 'Customer already exist!') {
490
+ setError('Sorry, You already claimed the prize.');
491
+ } else {
492
+ setError(response.error);
493
+ }
494
+ }
495
+ if (response.code && response.description) {
496
+ storeDataInLocalStorage(
497
+ LOCAL_STORAGE_KEYS.BIK_PHONE_NUMBER,
498
+ primaryPhoneNumber,
499
+ );
500
+ storeDataInLocalStorage(LOCAL_STORAGE_KEYS.BIK_EMAIL, emailId);
501
+ if (visibility.triggers?.hideAfterClaimed) {
502
+ setCookie(`bik-${props.id}-claimed`, response.code, 24820);
503
+ }
504
+ setCouponCodeDetails({
505
+ discountCodeTitle: response.code,
506
+ discountCodeDescription: response.description,
507
+ });
508
+ const stringifiedCouponData = JSON.stringify({
509
+ code: response.code,
510
+ description: response.description,
511
+ });
512
+ if (primaryPhoneNumber) {
513
+ storeDataInLocalStorage(
514
+ `${LOCAL_STORAGE_KEYS.BIK_COUPON_DISBURSED}-${props.id}-${primaryPhoneNumber}`,
515
+ stringifiedCouponData,
516
+ );
517
+ }
518
+ if (secondaryPhoneNumber) {
519
+ storeDataInLocalStorage(
520
+ `${LOCAL_STORAGE_KEYS.BIK_COUPON_DISBURSED}-${props.id}-${secondaryPhoneNumber}`,
521
+ stringifiedCouponData,
522
+ );
523
+ }
524
+ if (emailId) {
525
+ storeDataInLocalStorage(
526
+ `${LOCAL_STORAGE_KEYS.BIK_COUPON_DISBURSED}-${props.id}-${emailId}`,
527
+ stringifiedCouponData,
528
+ );
529
+ }
530
+ setShowComponents(prev => ({
531
+ ...showComponents,
532
+ userDetails: false,
533
+ couponDetails: true,
534
+ }));
535
+ }
536
+ } else {
537
+ storeDataInLocalStorage(
538
+ LOCAL_STORAGE_KEYS.BIK_PHONE_NUMBER,
539
+ primaryPhoneNumber,
540
+ );
541
+ storeDataInLocalStorage(LOCAL_STORAGE_KEYS.BIK_EMAIL, emailId);
542
+ await addLead(data, environment);
543
+ setIsLoading(false);
544
+ if (visibility.triggers?.hideAfterClaimed) {
545
+ setCookie(`bik-${props.id}-claimed`, true, 24820);
546
+ }
547
+ setShowComponents(prev => ({
548
+ ...showComponents,
549
+ userDetails: false,
550
+ couponDetails: true,
551
+ }));
552
+ }
553
+ };
554
+
555
+ return (
556
+ <>
557
+ {getExitIntentHook()}
558
+ <DirectRewardTemplate
559
+ {...(props as any)}
560
+ claimPrizeHandle={claimPrizeHandle}
561
+ onCloseHandle={onCloseHandle}
562
+ sameMobileNumberTogglers={sameMobileNumberTogglers}
563
+ setSameMobileNumberTogglers={setSameMobileNumberTogglers}
564
+ discountCodeDetails={couponCodeDetails}
565
+ error={error}
566
+ isLoading={isLoading}
567
+ templateName={templateName}
568
+ widgetCustomisation={widgetCustomisation as IDRWidgetCustomisation}
569
+ showComponents={showComponents}
570
+ containerReference={directRewardContainer}
571
+ setShowComponents={setShowComponents}
572
+ />
573
+ </>
574
+ );
575
+ };
576
+ export default DirectReward;
577
+ if (process.env.NODE_ENV !== 'development') {
578
+ includeMe(DirectReward);
579
+ }