import React, { useEffect, useState } from 'react'; import Modal, { RequiredModalProps } from '@/components/elements/Modal'; import { Field as FormikField, Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import { object, string } from 'yup'; import Field from '@/components/elements/Field'; import FormikFieldWrapper from '@/components/elements/FormikFieldWrapper'; import useFlash from '@/plugins/useFlash'; import useServer from '@/plugins/useServer'; import createServerBackup from '@/api/server/backups/createServerBackup'; import { httpErrorToHuman } from '@/api/http'; import FlashMessageRender from '@/components/FlashMessageRender'; import { ServerContext } from '@/state/server'; import Button from '@/components/elements/Button'; import tw from 'twin.macro'; import Input, { Textarea } from '@/components/elements/Input'; interface Values { name: string; ignored: string; } const ModalContent = ({ ...props }: RequiredModalProps) => { const { isSubmitting } = useFormikContext(); return (

Create server backup

); }; export default () => { const { uuid } = useServer(); const { addError, clearFlashes } = useFlash(); const [ visible, setVisible ] = useState(false); const appendBackup = ServerContext.useStoreActions(actions => actions.backups.appendBackup); useEffect(() => { clearFlashes('backups:create'); }, [ visible ]); const submit = ({ name, ignored }: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('backups:create'); createServerBackup(uuid, name, ignored) .then(backup => { appendBackup(backup); setVisible(false); }) .catch(error => { console.error(error); addError({ key: 'backups:create', message: httpErrorToHuman(error) }); setSubmitting(false); }); }; return ( <> {visible && setVisible(false)} /> } ); };