2026-07-08 12:55:37 +02:00
|
|
|
import { Navigate, Outlet } from 'react-router-dom'
|
2026-07-12 16:27:34 +02:00
|
|
|
import { useEffect, useState } from 'react'
|
2026-07-10 14:26:14 +02:00
|
|
|
import { ModeAreaShell } from '../../components/ModeAreaShell.jsx'
|
|
|
|
|
import { ModeAreaNav } from '../../components/ModeAreaNav.jsx'
|
2026-07-08 12:55:37 +02:00
|
|
|
import { ModeShell } from '../../components/ModeShell.jsx'
|
2026-07-10 14:26:14 +02:00
|
|
|
import { WORK_NAV_ITEMS, resolveWorkNavActiveKey } from '../../config/workNav.js'
|
2026-07-12 16:27:34 +02:00
|
|
|
import { useProgramScope } from '../../context/ProgramScopeContext.jsx'
|
|
|
|
|
import { getActiveWorkCycle } from '../../api/workCycles.js'
|
|
|
|
|
import { getInitiative } from '../../api/initiatives.js'
|
2026-07-08 12:55:37 +02:00
|
|
|
|
|
|
|
|
export function WorkLayout() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="app-page">
|
|
|
|
|
<ModeShell modeKey="work" />
|
2026-07-10 14:26:14 +02:00
|
|
|
<ModeAreaShell
|
|
|
|
|
nav={
|
|
|
|
|
<ModeAreaNav
|
|
|
|
|
modeLabel="Ausführen"
|
|
|
|
|
items={WORK_NAV_ITEMS}
|
|
|
|
|
resolveActiveKey={resolveWorkNavActiveKey}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Outlet />
|
|
|
|
|
</ModeAreaShell>
|
2026-07-08 12:55:37 +02:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function WorkIndexRedirect() {
|
2026-07-12 16:27:34 +02:00
|
|
|
const { initiativeId } = useProgramScope()
|
|
|
|
|
const [target, setTarget] = useState('/work/today')
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!initiativeId) {
|
|
|
|
|
setTarget('/work/today')
|
|
|
|
|
return undefined
|
|
|
|
|
}
|
|
|
|
|
let cancelled = false
|
|
|
|
|
Promise.all([getInitiative(initiativeId), getActiveWorkCycle(initiativeId)])
|
|
|
|
|
.then(([initiative, activeCycle]) => {
|
|
|
|
|
if (cancelled) return
|
|
|
|
|
if (
|
|
|
|
|
initiative?.archetype_key === 'initiative.product' &&
|
|
|
|
|
activeCycle?.id
|
|
|
|
|
) {
|
|
|
|
|
setTarget(`/work/sprint?initiative=${initiativeId}`)
|
|
|
|
|
} else {
|
|
|
|
|
setTarget(`/work/today?initiative=${initiativeId}`)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
if (!cancelled) setTarget('/work/today')
|
|
|
|
|
})
|
|
|
|
|
return () => {
|
|
|
|
|
cancelled = true
|
|
|
|
|
}
|
|
|
|
|
}, [initiativeId])
|
|
|
|
|
|
|
|
|
|
return <Navigate to={target} replace />
|
2026-07-08 12:55:37 +02:00
|
|
|
}
|