build: upgrade Mui & d'autres lib liées
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import {useState, useRef, useEffect} from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import Grid from '@mui/material/Grid2'
|
||||
import Grid from '@mui/material/Grid'
|
||||
import Typography from '@mui/material/Typography'
|
||||
import HomeIcon from '@mui/icons-material/Home'
|
||||
import Box from '@mui/material/Box'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Box from '@mui/material/Box'
|
||||
import Typography from '@mui/material/Typography'
|
||||
import Paper from '@mui/material/Paper'
|
||||
import Grid from '@mui/material/Grid2'
|
||||
import Grid from '@mui/material/Grid'
|
||||
import PropTypes from 'prop-types'
|
||||
import Snackbar from '@mui/material/Snackbar'
|
||||
import Alert from '@mui/material/Alert'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {useRef, useState} from 'react'
|
||||
import {useRef, useState, useEffect} from 'react'
|
||||
import {useTheme} from '@mui/material/styles'
|
||||
import PropTypes from 'prop-types'
|
||||
import Box from '@mui/material/Box'
|
||||
@@ -34,17 +34,25 @@ import PrintButton from './print-button.js'
|
||||
import {formatDate} from '@/lib/format.js'
|
||||
import {compareVersion} from '@/lib/directus.js'
|
||||
|
||||
function getVersionStatus(version, index, totalVersions) {
|
||||
function getVersionStatus(version, index, totalVersions, data) {
|
||||
// Logic to determine version status based on position and data
|
||||
if (index === 0) {
|
||||
return 'current' // Most recent
|
||||
}
|
||||
// Find which version is the "main" (published) by checking if it matches current content
|
||||
// This would require the current item content to be passed
|
||||
// For now, we assume the most recent is current unless it's been promoted
|
||||
|
||||
// Check if this is the initial version
|
||||
if (index === totalVersions - 1) {
|
||||
return 'initial' // First version
|
||||
}
|
||||
|
||||
return 'archived' // Intermediate versions
|
||||
// If there's a more recent version after this one, this is outdated
|
||||
// unless this IS the main version (would need item content to determine)
|
||||
if (index > 0) {
|
||||
return 'outdated' // Older versions are outdated
|
||||
}
|
||||
|
||||
// Most recent version is current (being edited/proposed)
|
||||
return 'current'
|
||||
}
|
||||
|
||||
function getStatusConfig(status) {
|
||||
@@ -115,15 +123,56 @@ function VersionCard({
|
||||
onVoteResult
|
||||
}) {
|
||||
const theme = useTheme()
|
||||
const status = getVersionStatus(version, index, totalVersions)
|
||||
const [versionStatus, setVersionStatus] = useState(null)
|
||||
const [isOutdated, setIsOutdated] = useState(false)
|
||||
|
||||
// Fetch real status from API
|
||||
useEffect(() => {
|
||||
async function fetchVersionStatus() {
|
||||
try {
|
||||
const comparisonData = await compareVersion({
|
||||
accessToken,
|
||||
userId,
|
||||
versionId: version.id,
|
||||
countdownRef,
|
||||
setError,
|
||||
setIsErrorAlertOpen
|
||||
})
|
||||
|
||||
if (comparisonData) {
|
||||
// Store outdated flag for vote disabling
|
||||
setIsOutdated(comparisonData.outdated)
|
||||
|
||||
// Determine status based on API response
|
||||
let status
|
||||
if (comparisonData.outdated) {
|
||||
status = 'outdated'
|
||||
} else if (index === totalVersions - 1) {
|
||||
status = 'initial'
|
||||
} else {
|
||||
status = 'current'
|
||||
}
|
||||
setVersionStatus(status)
|
||||
}
|
||||
} catch (error) {
|
||||
// Fallback to position-based status on error
|
||||
setVersionStatus(getVersionStatus(version, index, totalVersions, null))
|
||||
}
|
||||
}
|
||||
|
||||
fetchVersionStatus()
|
||||
}, [version.id, index, totalVersions, accessToken, userId, countdownRef, setError, setIsErrorAlertOpen])
|
||||
|
||||
const status = versionStatus || getVersionStatus(version, index, totalVersions, null)
|
||||
|
||||
const statusConfig = getStatusConfig(status)
|
||||
const userDisplayName = version.user_created?.split('-')[0] || 'Système'
|
||||
|
||||
// Check if voting is disabled (after 3 days)
|
||||
// Check if voting is disabled (after 3 days OR if outdated)
|
||||
const createdAt = new Date(version.date_created)
|
||||
const threeDaysAgo = new Date(Date.now() - (3 * 24 * 60 * 60 * 1000))
|
||||
const isVoteDisabled = createdAt < threeDaysAgo
|
||||
const isExpired = createdAt < threeDaysAgo
|
||||
const isVoteDisabled = isExpired || isOutdated
|
||||
|
||||
const handleCompareClick = async () => {
|
||||
const comparisonData = await compareVersion({
|
||||
@@ -214,7 +263,7 @@ function VersionCard({
|
||||
size='small'
|
||||
variant='outlined'
|
||||
/>
|
||||
{isVoteDisabled && (
|
||||
{isExpired && !isOutdated && (
|
||||
<Chip
|
||||
label='Vote fermé'
|
||||
color='error'
|
||||
|
||||
Reference in New Issue
Block a user