build: upgrade Mui & d'autres lib liées

This commit is contained in:
2026-01-04 11:00:48 +04:00
parent 5679d71b5b
commit 47d58680b3
5 changed files with 166 additions and 207 deletions
+59 -10
View File
@@ -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'