Skip to content

Commit

Permalink
Fix multiple SIS terms forms initial values
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Jan 29, 2018
1 parent c7e4118 commit 4c8a2d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
6 changes: 5 additions & 1 deletion src/components/SisIntegration/EditTerm/EditTerm.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ EditTerm.propTypes = {
isOpen: PropTypes.bool.isRequired
};

export default reduxForm({ form: 'edit-sis-term' })(EditTerm);
export default reduxForm({
form: 'edit-sis-term',
enableReinitialize: true,
keepDirtyOnReinitialize: false
})(EditTerm);
33 changes: 15 additions & 18 deletions src/components/SisIntegration/TermsListItem/TermsListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,43 @@ 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
}) =>
const TermsListItem = ({ data, createActions }) =>
<tr>
<td>
{year}
{data.year}
</td>
<td>
{term === 1 &&
{data.term === 1 &&
<FormattedMessage id="app.termsList.winter" defaultMessage="Winter" />}
{term === 2 &&
{data.term === 2 &&
<FormattedMessage id="app.termsList.summer" defaultMessage="Summer" />}
{term !== 1 &&
term !== 2 &&
{data.term !== 1 &&
data.term !== 2 &&
<span>
{term}
{data.term}
</span>}
</td>
<td>
{beginning
? <FormattedDate value={new Date(beginning * 1000)} />
{data.beginning
? <FormattedDate value={new Date(data.beginning * 1000)} />
: <span>&mdash;</span>}
</td>
<td>
{end
? <FormattedDate value={new Date(end * 1000)} />
{data.end
? <FormattedDate value={new Date(data.end * 1000)} />
: <span>&mdash;</span>}
</td>
<td>
{advertiseUntil
{data.advertiseUntil
? <span>
<FormattedDate value={new Date(advertiseUntil * 1000)} />
<FormattedDate value={new Date(data.advertiseUntil * 1000)} />
{', '}
<FormattedTime value={new Date(advertiseUntil * 1000)} />
<FormattedTime value={new Date(data.advertiseUntil * 1000)} />
</span>
: <span>&mdash;</span>}
</td>
<td className="text-right">
{createActions && createActions(id)}
{createActions && createActions(data.id, data)}
</td>
</tr>;

Expand Down
9 changes: 7 additions & 2 deletions src/pages/SisIntegration/SisIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SisIntegration extends Component {
>
<TermsList
terms={sisTerms}
createActions={id =>
createActions={(id, data) =>
<div>
<Button
bsSize="xs"
Expand Down Expand Up @@ -125,13 +125,18 @@ class SisIntegration extends Component {
</Button>
</Confirm>
<EditTerm
id={id}
form={id}
isOpen={this.state.openEdit === id}
onClose={() => this.setState({ openEdit: null })}
onSubmit={data =>
editTerm(this.state.openEdit, data).then(() =>
this.setState({ openEdit: null })
)}
initialValues={{
beginning: data.beginning * 1000,
end: data.end * 1000,
advertiseUntil: data.advertiseUntil * 1000
}}
/>
</div>}
/>
Expand Down

0 comments on commit 4c8a2d1

Please sign in to comment.