Kairo-Jinkendo/frontend/src/pages/objects/ProjectObjectPage.jsx
Lars e42edd86fa
Some checks failed
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Failing after 1m46s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
AP1.9a: Arbeitsmodi-Shell mit Scope, Objekt-Routen und Legacy-Redirects.
Ersetzt die Vorhaben-Tab-Navigation durch Cockpit/Ausführen/Planen/Kontrolle/Team, Deep Links für APs/Projekte/Gates und Programm-Scope im Header.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-08 12:55:37 +02:00

90 lines
2.6 KiB
JavaScript

import { useEffect, useState } from 'react'
import { useParams, useSearchParams } from 'react-router-dom'
import { getProject } from '../../api/projects.js'
import { LoadingState } from '../../components/LoadingState.jsx'
import { ErrorState } from '../../components/ErrorState.jsx'
import { useProgramScope } from '../../context/ProgramScopeContext.jsx'
import { ScopedInitiativeProvider } from '../../layout/ScopedInitiativeProvider.jsx'
import { ProjectDetailPage } from '../initiative/ProjectDetailPage.jsx'
import { recordRecentObject } from '../../utils/recentObjects.js'
import { projectPath } from '../../utils/routes.js'
export function ProjectObjectPage() {
const { projectId } = useParams()
const [searchParams] = useSearchParams()
const { initiativeId: scopeInitiativeId, applyFromInitiative, applyFromProject } =
useProgramScope()
const initiativeFromQuery = searchParams.get('initiative') || scopeInitiativeId
const [project, setProject] = useState(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState(null)
useEffect(() => {
if (projectId === 'new') {
if (initiativeFromQuery) applyFromInitiative(initiativeFromQuery)
setProject(null)
setLoading(false)
return
}
let cancelled = false
setLoading(true)
setError(null)
getProject(projectId)
.then((data) => {
if (cancelled) return
setProject(data)
applyFromProject(data)
recordRecentObject({
type: 'project',
id: data.id,
title: data.title,
href: projectPath(data.id),
initiativeId: data.initiative_id,
})
})
.catch((err) => {
if (!cancelled) setError(err.message)
})
.finally(() => {
if (!cancelled) setLoading(false)
})
return () => {
cancelled = true
}
}, [projectId, initiativeFromQuery, applyFromInitiative, applyFromProject])
if (loading) {
return (
<div className="app-page">
<LoadingState message="Lade Projekt …" />
</div>
)
}
if (error) {
return (
<div className="app-page">
<ErrorState message={error} />
</div>
)
}
const initiativeId = project?.initiative_id || initiativeFromQuery
if (projectId === 'new' && !initiativeId) {
return (
<div className="app-page">
<ErrorState message="Für ein neues Projekt braucht es ein Vorhaben im Scope (?initiative=)." />
</div>
)
}
return (
<div className="app-page">
<ScopedInitiativeProvider initiativeId={initiativeId}>
<ProjectDetailPage />
</ScopedInitiativeProvider>
</div>
)
}