ui(admin): add user create and user update
This commit is contained in:
parent
1d290919b7
commit
27c93365e9
6 changed files with 299 additions and 7 deletions
|
@ -1,8 +1,31 @@
|
|||
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 { useHistory } from 'react-router-dom';
|
||||
import { Actions, useStoreActions } from 'easy-peasy';
|
||||
import { ApplicationStore } from '@/state';
|
||||
import { FormikHelpers } from 'formik';
|
||||
import createUser, { Values } from '@/api/admin/users/createUser';
|
||||
|
||||
export default () => {
|
||||
const history = useHistory();
|
||||
|
||||
const { clearFlashes, clearAndAddHttpError } = useStoreActions((actions: Actions<ApplicationStore>) => actions.flashes);
|
||||
|
||||
const submit = (values: Values, { setSubmitting }: FormikHelpers<Values>) => {
|
||||
clearFlashes('user:create');
|
||||
|
||||
createUser(values)
|
||||
.then(user => history.push(`/admin/users/${user.id}`))
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
clearAndAddHttpError({ key: 'user:create', error });
|
||||
})
|
||||
.then(() => setSubmitting(false));
|
||||
};
|
||||
|
||||
return (
|
||||
<AdminContentBlock title={'New User'}>
|
||||
<div css={tw`w-full flex flex-row items-center mb-8`}>
|
||||
|
@ -11,6 +34,10 @@ export default () => {
|
|||
<p css={tw`text-base text-neutral-400 whitespace-nowrap overflow-ellipsis overflow-hidden`}>Add a new user to the panel.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FlashMessageRender byKey={'user:create'} css={tw`mb-4`}/>
|
||||
|
||||
<InformationContainer title={'Create User'} onSubmit={submit}/>
|
||||
</AdminContentBlock>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue