From 08546e6076381e965d0dd13cb908ea0eb6ddcec7 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Sat, 6 Mar 2021 16:57:13 -0700 Subject: [PATCH] ui(admin): implement NewDatabaseContainer.tsx --- .../admin/databases/DatabaseEditContainer.tsx | 109 ++++++++++++------ .../admin/databases/NewDatabaseContainer.tsx | 27 +++++ .../nodes/NodeConfigurationContainer.tsx | 2 +- 3 files changed, 99 insertions(+), 39 deletions(-) diff --git a/resources/scripts/components/admin/databases/DatabaseEditContainer.tsx b/resources/scripts/components/admin/databases/DatabaseEditContainer.tsx index c20a2a1a8..d99365e1d 100644 --- a/resources/scripts/components/admin/databases/DatabaseEditContainer.tsx +++ b/resources/scripts/components/admin/databases/DatabaseEditContainer.tsx @@ -30,7 +30,7 @@ export const Context = createContextStore({ }), }); -interface Values { +export interface Values { name: string; host: string; port: number; @@ -38,42 +38,33 @@ interface Values { password: string; } -const EditInformationContainer = () => { - const history = useHistory(); +export interface Params { + title: string; + initialValues?: Values; + children?: React.ReactNode; - const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); + onSubmit: (values: Values, helpers: FormikHelpers) => void; +} - const database = Context.useStoreState(state => state.database); - const setDatabase = Context.useStoreActions(actions => actions.setDatabase); - - if (database === undefined) { - return ( - <> - ); - } - - const submit = ({ name, host, port, username, password }: Values, { setSubmitting }: FormikHelpers) => { - clearFlashes('database'); - - updateDatabase(database.id, name, host, port, username, password || undefined) - .then(() => setDatabase({ ...database, name, host, port, username })) - .catch(error => { - console.error(error); - clearAndAddHttpError({ key: 'database', error }); - }) - .then(() => setSubmitting(false)); +export const InformationContainer = ({ title, initialValues, children, onSubmit }: Params) => { + const submit = (values: Values, helpers: FormikHelpers) => { + onSubmit(values, helpers); }; + if (!initialValues) { + initialValues = { + name: '', + host: '', + port: 3306, + username: '', + password: '', + }; + } + return ( { { ({ isSubmitting, isValid }) => ( - +
@@ -140,13 +131,7 @@ const EditInformationContainer = () => {
-
- history.push('/admin/databases')} - /> -
- + {children}
+ + + + ); }; diff --git a/resources/scripts/components/admin/nodes/NodeConfigurationContainer.tsx b/resources/scripts/components/admin/nodes/NodeConfigurationContainer.tsx index 86e6669ac..732c1571e 100644 --- a/resources/scripts/components/admin/nodes/NodeConfigurationContainer.tsx +++ b/resources/scripts/components/admin/nodes/NodeConfigurationContainer.tsx @@ -35,7 +35,7 @@ export default () => {
- +