misc_pterodactyl-panel/resources/scripts/components/admin/users/UserAboutContainer.tsx

64 lines
2 KiB
TypeScript
Raw Normal View History

2022-02-27 20:26:26 +00:00
import { updateUser, UpdateUserValues } from '@/api/admin/users';
2021-09-12 23:00:22 +00:00
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<ApplicationStore>) => actions.flashes);
const user = Context.useStoreState(state => state.user);
const setUser = Context.useStoreActions(actions => actions.setUser);
if (user === undefined) {
return (
<></>
);
}
2022-02-27 20:26:26 +00:00
const submit = (values: UpdateUserValues, { setSubmitting }: FormikHelpers<UpdateUserValues>) => {
2021-09-12 23:00:22 +00:00
clearFlashes('user');
updateUser(user.id, values)
.then(() => setUser({ ...user, ...values }))
.catch(error => {
console.error(error);
clearAndAddHttpError({ key: 'user', error });
})
.then(() => setSubmitting(false));
};
return (
<UserForm
title={'Edit User'}
initialValues={{
externalId: user.externalId,
2021-09-12 23:00:22 +00:00
username: user.username,
email: user.email,
adminRoleId: user.adminRoleId,
password: '',
2022-02-27 20:26:26 +00:00
rootAdmin: user.isRootAdmin,
2021-09-12 23:00:22 +00:00
}}
onSubmit={submit}
uuid={user.uuid}
role={user.relationships.role || null}
2021-09-12 23:00:22 +00:00
>
<div css={tw`flex`}>
<UserDeleteButton
userId={user.id}
onDeleted={() => history.push('/admin/users')}
/>
</div>
</UserForm>
);
};
export default UserAboutContainer;