generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
207 additions
and
30 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
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 |
---|---|---|
@@ -1,44 +1,136 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
Button, | ||
Collapsible, | ||
DataTable, | ||
} from '@openedx/paragon'; | ||
import { Add } from '@openedx/paragon/icons'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
|
||
import messages from '../messages'; | ||
import { useAllowancesData } from '../hooks'; | ||
|
||
import './AllowanceList.scss'; | ||
import AllowanceListActions from './AllowanceListActions'; | ||
|
||
const AllowanceList = ({ allowances }) => { | ||
const AllowanceList = () => { | ||
const { formatMessage } = useIntl(); | ||
|
||
const { | ||
allowancesList, | ||
} = useAllowancesData(); | ||
|
||
const allowancesByUser = allowancesList.reduce((acc, curr) => { | ||
const { | ||
id, | ||
exam_id: examId, | ||
user_id: userId, | ||
extra_time_mins: extraTimeMins, | ||
username, | ||
exam_name: examName, | ||
email, | ||
} = curr; | ||
|
||
const allowance = { | ||
id, | ||
examId, | ||
examName, | ||
allowanceType: 'Additional time (minutes)', | ||
extraTimeMins, | ||
}; | ||
|
||
const user = acc.find(u => u.userId === userId); | ||
|
||
if (user) { | ||
user.allowances.push(allowance); | ||
|
||
return acc; | ||
} | ||
|
||
acc.push({ | ||
userId, | ||
username, | ||
email, | ||
allowances: [allowance], | ||
}); | ||
|
||
return acc; | ||
}, []); | ||
|
||
const handleAdd = () => { | ||
console.log('Add'); // eslint-disable-line no-console | ||
}; | ||
|
||
const handleEdit = (row) => { | ||
console.log('Edit', row); // eslint-disable-line no-console | ||
}; | ||
|
||
const handleDelete = (row) => { | ||
console.log('Delete', row); // eslint-disable-line no-console | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="allowances-header"> | ||
<h3 data-testid="allowances"> {formatMessage(messages.allowanceDashboardTabTitle)} </h3> | ||
<Button variant="outline-primary" iconBefore={Add} size="sm" className="header-allowance-button"> | ||
<h3 data-testid="allowances">{formatMessage(messages.allowanceDashboardTabTitle)}</h3> | ||
<Button variant="outline-primary" iconBefore={Add} size="sm" className="header-allowance-button" onClick={handleAdd}> | ||
{formatMessage(messages.allowanceButton)} | ||
</Button> | ||
</div> | ||
<div className="allowances-body"> | ||
{ allowances.length === 0 | ||
{!allowancesByUser.length | ||
? ( | ||
<> | ||
<div className="allowances-empty"> | ||
<h4> {formatMessage(messages.noAllowancesHeader)} </h4> | ||
<p> {formatMessage(messages.noAllowancesBody)} </p> | ||
<Button variant="primary" iconBefore={Add}> | ||
<Button variant="primary" iconBefore={Add} onClick={handleAdd}> | ||
{formatMessage(messages.allowanceButton)} | ||
</Button> | ||
</> | ||
) | ||
: null } | ||
</div> | ||
) : ( | ||
<div className="allowances-list"> | ||
{allowancesByUser.map(({ | ||
userId, username, email, allowances, | ||
}) => ( | ||
<Collapsible | ||
defaultOpen | ||
key={userId} | ||
styling="card-lg" | ||
title={<p><strong>{username}</strong> (<a href={`mailto: ${email}`} target="_blank" onClick={e => e.stopPropagation()} rel="noreferrer">{email}</a>)</p>} | ||
> | ||
<DataTable | ||
itemCount={allowances.length} | ||
data={allowances} | ||
columns={[ | ||
{ | ||
Header: 'Exam Name', | ||
accessor: 'examName', | ||
|
||
}, | ||
{ | ||
Header: 'Allowance Type', | ||
accessor: 'allowanceType', | ||
}, | ||
{ | ||
Header: 'Allowance Value', | ||
accessor: 'extraTimeMins', | ||
}, | ||
]} | ||
additionalColumns={[ | ||
{ | ||
id: 'actions', | ||
Cell: () => AllowanceListActions({ onEdit: handleEdit, onDelete: handleDelete }), | ||
}, | ||
]} | ||
> | ||
<DataTable.Table /> | ||
</DataTable> | ||
</Collapsible> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
AllowanceList.propTypes = { | ||
allowances: PropTypes.arrayOf(PropTypes.object).isRequired, // eslint-disable-line react/forbid-prop-types | ||
}; | ||
|
||
export default AllowanceList; |
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
.allowances-header { | ||
padding: 40px 0 32px; | ||
display: flex; | ||
justify-content: space-between; | ||
gap: 10px; | ||
} | ||
|
||
.allowances-body { | ||
display: inline-block; | ||
text-align: center; | ||
width: 100%; | ||
padding-bottom: 50px; | ||
} | ||
|
||
.allowances-header { | ||
width: 100%; | ||
padding: 10px; | ||
position: relative; | ||
|
||
.header-allowance-button { | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
} | ||
.allowances-empty { | ||
padding: 100px 20px; | ||
} | ||
|
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,41 @@ | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Icon, | ||
IconButtonWithTooltip, | ||
} from '@openedx/paragon'; | ||
import { EditOutline, DeleteOutline } from '@openedx/paragon/icons'; | ||
|
||
import './AllowanceList.scss'; | ||
|
||
const AllowanceListActions = ({ onEdit, onDelete }) => ( | ||
<div className="allowances-actions text-right"> | ||
<IconButtonWithTooltip | ||
tooltipPlacement="top" | ||
tooltipContent={<div>Edit allowance</div>} | ||
src={EditOutline} | ||
iconAs={Icon} | ||
alt="Edit" | ||
onClick={onEdit} | ||
variant="primary" | ||
className="mr-2" | ||
size="sm" | ||
/> | ||
<IconButtonWithTooltip | ||
tooltipPlacement="top" | ||
tooltipContent={<div>Delete allowance</div>} | ||
src={DeleteOutline} | ||
iconAs={Icon} | ||
alt="Delete" | ||
onClick={onDelete} | ||
variant="secondary" | ||
size="sm" | ||
/> | ||
</div> | ||
); | ||
|
||
AllowanceListActions.propTypes = { | ||
onEdit: PropTypes.func.isRequired, | ||
onDelete: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default AllowanceListActions; |
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
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