import React, { useEffect } from "react"; import { FormattedMessage, useIntl } from "react-intl"; import { fetchMapById } from ".."; import BaseDialog from "../base-dialog"; import { FormControl, FormControlLabel, MenuItem, Radio, RadioGroup, Select } from "@material-ui/core"; import { useStyles } from './style'; import { Alert } from "@material-ui/lab"; type ExportFormat = 'pdf' | 'svg' | 'jpeg' | 'png' | 'txt' | 'mm' | 'wxml' | 'xls' | 'txt'; type ExportGroup = 'image' | 'document' | 'mindmap-tool'; type ExportDialogProps = { mapId: number, enableImgExport: boolean, svgXml?: string, onClose: () => void, } const ExportDialog = (props: ExportDialogProps) => { const intl = useIntl(); const { mapId, onClose, enableImgExport, svgXml } = props; const [submit, setSubmit] = React.useState(false); const [formExportRef, setExportFormRef] = React.useState(); const [formTransformtRef, setTransformFormRef] = React.useState(); const [exportGroup, setExportGroup] = React.useState(enableImgExport ? 'image' : 'document'); const [exportFormat, setExportFormat] = React.useState(enableImgExport ? 'svg' : 'xls'); const classes = useStyles(); const handleOnExportFormatChange = (event) => { setExportFormat(event.target.value); }; const handleOnGroupChange = (event) => { const value: ExportGroup = event.target.value; setExportGroup(value); let defaultFormat: ExportFormat; switch (value) { case 'document': defaultFormat = 'pdf'; break; case 'image': defaultFormat = 'svg'; break; case 'mindmap-tool': defaultFormat = 'wxml'; break; } setExportFormat(defaultFormat); } const handleOnClose = (): void => { onClose(); }; const handleOnSubmit = (): void => { setSubmit(true); } useEffect(() => { if (submit) { // Depending on the type of export. It will require differt POST. if (exportFormat == 'pdf' || exportFormat == "svg" || exportFormat == "jpeg" || exportFormat == "png") { formTransformtRef.submit(); } else { formExportRef.submit(); } onClose(); } }, [submit]); const { map } = fetchMapById(mapId); return (
} label={intl.formatMessage({ id: "export.image", defaultMessage: "Image: Get a graphic representation of your map including all colors and shapes." })} color="secondary" style={{ fontSize: '9px' }} /> {(exportGroup == 'image') && () } } label={intl.formatMessage({ id: "export.document", defaultMessage: "Document: Export your mindmap in a self-contained document ready to share" })} color="secondary" /> {exportGroup == 'document' && () } } label={intl.formatMessage({ id: "export.document", defaultMessage: "Mindmap Tools: Export your mindmap in thirdparty mindmap tool formats" })} color="secondary" /> {exportGroup == 'mindmap-tool' && () } {/* Hidden form for the purpose of summit */}
); } export default ExportDialog;