2020-08-03 12:04:07 +02:00
|
|
|
import FunctionTabs from '../../components/FunctionPage/FunctionTabs'
|
|
|
|
import FunctionForm from '../../components/FunctionPage/FunctionForm'
|
|
|
|
import FunctionArticle from '../../components/FunctionPage/FunctionArticle'
|
|
|
|
import FunctionComments from '../../components/FunctionPage/FunctionComments/FunctionComments'
|
|
|
|
import FunctionPage from '../../components/FunctionPage/FunctionPage'
|
|
|
|
import redirect from '../../utils/redirect'
|
|
|
|
import api from '../../utils/api'
|
2020-03-21 23:54:08 +01:00
|
|
|
|
2020-08-03 14:37:05 +02:00
|
|
|
const FunctionTabManager = props => {
|
2020-08-03 12:04:07 +02:00
|
|
|
if (props.type === 'form') {
|
2020-03-21 23:54:08 +01:00
|
|
|
return (
|
2020-08-03 14:37:05 +02:00
|
|
|
<FunctionTabs
|
|
|
|
setSlideIndex={props.setSlideIndex}
|
|
|
|
slideIndex={props.slideIndex}
|
|
|
|
>
|
2020-08-03 12:04:07 +02:00
|
|
|
<div className='FunctionComponent__slide'>
|
2020-08-03 14:37:05 +02:00
|
|
|
<FunctionForm
|
|
|
|
inputsArray={[...(props.utilizationForm || [])]}
|
|
|
|
slug={props.slug}
|
|
|
|
/>
|
2020-08-03 12:04:07 +02:00
|
|
|
</div>
|
|
|
|
<div className='FunctionComponent__slide'>
|
|
|
|
<FunctionArticle article={props.article} />
|
|
|
|
</div>
|
|
|
|
<div className='FunctionComponent__slide'>
|
|
|
|
<FunctionComments functionId={props.id} />
|
|
|
|
</div>
|
|
|
|
</FunctionTabs>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-08-03 14:37:05 +02:00
|
|
|
<FunctionTabs
|
|
|
|
setSlideIndex={props.setSlideIndex}
|
|
|
|
slideIndex={props.slideIndex}
|
|
|
|
>
|
2020-08-03 12:04:07 +02:00
|
|
|
<div className='FunctionComponent__slide'>
|
|
|
|
<FunctionArticle article={props.article} />
|
|
|
|
</div>
|
|
|
|
<div className='FunctionComponent__slide'>
|
|
|
|
<FunctionComments functionId={props.id} />
|
|
|
|
</div>
|
|
|
|
</FunctionTabs>
|
|
|
|
)
|
2020-03-21 23:54:08 +01:00
|
|
|
}
|
|
|
|
|
2020-08-03 14:37:05 +02:00
|
|
|
const FunctionComponent = props => (
|
2020-08-03 12:04:07 +02:00
|
|
|
<FunctionPage
|
|
|
|
FunctionTabManager={FunctionTabManager}
|
|
|
|
{...props}
|
2020-08-03 14:37:05 +02:00
|
|
|
tabNames={
|
|
|
|
props.type === 'form'
|
|
|
|
? ['⚙️ Utilisation', '📝 Article', '📬 Commentaires']
|
|
|
|
: ['📝 Article', '📬 Commentaires']
|
|
|
|
}
|
2020-08-03 12:04:07 +02:00
|
|
|
/>
|
|
|
|
)
|
2020-04-23 17:31:36 +02:00
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
export async function getServerSideProps (context) {
|
|
|
|
const { slug } = context.params
|
2020-08-03 14:37:05 +02:00
|
|
|
return api
|
|
|
|
.get(`/functions/${slug}`)
|
|
|
|
.then(response => ({ props: response.data }))
|
2020-08-03 12:04:07 +02:00
|
|
|
.catch(() => redirect(context, '/404'))
|
2020-03-23 21:22:41 +01:00
|
|
|
}
|
|
|
|
|
2020-08-03 12:04:07 +02:00
|
|
|
export default FunctionComponent
|