import { Fragment, useState } from 'react'; import Cookies from "universal-cookie"; import SwipeableViews from 'react-swipeable-views'; import HeadTag from '../../components/HeadTag'; import AddEditFunction from '../../components/AddEditFunction'; import EditArticleFunction from '../../components/EditArticleFunction'; import EditFormFunction from '../../components/EditFormFunction'; import redirect from '../../utils/redirect'; import api from '../../utils/api'; import { API_URL } from '../../utils/config'; import '../../components/FunctionTabs/FunctionTabs.css'; import '../../public/css/pages/admin.css'; const AdminFunctionComponent = (props) => { const [slideIndex, setSlideIndex] = useState(0); return (
setSlideIndex(index)} index={slideIndex}>
); } export async function getServerSideProps(context) { const cookies = new Cookies(context.req.headers.cookie); const user = { ...cookies.get('user') }; const { slug } = context.params; if (!user.isAdmin) { return redirect(context, '/404'); } return api.get(`/admin/functions/${slug}`, { headers: { 'Authorization': user.token } }) .then((response) => { return { props: { user, functionInfo: response.data } }; }) .catch(() => redirect(context, '/404')); } export default AdminFunctionComponent;