Filter INITIAL_LOADING_ACTIONS based on products

Signed-off-by: kielosz <kielosz@gmail.com>
This commit is contained in:
kielosz
2022-08-04 21:32:38 +02:00
parent b746eca638
commit 67cce9b9f6
2 changed files with 13 additions and 1 deletions
+12 -1
View File
@@ -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 => {