Files

84 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2024-05-17 08:29:06 +04:00
import {createDirectus, rest, readItems} from '@directus/sdk'
2024-05-17 09:00:25 +04:00
import Container from '@mui/material/Container'
import Box from '@mui/material/Box'
2024-05-17 09:00:25 +04:00
import Typography from '@mui/material/Typography'
2024-09-15 18:04:04 +04:00
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings'
2024-06-18 11:10:30 +04:00
import {auth} from '../auth.js'
2024-05-20 04:17:45 +04:00
import Konstitisyon from '@/components/konstitisyon/index.js'
import Footer from '@/components/footer.js'
2024-05-20 04:18:02 +04:00
import Sign from '@/components/session/sign.js'
2024-06-22 07:52:32 +04:00
import Create from '@/components/konstitisyon/create/index.js'
2024-05-17 08:29:06 +04:00
2024-05-17 09:00:25 +04:00
const apiUrl = process.env.DIRECTUS_API_URL
const appTitle = process.env.APP_TITLE
2024-05-17 08:29:06 +04:00
2024-09-15 18:04:04 +04:00
const navButton = {
title: 'Tableau de bord',
path: '/dashboard',
color: 'success',
icon: <AdminPanelSettingsIcon fontSize='large' />
}
2024-05-17 09:00:25 +04:00
async function getData() {
2024-05-17 08:29:06 +04:00
if (!apiUrl) {
throw new Error('DIRECTUS_API_URL is required')
}
const client = createDirectus(apiUrl).with(rest())
try {
const titres = await client.request(
readItems('titres', {
2024-07-02 11:04:24 +02:00
filter: {
status: {
_eq: 'published'
}
},
2024-05-17 08:29:06 +04:00
sort: 'numero'
})
)
const articles = await client.request(
readItems('articles', {
2024-07-02 11:04:24 +02:00
filter: {
status: {
_eq: 'published'
}
},
2024-05-17 08:29:06 +04:00
sort: 'numero'
})
)
return {
titres,
articles
}
2024-12-16 13:34:05 +04:00
} catch (error) {
throw new Error(error.cause)
2024-05-17 08:29:06 +04:00
}
}
export default async function Page() {
2024-06-18 11:10:30 +04:00
const session = await auth()
const {titres, articles} = await getData()
2024-05-16 19:38:20 +04:00
2024-05-17 09:00:25 +04:00
return (
<Box sx={{
display: 'flex',
flexDirection: 'column',
minHeight: '100vh',
}}
>
<Container maxWidth='sm'>
<Typography mt={1} component='h1' textAlign='center' variant='h4'>{appTitle.toUpperCase()}</Typography>
2024-09-15 18:04:04 +04:00
<Sign session={session} navButton={navButton} />
2024-05-20 14:49:31 +04:00
{session && (
<Create session={session} titres={titres} />
2024-05-20 14:49:31 +04:00
)}
<Konstitisyon session={session} titres={titres} articles={articles} />
</Container>
<Footer />
</Box>
2024-05-17 09:00:25 +04:00
)
2024-05-16 02:17:33 +04:00
}