♻️ Fix hooks in the TabOverview component

This commit is contained in:
Philipp Stracker 2025-02-17 14:07:00 +01:00
parent b9785d1705
commit 180e47fa0a
No known key found for this signature in database

View file

@ -12,11 +12,12 @@ import {
import { Content, ContentWrapper } from '../../../ReusableComponents/Elements'; import { Content, ContentWrapper } from '../../../ReusableComponents/Elements';
import SettingsCard from '../../../ReusableComponents/SettingsCard'; import SettingsCard from '../../../ReusableComponents/SettingsCard';
import { TITLE_BADGE_POSITIVE } from '../../../ReusableComponents/TitleBadge'; import { TITLE_BADGE_POSITIVE } from '../../../ReusableComponents/TitleBadge';
import { useTodos } from '../../../../data/todos/hooks'; import {
import { useMerchantInfo } from '../../../../data/common/hooks'; CommonStoreName,
import { STORE_NAME as COMMON_STORE_NAME } from '../../../../data/common'; TodosStoreName,
import { STORE_NAME as TODOS_STORE_NAME } from '../../../../data/todos'; CommonHooks,
import { CommonHooks, TodosHooks } from '../../../../data'; TodosHooks,
} from '../../../../data';
import { getFeatures } from '../Components/Overview/features-config'; import { getFeatures } from '../Components/Overview/features-config';
@ -27,9 +28,13 @@ import {
import SpinnerOverlay from '../../../ReusableComponents/SpinnerOverlay'; import SpinnerOverlay from '../../../ReusableComponents/SpinnerOverlay';
const TabOverview = () => { const TabOverview = () => {
const { isReady: areTodosReady } = TodosHooks.useTodos(); const { isReady: areTodosReady } = TodosHooks.useStore();
const { isReady: merchantIsReady } = CommonHooks.useStore(); const { isReady: merchantIsReady } = CommonHooks.useStore();
// TODO: Workaround before we implement the standard "persistentData" resolver.
// Calling this hook ensures that todos are loaded from the REST API at this point.
const {} = TodosHooks.useTodos();
if ( ! areTodosReady || ! merchantIsReady ) { if ( ! areTodosReady || ! merchantIsReady ) {
return <SpinnerOverlay asModal={ true } />; return <SpinnerOverlay asModal={ true } />;
} }
@ -47,11 +52,12 @@ export default TabOverview;
const OverviewTodos = () => { const OverviewTodos = () => {
const [ isResetting, setIsResetting ] = useState( false ); const [ isResetting, setIsResetting ] = useState( false );
const { todos, isReady: areTodosReady, dismissTodo } = useTodos(); const { todos, dismissTodo } = TodosHooks.useTodos();
const { isReady: areTodosReady } = TodosHooks.useStore();
const { setActiveModal, setActiveHighlight } = const { setActiveModal, setActiveHighlight } =
useDispatch( COMMON_STORE_NAME ); useDispatch( CommonStoreName );
const { resetDismissedTodos, setDismissedTodos } = const { resetDismissedTodos, setDismissedTodos } =
useDispatch( TODOS_STORE_NAME ); useDispatch( TodosStoreName );
const { createSuccessNotice } = useDispatch( noticesStore ); const { createSuccessNotice } = useDispatch( noticesStore );
const showTodos = areTodosReady && todos.length > 0; const showTodos = areTodosReady && todos.length > 0;
@ -118,9 +124,10 @@ const OverviewTodos = () => {
const OverviewFeatures = () => { const OverviewFeatures = () => {
const [ isRefreshing, setIsRefreshing ] = useState( false ); const [ isRefreshing, setIsRefreshing ] = useState( false );
const { merchant, features: merchantFeatures } = useMerchantInfo(); const { merchant, features: merchantFeatures } =
CommonHooks.useMerchantInfo();
const { refreshFeatureStatuses, setActiveModal } = const { refreshFeatureStatuses, setActiveModal } =
useDispatch( COMMON_STORE_NAME ); useDispatch( CommonStoreName );
const { createSuccessNotice, createErrorNotice } = const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore ); useDispatch( noticesStore );