@envive-ai/react-hooks 0.2.6-alpha-5 → 0.2.6-alpha-7
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/dist/{AmplitudeOperations-CNFlPr53.cjs → AmplitudeOperations-DbUiR0N_.cjs} +3 -3
- package/dist/{AmplitudeOperations-cmAprPCA.js → AmplitudeOperations-DjqOM3uE.js} +2 -2
- package/dist/{NewOrgConfig-Bicbf8I7.js → NewOrgConfig-C_1T1iOt.js} +2 -2
- package/dist/{NewOrgConfig-6dFyYjJG.cjs → NewOrgConfig-D2Kvqa1z.cjs} +2 -2
- package/dist/{TrackComponentVisibleEvent-BebTjNtS.js → TrackComponentVisibleEvent-BxOhr9Da.js} +4 -4
- package/dist/{TrackComponentVisibleEvent-COwxsJRE.cjs → TrackComponentVisibleEvent-CDbecFPM.cjs} +5 -5
- package/dist/amplitudeContext-BWmXliMI.cjs +243 -0
- package/dist/amplitudeContext-BjMlg5RV.js +227 -0
- package/dist/amplitudeTrackEventAtom-D66l5oFp.js +8 -0
- package/dist/amplitudeTrackEventAtom-f22P2U0u.cjs +15 -0
- package/dist/app-Bs2KxG_8.js +515 -0
- package/dist/app-DSnDDqcW.cjs +570 -0
- package/dist/application/models/graphql/index.d.ts +1 -1
- package/dist/application/models/guards/api/index.d.ts +2 -2
- package/dist/application/models/guards/utils.d.ts +1 -1
- package/dist/application/models/index.cjs +2 -2
- package/dist/application/models/index.d.ts +4 -4
- package/dist/application/models/index.js +2 -2
- package/dist/application/utils/index.cjs +5 -14
- package/dist/application/utils/index.d.cts +7 -8
- package/dist/application/utils/index.d.ts +8 -9
- package/dist/application/utils/index.js +5 -14
- package/dist/{atomStore-CZKe3itM.cjs → atomStore-BQVO5haU.cjs} +1 -1
- package/dist/{atomStore-BuopbV9k.js → atomStore-CfzCqWB9.js} +1 -1
- package/dist/atoms/app/index.cjs +17 -19
- package/dist/atoms/app/index.d.cts +7 -7
- package/dist/atoms/app/index.d.ts +7 -7
- package/dist/atoms/app/index.js +12 -14
- package/dist/atoms/atomStore/index.cjs +1 -1
- package/dist/atoms/atomStore/index.d.ts +1 -1
- package/dist/atoms/atomStore/index.js +1 -1
- package/dist/atoms/chat/index.cjs +15 -17
- package/dist/atoms/chat/index.d.cts +33 -34
- package/dist/atoms/chat/index.d.ts +34 -35
- package/dist/atoms/chat/index.js +15 -17
- package/dist/atoms/globalSearch/index.cjs +1 -1
- package/dist/atoms/globalSearch/index.d.cts +6 -6
- package/dist/atoms/globalSearch/index.d.ts +6 -6
- package/dist/atoms/globalSearch/index.js +1 -1
- package/dist/atoms/org/index.cjs +2 -2
- package/dist/atoms/org/index.d.cts +17 -17
- package/dist/atoms/org/index.d.ts +17 -17
- package/dist/atoms/org/index.js +2 -2
- package/dist/atoms/search/index.cjs +6 -6
- package/dist/atoms/search/index.d.cts +15 -15
- package/dist/atoms/search/index.d.ts +14 -14
- package/dist/atoms/search/index.js +6 -6
- package/dist/atoms/search/utils.cjs +1 -1
- package/dist/atoms/search/utils.d.cts +1 -1
- package/dist/atoms/search/utils.d.ts +1 -1
- package/dist/atoms/search/utils.js +1 -1
- package/dist/{cdnContext-CuZwc-PI.js → cdnContext-CJ2BNLAD.js} +2 -2
- package/dist/{cdnContext-ClAEcKhO.cjs → cdnContext-lkC-AE6A.cjs} +2 -2
- package/dist/chat-C5afTKUY.js +226 -0
- package/dist/{chat-BJL3nXR7.cjs → chat-CCjM6fS_.cjs} +6 -7
- package/dist/{chat-DCGriB7h.cjs → chat-CJ9D8n7g.cjs} +1 -1
- package/dist/{chat-ClvJ9xEj.js → chat-EJbfGWRr.js} +1 -1
- package/dist/chatState-BbI93m6r.js +33 -0
- package/dist/chatState-DlJpHAsW.cjs +119 -0
- package/dist/{common-DQPvV_S_.cjs → common-CuwWqIJ1.cjs} +1 -1
- package/dist/{common-c_4eX0qn.js → common-Df2bwzd2.js} +1 -1
- package/dist/{components-DKwVHIjq.cjs → components-BCfFLf9X.cjs} +1 -1
- package/dist/{components-CDpaMUjK.js → components-QGCWJ26c.js} +1 -1
- package/dist/config/index.cjs +4 -4
- package/dist/config/index.d.cts +4 -4
- package/dist/config/index.d.ts +4 -4
- package/dist/config/index.js +4 -4
- package/dist/config/locators/components/chat/index.cjs +1 -1
- package/dist/config/locators/components/chat/index.d.cts +1 -1
- package/dist/config/locators/components/chat/index.d.ts +1 -1
- package/dist/config/locators/components/chat/index.js +1 -1
- package/dist/config/locators/components/common/index.cjs +1 -1
- package/dist/config/locators/components/common/index.d.cts +1 -1
- package/dist/config/locators/components/common/index.d.ts +1 -1
- package/dist/config/locators/components/common/index.js +1 -1
- package/dist/config/locators/components/index.cjs +1 -1
- package/dist/config/locators/components/index.d.cts +1 -1
- package/dist/config/locators/components/index.d.ts +1 -1
- package/dist/config/locators/components/index.js +1 -1
- package/dist/config/locators/index.cjs +4 -4
- package/dist/config/locators/index.d.cts +4 -4
- package/dist/config/locators/index.d.ts +4 -4
- package/dist/config/locators/index.js +4 -4
- package/dist/contexts/amplitudeContext/index.cjs +18 -17
- package/dist/contexts/amplitudeContext/index.d.cts +11 -2
- package/dist/contexts/amplitudeContext/index.d.ts +11 -2
- package/dist/contexts/amplitudeContext/index.js +17 -15
- package/dist/contexts/cdnContext/index.cjs +3 -3
- package/dist/contexts/cdnContext/index.d.cts +1 -1
- package/dist/contexts/cdnContext/index.js +3 -3
- package/dist/contexts/enviveConfigContext/index.cjs +3 -3
- package/dist/contexts/enviveConfigContext/index.d.cts +1 -1
- package/dist/contexts/enviveConfigContext/index.js +3 -3
- package/dist/contexts/enviveCssContext/index.cjs +10 -10
- package/dist/contexts/enviveCssContext/index.js +10 -10
- package/dist/contexts/featureFlagContext/index.cjs +4 -4
- package/dist/contexts/featureFlagContext/index.js +4 -4
- package/dist/contexts/featureFlagServiceContext/index.cjs +3 -3
- package/dist/contexts/featureFlagServiceContext/index.d.cts +1 -1
- package/dist/contexts/featureFlagServiceContext/index.d.ts +1 -1
- package/dist/contexts/featureFlagServiceContext/index.js +3 -3
- package/dist/contexts/graphqlContext/index.cjs +4 -4
- package/dist/contexts/graphqlContext/index.js +4 -4
- package/dist/contexts/localStorageContext/index.cjs +2 -2
- package/dist/contexts/localStorageContext/index.d.cts +1 -1
- package/dist/contexts/localStorageContext/index.js +2 -2
- package/dist/contexts/newOrgConfigContext/index.cjs +9 -9
- package/dist/contexts/newOrgConfigContext/index.js +9 -9
- package/dist/contexts/searchContext/index.cjs +18 -19
- package/dist/contexts/searchContext/index.js +18 -19
- package/dist/contexts/sessionStorageContext/index.cjs +1 -1
- package/dist/contexts/sessionStorageContext/index.js +1 -1
- package/dist/contexts/shopifyUrlContext/index.cjs +2 -2
- package/dist/contexts/shopifyUrlContext/index.d.cts +1 -1
- package/dist/contexts/shopifyUrlContext/index.js +2 -2
- package/dist/contexts/systemSettingsContext/index.cjs +3 -3
- package/dist/contexts/systemSettingsContext/index.d.cts +2 -2
- package/dist/contexts/systemSettingsContext/index.js +3 -3
- package/dist/contexts/userIdentityContext/index.cjs +14 -16
- package/dist/contexts/userIdentityContext/index.js +12 -14
- package/dist/{dist-CIM4YRqp.js → dist-C38adNK1.js} +1 -1
- package/dist/{dist-BZX_Mgfn.cjs → dist-VxRI6eQv.cjs} +1 -1
- package/dist/{domObserver-CwieVNgj.cjs → domObserver-C2oQO8vi.cjs} +1 -1
- package/dist/{domObserver-B19-69gW.js → domObserver-DNeeSh1F.js} +1 -1
- package/dist/{enviveConfig-CBnoutoK.js → enviveConfig-Ciq4ASoV.js} +2 -2
- package/dist/{enviveConfig-BwIaVAAm.cjs → enviveConfig-Dp80h9yu.cjs} +2 -2
- package/dist/{enviveConfigContext-B4nejwV9.js → enviveConfigContext-CCjJUmwp.js} +2 -2
- package/dist/{enviveConfigContext-DgewMgYS.cjs → enviveConfigContext-DoYP8KSw.cjs} +2 -2
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.js +1 -1
- package/dist/{events-BHBRLPWS.js → events-CXiS1aTc.js} +1 -1
- package/dist/{events-C8LA-0Tp.cjs → events-DBin1Z7o.cjs} +1 -1
- package/dist/exceptions/index.cjs +1 -1
- package/dist/exceptions/index.d.ts +1 -1
- package/dist/exceptions/index.js +1 -1
- package/dist/{exceptions-BBXmiU8P.cjs → exceptions-BjDgLzGi.cjs} +1 -1
- package/dist/{exceptions--fSXOzkB.js → exceptions-CUGY31Ua.js} +1 -1
- package/dist/{featureFlagServiceContext-B7je7VZV.d.cts → featureFlagServiceContext-ClnlCJV5.d.cts} +1 -1
- package/dist/{featureFlagServiceContext-CZj3qPX7.js → featureFlagServiceContext-Cvp7NlpC.js} +2 -2
- package/dist/{featureFlagServiceContext-DiYIv0jI.d.ts → featureFlagServiceContext-CyPGEe2d.d.ts} +1 -1
- package/dist/{featureFlagServiceContext-BkamHViU.cjs → featureFlagServiceContext-DHtkQAtq.cjs} +2 -2
- package/dist/{globalSearch-C94-vEVh.cjs → globalSearch-Cpc8egsM.cjs} +1 -1
- package/dist/{globalSearch-Dlbnfasm.js → globalSearch-nmrfGLOn.js} +1 -1
- package/dist/{graphqlContext-Capum8x6.js → graphqlContext-0cg9fEUw.js} +3 -3
- package/dist/{graphqlContext-C3HXFiHx.cjs → graphqlContext-ChXlE8Ul.cjs} +3 -3
- package/dist/hooks/AmplitudeOperations/index.cjs +17 -15
- package/dist/hooks/AmplitudeOperations/index.d.cts +1 -1
- package/dist/hooks/AmplitudeOperations/index.js +17 -15
- package/dist/hooks/AppDetails/index.cjs +15 -17
- package/dist/hooks/AppDetails/index.js +15 -17
- package/dist/hooks/BlockBackButton/index.d.cts +1 -1
- package/dist/hooks/CdnOperations/index.cjs +3 -3
- package/dist/hooks/CdnOperations/index.d.cts +1 -1
- package/dist/hooks/CdnOperations/index.d.ts +1 -1
- package/dist/hooks/CdnOperations/index.js +3 -3
- package/dist/hooks/ChatToggle/index.cjs +21 -19
- package/dist/hooks/ChatToggle/index.d.cts +1 -1
- package/dist/hooks/ChatToggle/index.js +20 -18
- package/dist/hooks/ChatToggleAnalytics/index.cjs +19 -17
- package/dist/hooks/ChatToggleAnalytics/index.d.cts +1 -1
- package/dist/hooks/ChatToggleAnalytics/index.js +19 -17
- package/dist/hooks/Debounce/index.d.cts +1 -1
- package/dist/hooks/ElementObserver/index.cjs +1 -1
- package/dist/hooks/ElementObserver/index.d.cts +1 -1
- package/dist/hooks/ElementObserver/index.d.ts +1 -1
- package/dist/hooks/ElementObserver/index.js +1 -1
- package/dist/hooks/GraphQLConfig/index.cjs +5 -5
- package/dist/hooks/GraphQLConfig/index.d.cts +1 -1
- package/dist/hooks/GraphQLConfig/index.js +5 -5
- package/dist/hooks/IdentifyUser/index.cjs +14 -16
- package/dist/hooks/IdentifyUser/index.d.cts +1 -1
- package/dist/hooks/IdentifyUser/index.js +13 -15
- package/dist/hooks/ImageResolver/index.cjs +2 -2
- package/dist/hooks/ImageResolver/index.d.cts +1 -1
- package/dist/hooks/ImageResolver/index.js +2 -2
- package/dist/hooks/Intersection/index.cjs +1 -1
- package/dist/hooks/Intersection/index.js +1 -1
- package/dist/hooks/IsSmallScreen/index.d.cts +1 -1
- package/dist/hooks/LocalStorageOperations/index.cjs +2 -2
- package/dist/hooks/LocalStorageOperations/index.d.cts +1 -1
- package/dist/hooks/LocalStorageOperations/index.js +2 -2
- package/dist/hooks/MessageFilter/index.cjs +1 -1
- package/dist/hooks/MessageFilter/index.d.cts +1 -1
- package/dist/hooks/MessageFilter/index.js +1 -1
- package/dist/hooks/MessageScrollObserver/index.d.cts +1 -1
- package/dist/hooks/NewOrgConfig/index.cjs +10 -10
- package/dist/hooks/NewOrgConfig/index.d.cts +2 -2
- package/dist/hooks/NewOrgConfig/index.d.ts +2 -2
- package/dist/hooks/NewOrgConfig/index.js +10 -10
- package/dist/hooks/Search/index.cjs +25 -23
- package/dist/hooks/Search/index.js +25 -23
- package/dist/hooks/SearchOperations/index.cjs +19 -20
- package/dist/hooks/SearchOperations/index.js +19 -20
- package/dist/hooks/SessionStorageOperations/index.cjs +1 -1
- package/dist/hooks/SessionStorageOperations/index.js +1 -1
- package/dist/hooks/ShopifyUrlOperations/index.cjs +2 -2
- package/dist/hooks/ShopifyUrlOperations/index.d.cts +2 -2
- package/dist/hooks/ShopifyUrlOperations/index.d.ts +2 -2
- package/dist/hooks/ShopifyUrlOperations/index.js +2 -2
- package/dist/hooks/SystemSettingsContext/index.cjs +3 -3
- package/dist/hooks/SystemSettingsContext/index.d.cts +4 -4
- package/dist/hooks/SystemSettingsContext/index.d.ts +4 -4
- package/dist/hooks/SystemSettingsContext/index.js +3 -3
- package/dist/hooks/TrackComponentVisibleEvent/index.cjs +18 -16
- package/dist/hooks/TrackComponentVisibleEvent/index.js +18 -16
- package/dist/hooks/UpdateAnalyticsProps/index.cjs +20 -18
- package/dist/hooks/UpdateAnalyticsProps/index.js +17 -15
- package/dist/hooks/utils.cjs +1 -1
- package/dist/hooks/utils.d.cts +1 -1
- package/dist/hooks/utils.js +1 -1
- package/dist/{index-CAhGZxMI.d.ts → index-5li6ZMDu.d.ts} +1 -1
- package/dist/{index-ca7Qn8o0.d.cts → index-BbqT4BQv.d.cts} +1 -1
- package/dist/{index-w64il54a.d.cts → index-CAJq_8bO.d.cts} +1 -1
- package/dist/index-CMZcE7pk.d.cts +1 -1
- package/dist/{index-BQpWG3Jm.d.cts → index-ChiZg0yw.d.cts} +1 -1
- package/dist/{index-DNccxbJi.d.ts → index-CsmO1rDH.d.ts} +1 -1
- package/dist/{index-Dgu085Lu.d.ts → index-CuihhoIF.d.ts} +2 -2
- package/dist/{index-BR1G8yyg.d.ts → index-DtzPIcQp.d.ts} +1 -1
- package/dist/{index-ZQMda2Iu.d.ts → index-bEjLKG_Q.d.ts} +1 -1
- package/dist/{index-DiIHuPq2.d.ts → index-jFQefHda.d.ts} +1 -1
- package/dist/{index-BO-ZLYtR.d.ts → index-mv7KvWDq.d.ts} +1 -1
- package/dist/{index-ClVBVK15.d.cts → index-npqPeJ1g.d.cts} +1 -1
- package/dist/interceptors/index.cjs +1 -1
- package/dist/interceptors/index.d.cts +1 -1
- package/dist/interceptors/index.d.ts +1 -1
- package/dist/interceptors/index.js +1 -1
- package/dist/{localStorageContext-p_4U0RPI.js → localStorageContext-BFwvuEcf.js} +2 -2
- package/dist/{localStorageContext-CPrkpt8i.cjs → localStorageContext-CWc5xJ6U.cjs} +2 -2
- package/dist/{locators-BMQGmGLq.js → locators-C2fWd-74.js} +1 -1
- package/dist/{locators-DxYdak1F.cjs → locators-Cx3q6Z_h.cjs} +1 -1
- package/dist/{models-L2w8FYCa.js → models-Cw0QcbQv.js} +2 -2
- package/dist/{models-OyYkll03.cjs → models-Dl0_Ujgj.cjs} +2 -2
- package/dist/{newOrgConfigAtom-Dsk0fJNR.js → newOrgConfigAtom-BuQE_zPK.js} +1 -1
- package/dist/{newOrgConfigAtom-hs5A1pbZ.cjs → newOrgConfigAtom-rrYHmp1b.cjs} +1 -1
- package/dist/{newOrgConfigContext-BuqDUkPz.js → newOrgConfigContext-D-gU5ppl.js} +5 -5
- package/dist/{newOrgConfigContext-N4CQzvlH.cjs → newOrgConfigContext-d3RHl430.cjs} +5 -5
- package/dist/{nodeSelector-0gJ8Xayf.d.ts → nodeSelector-BAKg1h_y.d.ts} +1 -1
- package/dist/{nodeSelector-Cj-Xl1LP.d.cts → nodeSelector-BYEAyrsj.d.cts} +1 -1
- package/dist/org-15F128Ah.js +32 -0
- package/dist/org-CIFgIcO4.cjs +111 -0
- package/dist/{search-C_N_oRVZ.js → search--80x6CfL.js} +5 -5
- package/dist/{search-8bPfo07V.cjs → search-Ch6LKNh4.cjs} +5 -5
- package/dist/{searchContext-DdJbpDsU.cjs → searchContext-B0qEUoKb.cjs} +6 -6
- package/dist/{searchContext-BohH5i8s.js → searchContext-BkPoTq1o.js} +6 -6
- package/dist/{searchServiceAdapter-BSPZOg1r.js → searchServiceAdapter-B0h7psvh.js} +1 -1
- package/dist/{searchServiceAdapter-DrjFCiw8.cjs → searchServiceAdapter-BclWy4fE.cjs} +1 -1
- package/dist/{sessionStorageContext-CH37Dkb-.cjs → sessionStorageContext-BuWrJQwc.cjs} +1 -1
- package/dist/{sessionStorageContext-CqrutoVq.js → sessionStorageContext-DvFHbk81.js} +1 -1
- package/dist/{shopifyUrlContext-Ba6MQdNV.cjs → shopifyUrlContext-Bw1kAZ2P.cjs} +2 -2
- package/dist/{shopifyUrlContext-BI3fVtA5.js → shopifyUrlContext-DnJiUmMA.js} +2 -2
- package/dist/src/application/commerce-api.js +408 -0
- package/dist/src/application/logging/logger.js +16 -0
- package/dist/src/application/models/graphql/index.js +3 -0
- package/dist/src/application/models/graphql/queries/getMerchantColorsQuery.js +13 -0
- package/dist/src/application/models/graphql/queries/getMerchantFrontendConfigQuery.js +13 -0
- package/dist/src/application/models/graphql/queries/getMerchantOrgIdQuery.js +10 -0
- package/dist/src/application/models/guards/api/index.js +12 -0
- package/dist/src/application/models/guards/api/isApiFormResponse.js +59 -0
- package/dist/src/application/models/guards/api/isApiFormSubmittedResponseAttributes.js +22 -0
- package/dist/src/application/models/guards/api/isApiOrderResponseAttributes.js +91 -0
- package/dist/src/application/models/guards/api/isApiOrgConfigResults.js +188 -0
- package/dist/src/application/models/guards/api/isApiOrganizationConfig.js +115 -0
- package/dist/src/application/models/guards/api/isApiPDPEventAttributes.js +16 -0
- package/dist/src/application/models/guards/api/isApiPLPEventAttributes.js +26 -0
- package/dist/src/application/models/guards/api/isApiPageResponseAttributes.js +15 -0
- package/dist/src/application/models/guards/api/isApiProductResponseAttributes.js +65 -0
- package/dist/src/application/models/guards/api/isApiProductSearchAttributes.js +15 -0
- package/dist/src/application/models/guards/api/isApiProductSearchFilterAttributes.js +10 -0
- package/dist/src/application/models/guards/api/isApiQueryTypedEventAttributes.js +4 -0
- package/dist/src/application/models/guards/api/isApiResponse.js +33 -0
- package/dist/src/application/models/guards/api/isApiReviewResponseAttributes.js +22 -0
- package/dist/src/application/models/guards/api/isApiReviewRichInformation.js +23 -0
- package/dist/src/application/models/guards/api/isApiSearchEventAttributes.js +20 -0
- package/dist/src/application/models/guards/api/isApiSuggestion.js +24 -0
- package/dist/src/application/models/guards/api/isApiSuggestionClickedEventAttributes.js +4 -0
- package/dist/src/application/models/guards/api/isApiTextResponseAttributes.js +4 -0
- package/dist/src/application/models/guards/api/isApiUserEvent.js +18 -0
- package/dist/src/application/models/guards/graphQL/isGraphQLColorsConfig.js +41 -0
- package/dist/src/application/models/guards/isBaseEcommerceEvent.js +14 -0
- package/dist/src/application/models/guards/isGA4EcommerceEvent.js +14 -0
- package/dist/src/application/models/guards/isLegacyUAEcommerceEvent.js +14 -0
- package/dist/src/application/models/guards/isMobilePLPChatPlacementParameter.js +4 -0
- package/dist/src/application/models/guards/isSpanxTakeAQuizCtaParameter.js +1 -0
- package/dist/src/application/models/guards/isVariantInfo.js +28 -0
- package/dist/src/application/models/guards/utils.js +34 -0
- package/dist/src/application/models/index.js +34 -0
- package/dist/src/application/models/utils/snakeToCamelTransformer.js +71 -0
- package/dist/src/application/models/utils/stringToFulfillmentDisplayStatusEnumValue.js +65 -0
- package/dist/src/application/models/validators/validateGraphQLColorsConfig.js +9 -0
- package/dist/src/application/models/validators/validateGraphQLFrontendConfig.js +420 -0
- package/dist/src/application/models/validators/validateGraphQLOrgId.js +6 -0
- package/dist/src/application/models/validators/validateMobilePLPChatPlacementParameter.js +9 -0
- package/dist/src/application/models/validators/validateOrgConfigResults.js +44 -0
- package/dist/src/application/models/validators/validateOrganizationConfig.js +34 -0
- package/dist/src/application/models/validators/validateResponse.js +173 -0
- package/dist/src/application/models/validators/validateSuggestion.js +13 -0
- package/dist/src/application/models/validators/validateUserEvent.js +91 -0
- package/dist/src/application/utils/analyticsUtils.js +95 -0
- package/dist/src/application/utils/coreContextToApiContext.js +8 -0
- package/dist/src/application/utils/coreUserEventToApiUserEvent.js +90 -0
- package/dist/src/application/utils/divideArray.js +7 -0
- package/dist/src/application/utils/domObserver.js +85 -0
- package/dist/src/application/utils/elementObserver.js +186 -0
- package/dist/src/application/utils/imageFilter.js +11 -0
- package/dist/src/application/utils/index.js +21 -0
- package/dist/src/application/utils/merchantUtils.js +15 -0
- package/dist/src/application/utils/messageFromFormSubmittedEvent.js +19 -0
- package/dist/src/application/utils/messageFromQueryEvent.js +35 -0
- package/dist/src/application/utils/messageFromResponse.js +123 -0
- package/dist/src/application/utils/messageFromSuggestionEvent.js +27 -0
- package/dist/src/application/utils/mouseEventTypes.js +1 -0
- package/dist/src/application/utils/mutationHelper.js +33 -0
- package/dist/src/application/utils/nextMessageRequestToApiRequest.js +29 -0
- package/dist/src/application/utils/nodeSelector.js +101 -0
- package/dist/src/application/utils/overrides.js +144 -0
- package/dist/src/application/utils/stringUtils.js +47 -0
- package/dist/src/application/utils/supportedEventRequestToApiRequest.js +7 -0
- package/dist/src/application/utils/urlsParser.js +33 -0
- package/dist/src/application/utils/validation.js +5 -0
- package/dist/src/atoms/amplitude/amplitudeTrackEventAtom.js +4 -0
- package/dist/src/atoms/app/index.js +23 -0
- package/dist/src/atoms/app/variant.js +102 -0
- package/dist/src/atoms/atomStore/atomStore.js +28 -0
- package/dist/src/atoms/atomStore/index.js +1 -0
- package/dist/src/atoms/chat/chatState.js +32 -0
- package/dist/src/atoms/chat/form.js +16 -0
- package/dist/src/atoms/chat/index.js +23 -0
- package/dist/src/atoms/chat/lastMessage.js +10 -0
- package/dist/src/atoms/chat/messageQueue.js +68 -0
- package/dist/src/atoms/chat/performanceMetrics.js +70 -0
- package/dist/src/atoms/chat/renderedWidgetRefs.js +24 -0
- package/dist/src/atoms/chat/replies.js +42 -0
- package/dist/src/atoms/chat/suggestions.js +29 -0
- package/dist/src/atoms/envive/enviveConfig.js +67 -0
- package/dist/src/atoms/globalSearch/globalSearch.js +8 -0
- package/dist/src/atoms/globalSearch/index.js +1 -0
- package/dist/src/atoms/org/customerService.js +6 -0
- package/dist/src/atoms/org/graphqlConfig.js +8 -0
- package/dist/src/atoms/org/index.js +4 -0
- package/dist/src/atoms/org/newOrgConfigAtom.js +2 -0
- package/dist/src/atoms/org/orgAnalyticsConfig.js +8 -0
- package/dist/src/atoms/search/index.js +1 -0
- package/dist/src/atoms/search/productFilters.js +163 -0
- package/dist/src/atoms/search/productRetrievalAPI.js +50 -0
- package/dist/src/atoms/search/productRetrievalAdapter.js +14 -0
- package/dist/src/atoms/search/productSorter.js +13 -0
- package/dist/src/atoms/search/searchAPI.js +140 -0
- package/dist/src/atoms/search/searchServiceAdapter.js +14 -0
- package/dist/src/atoms/search/utils.js +15 -0
- package/dist/src/config/index.js +1 -0
- package/dist/src/config/locators/components/chat/entrypoints.js +10 -0
- package/dist/src/config/locators/components/chat/index.js +21 -0
- package/dist/src/config/locators/components/chat/preview.js +11 -0
- package/dist/src/config/locators/components/chat/variants/index.js +12 -0
- package/dist/src/config/locators/components/common/buttons.js +6 -0
- package/dist/src/config/locators/components/common/cards.js +17 -0
- package/dist/src/config/locators/components/common/index.js +4 -0
- package/dist/src/config/locators/components/common/links.js +1 -0
- package/dist/src/config/locators/components/common/tables.js +1 -0
- package/dist/src/config/locators/components/floating-button.js +2 -0
- package/dist/src/config/locators/components/index.js +3 -0
- package/dist/src/config/locators/components/report-issue.js +13 -0
- package/dist/src/config/locators/components/search/index.js +5 -0
- package/dist/src/config/locators/components/shadow-dom.js +1 -0
- package/dist/src/config/locators/embedded.js +20 -0
- package/dist/src/config/locators/index.js +4 -0
- package/dist/src/contexts/amplitudeContext/amplitudeContext.js +271 -0
- package/dist/src/contexts/amplitudeContext/index.js +1 -0
- package/dist/src/contexts/cdnContext/cdnContext.js +28 -0
- package/dist/src/contexts/cdnContext/index.js +1 -0
- package/dist/src/contexts/enviveConfigContext/enviveConfigContext.js +37 -0
- package/dist/src/contexts/enviveConfigContext/index.js +1 -0
- package/dist/src/contexts/enviveCssContext/enviveCssContext.js +31 -0
- package/dist/src/contexts/enviveCssContext/index.js +1 -0
- package/dist/src/contexts/featureFlagContext/featureFlagContext.js +109 -0
- package/dist/src/contexts/featureFlagContext/index.js +1 -0
- package/dist/src/contexts/featureFlagServiceContext/featureFlagServiceContext.js +47 -0
- package/dist/src/contexts/featureFlagServiceContext/index.js +1 -0
- package/dist/src/contexts/graphqlContext/graphqlContext.js +87 -0
- package/dist/src/contexts/graphqlContext/index.js +1 -0
- package/dist/src/contexts/localStorageContext/index.js +1 -0
- package/dist/src/contexts/localStorageContext/localStorageContext.js +95 -0
- package/dist/src/contexts/newOrgConfigContext/index.js +1 -0
- package/dist/src/contexts/newOrgConfigContext/newOrgConfigContext.js +33 -0
- package/dist/src/contexts/searchContext/index.js +1 -0
- package/dist/src/contexts/searchContext/searchContext.js +131 -0
- package/dist/src/contexts/sessionStorageContext/index.js +1 -0
- package/dist/src/contexts/sessionStorageContext/sessionStorageContext.js +43 -0
- package/dist/src/contexts/shopifyUrlContext/index.js +1 -0
- package/dist/src/contexts/shopifyUrlContext/shopifyUrlContext.js +62 -0
- package/dist/src/contexts/systemSettingsContext/index.js +1 -0
- package/dist/src/contexts/systemSettingsContext/systemSettingsContext.js +29 -0
- package/dist/src/contexts/userIdentityContext/index.js +1 -0
- package/dist/src/contexts/userIdentityContext/userIdentityContext.js +118 -0
- package/dist/src/events/index.js +51 -0
- package/dist/src/events/registerAnalyticsListeners.js +32 -0
- package/dist/src/exceptions/index.js +2 -0
- package/dist/src/exceptions/sessionExceptions.js +6 -0
- package/dist/src/exceptions/unsupportedProductExceptions.js +6 -0
- package/dist/src/hooks/AmplitudeOperations/index.js +1 -0
- package/dist/src/hooks/AmplitudeOperations/useAmplitudeOperations.js +24 -0
- package/dist/src/hooks/AppDetails/index.js +1 -0
- package/dist/src/hooks/AppDetails/useAppDetails.js +26 -0
- package/dist/src/hooks/BlockBackButton/index.js +1 -0
- package/dist/src/hooks/BlockBackButton/useBlockBackButton.js +23 -0
- package/dist/src/hooks/CdnOperations/index.js +1 -0
- package/dist/src/hooks/CdnOperations/useCdnOperations.js +13 -0
- package/dist/src/hooks/ChatToggle/index.js +1 -0
- package/dist/src/hooks/ChatToggle/useChatToggle.js +50 -0
- package/dist/src/hooks/ChatToggleAnalytics/index.js +1 -0
- package/dist/src/hooks/ChatToggleAnalytics/useChatToggleAnalytics.js +11 -0
- package/dist/src/hooks/CustomerSupportHandoff/index.js +1 -0
- package/dist/src/hooks/CustomerSupportHandoff/useCustomerSupportHandoff.js +32 -0
- package/dist/src/hooks/Debounce/index.js +1 -0
- package/dist/src/hooks/Debounce/useDebounce.js +13 -0
- package/dist/src/hooks/ElementObserver/index.js +1 -0
- package/dist/src/hooks/ElementObserver/useElementObserver.js +208 -0
- package/dist/src/hooks/GrabAndScroll/index.js +1 -0
- package/dist/src/hooks/GrabAndScroll/useGrabAndScroll.js +105 -0
- package/dist/src/hooks/GraphQLConfig/index.js +1 -0
- package/dist/src/hooks/GraphQLConfig/useGraphQLConfig.js +54 -0
- package/dist/src/hooks/IdentifyUser/index.js +1 -0
- package/dist/src/hooks/IdentifyUser/useIdentifyUser.js +28 -0
- package/dist/src/hooks/ImageResolver/index.js +1 -0
- package/dist/src/hooks/ImageResolver/useImageResolver.js +45 -0
- package/dist/src/hooks/Intersection/index.js +1 -0
- package/dist/src/hooks/Intersection/useIntersection.js +20 -0
- package/dist/src/hooks/IsSmallScreen/index.js +1 -0
- package/dist/src/hooks/IsSmallScreen/useIsSmallScreen.js +16 -0
- package/dist/src/hooks/LocalStorageOperations/index.js +1 -0
- package/dist/src/hooks/LocalStorageOperations/useLocalStorageOperations.js +64 -0
- package/dist/src/hooks/MessageFilter/index.js +1 -0
- package/dist/src/hooks/MessageFilter/useMessageFilter.js +37 -0
- package/dist/src/hooks/MessageScrollObserver/index.js +1 -0
- package/dist/src/hooks/MessageScrollObserver/useMessageScrollObserver.js +35 -0
- package/dist/src/hooks/NewOrgConfig/index.js +1 -0
- package/dist/src/hooks/NewOrgConfig/useNewOrgConfig.js +5 -0
- package/dist/src/hooks/Search/index.js +1 -0
- package/dist/src/hooks/Search/useRecommendedProducts.js +35 -0
- package/dist/src/hooks/Search/useSearch.js +224 -0
- package/dist/src/hooks/Search/useSearchInput.js +192 -0
- package/dist/src/hooks/SearchOperations/index.js +1 -0
- package/dist/src/hooks/SearchOperations/useSearchOperations.js +78 -0
- package/dist/src/hooks/SessionStorageOperations/index.js +1 -0
- package/dist/src/hooks/SessionStorageOperations/useSessionStorageOperations.js +20 -0
- package/dist/src/hooks/ShopifyUrlOperations/index.js +1 -0
- package/dist/src/hooks/ShopifyUrlOperations/useShopifyUrlOperations.js +34 -0
- package/dist/src/hooks/SnapCalculator/index.js +1 -0
- package/dist/src/hooks/SnapCalculator/useSnapCalculator.js +22 -0
- package/dist/src/hooks/SystemSettingsContext/index.js +1 -0
- package/dist/src/hooks/SystemSettingsContext/useSystemSettingsContext.js +9 -0
- package/dist/src/hooks/TrackComponentVisibleEvent/index.js +1 -0
- package/dist/src/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.js +45 -0
- package/dist/src/hooks/UpdateAnalyticsProps/index.js +1 -0
- package/dist/src/hooks/UpdateAnalyticsProps/useUpdateAnalyticsProps.js +43 -0
- package/dist/src/hooks/utils.js +116 -0
- package/dist/src/interceptors/index.js +1 -0
- package/dist/src/interceptors/useMessageInterceptor.js +24 -0
- package/dist/src/types/ApiResponse.js +1 -0
- package/dist/src/types/FilterAttribute.js +3 -0
- package/dist/src/types/Message.js +24 -0
- package/dist/src/types/Suggestion.js +3 -0
- package/dist/src/types/index.js +4 -0
- package/dist/src/util/colorVar.js +3 -0
- package/dist/src/util/configVersion.js +4 -0
- package/dist/src/util/domInsertion.js +16 -0
- package/dist/{systemSettingsContext-CYce8iqH.cjs → systemSettingsContext-068vQuP2.cjs} +2 -2
- package/dist/{systemSettingsContext-D9BZ9EwQ.js → systemSettingsContext-DPdDfVhj.js} +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/{urlsParser-C-Vzs--G.cjs → urlsParser-bb8ciRFg.cjs} +1 -1
- package/dist/{urlsParser-G7Ocwg0M.js → urlsParser-v_1DKvyf.js} +1 -1
- package/dist/{useAppDetails-CSpw8teP.js → useAppDetails-BPXln8UE.js} +4 -4
- package/dist/{useAppDetails-DNG_-DI9.cjs → useAppDetails-eP2hBuid.cjs} +7 -7
- package/dist/{useGraphQLConfig-D1REGfFB.js → useGraphQLConfig-Btszi6cG.js} +2 -2
- package/dist/{useGraphQLConfig-CKtaLlQ-.cjs → useGraphQLConfig-v9veUbvJ.cjs} +2 -2
- package/dist/{useIntersection-BQMfiS4x.cjs → useIntersection-BcBCa890.cjs} +1 -1
- package/dist/{useIntersection-D-ol9eH8.js → useIntersection-BkMkuJcZ.js} +1 -1
- package/dist/{utils-sosM0bEk.d.ts → utils-BitIIghf.d.ts} +1 -1
- package/dist/{utils-hYTjy7hJ.cjs → utils-CJk5iwQI.cjs} +1 -1
- package/dist/utils-CWzuvlOR.js +607 -0
- package/dist/{utils-BBICrPjW.cjs → utils-CqVRbvfN.cjs} +1 -1
- package/dist/{utils-w4-xONRA.js → utils-DQhbbAnt.js} +1 -1
- package/dist/{utils-D_kATUj6.js → utils-D_nGHczN.js} +1 -1
- package/dist/utils-SjlIHajO.cjs +716 -0
- package/package.json +1 -1
- package/src/application/commerce-api.ts +2 -0
- package/src/application/utils/analyticsUtils.ts +31 -16
- package/src/atoms/amplitude/amplitudeTrackEventAtom.ts +1 -1
- package/src/atoms/chat/chatState.ts +12 -7
- package/src/atoms/chat/replies.ts +42 -40
- package/src/contexts/amplitudeContext/amplitudeContext.tsx +116 -130
- package/dist/amplitudeContext-CMTvCsJC.d.ts +0 -52
- package/dist/amplitudeContext-ZkerrMUa.d.cts +0 -52
- package/dist/amplitudeTrackEventAtom-D9vs8dpE.cjs +0 -15
- package/dist/amplitudeTrackEventAtom-iEIu11Om.js +0 -8
- package/dist/chat-ChCtIEwh.js +0 -227
- package/dist/chatState-BYB77nbx.cjs +0 -120
- package/dist/chatState-CzH7APPP.js +0 -34
- package/dist/org-C2kLSSe9.cjs +0 -111
- package/dist/org-CIczyLRP.js +0 -32
- package/dist/utils-DGpMn2pp.js +0 -1364
- package/dist/utils-DqxtxrFe.cjs +0 -1546
- /package/dist/{featureFlagServiceContext-DgoR6euC.js → featureFlagServiceContext-CISyb90N.js} +0 -0
- /package/dist/{featureFlagServiceContext-b-rYgf0u.cjs → featureFlagServiceContext-Csgo-MUv.cjs} +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { ProductSorting, SpiffyMetricsEventName, SpiffyWidgets, } from "@envive-ai/types";
|
|
4
|
+
import { addSearchFilterAtom, clearSearchFiltersAtom, createFilterOption, filteredSearchProductsAtom, performSearchAtom, removeSearchFilterAtom, searchAtom, searchFiltersAtom, searchParamsAtom, searchProductSortingAtom, searchSelectedFiltersAtom, } from "../../atoms/search";
|
|
5
|
+
import { isFilterOpenAtom } from "../../atoms/globalSearch/globalSearch";
|
|
6
|
+
import { formatFilterDisplayName } from "../../atoms/search/utils";
|
|
7
|
+
import { amplitudeTrackEventAtom } from "../../atoms/amplitude/amplitudeTrackEventAtom";
|
|
8
|
+
import { orgShortNameAtom } from "../../atoms/envive/enviveConfig";
|
|
9
|
+
import { newOrgConfigAtom } from "../../atoms/org/newOrgConfigAtom";
|
|
10
|
+
import { retrievedProductsAtom } from "../../atoms/search/productRetrievalAPI";
|
|
11
|
+
import { useTrackComponentVisibleEvent } from "../TrackComponentVisibleEvent";
|
|
12
|
+
import { getSearchResultsState } from "../utils";
|
|
13
|
+
import { useSearchInput } from "./useSearchInput";
|
|
14
|
+
export const useSearch = () => {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
// Atoms
|
|
17
|
+
const trackEvent = useAtomValue(amplitudeTrackEventAtom);
|
|
18
|
+
const config = useAtomValue(newOrgConfigAtom);
|
|
19
|
+
const orgShortName = useAtomValue(orgShortNameAtom);
|
|
20
|
+
const { data: searchData, loading: isLoadingSearch } = useAtomValue(searchAtom);
|
|
21
|
+
const productList = useAtomValue(filteredSearchProductsAtom);
|
|
22
|
+
const performSearch = useSetAtom(performSearchAtom);
|
|
23
|
+
const [{ query }] = useAtom(searchParamsAtom);
|
|
24
|
+
const [isFilterOpen, setIsFilterOpen] = useAtom(isFilterOpenAtom);
|
|
25
|
+
const [selectedFilterOptions] = useAtom(searchSelectedFiltersAtom);
|
|
26
|
+
const addFilter = useSetAtom(addSearchFilterAtom);
|
|
27
|
+
const removeFilter = useSetAtom(removeSearchFilterAtom);
|
|
28
|
+
const [productSorting, setProductSorting] = useAtom(searchProductSortingAtom);
|
|
29
|
+
const clearFilters = useSetAtom(clearSearchFiltersAtom);
|
|
30
|
+
const searchFilters = useAtomValue(searchFiltersAtom);
|
|
31
|
+
const recommendedProducts = useAtomValue(retrievedProductsAtom);
|
|
32
|
+
// Refs
|
|
33
|
+
const searchResultsRef = useRef(null);
|
|
34
|
+
// Utilities
|
|
35
|
+
const scrollToTop = useCallback(() => {
|
|
36
|
+
const container = searchResultsRef.current;
|
|
37
|
+
if (container) {
|
|
38
|
+
container.scrollTo({ top: 0, behavior: "smooth" });
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
42
|
+
}
|
|
43
|
+
}, []);
|
|
44
|
+
// Search Input Hook
|
|
45
|
+
const searchInput = useSearchInput({
|
|
46
|
+
initialSearchText: query || "",
|
|
47
|
+
searchOrigin: SpiffyWidgets.SearchResults,
|
|
48
|
+
onSearchSubmit: (searchQuery) => {
|
|
49
|
+
performSearch({ query: searchQuery });
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const { searchText, focusedIndex, focusedOptionId, autocompleteResults, shouldShowAutocomplete, handleSearchInputChange, handleSearchInputFocus, handleSearchInputBlur, handleKeyDown, handleAutocompleteSelect, handleSubmitSearch, setSearchText, } = searchInput;
|
|
53
|
+
const searchResultsState = getSearchResultsState(isLoadingSearch, searchData);
|
|
54
|
+
const dynamicFilters = (searchData === null || searchData === void 0 ? void 0 : searchData.filters) || [];
|
|
55
|
+
// Provide fallback values when config is not yet available
|
|
56
|
+
const safeProductCardConfig = ((_b = (_a = config === null || config === void 0 ? void 0 : config.frontendConfig) === null || _a === void 0 ? void 0 : _a.uiConfigs) === null || _b === void 0 ? void 0 : _b.productCardConfig) || {
|
|
57
|
+
variant: "minimal",
|
|
58
|
+
hoverVariant: "none",
|
|
59
|
+
layoutVariant: "square",
|
|
60
|
+
};
|
|
61
|
+
const safeMerchantShortName = orgShortName || "";
|
|
62
|
+
const availableDynamicFilters = useMemo(() => {
|
|
63
|
+
return dynamicFilters
|
|
64
|
+
.filter((dynamicFilterName) => !selectedFilterOptions.some((option) => option.id === `dynamic:${dynamicFilterName}`))
|
|
65
|
+
.map((dynamicFilterName) => ({
|
|
66
|
+
name: dynamicFilterName,
|
|
67
|
+
displayName: formatFilterDisplayName(dynamicFilterName),
|
|
68
|
+
}));
|
|
69
|
+
}, [dynamicFilters, selectedFilterOptions]);
|
|
70
|
+
const filters = useMemo(() => {
|
|
71
|
+
const sortOptions = [
|
|
72
|
+
{
|
|
73
|
+
filterItemId: String(ProductSorting.FEATURED),
|
|
74
|
+
displayName: "Relevance",
|
|
75
|
+
productCount: 0,
|
|
76
|
+
isSelected: productSorting === ProductSorting.FEATURED,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
filterItemId: String(ProductSorting.PRICE_ASC),
|
|
80
|
+
displayName: "Price: Low to High",
|
|
81
|
+
productCount: 0,
|
|
82
|
+
isSelected: productSorting === ProductSorting.PRICE_ASC,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
filterItemId: String(ProductSorting.PRICE_DESC),
|
|
86
|
+
displayName: "Price: High to Low",
|
|
87
|
+
productCount: 0,
|
|
88
|
+
isSelected: productSorting === ProductSorting.PRICE_DESC,
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
return [
|
|
92
|
+
{ filterId: "sort", displayName: "SORT", items: sortOptions },
|
|
93
|
+
...searchFilters,
|
|
94
|
+
];
|
|
95
|
+
}, [productSorting, searchFilters]);
|
|
96
|
+
const filterButtonText = useMemo(() => {
|
|
97
|
+
const selectedCount = filters.reduce((acc, filter) => {
|
|
98
|
+
if (filter.filterId === "sort") {
|
|
99
|
+
return acc;
|
|
100
|
+
}
|
|
101
|
+
return acc + filter.items.filter((item) => item.isSelected).length;
|
|
102
|
+
}, 0);
|
|
103
|
+
if (selectedCount === 0) {
|
|
104
|
+
return "Filter & Sort";
|
|
105
|
+
}
|
|
106
|
+
return `Filter & Sort (${selectedCount})`;
|
|
107
|
+
}, [filters]);
|
|
108
|
+
// Callbacks
|
|
109
|
+
const handleToggleDynamicFilter = useCallback(({ filter, dynamicFilterDisplayName, }) => {
|
|
110
|
+
trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
|
|
111
|
+
eventName: SpiffyMetricsEventName.SearchFilterClicked,
|
|
112
|
+
eventProps: {
|
|
113
|
+
filterType: "Dynamic",
|
|
114
|
+
filterValue: filter,
|
|
115
|
+
queryText: searchText,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
addFilter(createFilterOption("dynamic", filter, dynamicFilterDisplayName));
|
|
119
|
+
scrollToTop();
|
|
120
|
+
}, [addFilter, searchText, scrollToTop, trackEvent]);
|
|
121
|
+
const handleRemoveFilter = useCallback((filter) => {
|
|
122
|
+
removeFilter(filter.id);
|
|
123
|
+
scrollToTop();
|
|
124
|
+
}, [removeFilter, scrollToTop]);
|
|
125
|
+
const handleSelectFilterItem = useCallback(({ filterId, filterItemId, isSelected, displayName, }) => {
|
|
126
|
+
if (filterId === "sort") {
|
|
127
|
+
const newSort = filterItemId;
|
|
128
|
+
trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
|
|
129
|
+
eventName: SpiffyMetricsEventName.SearchSortClicked,
|
|
130
|
+
eventProps: {
|
|
131
|
+
sortType: newSort,
|
|
132
|
+
queryText: searchText,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
setProductSorting(newSort);
|
|
136
|
+
scrollToTop();
|
|
137
|
+
}
|
|
138
|
+
else if (!isSelected) {
|
|
139
|
+
removeFilter(`${filterId}:${filterItemId}`);
|
|
140
|
+
scrollToTop();
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
|
|
144
|
+
eventName: SpiffyMetricsEventName.SearchFilterClicked,
|
|
145
|
+
eventProps: {
|
|
146
|
+
filterType: "Static",
|
|
147
|
+
filterCategory: filterId,
|
|
148
|
+
filterValue: filterItemId,
|
|
149
|
+
queryText: searchText,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
addFilter(createFilterOption(filterId, filterItemId, displayName));
|
|
153
|
+
scrollToTop();
|
|
154
|
+
}
|
|
155
|
+
}, [
|
|
156
|
+
addFilter,
|
|
157
|
+
removeFilter,
|
|
158
|
+
setProductSorting,
|
|
159
|
+
searchText,
|
|
160
|
+
scrollToTop,
|
|
161
|
+
trackEvent,
|
|
162
|
+
]);
|
|
163
|
+
const handleClearAllFilters = useCallback(() => {
|
|
164
|
+
setProductSorting(ProductSorting.FEATURED);
|
|
165
|
+
clearFilters();
|
|
166
|
+
scrollToTop();
|
|
167
|
+
}, [setProductSorting, clearFilters, scrollToTop]);
|
|
168
|
+
// Side Effects
|
|
169
|
+
useTrackComponentVisibleEvent(SpiffyWidgets.SearchResults, searchResultsRef, {}, SpiffyMetricsEventName.SearchComponentVisible);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (productList.length > 0) {
|
|
172
|
+
trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
|
|
173
|
+
eventName: SpiffyMetricsEventName.SearchResultsViewed,
|
|
174
|
+
eventProps: {
|
|
175
|
+
queryText: searchText,
|
|
176
|
+
resultsCount: productList.length,
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}, [productList.length, searchText, trackEvent]);
|
|
181
|
+
// This is the single source of truth for the search text triggering a search
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (query && query !== searchText) {
|
|
184
|
+
const esq = new URLSearchParams(window.location.search).get("esq");
|
|
185
|
+
setSearchText(query);
|
|
186
|
+
performSearch({ query: esq !== null && esq !== void 0 ? esq : query });
|
|
187
|
+
}
|
|
188
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
189
|
+
}, [performSearch, query, setSearchText]);
|
|
190
|
+
return {
|
|
191
|
+
searchData,
|
|
192
|
+
searchResponseId: (_c = searchData === null || searchData === void 0 ? void 0 : searchData.searchResponseId) !== null && _c !== void 0 ? _c : "",
|
|
193
|
+
merchantShortName: safeMerchantShortName,
|
|
194
|
+
productCardConfig: safeProductCardConfig,
|
|
195
|
+
productList,
|
|
196
|
+
recommendedProducts,
|
|
197
|
+
autocompleteResults,
|
|
198
|
+
searchFilters: filters,
|
|
199
|
+
availableDynamicFilters,
|
|
200
|
+
selectedFilterOptions,
|
|
201
|
+
searchText,
|
|
202
|
+
query: query || "",
|
|
203
|
+
searchResultsState,
|
|
204
|
+
isLoadingSearch,
|
|
205
|
+
isLoadingAutocomplete: false,
|
|
206
|
+
isFilterOpen,
|
|
207
|
+
shouldShowAutocomplete,
|
|
208
|
+
focusedIndex,
|
|
209
|
+
focusedOptionId,
|
|
210
|
+
filterButtonText,
|
|
211
|
+
onSearchInputChange: handleSearchInputChange,
|
|
212
|
+
onSubmitSearch: handleSubmitSearch,
|
|
213
|
+
onAutocompleteSelect: handleAutocompleteSelect,
|
|
214
|
+
onKeyDown: handleKeyDown,
|
|
215
|
+
onSearchInputFocus: handleSearchInputFocus,
|
|
216
|
+
onSearchInputBlur: handleSearchInputBlur,
|
|
217
|
+
onToggleDynamicFilter: handleToggleDynamicFilter,
|
|
218
|
+
onSelectFilterItem: handleSelectFilterItem,
|
|
219
|
+
onRemoveFilter: handleRemoveFilter,
|
|
220
|
+
onClearAllFilters: handleClearAllFilters,
|
|
221
|
+
setIsFilterOpen,
|
|
222
|
+
searchResultsRef,
|
|
223
|
+
};
|
|
224
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { useState, useCallback, useRef, useMemo } from "react";
|
|
2
|
+
import { useAtomValue } from "jotai";
|
|
3
|
+
import Fuse from "fuse.js";
|
|
4
|
+
import { SpiffyMetricsEventName, } from "@envive-ai/types";
|
|
5
|
+
import { autocompleteStateAtom } from "src/atoms/globalSearch";
|
|
6
|
+
import { amplitudeTrackEventAtom } from "src/atoms/amplitude/amplitudeTrackEventAtom";
|
|
7
|
+
export const useSearchInput = ({ initialSearchText = "", searchOrigin, onSearchSubmit, }) => {
|
|
8
|
+
const track = useAtomValue(amplitudeTrackEventAtom);
|
|
9
|
+
// State
|
|
10
|
+
const [searchText, setSearchText] = useState(initialSearchText);
|
|
11
|
+
const [hasText, setHasText] = useState(initialSearchText.trim().length > 0);
|
|
12
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
13
|
+
const [focusedIndex, setFocusedIndex] = useState(-1);
|
|
14
|
+
const [focusedOptionId, setFocusedOptionId] = useState(undefined);
|
|
15
|
+
const autocompleteState = useAtomValue(autocompleteStateAtom);
|
|
16
|
+
const globalAutocompleteResults = autocompleteState.results;
|
|
17
|
+
const isAutocompleteEnabled = globalAutocompleteResults.length > 0;
|
|
18
|
+
// Refs
|
|
19
|
+
const isSelectingAutocomplete = useRef(false);
|
|
20
|
+
// Computed
|
|
21
|
+
const shouldShowAutocomplete = hasText && isFocused && isAutocompleteEnabled;
|
|
22
|
+
const autocompleteResultsLimit = 5;
|
|
23
|
+
// Configure Fuse.js for fuzzy search with custom scoring
|
|
24
|
+
const fuseOptions = useMemo(() => ({
|
|
25
|
+
includeScore: true,
|
|
26
|
+
includeMatches: true,
|
|
27
|
+
// Fuzzy matching threshold (0.0 = perfect match, 1.0 = match anything)
|
|
28
|
+
threshold: 0.3,
|
|
29
|
+
// Location where match is expected (0 = beginning)
|
|
30
|
+
location: 0,
|
|
31
|
+
// Distance from location where match can be found - smaller for prefix preference
|
|
32
|
+
distance: 4,
|
|
33
|
+
// Minimum character length before fuzzy matching starts
|
|
34
|
+
minMatchCharLength: 1,
|
|
35
|
+
// Keys to search (we're searching strings directly, so no keys needed)
|
|
36
|
+
keys: [],
|
|
37
|
+
// Use extended search for exact matches and prefix matching
|
|
38
|
+
useExtendedSearch: false,
|
|
39
|
+
// Don't ignore location - this helps prioritize matches at the beginning
|
|
40
|
+
ignoreLocation: false,
|
|
41
|
+
}), []);
|
|
42
|
+
const fuse = useMemo(() => {
|
|
43
|
+
if (!globalAutocompleteResults.length)
|
|
44
|
+
return null;
|
|
45
|
+
return new Fuse(globalAutocompleteResults, fuseOptions);
|
|
46
|
+
}, [globalAutocompleteResults, fuseOptions]);
|
|
47
|
+
// Autocomplete fuzzy search using Fuse.js
|
|
48
|
+
const autocompleteResults = useMemo(() => {
|
|
49
|
+
if (!isAutocompleteEnabled || !fuse) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
if (!searchText.trim()) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
const fuseResults = fuse.search(searchText);
|
|
56
|
+
// Use only Fuse.js scoring (results are already sorted by relevance)
|
|
57
|
+
return fuseResults
|
|
58
|
+
.slice(0, autocompleteResultsLimit)
|
|
59
|
+
.map((result) => result.item);
|
|
60
|
+
}, [isAutocompleteEnabled, fuse, searchText, autocompleteResultsLimit]);
|
|
61
|
+
// Handlers
|
|
62
|
+
const handleSearchInputChange = useCallback((newValue) => {
|
|
63
|
+
// If the user is changing text, they must be interacting with the input
|
|
64
|
+
// So we can safely assume they're focused
|
|
65
|
+
if (newValue !== searchText) {
|
|
66
|
+
setIsFocused(true);
|
|
67
|
+
}
|
|
68
|
+
if (newValue.length === 1) {
|
|
69
|
+
track === null || track === void 0 ? void 0 : track({
|
|
70
|
+
eventName: SpiffyMetricsEventName.SearchInputStarted,
|
|
71
|
+
eventProps: {
|
|
72
|
+
searchOrigin,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
setSearchText(newValue);
|
|
77
|
+
setHasText(newValue.trim().length > 0);
|
|
78
|
+
setFocusedIndex(-1);
|
|
79
|
+
setFocusedOptionId(undefined);
|
|
80
|
+
}, [searchOrigin, searchText, track]);
|
|
81
|
+
const handleSearchInputFocus = useCallback(() => {
|
|
82
|
+
setIsFocused(true);
|
|
83
|
+
}, []);
|
|
84
|
+
const handleSearchInputBlur = useCallback(() => {
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
if (!isSelectingAutocomplete.current) {
|
|
87
|
+
setIsFocused(false);
|
|
88
|
+
setFocusedIndex(-1);
|
|
89
|
+
setFocusedOptionId(undefined);
|
|
90
|
+
}
|
|
91
|
+
}, 150);
|
|
92
|
+
}, []);
|
|
93
|
+
const handleSubmitSearch = useCallback(() => {
|
|
94
|
+
setIsFocused(false);
|
|
95
|
+
if (searchText.trim() && onSearchSubmit) {
|
|
96
|
+
track === null || track === void 0 ? void 0 : track({
|
|
97
|
+
eventName: SpiffyMetricsEventName.SearchQuerySubmitted,
|
|
98
|
+
eventProps: {
|
|
99
|
+
searchOrigin,
|
|
100
|
+
queryText: searchText.trim(),
|
|
101
|
+
},
|
|
102
|
+
alsoSendToGoogleAnalytics: true,
|
|
103
|
+
});
|
|
104
|
+
onSearchSubmit(searchText.trim());
|
|
105
|
+
}
|
|
106
|
+
}, [searchText, onSearchSubmit, searchOrigin, track]);
|
|
107
|
+
const handleAutocompleteSelect = useCallback((suggestion, rankPosition) => {
|
|
108
|
+
isSelectingAutocomplete.current = true;
|
|
109
|
+
setSearchText(suggestion);
|
|
110
|
+
setHasText(suggestion.trim().length > 0);
|
|
111
|
+
setIsFocused(false);
|
|
112
|
+
track === null || track === void 0 ? void 0 : track({
|
|
113
|
+
eventName: SpiffyMetricsEventName.SearchInputStarted,
|
|
114
|
+
eventProps: {
|
|
115
|
+
searchOrigin,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
if (onSearchSubmit) {
|
|
119
|
+
onSearchSubmit(suggestion.trim());
|
|
120
|
+
}
|
|
121
|
+
setTimeout(() => {
|
|
122
|
+
isSelectingAutocomplete.current = false;
|
|
123
|
+
}, 100);
|
|
124
|
+
}, [onSearchSubmit, searchOrigin, track]);
|
|
125
|
+
const handleKeyDown = useCallback((event) => {
|
|
126
|
+
if (event.key === "ArrowDown") {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
const newIndex = (focusedIndex + 1) % autocompleteResults.length;
|
|
129
|
+
setFocusedIndex(newIndex);
|
|
130
|
+
setFocusedOptionId(`option-${newIndex}`);
|
|
131
|
+
}
|
|
132
|
+
else if (event.key === "ArrowUp") {
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
const newIndex = (focusedIndex - 1 + autocompleteResults.length) %
|
|
135
|
+
autocompleteResults.length;
|
|
136
|
+
setFocusedIndex(newIndex);
|
|
137
|
+
setFocusedOptionId(`option-${newIndex}`);
|
|
138
|
+
}
|
|
139
|
+
else if (event.key === "Enter") {
|
|
140
|
+
if (focusedIndex === -1) {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
handleSubmitSearch();
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
const suggestionText = autocompleteResults[focusedIndex];
|
|
147
|
+
handleAutocompleteSelect(suggestionText, focusedIndex);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (event.key === "Escape") {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
setFocusedIndex(-1);
|
|
153
|
+
setFocusedOptionId(undefined);
|
|
154
|
+
}
|
|
155
|
+
}, [
|
|
156
|
+
autocompleteResults,
|
|
157
|
+
focusedIndex,
|
|
158
|
+
handleAutocompleteSelect,
|
|
159
|
+
handleSubmitSearch,
|
|
160
|
+
]);
|
|
161
|
+
const setSearchTextUtility = useCallback((text) => {
|
|
162
|
+
setSearchText(text);
|
|
163
|
+
setHasText(text.trim().length > 0);
|
|
164
|
+
}, []);
|
|
165
|
+
const resetSearch = useCallback(() => {
|
|
166
|
+
setSearchText("");
|
|
167
|
+
setHasText(false);
|
|
168
|
+
setIsFocused(false);
|
|
169
|
+
setFocusedIndex(-1);
|
|
170
|
+
setFocusedOptionId(undefined);
|
|
171
|
+
}, []);
|
|
172
|
+
return {
|
|
173
|
+
// State
|
|
174
|
+
searchText,
|
|
175
|
+
hasText,
|
|
176
|
+
isFocused,
|
|
177
|
+
focusedIndex,
|
|
178
|
+
focusedOptionId,
|
|
179
|
+
autocompleteResults,
|
|
180
|
+
shouldShowAutocomplete,
|
|
181
|
+
// Handlers
|
|
182
|
+
handleSearchInputChange,
|
|
183
|
+
handleSearchInputFocus,
|
|
184
|
+
handleSearchInputBlur,
|
|
185
|
+
handleKeyDown,
|
|
186
|
+
handleAutocompleteSelect,
|
|
187
|
+
handleSubmitSearch,
|
|
188
|
+
// Utilities
|
|
189
|
+
setSearchText: setSearchTextUtility,
|
|
190
|
+
resetSearch,
|
|
191
|
+
};
|
|
192
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useSearchOperations";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { useSearchService } from 'src/contexts/searchContext';
|
|
3
|
+
export const useProductSearch = () => {
|
|
4
|
+
const { searchProducts, isReady } = useSearchService();
|
|
5
|
+
const [data, setData] = useState();
|
|
6
|
+
const [loading, setLoading] = useState(false);
|
|
7
|
+
const [error, setError] = useState(null);
|
|
8
|
+
const search = useCallback(async (params) => {
|
|
9
|
+
if (!isReady) {
|
|
10
|
+
setError(new Error('Search service not ready - missing dependencies'));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
setLoading(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
try {
|
|
16
|
+
const result = await searchProducts(params);
|
|
17
|
+
setData(result);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
setError(err instanceof Error ? err : new Error('Unknown search error'));
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
setLoading(false);
|
|
24
|
+
}
|
|
25
|
+
}, [searchProducts, isReady]);
|
|
26
|
+
const reset = useCallback(() => {
|
|
27
|
+
setData(undefined);
|
|
28
|
+
setError(null);
|
|
29
|
+
setLoading(false);
|
|
30
|
+
}, []);
|
|
31
|
+
return {
|
|
32
|
+
data,
|
|
33
|
+
loading,
|
|
34
|
+
error,
|
|
35
|
+
search,
|
|
36
|
+
reset,
|
|
37
|
+
isReady,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const useSearchWithQuery = (params) => {
|
|
41
|
+
const { searchProducts, isReady } = useSearchService();
|
|
42
|
+
const [data, setData] = useState();
|
|
43
|
+
const [loading, setLoading] = useState(false);
|
|
44
|
+
const [error, setError] = useState(null);
|
|
45
|
+
const executeSearch = useCallback(async (searchParams) => {
|
|
46
|
+
if (!isReady)
|
|
47
|
+
return;
|
|
48
|
+
setLoading(true);
|
|
49
|
+
setError(null);
|
|
50
|
+
try {
|
|
51
|
+
const result = await searchProducts(searchParams);
|
|
52
|
+
setData(result);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
setError(err instanceof Error ? err : new Error('Unknown search error'));
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
setLoading(false);
|
|
59
|
+
}
|
|
60
|
+
}, [searchProducts, isReady]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (params && isReady) {
|
|
63
|
+
executeSearch(params);
|
|
64
|
+
}
|
|
65
|
+
}, [params, isReady, executeSearch]);
|
|
66
|
+
const refetch = useCallback(() => {
|
|
67
|
+
if (params) {
|
|
68
|
+
executeSearch(params);
|
|
69
|
+
}
|
|
70
|
+
}, [params, executeSearch]);
|
|
71
|
+
return {
|
|
72
|
+
data,
|
|
73
|
+
loading,
|
|
74
|
+
error,
|
|
75
|
+
refetch,
|
|
76
|
+
isReady,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useSessionStorageOperations";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from "react";
|
|
2
|
+
import { useSessionStorage } from "src/contexts/sessionStorageContext";
|
|
3
|
+
export const useSessionStorageValue = (key) => {
|
|
4
|
+
const { getItem, setItem } = useSessionStorage();
|
|
5
|
+
const [value, setValue] = useState(() => getItem(key));
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const handleStorageChange = (event) => {
|
|
8
|
+
if (event.key === key) {
|
|
9
|
+
setValue(event.newValue);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
window.addEventListener("storage", handleStorageChange);
|
|
13
|
+
return () => window.removeEventListener("storage", handleStorageChange);
|
|
14
|
+
}, [key, getItem]);
|
|
15
|
+
const updateValue = useCallback((newValue) => {
|
|
16
|
+
setItem(key, newValue);
|
|
17
|
+
setValue(newValue);
|
|
18
|
+
}, [key, setItem]);
|
|
19
|
+
return { value, setValue: updateValue };
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useShopifyUrlOperations";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useShopifyUrl } from 'src/contexts/shopifyUrlContext/shopifyUrlContext';
|
|
3
|
+
export const useShopifyUrlOperations = () => {
|
|
4
|
+
const { getTrimmedPathName, getPlpOrPdpId, isOnPdpPage, isOnPlpPage, isReady } = useShopifyUrl();
|
|
5
|
+
return {
|
|
6
|
+
getTrimmedPathName,
|
|
7
|
+
getPlpOrPdpId,
|
|
8
|
+
isOnPdpPage,
|
|
9
|
+
isOnPlpPage,
|
|
10
|
+
isReady,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export const useCurrentPageType = () => {
|
|
14
|
+
const { isOnPdpPage, isOnPlpPage, isReady } = useShopifyUrl();
|
|
15
|
+
const getPageType = useCallback(() => {
|
|
16
|
+
if (!isReady)
|
|
17
|
+
return 'unknown';
|
|
18
|
+
if (isOnPdpPage())
|
|
19
|
+
return 'pdp';
|
|
20
|
+
if (isOnPlpPage())
|
|
21
|
+
return 'plp';
|
|
22
|
+
return 'other';
|
|
23
|
+
}, [isReady, isOnPdpPage, isOnPlpPage]);
|
|
24
|
+
return { getPageType, isReady };
|
|
25
|
+
};
|
|
26
|
+
export const useProductId = (extractor) => {
|
|
27
|
+
const { getPlpOrPdpId, isReady } = useShopifyUrl();
|
|
28
|
+
const productId = useCallback(() => {
|
|
29
|
+
if (!isReady)
|
|
30
|
+
return null;
|
|
31
|
+
return getPlpOrPdpId(extractor);
|
|
32
|
+
}, [isReady, getPlpOrPdpId, extractor]);
|
|
33
|
+
return { productId, isReady };
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useSnapCalculator";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
export const useSnapCalculator = (snaps, maxHeight, unit) => {
|
|
3
|
+
const viewportHeightPx = document.documentElement.clientHeight;
|
|
4
|
+
const swipeviewHeightPx = unit === 'percent' ? Math.floor(viewportHeightPx * (maxHeight / 100)) : maxHeight;
|
|
5
|
+
const snapsToPixels = useMemo(() => snaps === null || snaps === void 0 ? void 0 : snaps.map((snap) => Math.abs((unit === 'percent' ? Math.floor(swipeviewHeightPx * (snap / 100)) : snap) -
|
|
6
|
+
swipeviewHeightPx)), [viewportHeightPx]);
|
|
7
|
+
const getPixelToSnap = (pixels) => {
|
|
8
|
+
const snapIdx = (snapsToPixels === null || snapsToPixels === void 0 ? void 0 : snapsToPixels.indexOf(pixels)) || 0;
|
|
9
|
+
return (snaps === null || snaps === void 0 ? void 0 : snaps[snapIdx]) || 0;
|
|
10
|
+
};
|
|
11
|
+
const getSnapToPixel = (snap) => {
|
|
12
|
+
const snapIdx = (snaps === null || snaps === void 0 ? void 0 : snaps.indexOf(snap)) || 0;
|
|
13
|
+
return (snapsToPixels === null || snapsToPixels === void 0 ? void 0 : snapsToPixels[snapIdx]) || 0;
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
viewportHeightPx,
|
|
17
|
+
snapsToPixels,
|
|
18
|
+
swipeviewHeightPx,
|
|
19
|
+
getPixelToSnap,
|
|
20
|
+
getSnapToPixel,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useSystemSettingsContext";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { SystemSettingsContext } from "src/contexts/systemSettingsContext";
|
|
3
|
+
export const useSystemSettingsContext = () => {
|
|
4
|
+
const context = useContext(SystemSettingsContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("useSystemSettingsContext must be used within a SystemSettingsContextProvider");
|
|
7
|
+
}
|
|
8
|
+
return { ...context };
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useTrackComponentVisibleEvent";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useIntersection } from 'src/hooks/Intersection/useIntersection';
|
|
3
|
+
import { useAmplitude } from 'src/contexts/amplitudeContext/amplitudeContext';
|
|
4
|
+
import { SpiffyMetricsEventName } from '@envive-ai/types';
|
|
5
|
+
/**
|
|
6
|
+
* Tracks a component and logs an event to Amplitude when the component is visible.
|
|
7
|
+
*
|
|
8
|
+
* @param component - The component to track.
|
|
9
|
+
* @param element - The element to track visibility of.
|
|
10
|
+
* @param eventProps - Additional properties to include with the event.
|
|
11
|
+
* @param eventName - The Amplitude event name to track (defaults to ChatComponentVisible).
|
|
12
|
+
*/
|
|
13
|
+
export const useTrackComponentVisibleEvent = (component, element, eventProps, eventName = SpiffyMetricsEventName.ChatComponentVisible) => {
|
|
14
|
+
const isVisible = useIntersection(element, '0px');
|
|
15
|
+
const hasTrackedEvent = useRef(false);
|
|
16
|
+
const { trackEvent } = useAmplitude();
|
|
17
|
+
const componentProps = (() => {
|
|
18
|
+
if (eventName === SpiffyMetricsEventName.ChatComponentVisible) {
|
|
19
|
+
return {
|
|
20
|
+
chat_component: component,
|
|
21
|
+
...eventProps,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (eventName === SpiffyMetricsEventName.SearchComponentVisible) {
|
|
25
|
+
return {
|
|
26
|
+
search_component: component,
|
|
27
|
+
...eventProps,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// Default case for other event types
|
|
31
|
+
return {
|
|
32
|
+
component,
|
|
33
|
+
...eventProps,
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (isVisible && !hasTrackedEvent.current) {
|
|
38
|
+
trackEvent({
|
|
39
|
+
eventName,
|
|
40
|
+
eventProps: componentProps,
|
|
41
|
+
});
|
|
42
|
+
hasTrackedEvent.current = true;
|
|
43
|
+
}
|
|
44
|
+
}, [isVisible, component, eventProps, eventName, componentProps, trackEvent]);
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useUpdateAnalyticsProps";
|