feat(simulations): resume session + RapportPage tolère rapport=null (FTD-21)

This commit is contained in:
Hermann_Kitio 2026-04-21 04:52:51 +03:00
parent aaecc3f804
commit ae8d8af1df
2 changed files with 48 additions and 5 deletions

View file

@ -11,6 +11,7 @@
* Règle H : logique de floutage dans entities/report/lib.ts.
*/
import { useEffect } from 'react'
import ReactMarkdown from 'react-markdown'
import { Link, useNavigate, useParams } from 'react-router-dom'
import { useQuery } from '@tanstack/react-query'
@ -23,6 +24,15 @@ import { Badge } from '@/shared/ui/Badge'
import { Button } from '@/shared/ui/Button'
import type { Critere } from '@/entities/report/types'
function isReportNotReady(err: unknown): boolean {
return (
typeof err === 'object' &&
err !== null &&
'code' in err &&
(err as { code: unknown }).code === 'REPORT_NOT_READY'
)
}
// ── Composants internes ──────────────────────────────────────────────────────
function RapportSkeleton() {
@ -105,7 +115,16 @@ export function RapportPage() {
const { id = '' } = useParams<{ id: string }>()
const navigate = useNavigate()
const { rapport, isLoading, isError } = useRapport(id)
const { rapport, isLoading, isError, error } = useRapport(id)
const isInProgress = isError && isReportNotReady(error)
// FTD-21 — si la simulation n'est pas encore corrigée, rediriger vers /simulation/ee.
// Le SimulationFlowProvider restaurera la session via localStorage si présent.
useEffect(() => {
if (isInProgress) {
navigate('/simulation/ee', { replace: true })
}
}, [isInProgress, navigate])
const {
data: planData,
@ -137,8 +156,15 @@ export function RapportPage() {
{/* Loading */}
{(isLoading || isPlanLoading) && <RapportSkeleton />}
{/* Erreur */}
{(isError || isPlanError) && !isLoading && !isPlanLoading && (
{/* FTD-21 — simulation en cours : message discret avant redirection via useEffect */}
{isInProgress && (
<p className="text-center text-sm text-ink-4" aria-live="polite">
Votre simulation est en cours.
</p>
)}
{/* Erreur (hors "en cours" déjà géré au-dessus) */}
{(isError || isPlanError) && !isInProgress && !isLoading && !isPlanLoading && (
<div
role="alert"
className="space-y-3 rounded-lg border border-danger/30 bg-danger-bg px-4 py-6 text-center"