diff --git a/resources/scripts/components/server/settings/RenameServerBox.tsx b/resources/scripts/components/server/settings/RenameServerBox.tsx index 5b1ed3181..83c0b2f6b 100644 --- a/resources/scripts/components/server/settings/RenameServerBox.tsx +++ b/resources/scripts/components/server/settings/RenameServerBox.tsx @@ -1,66 +1,69 @@ 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 { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; +import { Actions, useStoreActions } 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; -} +import { ApplicationStore } from '@/state'; +import { httpErrorToHuman } from '@/api/http'; interface Values { name: string; } -const RenameServerBox = ({ isSubmitting, ...props }: OwnProps & FormikProps) => ( - - -
- -
- -
- -
-); +const RenameServerBox = () => { + const { isSubmitting } = useFormikContext(); -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); + return ( + + +
+ +
+ +
+ +
+ ); +}; export default () => { const server = ServerContext.useStoreState(state => state.server.data!); const setServer = ServerContext.useStoreActions(actions => actions.server.setServer); + const { addError, clearFlashes } = useStoreActions((actions: Actions) => actions.flashes); - return ; + const submit = ({ name }: Values, { setSubmitting }: FormikHelpers) => { + clearFlashes('settings'); + renameServer(server.uuid, name) + .then(() => setServer({ ...server, name })) + .catch(error => { + console.error(error); + addError({ key: 'settings', message: httpErrorToHuman(error) }); + }) + .then(() => setSubmitting(false)); + }; + + return ( + + + + ); }; diff --git a/resources/scripts/components/server/settings/SettingsContainer.tsx b/resources/scripts/components/server/settings/SettingsContainer.tsx index 104de803f..d487bfc8f 100644 --- a/resources/scripts/components/server/settings/SettingsContainer.tsx +++ b/resources/scripts/components/server/settings/SettingsContainer.tsx @@ -5,52 +5,56 @@ import { useStoreState } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import { UserData } from '@/state/user'; import RenameServerBox from '@/components/server/settings/RenameServerBox'; +import FlashMessageRender from '@/components/FlashMessageRender'; export default () => { const user = useStoreState(state => state.user.data!); const server = ServerContext.useStoreState(state => state.server.data!); return ( -
- -
- - -
-
- - -
-
-
-
-

- Your SFTP password is the same as the password you use to access this panel. -

+
+ +
+ +
+ + +
+
+ + +
+
+
+
+

+ Your SFTP password is the same as the password you use to access this panel. +

+
+
+
- +
+
+
- -
-
);