Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in simple config forms #169

Merged
merged 3 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 68 additions & 41 deletions src/components/forms/EditGroupForm/EditGroupForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { reduxForm, Field, FieldArray } from 'redux-form';
import { Alert } from 'react-bootstrap';
import { Alert, Row, Col } from 'react-bootstrap';
import FormBox from '../../widgets/FormBox';
import SubmitButton from '../SubmitButton';
import LocalizedTextsFormField from '../LocalizedTextsFormField';
Expand All @@ -17,7 +17,7 @@ const EditGroupForm = ({
submitSucceeded = false,
invalid,
createNew = false,
formValues: { localizedTexts } = {},
formValues: { localizedTexts, hasThreshold } = {},
collapsable = false,
isOpen = true
}) =>
Expand Down Expand Up @@ -101,46 +101,70 @@ const EditGroupForm = ({
/>
}
/>

<Field
name="isPublic"
tabIndex={4}
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.createGroup.isPublic"
defaultMessage="Students can join the group themselves"
<Row>
<Col lg={6}>
<Field
name="isPublic"
tabIndex={4}
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.createGroup.isPublic"
defaultMessage="Students can join the group themselves"
/>
}
required
/>
}
required
/>

<Field
name="publicStats"
tabIndex={5}
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.createGroup.publicStats"
defaultMessage="Students can see statistics of each other"
</Col>
<Col lg={6}>
<Field
name="publicStats"
tabIndex={5}
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.createGroup.publicStats"
defaultMessage="Students can see statistics of each other"
/>
}
required
/>
}
required
/>
</Col>
</Row>

<Field
name="threshold"
tabIndex={6}
component={TextField}
label={
<FormattedMessage
id="app.createGroup.threshold"
defaultMessage="Minimum percent of the total points count needed to complete the course:"
<Row>
<Col lg={6}>
<Field
name="hasThreshold"
tabIndex={6}
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.createGroup.hasThreshold"
defaultMessage="Students require cetrain number of points to complete the course"
/>
}
required
/>
}
/>
</Col>
<Col lg={6}>
{hasThreshold &&
<Field
name="threshold"
tabIndex={7}
component={TextField}
label={
<FormattedMessage
id="app.createGroup.threshold"
defaultMessage="Minimum percent of the total points count needed to complete the course:"
/>
}
/>}
</Col>
</Row>
</FormBox>;

EditGroupForm.propTypes = {
Expand All @@ -159,13 +183,16 @@ EditGroupForm.propTypes = {
isOpen: PropTypes.bool
};

const validate = ({ localizedTexts = [], threshold }) => {
const validate = ({ localizedTexts = [], hasThreshold, threshold }) => {
const errors = {};

if (threshold) {
if (hasThreshold) {
threshold = String(threshold);
const numericThreshold = Number(threshold);
if (threshold !== Math.round(numericThreshold).toString()) {
if (
isNaN(numericThreshold) ||
threshold !== Math.round(numericThreshold).toString()
) {
errors['threshold'] = (
<FormattedMessage
id="app.createGroup.validation.thresholdMustBeInteger"
Expand Down
1 change: 0 additions & 1 deletion src/components/forms/EditTestsForm/EditTestsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ const validate = ({ isUniform, tests }) => {
testsErrors[i] = testErrors;
}
errors['tests'] = testsErrors;

return errors;
};

Expand Down
11 changes: 8 additions & 3 deletions src/components/forms/EditTestsForm/EditTestsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ const EditTestsTest = ({ fields, isUniform, testValues }) => {
key={index}
test={test}
isUniform={isUniform}
percent={prettyPrintPercent(
(isUniform ? 1 : Number(testValues[index].weight)) / weightSum
)}
percent={
testValues[index] && testValues[index].weight
? prettyPrintPercent(
(isUniform ? 1 : Number(testValues[index].weight)) /
weightSum
)
: '?'
}
onRemove={() => fields.remove(index)}
/>
)}
Expand Down
Loading