diff --git a/public/img/fail-kidneys.jpg b/public/img/fail-kidneys.jpg new file mode 100644 index 0000000..484bb3e Binary files /dev/null and b/public/img/fail-kidneys.jpg differ diff --git a/public/img/happy-kidneys.jpg b/public/img/happy-kidneys.jpg new file mode 100644 index 0000000..674907c Binary files /dev/null and b/public/img/happy-kidneys.jpg differ diff --git a/src/actions/Validation/validationActions.js b/src/actions/Validation/validationActions.js new file mode 100644 index 0000000..9c0baca --- /dev/null +++ b/src/actions/Validation/validationActions.js @@ -0,0 +1,31 @@ +import actionNames from '../actionNames'; +import Api from '../../helpers/Api'; +import { sendMessageToBackend } from '../Error/errorActions'; + +const api = Api.getInstance(); + +export const setValidationResult = (result) => { + return { + type: actionNames.SET_VALIDATION_RESULT, + payload: result + } +} + +export const validateFilenames = (formData) => { + return (dispatch) => { + api.post('/api//v1/package/files/validation', formData) + .then(res => { + dispatch(setValidationResult(res.data)); + }) + .catch(error => { + console.log(error); + dispatch(sendMessageToBackend(error)); + }); + } +} + +export const clearValidationResult = () => { + return { + type: actionNames.CLEAR_VALIDATION_RESULT + } +} \ No newline at end of file diff --git a/src/actions/Validation/validationActions.test.js b/src/actions/Validation/validationActions.test.js new file mode 100644 index 0000000..49d96c6 --- /dev/null +++ b/src/actions/Validation/validationActions.test.js @@ -0,0 +1,26 @@ +import actionNames from '../actionNames'; +import { setValidationResult, clearValidationResult } from './validationActions'; + +describe('setValidationResult', () => { + it('should return the result in the correct structure', () => { + let expectedResult = { + type: actionNames.SET_VALIDATION_RESULT, + payload: { 'key': 'value' } + }; + + let result = setValidationResult({ 'key': 'value' }); + + expect(result).toEqual(expectedResult); + }); +}); +describe('clearValidationResult', () => { + it('should return the result in the correct structure', () => { + let expectedResult = { + type: actionNames.CLEAR_VALIDATION_RESULT + }; + + let result = clearValidationResult(); + + expect(result).toEqual(expectedResult); + }); +}); \ No newline at end of file diff --git a/src/actions/actionNames.js b/src/actions/actionNames.js index 819ab34..f00142c 100644 --- a/src/actions/actionNames.js +++ b/src/actions/actionNames.js @@ -1,7 +1,9 @@ const actionNames = { - RESET_STATE: 'RESET_STATE', - SET_PACKAGES: 'SET_PACKAGES', - GET_PACKAGES: 'GET_PACKAGES' + CLEAR_VALIDATION_RESULT: 'CLEAR_VALIDATION_RESULT', + GET_PACKAGES: 'GET_PACKAGES', + RESET_STATE: 'RESET_STATE', + SET_PACKAGES: 'SET_PACKAGES', + SET_VALIDATION_RESULT: 'SET_VALIDATION_RESULT' }; export default actionNames; diff --git a/src/components/Validation/FilenameValidationPage.js b/src/components/Validation/FilenameValidationPage.js index 71b017f..809ad99 100644 --- a/src/components/Validation/FilenameValidationPage.js +++ b/src/components/Validation/FilenameValidationPage.js @@ -1,5 +1,7 @@ import React, { Component } from 'react'; import { Container, Row, Col, Button } from 'reactstrap'; +import ValidationSuccess from './ValidationSuccess'; +import ValidationFailure from './ValidationFailure'; class FilenameValidationPage extends Component { @@ -9,6 +11,7 @@ class FilenameValidationPage extends Component { packageId: '', filenames: '' }; + this.props.clearValidationResult(); this.handleSubmit = this.handleSubmit.bind(this); } @@ -22,41 +25,57 @@ class FilenameValidationPage extends Component { handleSubmit(e) { e.preventDefault(); + this.props.validateFilenames(this.state); } render() { const { packageId, filenames } = this.state; const isEnabled = packageId.length > 0 && filenames.length > 0; - return ( - -
- - - - - - this.packageId = input} onChange={this.handlePackageIdChange}/> - - - - - - - -