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].js
2020-04-23 17:31:36 +02:00

54 lines
2.1 KiB
JavaScript

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) => {
if (props.type === "form") {
return (
<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>
);
}
const FunctionComponent = (props) => (
<FunctionPage
FunctionTabManager={FunctionTabManager}
{ ...props }
tabNames={(props.type === "form") ? ["⚙️ Utilisation", "📝 Article", "📬 Commentaires"] : ["📝 Article", "📬 Commentaires"]}
/>
);
export async function getServerSideProps(context) {
const { slug } = context.params;
return api.get(`/functions/${slug}`)
.then((response) => ({ props: response.data }))
.catch(() => redirect(context, '/404'));
}
export default FunctionComponent;