This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/website/pages/functions/[slug].jsx

69 lines
2.0 KiB
React
Raw Normal View History

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'
const FunctionTabManager = props => {
2020-08-03 12:04:07 +02:00
if (props.type === 'form') {
return (
<FunctionTabs
setSlideIndex={props.setSlideIndex}
slideIndex={props.slideIndex}
>
2020-08-03 12:04:07 +02:00
<div className='FunctionComponent__slide'>
<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 (
<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>
)
}
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-08-03 12:04:07 +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 }))
2020-08-03 12:04:07 +02:00
.catch(() => redirect(context, '/404'))
}
2020-08-03 12:04:07 +02:00
export default FunctionComponent