import React from 'react'; import { ServerContext } from '@/state/server'; import TitledGreyBox from '@/components/elements/TitledGreyBox'; import { Form, FormikProps, withFormik } from 'formik'; import { Server } from '@/api/server/getServer'; import { ActionCreator } from 'easy-peasy'; import renameServer from '@/api/server/renameServer'; import Field from '@/components/elements/Field'; import { object, string } from 'yup'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; interface OwnProps { server: Server; setServer: ActionCreator; } interface Values { name: string; } const RenameServerBox = ({ isSubmitting, ...props }: OwnProps & FormikProps) => (
); const EnhancedForm = withFormik({ displayName: 'RenameServerBoxForm', mapPropsToValues: props => ({ name: props.server.name, }), validationSchema: () => object().shape({ name: string().required().min(1), }), handleSubmit: (values, { props, setSubmitting }) => { renameServer(props.server.uuid, values.name) .then(() => props.setServer({ ...props.server, name: values.name })) .catch(error => { console.error(error); }) .then(() => setSubmitting(false)); }, })(RenameServerBox); export default () => { const server = ServerContext.useStoreState(state => state.server.data!); const setServer = ServerContext.useStoreActions(actions => actions.server.setServer); return ; };