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 { 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 (
|
2023-08-25 04:51:45 -04:00
|
|
|
<tr
|
2023-06-30 04:30:20 -04:00
|
|
|
key={`user-${user.email}`}
|
|
|
|
className={`managed-user-row ${user.invite ? 'text-muted' : ''}`}
|
|
|
|
>
|
2023-08-25 05:19:33 -04:00
|
|
|
<td className="cell-checkbox">
|
|
|
|
{user.enrollment?.managedBy ? null : (
|
|
|
|
<>
|
|
|
|
<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)}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</td>
|
2023-08-25 04:51:45 -04:00
|
|
|
<td className="cell-email">
|
|
|
|
<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>
|
|
|
|
</td>
|
|
|
|
<td className="cell-name">
|
|
|
|
{user.first_name} {user.last_name}
|
|
|
|
</td>
|
|
|
|
<td className="cell-last-active">
|
|
|
|
{user.last_active_at
|
|
|
|
? moment(user.last_active_at).format('Do MMM YYYY')
|
|
|
|
: 'N/A'}
|
|
|
|
</td>
|
|
|
|
<td className="cell-security">
|
|
|
|
<div className="managed-user-security">
|
|
|
|
<ManagedUserStatus user={user} />
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td className="cell-dropdown">
|
|
|
|
<ManagedUserDropdownButton
|
|
|
|
user={user}
|
|
|
|
openOffboardingModalForUser={openOffboardingModalForUser}
|
|
|
|
setManagedUserAlert={setManagedUserAlert}
|
|
|
|
groupId={groupId}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2023-06-30 04:30:20 -04:00
|
|
|
)
|
|
|
|
}
|