import GenericFallback from "../GenericFallback/index.jsx"; import Fallback from "../Fallback/index.jsx"; import { Typography } from "@mui/material"; import { useTheme } from "@emotion/react"; import { useTranslation } from "react-i18next"; import { useIsAdmin } from "@/Hooks/useIsAdmin.js"; import PropTypes from "prop-types"; const PageStateWrapper = ({ networkError, isLoading, items, type, fallbackLink, fallbackChildren, children, }) => { const theme = useTheme(); const { t } = useTranslation(); const isAdmin = useIsAdmin(); const isEmpty = items === null || (Array.isArray(items) && items.length === 0); const hasInitialized = items !== undefined && !(isLoading && isEmpty); const showEmpty = !isLoading && isEmpty; if (networkError) { return ( {t("common.toasts.networkError")} {t("common.toasts.checkConnection")} ); } if (!hasInitialized) { return null; } if (showEmpty) { return ( {fallbackChildren} ); } return <>{children}; }; PageStateWrapper.propTypes = { networkError: PropTypes.any, isLoading: PropTypes.bool, items: PropTypes.oneOfType([PropTypes.array, PropTypes.oneOf([null])]), type: PropTypes.string, fallbackLink: PropTypes.string, fallbackChildren: PropTypes.node, children: PropTypes.node, }; export default PageStateWrapper;