From e3483eec10f93a5d11e0a78ae524c1b03c2f775a Mon Sep 17 00:00:00 2001 From: Mohammed Al-yaseen Date: Wed, 12 Nov 2025 00:25:30 +0300 Subject: [PATCH] fix run-time issue installHook.js:1 TypeError: Cannot read properties of undefined (reading '0') at index-rjtklWbg.js:488:22731 at Array.map () --- src/features/order/orderSlice.ts | 22 ++++++++++++---------- src/features/theme/themeSlice.ts | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/features/order/orderSlice.ts b/src/features/order/orderSlice.ts index 39d4cb3..0aef39a 100644 --- a/src/features/order/orderSlice.ts +++ b/src/features/order/orderSlice.ts @@ -1,4 +1,4 @@ -import { createSlice, PayloadAction } from "@reduxjs/toolkit"; +import { createSelector, createSlice, PayloadAction } from "@reduxjs/toolkit"; import { OrderType } from "pages/checkout/hooks/types"; import { RootState } from "redux/store"; import { CartItem, RestaurantDetails, Tax } from "utils/types/appTypes"; @@ -648,8 +648,12 @@ export const selectCartItemsQuantityById = }; // Loyalty selectors -export const selectLoyaltyItems = (state: RootState) => - state.order.items.filter((item) => item.isHasLoyalty); +const selectOrderItems = (state: RootState) => state.order.items; + +export const selectLoyaltyItems = createSelector( + [selectOrderItems], + (items) => items.filter((item) => item.isHasLoyalty), +); export const selectHighestPricedLoyaltyItem = (state: RootState) => { const loyaltyItems = selectLoyaltyItems(state); @@ -667,11 +671,9 @@ export const selectDiscountTotal = (state: RootState) => ? selectHighestPricedLoyaltyItem(state)?.price || 0 : 0); -export const selectLoyaltyValidation = (state: RootState) => { - const useLoyaltyPoints = state.order.useLoyaltyPoints; - const loyaltyItems = selectLoyaltyItems(state); - - return { +export const selectLoyaltyValidation = createSelector( + [(state: RootState) => state.order.useLoyaltyPoints, selectLoyaltyItems], + (useLoyaltyPoints, loyaltyItems) => ({ canUseLoyaltyPoints: loyaltyItems.length > 0, hasLoyaltyItems: loyaltyItems.length > 0, loyaltyItemsCount: loyaltyItems.length, @@ -679,8 +681,8 @@ export const selectLoyaltyValidation = (state: RootState) => { useLoyaltyPoints && loyaltyItems.length === 0 ? "cart.noLoyaltyItemsInCart" : null, - }; -}; + }), +); // Tax selectors export const selectTaxes = (state: RootState) => state.order.restaurant.taxes; diff --git a/src/features/theme/themeSlice.ts b/src/features/theme/themeSlice.ts index 365cb56..d7751d7 100644 --- a/src/features/theme/themeSlice.ts +++ b/src/features/theme/themeSlice.ts @@ -1,7 +1,7 @@ import { createSlice } from "@reduxjs/toolkit"; import { RootState } from "redux/store"; -interface ThemeState { +export interface ThemeState { themeName: string; }