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

Create server backup

); }; export default () => { const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const { clearFlashes, clearAndAddHttpError } = useFlash(); const [ visible, setVisible ] = useState(false); const { mutate } = getServerBackups(); useEffect(() => { clearFlashes('backups:create'); }, [ visible ]); const submit = (values: Values, { setSubmitting }: FormikHelpers) => { clearFlashes('backups:create'); createServerBackup(uuid, values) .then(async (backup) => { await mutate(data => ({ ...data!, items: data!.items.concat(backup), backupCount: data!.backupCount + 1 }), false); setVisible(false); }) .catch(error => { clearAndAddHttpError({ key: 'backups:create', error }); setSubmitting(false); }); }; return ( <> {visible && setVisible(false)}/> } ); };