2023-06-30 04:30:20 -04:00
|
|
|
import moment from 'moment'
|
2023-08-22 17:38:37 -04:00
|
|
|
import { type Dispatch, type SetStateAction, useCallback } from 'react'
|
2023-06-30 04:30:20 -04:00
|
|
|
import { Col, Row } from 'react-bootstrap'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { User } from '../../../../../../types/group-management/user'
|
|
|
|
import Badge from '../../../../shared/components/badge'
|
|
|
|
import Tooltip from '../../../../shared/components/tooltip'
|
2023-08-22 17:38:37 -04:00
|
|
|
import type { ManagedUserAlert } from '../../utils/types'
|
|
|
|
import { useGroupMembersContext } from '../../context/group-members-context'
|
2023-06-30 04:30:20 -04:00
|
|
|
import ManagedUserStatus from './managed-user-status'
|
2023-08-22 17:38:37 -04:00
|
|
|
import ManagedUserDropdownButton from './managed-user-dropdown-button'
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
type ManagedUserRowProps = {
|
|
|
|
user: User
|
2023-07-13 04:50:43 -04:00
|
|
|
openOffboardingModalForUser: (user: User) => void
|
2023-08-22 17:38:37 -04:00
|
|
|
groupId: string
|
|
|
|
setManagedUserAlert: Dispatch<SetStateAction<ManagedUserAlert>>
|
2023-06-30 04:30:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function ManagedUserRow({
|
|
|
|
user,
|
2023-07-13 04:50:43 -04:00
|
|
|
openOffboardingModalForUser,
|
2023-08-22 17:38:37 -04:00
|
|
|
setManagedUserAlert,
|
|
|
|
groupId,
|
2023-06-30 04:30:20 -04:00
|
|
|
}: ManagedUserRowProps) {
|
|
|
|
const { t } = useTranslation()
|
2023-08-22 09:30:34 -04:00
|
|
|
const { selectedUsers, selectUser, unselectUser } = useGroupMembersContext()
|
2023-06-30 04:30:20 -04:00
|
|
|
|
|
|
|
const handleSelectUser = useCallback(
|
|
|
|
(event, user) => {
|
|
|
|
if (event.target.checked) {
|
|
|
|
selectUser(user)
|
|
|
|
} else {
|
|
|
|
unselectUser(user)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[selectUser, unselectUser]
|
|
|
|
)
|
|
|
|
|
2023-08-22 09:30:34 -04:00
|
|
|
const selected = selectedUsers.includes(user)
|
|
|
|
|
2023-06-30 04:30:20 -04:00
|
|
|
return (
|
|
|
|
<li
|
|
|
|
key={`user-${user.email}`}
|
|
|
|
className={`managed-user-row ${user.invite ? 'text-muted' : ''}`}
|
|
|
|
>
|
|
|
|
<Row>
|
|
|
|
<Col xs={6}>
|
|
|
|
<label htmlFor={`select-user-${user.email}`} className="sr-only">
|
|
|
|
{t('select_user')}
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
className="select-item"
|
|
|
|
id={`select-user-${user.email}`}
|
|
|
|
type="checkbox"
|
|
|
|
checked={selected}
|
|
|
|
onChange={e => handleSelectUser(e, user)}
|
|
|
|
/>
|
|
|
|
<span>
|
|
|
|
{user.email}
|
|
|
|
{user.invite ? (
|
|
|
|
<span>
|
|
|
|
|
|
|
|
<Tooltip
|
|
|
|
id={`pending-invite-symbol-${user._id}`}
|
|
|
|
description={t('pending_invite')}
|
|
|
|
>
|
|
|
|
<Badge aria-label={t('pending_invite')}>
|
|
|
|
{t('pending_invite')}
|
|
|
|
</Badge>
|
|
|
|
</Tooltip>
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
|
|
|
{user.isEntityAdmin && (
|
|
|
|
<span>
|
|
|
|
|
|
|
|
<Tooltip
|
|
|
|
id={`group-admin-symbol-${user._id}`}
|
|
|
|
description={t('group_admin')}
|
|
|
|
>
|
|
|
|
<i
|
|
|
|
className="fa fa-user-circle-o"
|
|
|
|
aria-hidden="true"
|
|
|
|
aria-label={t('group_admin')}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
</Col>
|
|
|
|
<Col xs={2}>
|
2023-07-13 04:50:43 -04:00
|
|
|
<span>
|
|
|
|
{user.first_name} {user.last_name}
|
|
|
|
</span>
|
2023-06-30 04:30:20 -04:00
|
|
|
</Col>
|
|
|
|
<Col xs={2}>
|
|
|
|
{user.last_active_at
|
|
|
|
? moment(user.last_active_at).format('Do MMM YYYY')
|
|
|
|
: 'N/A'}
|
|
|
|
</Col>
|
|
|
|
<Col xs={2}>
|
2023-08-03 06:06:13 -04:00
|
|
|
<div className="managed-user-security">
|
2023-06-30 04:30:20 -04:00
|
|
|
<ManagedUserStatus user={user} />
|
2023-08-03 06:06:13 -04:00
|
|
|
<ManagedUserDropdownButton
|
|
|
|
user={user}
|
|
|
|
openOffboardingModalForUser={openOffboardingModalForUser}
|
2023-08-22 17:38:37 -04:00
|
|
|
setManagedUserAlert={setManagedUserAlert}
|
|
|
|
groupId={groupId}
|
2023-08-03 06:06:13 -04:00
|
|
|
/>
|
|
|
|
</div>
|
2023-06-30 04:30:20 -04:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
}
|