import exportFromJSON from 'export-from-json'; import { useEffect, useState } from 'react'; import { useRecoilValue } from 'recoil'; import { Dialog, DialogButton, DialogTemplate } from '~/components'; import SaveAsPresetDialog from './SaveAsPresetDialog'; import cleanupPreset from '~/utils/cleanupPreset'; import { alternateName } from '~/utils'; import Settings from './Settings'; import store from '~/store'; import { localize } from '~/localization/Translation'; // A preset dialog to show readonly preset values. const EndpointOptionsDialog = ({ open, onOpenChange, preset: _preset, title }) => { const [preset, setPreset] = useState(_preset); const [saveAsDialogShow, setSaveAsDialogShow] = useState(false); const endpointsConfig = useRecoilValue(store.endpointsConfig); const endpointName = alternateName[preset?.endpoint] ?? 'Endpoint'; const lang = useRecoilValue(store.lang); const setOption = (param) => (newValue) => { let update = {}; update[param] = newValue; setPreset((prevState) => ({ ...prevState, ...update, })); }; const saveAsPreset = () => { setSaveAsDialogShow(true); }; const exportPreset = () => { exportFromJSON({ data: cleanupPreset({ preset, endpointsConfig }), fileName: `${preset?.title}.json`, exportType: exportFromJSON.types.json, }); }; useEffect(() => { setPreset(_preset); // eslint-disable-next-line react-hooks/exhaustive-deps }, [open]); return ( <>
} buttons={ <> {localize(lang, 'com_endpoint_save_as_preset')} } leftButtons={ <> {localize(lang, 'com_endpoint_export')} } />
); }; export default EndpointOptionsDialog;