overleaf/services/web/frontend/js/features/group-management/components/managed-users/managed-users-select-all-checkbox.tsx
Davinder Singh 3b48b32754 Revert "Revert "Group SSO - Adding a bug fix for sending emails"" (#15307)
* Revert "Revert "Group SSO - Adding a bug fix for sending emails""
* adding conditional rendering of columns and styling fixes for each render mode with some cypress test

GitOrigin-RevId: 168011503ffacff61c8f37bee4c4bfb012909c1f
2023-10-20 08:04:08 +00:00

50 lines
1.4 KiB
TypeScript

import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { useGroupMembersContext } from '../../context/group-members-context'
import getMeta from '@/utils/meta'
export default function ManagedUsersSelectAllCheckbox() {
const { t } = useTranslation()
const groupSSOActive = getMeta('ol-groupSSOActive')
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={
groupSSOActive ? 'cell-checkbox-with-sso-col ' : '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>
)
}