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

Commit

Permalink
Basic project form using React bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrohee committed Aug 3, 2016
1 parent 082ee88 commit b562cfe
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/components/application/ApplicationPage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import React from 'react'
import {Link} from 'react-router'
import ProjectForm from './Forms/ProjectForm'
import {Button} from 'react-bootstrap'

class ApplicationPage extends React.Component {
constructor(props, context) {
super(props, context)

this.state = {
project: {}
}

this.updateProjectState = this.updateProjectState.bind(this)
}

updateProjectState(event) {
const field = event.target.name
let project = this.state.project
project[field] = event.target.value
return this.setState({project})
}

render() {
return (
<div className="jumbotron">
<p>Bientôt votre candidature.</p>
<ProjectForm
project={this.state.project}
onChange={this.updateProjectState}
/>
<Button bsStyle="primary">Enregistrer</Button>
</div>
)
}
Expand Down
22 changes: 22 additions & 0 deletions src/components/application/Forms/ProjectForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, {PropTypes} from 'react'
import { FormGroup, ControlLabel, FormControl, HelpBlock } from 'react-bootstrap'

const ProjectForm = ({project, onChange}) => {
return (
<form>
<h1>Mon Projet</h1>
<FormGroup>
<ControlLabel>Nom de mon projet</ControlLabel>
<FormControl type="text" placeholder="Projet" onChange={onChange} value={project.value}/>
<HelpBlock>Le nom n'est pas obligatoire.</HelpBlock>
</FormGroup>
</form>
)
}

ProjectForm.propTypes = {
project: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired
}

export default ProjectForm
21 changes: 21 additions & 0 deletions src/components/application/Forms/ProjectForm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import expect from 'expect'
import React from 'react'
import {shallow} from 'enzyme'
import ProjectForm from './ProjectForm'

function setup() {
const props = {
project: {},
onChange: () => {}
}

return shallow(<ProjectForm {...props} />)
}

describe('<ProjectForm>', () => {
it('renders form and h1', () => {
const wrapper = setup()
expect(wrapper.find('form').length).toBe(1)
expect(wrapper.find('h1').text()).toEqual('Mon Projet')
})
})

0 comments on commit b562cfe

Please sign in to comment.