From 4854d286d6f750267cd008d25f1ea60f0f9f40ae Mon Sep 17 00:00:00 2001 From: Andra Constantin Date: Mon, 11 Nov 2024 18:10:26 -0500 Subject: [PATCH] set disabled button with tooltip when empty frontier --- src/components/ProjectExport/ExportButton.tsx | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/components/ProjectExport/ExportButton.tsx b/src/components/ProjectExport/ExportButton.tsx index 30e696c9a9..fe3d9c60f1 100644 --- a/src/components/ProjectExport/ExportButton.tsx +++ b/src/components/ProjectExport/ExportButton.tsx @@ -1,6 +1,7 @@ +import { Tooltip } from "@mui/material"; import { ButtonProps } from "@mui/material/Button"; import { enqueueSnackbar } from "notistack"; -import { ReactElement } from "react"; +import { ReactElement, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { isFrontierNonempty } from "backend"; @@ -13,11 +14,13 @@ import { type StoreState } from "rootRedux/types"; interface ExportButtonProps { projectId: string; buttonProps?: ButtonProps & { "data-testid"?: string }; + disabled?: boolean; } /** A button for exporting project to Lift file */ export default function ExportButton(props: ExportButtonProps): ReactElement { const dispatch = useAppDispatch(); + const [exports, setExports] = useState(false); const { t } = useTranslation(); async function exportProj(): Promise { @@ -38,17 +41,33 @@ export default function ExportButton(props: ExportButtonProps): ReactElement { exportResult.status === ExportStatus.Success || exportResult.status === ExportStatus.Downloading; + useEffect(() => { + const fetchNonempty = async (): Promise => { + await isFrontierNonempty(props.projectId).then(async (isNonempty) => { + if (isNonempty) { + setExports(true); + } + }); + }; + fetchNonempty().catch(console.error); + }); + return ( - - {t("buttons.export")} - + + + + {t("buttons.export")} + + + ); }