-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Listing, adding and deleting SIS terms
- Loading branch information
Showing
10 changed files
with
391 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Table } from 'react-bootstrap'; | ||
import { injectIntl, FormattedMessage } from 'react-intl'; | ||
import TermsListItem from '../TermsListItem'; | ||
|
||
const TermsList = ({ terms = [], createActions, intl, ...rest }) => | ||
<Table hover striped> | ||
<thead> | ||
<tr> | ||
<th> | ||
<FormattedMessage id="app.termsList.year" defaultMessage="Year" /> | ||
</th> | ||
<th> | ||
<FormattedMessage id="app.termsList.term" defaultMessage="Term" /> | ||
</th> | ||
<th> | ||
<FormattedMessage id="app.termsList.start" defaultMessage="Start" /> | ||
</th> | ||
<th> | ||
<FormattedMessage id="app.termsList.end" defaultMessage="End" /> | ||
</th> | ||
<th> | ||
<FormattedMessage | ||
id="app.termsList.advertiseUntil" | ||
defaultMessage="Advertise Until" | ||
/> | ||
</th> | ||
<th /> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{terms.map((term, i) => | ||
<TermsListItem key={i} data={term} createActions={createActions} /> | ||
)} | ||
|
||
{terms.length === 0 && | ||
<tr> | ||
<td className="text-center"> | ||
<FormattedMessage | ||
id="app.termsList.noTerms" | ||
defaultMessage="There are no SIS terms in this list." | ||
/> | ||
</td> | ||
</tr>} | ||
</tbody> | ||
</Table>; | ||
|
||
TermsList.propTypes = { | ||
terms: PropTypes.array, | ||
createActions: PropTypes.func, | ||
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired | ||
}; | ||
|
||
export default injectIntl(TermsList); |
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 @@ | ||
export default from './TermsList'; |
60 changes: 60 additions & 0 deletions
60
src/components/SisIntegration/TermsListItem/TermsListItem.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,60 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage, FormattedDate, FormattedTime } from 'react-intl'; | ||
|
||
const TermsListItem = ({ | ||
data: { id, year, term, beginning, end, advertiseUntil }, | ||
createActions | ||
}) => | ||
<tr> | ||
<td> | ||
{year} | ||
</td> | ||
<td> | ||
{term === 1 && | ||
<FormattedMessage id="app.termsList.winter" defaultMessage="Winter" />} | ||
{term === 2 && | ||
<FormattedMessage id="app.termsList.summer" defaultMessage="Summer" />} | ||
{term !== 1 && | ||
term !== 2 && | ||
<span> | ||
{term} | ||
</span>} | ||
</td> | ||
<td> | ||
{beginning | ||
? <FormattedDate value={new Date(beginning * 1000)} /> | ||
: <span>—</span>} | ||
</td> | ||
<td> | ||
{end | ||
? <FormattedDate value={new Date(end * 1000)} /> | ||
: <span>—</span>} | ||
</td> | ||
<td> | ||
{advertiseUntil | ||
? <span> | ||
<FormattedDate value={new Date(advertiseUntil * 1000)} /> | ||
{', '} | ||
<FormattedTime value={new Date(advertiseUntil * 1000)} /> | ||
</span> | ||
: <span>—</span>} | ||
</td> | ||
<td className="text-right"> | ||
{createActions && createActions(id)} | ||
</td> | ||
</tr>; | ||
|
||
TermsListItem.propTypes = { | ||
data: PropTypes.shape({ | ||
id: PropTypes.string.isRequired, | ||
year: PropTypes.number.isRequired, | ||
term: PropTypes.number.isRequired, | ||
beginning: PropTypes.number, | ||
end: PropTypes.number, | ||
advertiseUntil: PropTypes.number | ||
}), | ||
createActions: PropTypes.func | ||
}; | ||
|
||
export default TermsListItem; |
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 @@ | ||
export default from './TermsListItem'; |
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,139 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
FormattedMessage, | ||
defineMessages, | ||
intlShape, | ||
injectIntl | ||
} from 'react-intl'; | ||
import { reduxForm, Field } from 'redux-form'; | ||
import { Alert } from 'react-bootstrap'; | ||
import isInt from 'validator/lib/isInt'; | ||
import FormBox from '../../widgets/FormBox'; | ||
import SubmitButton from '../SubmitButton'; | ||
import { TextField, SelectField } from '../Fields'; | ||
|
||
const messages = defineMessages({ | ||
summerTerm: { | ||
id: 'app.addSisTermForm.summer', | ||
defaultMessage: 'Summer term' | ||
}, | ||
winterTerm: { | ||
id: 'app.addSisTermForm.winter', | ||
defaultMessage: 'Winter term' | ||
} | ||
}); | ||
|
||
const AddSisTermForm = ({ | ||
submitting, | ||
handleSubmit, | ||
anyTouched, | ||
submitFailed = false, | ||
submitSucceeded = false, | ||
invalid, | ||
intl: { formatMessage } | ||
}) => | ||
<FormBox | ||
title={ | ||
<FormattedMessage | ||
id="app.addSisTermForm.title" | ||
defaultMessage="Add new term" | ||
/> | ||
} | ||
type={submitSucceeded ? 'success' : undefined} | ||
isOpen={true} | ||
collapsable={false} | ||
footer={ | ||
<div className="text-center"> | ||
<SubmitButton | ||
id="add-sis-term" | ||
handleSubmit={handleSubmit} | ||
submitting={submitting} | ||
dirty={anyTouched} | ||
hasSucceeded={submitSucceeded} | ||
hasFailed={submitFailed} | ||
invalid={invalid} | ||
messages={{ | ||
submit: ( | ||
<FormattedMessage | ||
id="app.addSisTermForm.submit" | ||
defaultMessage="Save new term" | ||
/> | ||
), | ||
submitting: ( | ||
<FormattedMessage | ||
id="app.addSisTermForm.processing" | ||
defaultMessage="Saving ..." | ||
/> | ||
), | ||
success: ( | ||
<FormattedMessage | ||
id="app.addSisTermForm.success" | ||
defaultMessage="The term is saved." | ||
/> | ||
) | ||
}} | ||
/> | ||
</div> | ||
} | ||
> | ||
{submitFailed && | ||
<Alert bsStyle="danger"> | ||
<FormattedMessage | ||
id="app.addSisTermForm.failed" | ||
defaultMessage="Cannot save the new SIS term." | ||
/> | ||
</Alert>} | ||
|
||
<Field | ||
name="year" | ||
component={TextField} | ||
label={ | ||
<FormattedMessage id="app.addSisTermForm.year" defaultMessage="Year:" /> | ||
} | ||
/> | ||
<Field | ||
name="term" | ||
component={SelectField} | ||
label={ | ||
<FormattedMessage id="app.addSisTermForm.term" defaultMessage="Term:" /> | ||
} | ||
options={[ | ||
{ name: formatMessage(messages.winterTerm), key: 1 }, | ||
{ name: formatMessage(messages.summerTerm), key: 2 } | ||
]} | ||
addEmptyOption | ||
/> | ||
</FormBox>; | ||
|
||
AddSisTermForm.propTypes = { | ||
handleSubmit: PropTypes.func.isRequired, | ||
onSubmit: PropTypes.func.isRequired, | ||
submitFailed: PropTypes.bool, | ||
anyTouched: PropTypes.bool, | ||
submitSucceeded: PropTypes.bool, | ||
submitting: PropTypes.bool, | ||
invalid: PropTypes.bool, | ||
intl: intlShape.isRequired | ||
}; | ||
|
||
const validate = ({ year, term }) => { | ||
const errors = {}; | ||
if (year && !isInt(String(year))) { | ||
errors['year'] = ( | ||
<FormattedMessage | ||
id="app.addSisTermForm.validation.year" | ||
defaultMessage="The year must be an integer." | ||
/> | ||
); | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
export default injectIntl( | ||
reduxForm({ | ||
form: 'add-sis-term', | ||
validate | ||
})(AddSisTermForm) | ||
); |
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 @@ | ||
export default from './AddSisTermForm'; |
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.