Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding participating students list (for exam term) with unlock button…
…s so the teacher can release them.
- Loading branch information
1 parent
87acb2f
commit e31a49d
Showing
17 changed files
with
286 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/components/Groups/LockedStudentsTable/LockedStudentsTable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage, injectIntl } from 'react-intl'; | ||
import { Table } from 'react-bootstrap'; | ||
import { defaultMemoize } from 'reselect'; | ||
|
||
import UsersName from '../../Users/UsersName'; | ||
import ExamUnlockButtonContainer from '../../../containers/ExamUnlockButtonContainer'; | ||
import { createUserNameComparator } from '../../helpers/users'; | ||
|
||
const sortStudents = defaultMemoize((lockedStudents, locale) => { | ||
const sorted = [...lockedStudents]; | ||
return sorted.sort(createUserNameComparator(locale)); | ||
}); | ||
|
||
const LockedStudentsTable = ({ groupId, lockedStudents, currentUser, intl: { locale } }) => | ||
lockedStudents && lockedStudents.length > 0 ? ( | ||
<Table className="m-0" hover> | ||
<tbody> | ||
{sortStudents(lockedStudents).map(student => ( | ||
<tr key={student.id}> | ||
<td> | ||
<UsersName | ||
{...student} | ||
currentUserId={currentUser.id} | ||
showEmail="full" | ||
showExternalIdentifiers | ||
listItem | ||
/> | ||
</td> | ||
<td className="text-right"> | ||
<ExamUnlockButtonContainer groupId={groupId} userId={student.id} size="xs" /> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
) : ( | ||
<div className="text-center text-muted p-4"> | ||
<em> | ||
<FormattedMessage | ||
id="app.lockedStudentsTable.noLockedStudents" | ||
defaultMessage="There are no locked students yet." | ||
/> | ||
</em> | ||
</div> | ||
); | ||
|
||
LockedStudentsTable.propTypes = { | ||
groupId: PropTypes.string.isRequired, | ||
lockedStudents: PropTypes.array, | ||
currentUser: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
}), | ||
intl: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default injectIntl(LockedStudentsTable); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import LockedStudentsTable from './LockedStudentsTable'; | ||
export default LockedStudentsTable; |
24 changes: 24 additions & 0 deletions
24
src/components/buttons/ExamUnlockButton/ExamUnlockButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { UnlockIcon, LoadingIcon } from '../../icons'; | ||
import Button from '../../widgets/TheButton'; | ||
|
||
const ExamUnlockButton = ({ pending, disabled = false, unlockUserForExam, ...props }) => ( | ||
<Button | ||
{...props} | ||
variant={disabled ? 'secondary' : 'warning'} | ||
onClick={unlockUserForExam} | ||
disabled={pending || disabled}> | ||
{pending ? <LoadingIcon gapRight /> : <UnlockIcon gapRight />} | ||
<FormattedMessage id="app.groupExams.unlockStudentButton" defaultMessage="Unlock" /> | ||
</Button> | ||
); | ||
|
||
ExamUnlockButton.propTypes = { | ||
pending: PropTypes.bool.isRequired, | ||
disabled: PropTypes.bool, | ||
unlockUserForExam: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ExamUnlockButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import ExamUnlockButton from './ExamUnlockButton'; | ||
export default ExamUnlockButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/containers/ExamUnlockButtonContainer/ExamUnlockButtonContainer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { injectIntl } from 'react-intl'; | ||
import { defaultMemoize } from 'reselect'; | ||
|
||
import ExamUnlockButton from '../../components/buttons/ExamUnlockButton'; | ||
import { unlockStudentFromExam } from '../../redux/modules/groups'; | ||
import { groupPendingUserUnlock } from '../../redux/selectors/groups'; | ||
import { loggedInUserSelector } from '../../redux/selectors/users'; | ||
import { getErrorMessage } from '../../locales/apiErrorMessages'; | ||
import { addNotification } from '../../redux/modules/notifications'; | ||
|
||
const unlockStudentHandlingErrors = defaultMemoize( | ||
(unlockStudentFromExam, addNotification, formatMessage) => () => | ||
unlockStudentFromExam().catch(err => { | ||
addNotification(getErrorMessage(formatMessage)(err), false); | ||
}) | ||
); | ||
|
||
const ExamUnlockButtonContainer = ({ | ||
groupId, | ||
userId, | ||
pending = null, | ||
unlockStudentFromExam, | ||
addNotification, | ||
intl: { formatMessage }, | ||
...props | ||
}) => ( | ||
<ExamUnlockButton | ||
{...props} | ||
pending={pending} | ||
unlockUserForExam={unlockStudentHandlingErrors(unlockStudentFromExam, addNotification, formatMessage)} | ||
/> | ||
); | ||
|
||
ExamUnlockButtonContainer.propTypes = { | ||
groupId: PropTypes.string.isRequired, | ||
userId: PropTypes.string.isRequired, | ||
pending: PropTypes.string, | ||
unlockStudentFromExam: PropTypes.func.isRequired, | ||
addNotification: PropTypes.func.isRequired, | ||
intl: PropTypes.object, | ||
}; | ||
|
||
const mapStateToProps = (state, { groupId }) => ({ | ||
pending: groupPendingUserUnlock(state, groupId), | ||
currentUser: loggedInUserSelector(state), | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch, { groupId, userId }) => ({ | ||
unlockStudentFromExam: () => dispatch(unlockStudentFromExam(groupId, userId)), | ||
addNotification: (...args) => dispatch(addNotification(...args)), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(ExamUnlockButtonContainer)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import ExamUnlockButtonContainer from './ExamUnlockButtonContainer'; | ||
export default ExamUnlockButtonContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.