@envive-ai/react-hooks 0.2.6-alpha-2 → 0.2.6-alpha-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envive-ai/react-hooks",
3
- "version": "0.2.6-alpha-2",
3
+ "version": "0.2.6-alpha-3",
4
4
  "description": "React hooks for connecting to Envive AI services.",
5
5
  "keywords": [
6
6
  "react",
@@ -1,5 +1,5 @@
1
1
  import { useAtom, useAtomValue, useSetAtom } from "jotai";
2
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ import { useCallback, useEffect, useMemo, useRef } from "react";
3
3
  import {
4
4
  SearchResultsHocProps,
5
5
  ProductSorting,
@@ -24,18 +24,18 @@ import {
24
24
  } from "../../atoms/search";
25
25
  import { isFilterOpenAtom } from "../../atoms/globalSearch/globalSearch";
26
26
  import { formatFilterDisplayName } from "../../atoms/search/utils";
27
- import { useAmplitude } from "../../contexts/amplitudeContext/amplitudeContext";
27
+ import { amplitudeTrackEventAtom } from "../../atoms/amplitude/amplitudeTrackEventAtom";
28
28
  import { orgShortNameAtom } from "../../atoms/envive/enviveConfig";
29
- import { useNewOrgConfig } from "../NewOrgConfig";
29
+ import { newOrgConfigAtom } from "../../atoms/org/newOrgConfigAtom";
30
+ import { retrievedProductsAtom } from "../../atoms/search/productRetrievalAPI";
30
31
  import { useTrackComponentVisibleEvent } from "../TrackComponentVisibleEvent";
31
32
  import { getSearchResultsState } from "../utils";
32
- import { useRecommendedProducts } from "./useRecommendedProducts";
33
33
  import { useSearchInput } from "./useSearchInput";
34
34
 
35
35
  export const useSearch = (): SearchResultsHocProps => {
36
36
  // Atoms
37
- const { trackEvent } = useAmplitude();
38
- const config = useNewOrgConfig();
37
+ const trackEvent = useAtomValue(amplitudeTrackEventAtom);
38
+ const config = useAtomValue(newOrgConfigAtom);
39
39
  const orgShortName = useAtomValue(orgShortNameAtom);
40
40
  const { data: searchData, loading: isLoadingSearch } =
41
41
  useAtomValue(searchAtom);
@@ -49,7 +49,7 @@ export const useSearch = (): SearchResultsHocProps => {
49
49
  const [productSorting, setProductSorting] = useAtom(searchProductSortingAtom);
50
50
  const clearFilters = useSetAtom(clearSearchFiltersAtom);
51
51
  const searchFilters = useAtomValue(searchFiltersAtom);
52
- const recommendedProducts = useRecommendedProducts();
52
+ const recommendedProducts = useAtomValue(retrievedProductsAtom);
53
53
 
54
54
  // Refs
55
55
  const searchResultsRef = useRef<HTMLDivElement>(null);
@@ -164,7 +164,7 @@ export const useSearch = (): SearchResultsHocProps => {
164
164
  filter: string;
165
165
  dynamicFilterDisplayName: string;
166
166
  }) => {
167
- trackEvent({
167
+ trackEvent?.({
168
168
  eventName: SpiffyMetricsEventName.SearchFilterClicked,
169
169
  eventProps: {
170
170
  filterType: "Dynamic",
@@ -202,7 +202,7 @@ export const useSearch = (): SearchResultsHocProps => {
202
202
  }) => {
203
203
  if (filterId === "sort") {
204
204
  const newSort = filterItemId as ProductSorting;
205
- trackEvent({
205
+ trackEvent?.({
206
206
  eventName: SpiffyMetricsEventName.SearchSortClicked,
207
207
  eventProps: {
208
208
  sortType: newSort,
@@ -215,7 +215,7 @@ export const useSearch = (): SearchResultsHocProps => {
215
215
  removeFilter(`${filterId}:${filterItemId}`);
216
216
  scrollToTop();
217
217
  } else {
218
- trackEvent({
218
+ trackEvent?.({
219
219
  eventName: SpiffyMetricsEventName.SearchFilterClicked,
220
220
  eventProps: {
221
221
  filterType: "Static",
@@ -254,7 +254,7 @@ export const useSearch = (): SearchResultsHocProps => {
254
254
 
255
255
  useEffect(() => {
256
256
  if (productList.length > 0) {
257
- trackEvent({
257
+ trackEvent?.({
258
258
  eventName: SpiffyMetricsEventName.SearchResultsViewed,
259
259
  eventProps: {
260
260
  queryText: searchText,
@@ -8,13 +8,14 @@ import {
8
8
  } from "@envive-ai/types";
9
9
  import { useAmplitudeTracking } from "../AmplitudeOperations";
10
10
  import { autocompleteStateAtom } from "src/atoms/globalSearch";
11
+ import { amplitudeTrackEventAtom } from "src/atoms/amplitude/amplitudeTrackEventAtom";
11
12
 
12
13
  export const useSearchInput = ({
13
14
  initialSearchText = "",
14
15
  searchOrigin,
15
16
  onSearchSubmit,
16
17
  }: UseSearchInputProps): UseSearchInputReturn => {
17
- const { track } = useAmplitudeTracking();
18
+ const track = useAtomValue(amplitudeTrackEventAtom);
18
19
 
19
20
  // State
20
21
  const [searchText, setSearchText] = useState(initialSearchText);
@@ -92,8 +93,11 @@ export const useSearchInput = ({
92
93
  }
93
94
 
94
95
  if (newValue.length === 1) {
95
- track(SpiffyMetricsEventName.SearchInputStarted, {
96
- searchOrigin,
96
+ track?.({
97
+ eventName: SpiffyMetricsEventName.SearchInputStarted,
98
+ eventProps: {
99
+ searchOrigin,
100
+ },
97
101
  });
98
102
  }
99
103
  setSearchText(newValue);
@@ -121,9 +125,13 @@ export const useSearchInput = ({
121
125
  const handleSubmitSearch = useCallback(() => {
122
126
  setIsFocused(false);
123
127
  if (searchText.trim() && onSearchSubmit) {
124
- track(SpiffyMetricsEventName.SearchQuerySubmitted, {
125
- searchOrigin,
126
- queryText: searchText.trim(),
128
+ track?.({
129
+ eventName: SpiffyMetricsEventName.SearchQuerySubmitted,
130
+ eventProps: {
131
+ searchOrigin,
132
+ queryText: searchText.trim(),
133
+ },
134
+ alsoSendToGoogleAnalytics: true,
127
135
  });
128
136
  onSearchSubmit(searchText.trim());
129
137
  }
@@ -136,9 +144,11 @@ export const useSearchInput = ({
136
144
  setHasText(suggestion.trim().length > 0);
137
145
  setIsFocused(false);
138
146
 
139
- track(SpiffyMetricsEventName.SearchQuerySubmitted, {
140
- searchOrigin,
141
- queryText: suggestion.trim(),
147
+ track?.({
148
+ eventName: SpiffyMetricsEventName.SearchInputStarted,
149
+ eventProps: {
150
+ searchOrigin,
151
+ },
142
152
  });
143
153
 
144
154
  if (onSearchSubmit) {