/
EditUserWithData.tsx
55 lines (47 loc) · 1.44 KB
/
EditUserWithData.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { isUserFederated, IUser } from '@rocket.chat/core-typings';
import { Box, Callout } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React, { useMemo, ReactElement } from 'react';
import { FormSkeleton } from '../../../components/Skeleton';
import { AsyncStatePhase } from '../../../hooks/useAsyncState';
import { useEndpointData } from '../../../hooks/useEndpointData';
import EditUser from './EditUser';
type EditUserWithDataProps = {
uid: IUser['_id'];
onReload: () => void;
};
const EditUserWithData = ({ uid, onReload, ...props }: EditUserWithDataProps): ReactElement => {
const t = useTranslation();
const { value: roleData, phase: roleState, error: roleError } = useEndpointData('/v1/roles.list');
const {
value: data,
phase: state,
error,
} = useEndpointData(
'/v1/users.info',
useMemo(() => ({ userId: uid }), [uid]),
);
if ([state, roleState].includes(AsyncStatePhase.LOADING)) {
return (
<Box p='x24'>
<FormSkeleton />
</Box>
);
}
if (error || roleError) {
return (
<Callout m='x16' type='danger'>
{t('User_not_found')}
</Callout>
);
}
if (data?.user && isUserFederated(data?.user as unknown as IUser)) {
return (
<Callout m='x16' type='danger'>
{t('Edit_Federated_User_Not_Allowed')}
</Callout>
);
}
return <EditUser data={data?.user} roles={roleData?.roles} onReload={onReload} {...props} />;
};
export default EditUserWithData;