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'
|
2024-05-18 09:37:09 +04:00
|
|
|
import Box from '@mui/material/Box'
|
2024-05-17 09:00:25 +04:00
|
|
|
import Typography from '@mui/material/Typography'
|
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-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', {
|
|
|
|
|
sort: 'numero'
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const articles = await client.request(
|
|
|
|
|
readItems('articles', {
|
|
|
|
|
sort: 'numero'
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (titres.length === 0 || articles.length === 0) {
|
|
|
|
|
throw new Error('No data')
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-18 09:37:09 +04:00
|
|
|
return {
|
|
|
|
|
titres,
|
|
|
|
|
articles
|
|
|
|
|
}
|
2024-05-17 08:29:06 +04:00
|
|
|
} catch {
|
|
|
|
|
throw new Error('Failed to fetch data')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async function Page() {
|
2024-06-18 11:10:30 +04:00
|
|
|
const session = await auth()
|
2024-05-18 09:37:09 +04:00
|
|
|
const {titres, articles} = await getData()
|
2024-05-16 19:38:20 +04:00
|
|
|
|
2024-05-17 09:00:25 +04:00
|
|
|
return (
|
2024-05-18 09:37:09 +04:00
|
|
|
<Box sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
minHeight: '100vh',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Container maxWidth='sm'>
|
|
|
|
|
<Typography mt={1} component='h1' textAlign='center' variant='h4'>{appTitle.toUpperCase()}</Typography>
|
2024-05-20 04:18:02 +04:00
|
|
|
<Sign session={session} />
|
2024-05-20 14:49:31 +04:00
|
|
|
{session && (
|
2024-06-22 07:52:32 +04:00
|
|
|
<Create session={session} />
|
2024-05-20 14:49:31 +04:00
|
|
|
)}
|
|
|
|
|
<Konstitisyon session={session} titres={titres} articles={articles} />
|
2024-05-18 09:37:09 +04:00
|
|
|
</Container>
|
|
|
|
|
<Footer />
|
|
|
|
|
</Box>
|
2024-05-17 09:00:25 +04:00
|
|
|
)
|
2024-05-16 02:17:33 +04:00
|
|
|
}
|