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:
@@ -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 { OrderType } from "pages/checkout/hooks/types";
|
||||||
import { RootState } from "redux/store";
|
import { RootState } from "redux/store";
|
||||||
import { CartItem, RestaurantDetails, Tax } from "utils/types/appTypes";
|
import { CartItem, RestaurantDetails, Tax } from "utils/types/appTypes";
|
||||||
@@ -648,8 +648,12 @@ export const selectCartItemsQuantityById =
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Loyalty selectors
|
// Loyalty selectors
|
||||||
export const selectLoyaltyItems = (state: RootState) =>
|
const selectOrderItems = (state: RootState) => state.order.items;
|
||||||
state.order.items.filter((item) => item.isHasLoyalty);
|
|
||||||
|
export const selectLoyaltyItems = createSelector(
|
||||||
|
[selectOrderItems],
|
||||||
|
(items) => items.filter((item) => item.isHasLoyalty),
|
||||||
|
);
|
||||||
|
|
||||||
export const selectHighestPricedLoyaltyItem = (state: RootState) => {
|
export const selectHighestPricedLoyaltyItem = (state: RootState) => {
|
||||||
const loyaltyItems = selectLoyaltyItems(state);
|
const loyaltyItems = selectLoyaltyItems(state);
|
||||||
@@ -667,11 +671,9 @@ export const selectDiscountTotal = (state: RootState) =>
|
|||||||
? selectHighestPricedLoyaltyItem(state)?.price || 0
|
? selectHighestPricedLoyaltyItem(state)?.price || 0
|
||||||
: 0);
|
: 0);
|
||||||
|
|
||||||
export const selectLoyaltyValidation = (state: RootState) => {
|
export const selectLoyaltyValidation = createSelector(
|
||||||
const useLoyaltyPoints = state.order.useLoyaltyPoints;
|
[(state: RootState) => state.order.useLoyaltyPoints, selectLoyaltyItems],
|
||||||
const loyaltyItems = selectLoyaltyItems(state);
|
(useLoyaltyPoints, loyaltyItems) => ({
|
||||||
|
|
||||||
return {
|
|
||||||
canUseLoyaltyPoints: loyaltyItems.length > 0,
|
canUseLoyaltyPoints: loyaltyItems.length > 0,
|
||||||
hasLoyaltyItems: loyaltyItems.length > 0,
|
hasLoyaltyItems: loyaltyItems.length > 0,
|
||||||
loyaltyItemsCount: loyaltyItems.length,
|
loyaltyItemsCount: loyaltyItems.length,
|
||||||
@@ -679,8 +681,8 @@ export const selectLoyaltyValidation = (state: RootState) => {
|
|||||||
useLoyaltyPoints && loyaltyItems.length === 0
|
useLoyaltyPoints && loyaltyItems.length === 0
|
||||||
? "cart.noLoyaltyItemsInCart"
|
? "cart.noLoyaltyItemsInCart"
|
||||||
: null,
|
: null,
|
||||||
};
|
}),
|
||||||
};
|
);
|
||||||
|
|
||||||
// Tax selectors
|
// Tax selectors
|
||||||
export const selectTaxes = (state: RootState) => state.order.restaurant.taxes;
|
export const selectTaxes = (state: RootState) => state.order.restaurant.taxes;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createSlice } from "@reduxjs/toolkit";
|
import { createSlice } from "@reduxjs/toolkit";
|
||||||
import { RootState } from "redux/store";
|
import { RootState } from "redux/store";
|
||||||
|
|
||||||
interface ThemeState {
|
export interface ThemeState {
|
||||||
themeName: string;
|
themeName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user