1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-10 01:16:39 +02:00
unleash.unleash/frontend/src/page/admin/users/del-user-component.jsx
Fredrik Strand Oseberg 0ca753e7e5 Feat/add new user (#273)
* chore: update changelog

* chore: update changelog

* fix: refactor AddUser

* feat: add screens for email and copy

* fix: remove interface

* fix: admin constant in userlist

* chore: fix changelog

* feat: user data fetching with useSWR

* feat: flesh out dialogues

* fix: remove useRequest

* refactor: remove redux for user admin

* refactor: remove from store

* refactor: userListItem

* fix: change type

* feat: add initial loading

* fix: useLayoutEffeect in useLoading

* fix: remove useEffect

* fix: update snapshots

* fix: remove status code

* fix: remove roles from store
2021-04-23 10:59:11 +02:00

86 lines
2.8 KiB
JavaScript

import React from 'react';
import Dialogue from '../../../component/common/Dialogue/Dialogue';
import ConditionallyRender from '../../../component/common/ConditionallyRender/ConditionallyRender';
import propTypes from 'prop-types';
import { REMOVE_USER_ERROR } from '../../../hooks/useAdminUsersApi';
import { Alert } from '@material-ui/lab';
import useLoading from '../../../hooks/useLoading';
import { Avatar, Typography } from '@material-ui/core';
import { useCommonStyles } from '../../../common.styles';
const DelUserComponent = ({
showDialog,
closeDialog,
user,
userLoading,
removeUser,
userApiErrors,
}) => {
const ref = useLoading(userLoading);
const commonStyles = useCommonStyles();
return (
<Dialogue
open={showDialog}
title="Really delete user?"
onClose={closeDialog}
onClick={() => removeUser(user)}
primaryButtonText="Delete user"
secondaryButtonText="Cancel"
>
<div ref={ref}>
<ConditionallyRender
condition={userApiErrors[REMOVE_USER_ERROR]}
show={
<Alert
data-loading
severity="error"
style={{ margin: '1rem 0' }}
>
{userApiErrors[REMOVE_USER_ERROR]}
</Alert>
}
/>
<div data-loading className={commonStyles.flexRow}>
<Avatar
variant="rounded"
alt={user.name}
src={user.imageUrl}
title={`${
user.name || user.email || user.username
} (id: ${user.id})`}
/>
<Typography
variant="subtitle1"
style={{ marginLeft: '1rem' }}
>
{user.username || user.email}
</Typography>
</div>
<Typography
data-loading
variant="body1"
style={{ marginTop: '1rem' }}
>
Are you sure you want to delete{' '}
{user
? `${user.name || 'user'} (${
user.email || user.username
})`
: ''}
?
</Typography>
</div>
</Dialogue>
);
};
DelUserComponent.propTypes = {
showDialog: propTypes.bool.isRequired,
closeDialog: propTypes.func.isRequired,
user: propTypes.object.isRequired,
removeUser: propTypes.func.isRequired,
};
export default DelUserComponent;