2020-03-27 22:32:33 +00:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { Subuser } from '@/state/server/subusers';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2020-07-05 01:46:09 +00:00
|
|
|
import { faPencilAlt, faUnlockAlt, faUserLock } from '@fortawesome/free-solid-svg-icons';
|
2020-03-27 22:32:33 +00:00
|
|
|
import RemoveSubuserButton from '@/components/server/users/RemoveSubuserButton';
|
2020-03-27 22:40:24 +00:00
|
|
|
import EditSubuserModal from '@/components/server/users/EditSubuserModal';
|
2020-03-29 21:19:17 +00:00
|
|
|
import Can from '@/components/elements/Can';
|
2020-04-19 18:58:26 +00:00
|
|
|
import { useStoreState } from 'easy-peasy';
|
2020-07-04 23:26:07 +00:00
|
|
|
import tw from 'twin.macro';
|
|
|
|
import GreyRowBox from '@/components/elements/GreyRowBox';
|
2020-03-27 22:32:33 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
subuser: Subuser;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ({ subuser }: Props) => {
|
2020-04-19 18:58:26 +00:00
|
|
|
const uuid = useStoreState(state => state.user!.data!.uuid);
|
2020-03-27 22:40:24 +00:00
|
|
|
const [ visible, setVisible ] = useState(false);
|
2020-03-27 22:32:33 +00:00
|
|
|
|
|
|
|
return (
|
2020-07-04 23:26:07 +00:00
|
|
|
<GreyRowBox css={tw`mb-2`}>
|
2020-03-27 22:40:24 +00:00
|
|
|
{visible &&
|
|
|
|
<EditSubuserModal
|
2020-07-04 23:26:07 +00:00
|
|
|
appear
|
|
|
|
visible
|
2020-03-27 22:40:24 +00:00
|
|
|
subuser={subuser}
|
|
|
|
onDismissed={() => setVisible(false)}
|
|
|
|
/>
|
|
|
|
}
|
2020-09-13 17:02:25 +00:00
|
|
|
<div css={tw`w-10 h-10 rounded-full bg-white border-2 border-neutral-800 overflow-hidden hidden md:block`}>
|
2020-07-04 23:26:07 +00:00
|
|
|
<img css={tw`w-full h-full`} src={`${subuser.image}?s=400`}/>
|
2020-03-27 22:32:33 +00:00
|
|
|
</div>
|
2020-07-04 23:26:07 +00:00
|
|
|
<div css={tw`ml-4 flex-1`}>
|
2020-09-23 02:37:41 +00:00
|
|
|
<p css={tw`text-sm break-all`}>{subuser.email}</p>
|
2020-03-27 22:32:33 +00:00
|
|
|
</div>
|
2020-07-04 23:26:07 +00:00
|
|
|
<div css={tw`ml-4`}>
|
|
|
|
<p css={tw`font-medium text-center`}>
|
2020-03-27 23:42:27 +00:00
|
|
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={subuser.twoFactorEnabled ? faUserLock : faUnlockAlt}
|
2020-07-05 02:01:49 +00:00
|
|
|
fixedWidth
|
|
|
|
css={!subuser.twoFactorEnabled ? tw`text-red-400` : undefined}
|
2020-03-27 23:42:27 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
</p>
|
2020-09-13 17:02:25 +00:00
|
|
|
<p css={tw`text-2xs text-neutral-500 uppercase hidden md:block`}>2FA Enabled</p>
|
2020-03-27 23:42:27 +00:00
|
|
|
</div>
|
2020-09-13 17:02:25 +00:00
|
|
|
<div css={tw`ml-4 hidden md:block`}>
|
2020-07-04 23:26:07 +00:00
|
|
|
<p css={tw`font-medium text-center`}>
|
2020-04-17 17:21:15 +00:00
|
|
|
{subuser.permissions.filter(permission => permission !== 'websocket.connect').length}
|
2020-03-27 23:42:27 +00:00
|
|
|
</p>
|
2020-07-04 23:26:07 +00:00
|
|
|
<p css={tw`text-2xs text-neutral-500 uppercase`}>Permissions</p>
|
2020-03-27 23:42:27 +00:00
|
|
|
</div>
|
2020-08-02 04:25:28 +00:00
|
|
|
<Can action={'user.update'}>
|
|
|
|
{subuser.uuid !== uuid &&
|
|
|
|
<button
|
|
|
|
type={'button'}
|
|
|
|
aria-label={'Edit subuser'}
|
2020-09-13 17:02:25 +00:00
|
|
|
css={tw`block text-sm p-1 md:p-2 text-neutral-500 hover:text-neutral-100 transition-colors duration-150 mx-4`}
|
2020-08-02 04:25:28 +00:00
|
|
|
onClick={() => setVisible(true)}
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon icon={faPencilAlt}/>
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
</Can>
|
2020-03-29 21:19:17 +00:00
|
|
|
<Can action={'user.delete'}>
|
|
|
|
<RemoveSubuserButton subuser={subuser}/>
|
|
|
|
</Can>
|
2020-07-04 23:26:07 +00:00
|
|
|
</GreyRowBox>
|
2020-03-27 22:32:33 +00:00
|
|
|
);
|
|
|
|
};
|