'use client'
import {useState, useRef, useEffect} from 'react'
import PropTypes from 'prop-types'
import Grid from '@mui/material/Grid2'
import Typography from '@mui/material/Typography'
import Box from '@mui/material/Box'
import AuthAlert from '../auth-form/auth-alert.js'
import LogoutCountdown from '../session/logout-countdown.js'
import {Loading} from '../loading.js'
import ListVersions from './list-versions.js'
import {listVersions} from '@/lib/directus.js'
export default function GetVersions({session}) {
const {accessToken, userId} = session.user
const [versions, setVersions] = useState(null)
const [isErrorAlertOpen, setIsErrorAlertOpen] = useState(false)
const [error, setError] = useState('')
const countdownRef = useRef()
useEffect(() => {
async function fetchVersions() {
const data = await listVersions({
accessToken, userId, countdownRef, setError, setIsErrorAlertOpen
})
setVersions(data)
}
fetchVersions()
}, [accessToken, userId])
if (!versions) {
return (
<>
{error && }
>
)
}
const titres = versions?.filter(({collection}) => collection === 'titres')
const articles = versions?.filter(({collection}) => collection === 'articles')
return (
<>
{error && }
Liste des versions
0 && articles.length === 0) || (articles.length > 0 && titres.length === 0)
? 'center'
: 'flex-start'
}
>
{titres.length > 0 && (
0 ? 6 : 12}}>
)}
{articles.length > 0 && (
0 ? 6 : 12}}>
)}
>
)
}
GetVersions.propTypes = {
session: PropTypes.object.isRequired
}