2017-03-15 14:24:54 +00:00
|
|
|
import React from 'react'
|
2017-04-10 18:35:26 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2018-12-17 16:34:32 +00:00
|
|
|
import { Link } from 'next-url-prettifier'
|
|
|
|
import { Router } from '../routes'
|
2017-03-15 14:24:54 +00:00
|
|
|
|
|
|
|
export default class GreetingPage extends React.Component {
|
2018-12-17 16:34:32 +00:00
|
|
|
static getInitialProps ({ query: { lang, name } }) {
|
|
|
|
return { lang, name }
|
2017-03-15 14:24:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 04:06:33 +00:00
|
|
|
renderSwitchLanguageLink () {
|
2018-12-17 16:34:32 +00:00
|
|
|
const { lang, name } = this.props
|
2017-03-15 14:24:54 +00:00
|
|
|
const switchLang = lang === 'fr' ? 'en' : 'fr'
|
|
|
|
return (
|
2018-12-17 16:34:32 +00:00
|
|
|
<Link route={Router.linkPage('greeting', { name, lang: switchLang })}>
|
2017-03-15 14:24:54 +00:00
|
|
|
<a>{switchLang === 'fr' ? 'Français' : 'English'}</a>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-12-17 16:34:32 +00:00
|
|
|
const { lang, name } = this.props
|
2017-03-15 14:24:54 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2018-12-17 16:34:32 +00:00
|
|
|
<h1>
|
|
|
|
{lang === 'fr' ? 'Bonjour' : 'Hello'} {name}
|
|
|
|
</h1>
|
2017-05-03 04:06:33 +00:00
|
|
|
<div>{this.renderSwitchLanguageLink()}</div>
|
2017-03-15 14:24:54 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GreetingPage.propTypes = {
|
2017-04-10 18:35:26 +00:00
|
|
|
lang: PropTypes.string,
|
|
|
|
name: PropTypes.string
|
2017-03-15 14:24:54 +00:00
|
|
|
}
|