diff --git a/resources/scripts/components/admin/users/NewUserContainer.tsx b/resources/scripts/components/admin/users/NewUserContainer.tsx index a28449f57..428e4f985 100644 --- a/resources/scripts/components/admin/users/NewUserContainer.tsx +++ b/resources/scripts/components/admin/users/NewUserContainer.tsx @@ -2,7 +2,7 @@ import React from 'react'; import tw from 'twin.macro'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import FlashMessageRender from '@/components/FlashMessageRender'; -import { InformationContainer } from '@/components/admin/users/UserEditContainer'; +import UserForm from '@/components/admin/users/UserForm'; import { useHistory } from 'react-router-dom'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; @@ -37,7 +37,7 @@ export default () => { - + ); }; diff --git a/resources/scripts/components/admin/users/UserAboutContainer.tsx b/resources/scripts/components/admin/users/UserAboutContainer.tsx index e69de29bb..bae96aaac 100644 --- a/resources/scripts/components/admin/users/UserAboutContainer.tsx +++ b/resources/scripts/components/admin/users/UserAboutContainer.tsx @@ -0,0 +1,61 @@ +import updateUser, { Values } from '@/api/admin/users/updateUser'; +import UserDeleteButton from '@/components/admin/users/UserDeleteButton'; +import UserForm from '@/components/admin/users/UserForm'; +import { Context } from '@/components/admin/users/UserRouter'; +import { ApplicationStore } from '@/state'; +import { Actions, useStoreActions } from 'easy-peasy'; +import { FormikHelpers } from 'formik'; +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import tw from 'twin.macro'; + +const UserAboutContainer = () => { + const history = useHistory(); + + const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); + + const user = Context.useStoreState(state => state.user); + const setUser = Context.useStoreActions(actions => actions.setUser); + + if (user === undefined) { + return ( + <> + ); + } + + const submit = (values: Values, { setSubmitting }: FormikHelpers) => { + clearFlashes('user'); + + updateUser(user.id, values) + .then(() => setUser({ ...user, ...values })) + .catch(error => { + console.error(error); + clearAndAddHttpError({ key: 'user', error }); + }) + .then(() => setSubmitting(false)); + }; + + return ( + +
+ history.push('/admin/users')} + /> +
+
+ ); +}; + +export default UserAboutContainer; diff --git a/resources/scripts/components/admin/users/UserEditContainer.tsx b/resources/scripts/components/admin/users/UserForm.tsx similarity index 52% rename from resources/scripts/components/admin/users/UserEditContainer.tsx rename to resources/scripts/components/admin/users/UserForm.tsx index 0a893d1d7..1f17b2b5d 100644 --- a/resources/scripts/components/admin/users/UserEditContainer.tsx +++ b/resources/scripts/components/admin/users/UserForm.tsx @@ -1,23 +1,16 @@ -import React, { useEffect, useState } from 'react'; +import React from 'react'; import tw from 'twin.macro'; -import { useHistory, useRouteMatch } from 'react-router-dom'; -import { action, Action, Actions, createContextStore, useStoreActions } from 'easy-peasy'; +import { action, Action, createContextStore } from 'easy-peasy'; import { User } from '@/api/admin/users/getUsers'; -import getUser from '@/api/admin/users/getUser'; -import AdminContentBlock from '@/components/admin/AdminContentBlock'; -import Spinner from '@/components/elements/Spinner'; -import FlashMessageRender from '@/components/FlashMessageRender'; -import { ApplicationStore } from '@/state'; import AdminBox from '@/components/admin/AdminBox'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import { Form, Formik, FormikHelpers } from 'formik'; import { object, string } from 'yup'; import { Role } from '@/api/admin/roles/getRoles'; -import updateUser, { Values } from '@/api/admin/users/updateUser'; +import { Values } from '@/api/admin/users/updateUser'; import Button from '@/components/elements/Button'; import Field from '@/components/elements/Field'; import RoleSelect from '@/components/admin/users/RoleSelect'; -import UserDeleteButton from '@/components/admin/users/UserDeleteButton'; interface ctx { user: User | undefined; @@ -43,7 +36,7 @@ export interface Params { role: Role | null; } -export function InformationContainer ({ title, initialValues, children, onSubmit, exists, role }: Params) { +export default function UserForm ({ title, initialValues, children, onSubmit, exists, role }: Params) { const submit = (values: Values, helpers: FormikHelpers) => { onSubmit(values, helpers); }; @@ -127,109 +120,3 @@ export function InformationContainer ({ title, initialValues, children, onSubmit ); } - -function EditInformationContainer () { - const history = useHistory(); - - const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); - - const user = Context.useStoreState(state => state.user); - const setUser = Context.useStoreActions(actions => actions.setUser); - - if (user === undefined) { - return ( - <> - ); - } - - const submit = (values: Values, { setSubmitting }: FormikHelpers) => { - clearFlashes('user'); - - updateUser(user.id, values) - .then(() => setUser({ ...user, ...values })) - .catch(error => { - console.error(error); - clearAndAddHttpError({ key: 'user', error }); - }) - .then(() => setSubmitting(false)); - }; - - return ( - -
- history.push('/admin/users')} - /> -
-
- ); -} - -function UserEditContainer () { - const match = useRouteMatch<{ id?: string }>(); - - const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); - const [ loading, setLoading ] = useState(true); - - const user = Context.useStoreState(state => state.user); - const setUser = Context.useStoreActions(actions => actions.setUser); - - useEffect(() => { - clearFlashes('user'); - - getUser(Number(match.params?.id), [ 'role' ]) - .then(user => setUser(user)) - .catch(error => { - console.error(error); - clearAndAddHttpError({ key: 'user', error }); - }) - .then(() => setLoading(false)); - }, []); - - if (loading || user === undefined) { - return ( - - - -
- -
-
- ); - } - - return ( - -
-
-

{user.email}

-

{user.uuid}

-
-
- - - - -
- ); -} - -export default () => { - return ( - - - - ); -}; diff --git a/resources/scripts/components/admin/users/UserRouter.tsx b/resources/scripts/components/admin/users/UserRouter.tsx index af04b56ec..d81c04331 100644 --- a/resources/scripts/components/admin/users/UserRouter.tsx +++ b/resources/scripts/components/admin/users/UserRouter.tsx @@ -1,3 +1,4 @@ +import UserAboutContainer from '@/components/admin/users/UserAboutContainer'; import React, { useEffect, useState } from 'react'; import { useLocation } from 'react-router'; import tw from 'twin.macro'; @@ -38,7 +39,7 @@ const UserRouter = () => { useEffect(() => { clearFlashes('user'); - getUser(Number(match.params?.id), [ 'database_host', 'location' ]) + getUser(Number(match.params?.id), [ 'role' ]) .then(user => setUser(user)) .catch(error => { console.error(error); @@ -86,7 +87,7 @@ const UserRouter = () => { -

About

+
diff --git a/resources/scripts/components/admin/users/UserServers.tsx b/resources/scripts/components/admin/users/UserServers.tsx index 6bf8afabb..2b294e621 100644 --- a/resources/scripts/components/admin/users/UserServers.tsx +++ b/resources/scripts/components/admin/users/UserServers.tsx @@ -6,7 +6,7 @@ function UserServers () { const user = Context.useStoreState(state => state.user); return ( - + ); }