Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #388 from mupi/fix/accept-pdflink
Browse files Browse the repository at this point in the history
Fix/accept pdflink
  • Loading branch information
GlauciaSchnoeller authored Feb 13, 2020
2 parents fcf88e6 + db6f002 commit 0da706e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/containers/CreateClassPlanPageContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const mapDispatchToProps = (dispatch) => {
*/
onSubmit: (values, d, props) => {
const errors = [];

const newClassPlan = {
name: values.name,
disciplines_ids: values.disciplines.map(discipline => discipline.id),
Expand All @@ -130,6 +131,11 @@ const mapDispatchToProps = (dispatch) => {
description: values.description,
pdf: values.pdf && values.pdf.length !== 0 ? values.pdf : null,
};
const overMaxSize = values.pdf && values.pdf instanceof FileList && values.pdf.length > 0 && values.pdf[0].size > 2097152;
if (overMaxSize) {
errors.pdf = 'Insira um arquivo PDF de máx. 2mb';
}

if (Object.keys(errors).length !== 0) throw new SubmissionError(errors);

return dispatch(createClassPlan(newClassPlan));
Expand Down
5 changes: 5 additions & 0 deletions src/containers/EditClassPlanPageContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ const mapDispatchToProps = (dispatch) => {
description: values.description,
pdf: (values.pdf && isValidFile) ? values.pdf : null,
};
const overMaxSize = values.pdf && values.pdf instanceof FileList && values.pdf.length > 0 && values.pdf[0].size > 2097152;
if (overMaxSize) {
errors.pdf = 'Insira um arquivo PDF de máx. 2mb';
}


if (Object.keys(errors).length !== 0) throw new SubmissionError(errors);

Expand Down
16 changes: 15 additions & 1 deletion src/pages/ClassPlan/CreateClassPlanPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const renderLinks = ({ fields, meta: { error } }) => (
</>
);

export const fieldFile = ({ input, type }) => {
export const fieldFile = ({ input, type, meta: { touched, error, warning } }) => {
const newInput = input;
delete newInput.value;

Expand All @@ -193,6 +193,20 @@ export const fieldFile = ({ input, type }) => {
<Label htmlFor={input.name}>
<Input {...newInput} type={type} placeholder="Carregar pdf" />
</Label>
{ touched
&& ((error && (
<span className="error-message-text">
{error}
</span>
))
|| (warning && (
<span>
{' '}
{warning}
{' '}
</span>
)))
}
</div>
);
};
Expand Down
17 changes: 15 additions & 2 deletions src/pages/ClassPlan/EditClassPlanPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const renderLinks = ({ fields, meta: { error } }) => (
</>
);

export const fieldFile = ({ input, type }) => {
export const fieldFile = ({ input, type, meta: { touched, error, warning } }) => {
const newInput = input;
delete newInput.value;

Expand All @@ -195,11 +195,24 @@ export const fieldFile = ({ input, type }) => {
<label htmlFor={input.name}>
<input {...newInput} type={type} placeholder="Carregar pdf" />
</label>
{ touched
&& ((error && (
<span className="error-message-text">
{error}
</span>
))
|| (warning && (
<span>
{' '}
{warning}
{' '}
</span>
)))
}
</div>
);
};


class EditClassPlanPage extends Component {
componentDidMount() {
const {
Expand Down

0 comments on commit 0da706e

Please sign in to comment.