@sledge-app/react-instant-search 0.0.97 → 0.0.98

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.
@@ -1537,6 +1537,22 @@ const getReviewInfo = async (id) => {
1537
1537
  return;
1538
1538
  });
1539
1539
  };
1540
+ const getProductsReviewInfo = async (ids, token) => {
1541
+ let convertIds = ids.map((v) => sanitizeDataId(v));
1542
+ let sledgeAuthApp = token || localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP);
1543
+ var myHeaders = new Headers();
1544
+ myHeaders.append("Authorization", `Bearer ${sledgeAuthApp}`);
1545
+ var requestOptions = {
1546
+ method: "GET",
1547
+ headers: myHeaders,
1548
+ redirect: "follow"
1549
+ };
1550
+ return await fetch(`${API_URL}/review/info/ids/${convertIds.join(",")}`, requestOptions).then((response) => response.json()).then((result) => {
1551
+ return result;
1552
+ }).catch(() => {
1553
+ return;
1554
+ });
1555
+ };
1540
1556
  const Rating = (props) => {
1541
1557
  var _a, _b;
1542
1558
  const { total, average, size = "md", params, withSkeletonLoading = true, withTotal = true, isScrollToElementWidget = true, data: propsData, sledgeSettings } = props;
@@ -2174,6 +2190,7 @@ const ProductGrid = ({
2174
2190
  onAfterRenderProduct && onAfterRenderProduct("success");
2175
2191
  }, []);
2176
2192
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__product-grid ${className}`, "data-grid-type": type, children: data == null ? void 0 : data.map((item, index) => {
2193
+ var _a, _b, _c;
2177
2194
  const { product, variants } = item || {};
2178
2195
  const { id, title, image, url, vendor = "", currency } = product || {};
2179
2196
  const { id: variant_id = "", title: variant_title = "", price = "", sku = "" } = (variants == null ? void 0 : variants.length) ? variants[0] : {};
@@ -2190,7 +2207,13 @@ const ProductGrid = ({
2190
2207
  is_out_of_stock: Object.hasOwn(variants[index2], "inventory_quantity") ? !inventory_quantity : false
2191
2208
  };
2192
2209
  })
2193
- }
2210
+ },
2211
+ ...dataReviews && Object.keys(dataReviews).length ? {
2212
+ review: {
2213
+ total: ((_a = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _a.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
2214
+ average: ((_c = (_b = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _b.rating) == null ? void 0 : _c.average) ? dataReviews == null ? void 0 : dataReviews[id].rating.average : 0
2215
+ }
2216
+ } : {}
2194
2217
  },
2195
2218
  showPopupComponent,
2196
2219
  setShowPopupComponent
@@ -2787,6 +2810,7 @@ const SearchIconWidgetPopup = () => {
2787
2810
  const [keyword, setKeyword] = React__default.useState("");
2788
2811
  const [searchResultProduct, setSearchResultProduct] = React__default.useState([]);
2789
2812
  const [searchResultOther, setSearchResultOther] = React__default.useState([]);
2813
+ const [dataReviews, setDataReviews] = React__default.useState({});
2790
2814
  const [displaySettings, setDisplaySettings] = React__default.useState({});
2791
2815
  const [suggestionSettings, setSuggestionSettings] = React__default.useState({});
2792
2816
  const [suggestionIndex, setSuggestionIndex] = React__default.useState("");
@@ -2807,8 +2831,8 @@ const SearchIconWidgetPopup = () => {
2807
2831
  });
2808
2832
  const searchFieldRef = React__default.useRef(null);
2809
2833
  const previousState = usePrevious({ keyword });
2810
- const handleMultiSearch = async (data, onSearch = false) => {
2811
- var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2;
2834
+ const handleMultiSearch = async (data, onSearch = false, withFetchReviewInfo = false) => {
2835
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2;
2812
2836
  setIsLoading(true);
2813
2837
  const { tabs, suffix_index_product, hidden_tags, display, show_out_of_stock } = data;
2814
2838
  const suggestion = ((_a2 = display == null ? void 0 : display.search) == null ? void 0 : _a2.suggestion) || {};
@@ -2857,6 +2881,14 @@ const SearchIconWidgetPopup = () => {
2857
2881
  !keyword.length && Object.keys(suggestion).length && ((_f2 = (_e2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _e2.products) == null ? void 0 : _f2.active) && ((_i2 = (_h2 = (_g2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _g2.products) == null ? void 0 : _h2.list) == null ? void 0 : _i2.length)
2858
2882
  );
2859
2883
  let dataSearchResultProduct = isPriorityZeroCharacter ? (_k2 = (_j2 = suggestion[valueSuggestionIndex]) == null ? void 0 : _j2.products) == null ? void 0 : _k2.list : getValueSearchResultProduct;
2884
+ if (withFetchReviewInfo) {
2885
+ let searchResultProductIds = dataSearchResultProduct.map(({ id }) => id);
2886
+ let valueDataReviews = await getProductsReviewInfo(searchResultProductIds);
2887
+ if (((_l2 = valueDataReviews == null ? void 0 : valueDataReviews.status) == null ? void 0 : _l2.code) === 200)
2888
+ setDataReviews(valueDataReviews == null ? void 0 : valueDataReviews.data);
2889
+ } else {
2890
+ setDataReviews({});
2891
+ }
2860
2892
  setSearchResultProduct(dataSearchResultProduct);
2861
2893
  setSearchResultOther(valueSearchResultOther);
2862
2894
  setSuggestionIndex(valueSuggestionIndex);
@@ -2871,7 +2903,7 @@ const SearchIconWidgetPopup = () => {
2871
2903
  const { display } = response;
2872
2904
  setDisplaySettings(display);
2873
2905
  setSuggestionSettings((_a2 = display == null ? void 0 : display.search) == null ? void 0 : _a2.suggestion);
2874
- await handleMultiSearch(response);
2906
+ await handleMultiSearch(response, false, true);
2875
2907
  };
2876
2908
  React__default.useEffect(() => {
2877
2909
  if (!isRenderAppInstantSearch)
@@ -3037,7 +3069,8 @@ const SearchIconWidgetPopup = () => {
3037
3069
  onAfterRemoveWishlist: handleFunctions.onAfterRemoveWishlist,
3038
3070
  onAfterRenderProduct: handleFunctions.onAfterRenderProduct,
3039
3071
  showPopupComponent: showInfo,
3040
- setShowPopupComponent: setShowInfo
3072
+ setShowPopupComponent: setShowInfo,
3073
+ dataReviews
3041
3074
  }
3042
3075
  ) }) : Object.keys(suggestionSettings).length && ((_k = (_j = suggestionSettings[suggestionIndex]) == null ? void 0 : _j.products) == null ? void 0 : _k.active) && ((_n = (_m = (_l = suggestionSettings[suggestionIndex]) == null ? void 0 : _l.products) == null ? void 0 : _m.list) == null ? void 0 : _n.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3043
3076
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__icon-widget-search-form-result-product-suggestion-no-result-text", children: [