Skip to content

Commit

Permalink
Track cadet id stuff, prep work for quizzes
Browse files Browse the repository at this point in the history
  • Loading branch information
queso committed Sep 16, 2018
1 parent 5d40425 commit 3806962
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,26 @@ import { ApolloProvider } from 'react-apollo'
import { ServerStyleSheet } from 'styled-components'

class MyApp extends App {
componentDidMount() {
const cadetId = localStorage.getItem('cadetId') || this.props.router.query.cadet
if (cadetId)
this.setState({cadetId})
}

componentDidUpdate(prevProps, prevState) {
if(this.state && this.state.cadetId) {
localStorage.setItem('cadetId', this.state.cadetId)
}
}

updateCadet = (cadetId) => {
this.setState({cadetId})
}

render () {
const {Component, pageProps, apolloClient} = this.props
pageProps['updateCadet'] = this.updateCadet
pageProps['cadetId'] = this.state && this.state.cadetId
return <Container>
<ApolloProvider client={apolloClient}>
<Component {...pageProps} />
Expand Down
1 change: 1 addition & 0 deletions pages/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Apply extends React.Component {
addCadet({variables: { ...formData }})
.then((response) => {
ref.reset()
this.props.updateCadet(response.data.createCadet.id)
Router.push({ pathname: '/apply-thanks' })
})
.catch((err) => {
Expand Down

0 comments on commit 3806962

Please sign in to comment.