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

Commit

Permalink
Save application on 1st click
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrohee committed Aug 1, 2017
1 parent 9572f5e commit ad505dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 44 deletions.
15 changes: 12 additions & 3 deletions client/src/components/application/ApplicationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PepitePage from './Pepite/PepitePage'
import SendPage from './Send/SendPage'
import CareerPage from './Career/CareerPage'
import ProfilePage from './Profile/ProfilePage'
import { Modal } from 'react-bootstrap'
import { Modal, Button } from 'react-bootstrap'
import '../../styles/apply-form.css'
import { isEmptyObject } from '../common/validationHelper'

Expand Down Expand Up @@ -42,7 +42,13 @@ class ApplicationPage extends React.Component {
openSave(event) {
event.preventDefault()
if (this.props.actions.validateContact()) {
this.setState({ isSaveShown: true })
this.props.applicationActions.saveApplication()
.then((application) => {
this.setState({ isSaveShown: true })
})
.catch((err) => {
toastr.error(err)
})
} else {
toastr.error("Pour sauvegarder, 'Mes Informations' doit être complet et valide")
}
Expand Down Expand Up @@ -85,11 +91,14 @@ class ApplicationPage extends React.Component {
<Multistep steps={this.getSteps()} save={this.openSave} canNavigate={this.canNavigate} />
<Modal show={this.state.isSaveShown} onHide={this.closeSave}>
<Modal.Header>
<Modal.Title>Sauvegarder mon formulaire</Modal.Title>
<Modal.Title>Candidature sauvegardée</Modal.Title>
</Modal.Header>
<Modal.Body>
<SavePage />
</Modal.Body>
<Modal.Footer>
<Button bsStyle="info" onClick={this.closeSave}>Revenir à ma candidature</Button>
</Modal.Footer>
</Modal>
</div>
)
Expand Down
9 changes: 3 additions & 6 deletions client/src/components/application/Save/SaveForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@ import React, {PropTypes} from 'react'
import { FormGroup, ControlLabel, FormControl, Button, HelpBlock } from 'react-bootstrap'
import ValidatedFormControl from '../../common/ValidatedFormControl'

const SaveForm = ({link, saveForm, errors, onChange}) => {
const SaveForm = ({link, saveForm}) => {
return (
<form>
<FormGroup>
<ControlLabel>Lien vers ta candidature</ControlLabel>
<ValidatedFormControl name="link" type="url" placeholder="Clique sur sauvegarde pour obtenir un lien" onChange={onChange} value={link} disabled={link.length == 0}/>
<ValidatedFormControl name="link" type="url" value={link} disabled={link.length == 0}/>
<HelpBlock>Tu vas recevoir par mail un lien vers ta candidature pour la compléter ou la modifier plus tard</HelpBlock>
</FormGroup>
<Button bsStyle="success" className="save" onClick={saveForm}>Obtenir le lien</Button>
</form>
)
}

SaveForm.propTypes = {
link: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
saveForm: PropTypes.func.isRequired,
errors: PropTypes.object
saveForm: PropTypes.func.isRequired
}

export default SaveForm
38 changes: 3 additions & 35 deletions client/src/components/application/Save/SavePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,24 @@ import SaveForm from './SaveForm'
import Validation from '../../common/Validation'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import toastr from 'toastr'
import * as applicationActions from '../../../actions/applicationActions'

export class SavePage extends React.Component {
constructor(props, context) {
super(props, context)
this.state = {
link: '',
errors: {},
}
this.updateContactState = this.updateContactState.bind(this)
this.saveForm = this.saveForm.bind(this)
}

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

getAppliationUrl(applicationId) {
return window.location.href.replace(/application(\/)?.*/, `application/${applicationId}`)
}

saveForm(event) {
event.preventDefault()
this.props.actions.saveApplication()
.then((application) => {
this.setState({link: this.getAppliationUrl(application.id)})
toastr.success("Candidature sauvegardée")
})
.catch((err) => {
toastr.error(err)
})
}

render() {
return (
<SaveForm
link={this.state.link}
saveForm={this.saveForm}
onChange={this.updateContactState}
errors={this.state.errors}/>
link={this.props.link} />
)
}
}

function mapStateToProps(state, ownProps) {
return {
link: window.location.href.replace(/application(\/)?.*/, `application/${state.application.id}`)
}
}

Expand All @@ -63,7 +31,7 @@ function mapDispatchToProps(dispatch) {
}

SavePage.propTypes = {
actions: PropTypes.object.isRequired
link: PropTypes.string.isRequired
}

export default connect(mapStateToProps, mapDispatchToProps)(SavePage)

0 comments on commit ad505dc

Please sign in to comment.