import React, { useEffect } from "react"; import { FormattedMessage, useIntl } from "react-intl"; import BaseDialog from "../base-dialog"; import { useStyles } from './style'; import Alert from "@material-ui/lab/Alert"; import { fetchMapById } from "../../../../redux/clientSlice"; import FormControl from "@material-ui/core/FormControl"; import RadioGroup from "@material-ui/core/RadioGroup"; import FormControlLabel from "@material-ui/core/FormControlLabel"; import Radio from "@material-ui/core/Radio"; import Select from "@material-ui/core/Select"; import MenuItem from "@material-ui/core/MenuItem"; type ExportFormat = 'pdf' | 'svg' | 'jpg' | 'png' | 'txt' | 'mm' | 'wxml' | 'xls' | 'txt'; type ExportGroup = 'image' | 'document' | 'mindmap-tool'; type ExportDialogProps = { mapId: number, enableImgExport: boolean, svgXml?: string, onClose: () => void, } const ExportDialog = ({ mapId, onClose, enableImgExport, svgXml }: ExportDialogProps) => { const intl = useIntl(); 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 == "jpg" || 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-label", 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;