Filter INITIAL_LOADING_ACTIONS based on products
Signed-off-by: kielosz <kielosz@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import React, {
|
||||
SetStateAction,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useReducer,
|
||||
useState,
|
||||
} from 'react';
|
||||
@@ -32,6 +33,7 @@ import {
|
||||
INITIAL_LOADING_ACTIONS,
|
||||
} from '../utils/loading';
|
||||
import { useBackdropStyles as useStyles } from '../utils/styles';
|
||||
import { useConfig } from './useConfig';
|
||||
|
||||
export type LoadingContextProps = {
|
||||
state: Loading;
|
||||
@@ -54,7 +56,16 @@ function reducer(prevState: Loading, action: Partial<Loading>): Loading {
|
||||
|
||||
export const LoadingProvider = ({ children }: PropsWithChildren<{}>) => {
|
||||
const classes = useStyles();
|
||||
const actions = INITIAL_LOADING_ACTIONS;
|
||||
const { products } = useConfig();
|
||||
const actions = useMemo(
|
||||
() =>
|
||||
INITIAL_LOADING_ACTIONS.filter(
|
||||
action =>
|
||||
products.length ||
|
||||
action !== DefaultLoadingAction.CostInsightsProducts,
|
||||
),
|
||||
[products],
|
||||
);
|
||||
const [state, dispatch] = useReducer(reducer, getDefaultState(actions));
|
||||
const [isBackdropVisible, setBackdropVisible] = useState(false);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ export enum DefaultLoadingAction {
|
||||
export const INITIAL_LOADING_ACTIONS = [
|
||||
DefaultLoadingAction.UserGroups,
|
||||
DefaultLoadingAction.CostInsightsInitial,
|
||||
DefaultLoadingAction.CostInsightsProducts,
|
||||
];
|
||||
|
||||
export const getDefaultState = (loadingActions: string[]): Loading => {
|
||||
|
||||
Reference in New Issue
Block a user