Skip to content

Commit

Permalink
Adapt localized text form for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
SemaiCZE committed Oct 30, 2017
1 parent 9e39e5b commit 3982fa0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 86 deletions.
53 changes: 21 additions & 32 deletions src/components/forms/EditAssignmentForm/EditAssignmentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,6 @@ const EditAssignmentForm = ({
/>
</Alert>}

<Field
name="name"
component={TextField}
label={
<FormattedMessage
id="app.editAssignmentForm.name"
defaultMessage="Assignment default name:"
/>
}
/>

<Field
name="isPublic"
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.editAssignmentForm.isPublic"
defaultMessage="Visible to students"
/>
}
/>

<FieldArray
name="localizedTexts"
localizedTexts={localizedTexts}
Expand Down Expand Up @@ -250,6 +227,18 @@ const EditAssignmentForm = ({
/>
}
/>

<Field
name="isPublic"
component={CheckboxField}
onOff
label={
<FormattedMessage
id="app.editAssignmentForm.isPublic"
defaultMessage="Visible to students"
/>
}
/>
</FormBox>
</div>;

Expand Down Expand Up @@ -296,15 +285,6 @@ const validate = ({
}) => {
const errors = {};

if (!name) {
errors['name'] = (
<FormattedMessage
id="app.editAssignmentForm.validation.emptyName"
defaultMessage="Please fill the name of the assignment."
/>
);
}

if (localizedTexts.length < 1) {
errors['_error'] = (
<FormattedMessage
Expand All @@ -325,6 +305,15 @@ const validate = ({
/>
);
} else {
if (!localizedTexts[i].name) {
localeErrors['name'] = (
<FormattedMessage
id="app.editAssignmentForm.validation.emptyName"
defaultMessage="Please fill the name of the assignment."
/>
);
}

if (!localizedTexts[i].locale) {
localeErrors['locale'] = (
<FormattedMessage
Expand Down
73 changes: 23 additions & 50 deletions src/components/forms/EditExerciseForm/EditExerciseForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import { Alert } from 'react-bootstrap';
import Icon from 'react-fontawesome';
import { LinkContainer } from 'react-router-bootstrap';

import {
TextField,
SelectField,
CheckboxField,
MarkdownTextAreaField
} from '../Fields';
import { SelectField, CheckboxField } from '../Fields';

import FormBox from '../../widgets/FormBox';
import SubmitButton from '../SubmitButton';
Expand Down Expand Up @@ -126,15 +121,10 @@ const EditExerciseForm = ({
/>
</Alert>}

<Field
name="name"
component={TextField}
label={
<FormattedMessage
id="app.editExerciseForm.name"
defaultMessage="Exercise name:"
/>
}
<FieldArray
name="localizedTexts"
localizedTexts={localizedTexts}
component={LocalizedTextsFormField}
/>

<Field
Expand All @@ -154,17 +144,6 @@ const EditExerciseForm = ({
}
/>

<Field
name="description"
component={MarkdownTextAreaField}
label={
<FormattedMessage
id="app.editExerciseForm.description"
defaultMessage="Description for supervisors:"
/>
}
/>

<Field
name="isPublic"
component={CheckboxField}
Expand All @@ -188,12 +167,6 @@ const EditExerciseForm = ({
/>
}
/>

<FieldArray
name="localizedTexts"
localizedTexts={localizedTexts}
component={LocalizedTextsFormField}
/>
</FormBox>;

EditExerciseForm.propTypes = {
Expand All @@ -216,15 +189,6 @@ EditExerciseForm.propTypes = {
const validate = ({ name, description, difficulty, localizedTexts }) => {
const errors = {};

if (!name) {
errors['name'] = (
<FormattedMessage
id="app.editExerciseForm.validation.emptyName"
defaultMessage="Please fill the name of the exercise."
/>
);
}

if (!difficulty) {
errors['difficulty'] = (
<FormattedMessage
Expand All @@ -234,15 +198,6 @@ const validate = ({ name, description, difficulty, localizedTexts }) => {
);
}

if (!description) {
errors['description'] = (
<FormattedMessage
id="app.editExerciseForm.validation.description"
defaultMessage="Please fill the description of the exercise."
/>
);
}

if (localizedTexts.length < 1) {
errors['_error'] = (
<FormattedMessage
Expand All @@ -263,6 +218,15 @@ const validate = ({ name, description, difficulty, localizedTexts }) => {
/>
);
} else {
if (!localizedTexts[i].name) {
localeErrors['name'] = (
<FormattedMessage
id="app.editExerciseForm.validation.emptyName"
defaultMessage="Please fill the name of the exercise."
/>
);
}

if (!localizedTexts[i].locale) {
localeErrors['locale'] = (
<FormattedMessage
Expand All @@ -280,6 +244,15 @@ const validate = ({ name, description, difficulty, localizedTexts }) => {
/>
);
}

if (!localizedTexts[i].description) {
localeErrors['description'] = (
<FormattedMessage
id="app.editExerciseForm.validation.description"
defaultMessage="Please fill the description of the exercise."
/>
);
}
}

localizedTextsErrors[i] = localeErrors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@ import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Field } from 'redux-form';
import { MarkdownTextAreaField, LanguageSelectField } from '../Fields';
import {
MarkdownTextAreaField,
LanguageSelectField,
TextField
} from '../Fields';

const LocalizedTextFormField = ({ prefix }) => (
const LocalizedTextFormField = ({ prefix }) =>
<div>
<Field
name={`${prefix}.name`}
component={TextField}
label={
<FormattedMessage
id="app.editAssignmentForm.localized.name"
defaultMessage="Name:"
/>
}
/>

<Field
name={`${prefix}.locale`}
component={LanguageSelectField}
Expand All @@ -27,8 +42,18 @@ const LocalizedTextFormField = ({ prefix }) => (
/>
}
/>
</div>
);

<Field
name={`${prefix}.description`}
component={MarkdownTextAreaField}
label={
<FormattedMessage
id="app.editAssignmentForm.description"
defaultMessage="Description for supervisors:"
/>
}
/>
</div>;

LocalizedTextFormField.propTypes = {
prefix: PropTypes.string.isRequired
Expand Down

0 comments on commit 3982fa0

Please sign in to comment.