import { GlobalToastGeneratorEntry } from '@/features/ide-react/components/global-toasts' import { Trans, useTranslation } from 'react-i18next' const PreparingExportToast = () => { const { t } = useTranslation() return {t('preparing_for_export')} } const ExportDocumentErrorToast = ({ data }: { data?: any }) => { const { t } = useTranslation() const errorMessage = typeof data?.errorMessage === 'string' ? data.errorMessage : null return ( <>

{t('we_couldnt_export_this_document')}

, ]} /> {errorMessage && (
{t('conversion_error_details')}
            {errorMessage}
          
)} ) } const ExportDocumentSuccessToast = ({ data }: { data?: any }) => { const type = data?.type if (type === 'docx') { return ( , ]} /> ) } else if (type === 'markdown') { return ( , ]} /> ) } else if (type === 'html') { return ( , ]} /> ) } else { return ( , ]} /> ) } } const generators: GlobalToastGeneratorEntry[] = [ { key: 'export-document:error', generator: (data: any) => ({ content: , type: 'error', // Only auto-hide if we have no extra details autoHide: !data?.errorMessage, delay: 5000, isDismissible: true, }), }, { key: 'export-document:preparing', generator: () => ({ content: , type: 'info', autoHide: false, isDismissible: true, }), }, { key: 'export-document:success', generator: (data: any) => ({ content: , type: 'success', autoHide: true, delay: 45000, isDismissible: true, }), }, ] export default generators // We only ever care about the latest error toast, so use a static handle. const EXPORT_DOCUMENT_ERROR_HANDLE = 'export-document-error' export const showExportDocumentError = (errorMessage?: string) => { window.dispatchEvent( new CustomEvent('ide:show-toast', { detail: { key: 'export-document:error', handle: EXPORT_DOCUMENT_ERROR_HANDLE, errorMessage, }, }) ) } export const hideExportDocumentError = () => { window.dispatchEvent( new CustomEvent('ide:dismiss-toast', { detail: { handle: EXPORT_DOCUMENT_ERROR_HANDLE }, }) ) } export const showPreparingExportToast = () => { const handle = `export-document-preparing-${Date.now()}` window.dispatchEvent( new CustomEvent('ide:show-toast', { detail: { key: 'export-document:preparing', handle }, }) ) return handle } export const hidePreparingExportToast = (handle: string) => { window.dispatchEvent( new CustomEvent('ide:dismiss-toast', { detail: { key: 'export-document:preparing', handle }, }) ) } export const showExportDocumentSuccess = ( type: 'docx' | 'markdown' | 'html' ) => { window.dispatchEvent( new CustomEvent('ide:show-toast', { detail: { key: 'export-document:success', type }, }) ) }