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