fix run-time issue

installHook.js:1 TypeError: Cannot read properties of undefined (reading '0')
    at index-rjtklWbg.js:488:22731
    at Array.map (<anonymous>)
This commit is contained in:
2025-11-12 00:25:30 +03:00
parent 8b55162e06
commit e3483eec10
2 changed files with 13 additions and 11 deletions

View File

@@ -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;

View File

@@ -1,7 +1,7 @@
import { createSlice } from "@reduxjs/toolkit";
import { RootState } from "redux/store";
interface ThemeState {
export interface ThemeState {
themeName: string;
}