mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-12 06:01:36 -05:00
3b48b32754
* 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
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { useTranslation } from 'react-i18next'
|
|
import type { User } from '../../../../../../types/group-management/user'
|
|
import { useGroupMembersContext } from '../../context/group-members-context'
|
|
import { useCallback } from 'react'
|
|
import getMeta from '@/utils/meta'
|
|
|
|
type ManagedUsersSelectUserCheckboxProps = {
|
|
user: User
|
|
}
|
|
|
|
export default function ManagedUsersSelectUserCheckbox({
|
|
user,
|
|
}: ManagedUsersSelectUserCheckboxProps) {
|
|
const { t } = useTranslation()
|
|
const groupSSOActive = getMeta('ol-groupSSOActive')
|
|
const { users, selectedUsers, selectUser, unselectUser } =
|
|
useGroupMembersContext()
|
|
|
|
const handleSelectUser = useCallback(
|
|
(event, user) => {
|
|
if (event.target.checked) {
|
|
selectUser(user)
|
|
} else {
|
|
unselectUser(user)
|
|
}
|
|
},
|
|
[selectUser, unselectUser]
|
|
)
|
|
|
|
// Pending: user.enrollment will be `undefined`
|
|
// Non managed: user.enrollment will be an empty object
|
|
const nonManagedUsers = users.filter(user => !user.enrollment?.managedBy)
|
|
|
|
// Hide the entire `td` (entire column) if no more users available to be click
|
|
// because all users are currently managed
|
|
if (nonManagedUsers.length === 0) {
|
|
return null
|
|
}
|
|
|
|
const selected = selectedUsers.includes(user)
|
|
|
|
return (
|
|
<td
|
|
className={
|
|
groupSSOActive ? 'cell-checkbox-with-sso-col ' : 'cell-checkbox'
|
|
}
|
|
>
|
|
{/* the next check will hide the `checkbox` but still show the `td` */}
|
|
{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>
|
|
)
|
|
}
|