mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
4019c69ea8
[web] Fix click all email checkbox behaviour on managed users GitOrigin-RevId: 4c4e7171d4aed3d99bc08be4b029eb3badb0fac9
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { useCallback } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useGroupMembersContext } from '../../context/group-members-context'
|
|
|
|
export default function ManagedUsersSelectAllCheckbox() {
|
|
const { t } = useTranslation()
|
|
|
|
const { selectedUsers, users, selectAllNonManagedUsers, unselectAllUsers } =
|
|
useGroupMembersContext()
|
|
|
|
const handleSelectAllNonManagedClick = useCallback(
|
|
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
if (e.target.checked) {
|
|
selectAllNonManagedUsers()
|
|
} else {
|
|
unselectAllUsers()
|
|
}
|
|
},
|
|
[selectAllNonManagedUsers, unselectAllUsers]
|
|
)
|
|
|
|
// Pending: user.enrollment will be `undefined`
|
|
// Not managed: user.enrollment will be an empty object
|
|
const nonManagedUsers = users.filter(user => !user.enrollment?.managedBy)
|
|
|
|
if (nonManagedUsers.length === 0) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<td className="cell-checkbox">
|
|
<label htmlFor="select-all" className="sr-only">
|
|
{t('select_all')}
|
|
</label>
|
|
<input
|
|
className="select-all"
|
|
id="select-all"
|
|
type="checkbox"
|
|
onChange={handleSelectAllNonManagedClick}
|
|
checked={selectedUsers.length === nonManagedUsers.length}
|
|
/>
|
|
</td>
|
|
)
|
|
}
|