import { useEffect, useState } from "react"; import { Button, InlineLoading, InlineNotification } from "@carbon/react"; import { api } from "../lib/api"; import type { InvoiceExport } from "../hooks/useInvoiceExport"; import FlattenProgressModal from "./FlattenProgressModal"; /** Progress modal, spinner, success and error notices for one `useInvoiceExport`. */ export default function ExportFeedback({ exp }: { exp: InvoiceExport }) { const { busy, progress, request, error, result } = exp; const [actionError, setActionError] = useState(null); useEffect(() => setActionError(null), [result]); const flattenFailed = request?.mode === "flattened" && error?.flatten === true; const modalOpen = request?.mode === "flattened" && ((busy && progress?.phase !== "saving") || flattenFailed); const run = async (action: () => Promise) => { setActionError(null); try { await action(); } catch (e) { setActionError(String(e)); } }; return ( <> {busy && !modalOpen ? : null} {error && !flattenFailed ? (
) : null} {result ? ( <>
{result.identicalToIssued === false ? ( ) : null} {result.archiveError ? ( ) : null} {actionError ? setActionError(null)} /> : null} ) : null} ); }