feat: update version and enhance training unit management features
- Bumped application version to 0.8.11 and updated database schema version. - Added new API features for training units, including filtering by club and assigned trainer. - Enhanced the TrainingPlanningPage with options to filter training units by club and assigned trainer, improving user experience. - Implemented lead trainer assignment functionality, allowing users to take lead on training units. - Updated changelog with new version details and changes.
This commit is contained in:
1 parent
e69de82028
commit
0748990328
6 files changed
+511
-26
No files matched your search
@@ -1,18 +1,86 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { useAuth } from '../context/AuthContext'
|
||||
import api from '../utils/api'
|
||||
import EmailVerificationBanner from '../components/EmailVerificationBanner'
|
||||
|
||||
function unitWhenLabel(u) {
|
||||
const d = u.planned_date ? String(u.planned_date).slice(0, 10) : ''
|
||||
const t = u.planned_time_start ? String(u.planned_time_start).slice(0, 5) : ''
|
||||
const bits = [d, t].filter(Boolean)
|
||||
return bits.length ? bits.join(' · ') : 'Termin'
|
||||
}
|
||||
|
||||
function Dashboard() {
|
||||
const [version, setVersion] = useState(null)
|
||||
const [profile, setProfile] = useState(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [trainingHome, setTrainingHome] = useState(null)
|
||||
const [trainingHomeErr, setTrainingHomeErr] = useState(null)
|
||||
const { user } = useAuth()
|
||||
|
||||
useEffect(() => {
|
||||
loadData()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!user?.id) {
|
||||
setTrainingHome(null)
|
||||
setTrainingHomeErr(null)
|
||||
return undefined
|
||||
}
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
setTrainingHomeErr(null)
|
||||
try {
|
||||
const today = new Date().toISOString().slice(0, 10)
|
||||
const [upcomingRaw, recentRaw, plannedPool] = await Promise.all([
|
||||
api.listTrainingUnits({
|
||||
assigned_to_me: true,
|
||||
status: 'planned',
|
||||
start_date: today,
|
||||
sort: 'asc',
|
||||
limit: 8
|
||||
}),
|
||||
api.listTrainingUnits({
|
||||
assigned_to_me: true,
|
||||
status: 'completed',
|
||||
sort: 'desc',
|
||||
limit: 6
|
||||
}),
|
||||
api.listTrainingUnits({
|
||||
assigned_to_me: true,
|
||||
status: 'planned',
|
||||
start_date: today,
|
||||
sort: 'asc',
|
||||
limit: 40
|
||||
})
|
||||
])
|
||||
const noteHits = (plannedPool || []).filter((u) => {
|
||||
const tn = (u.trainer_notes || '').trim()
|
||||
const n = (u.notes || '').trim()
|
||||
return Boolean(tn || n)
|
||||
}).slice(0, 5)
|
||||
if (!cancelled) {
|
||||
setTrainingHome({
|
||||
upcoming: Array.isArray(upcomingRaw) ? upcomingRaw : [],
|
||||
recent: Array.isArray(recentRaw) ? recentRaw : [],
|
||||
plannedWithNotes: noteHits
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
if (!cancelled) {
|
||||
console.error('Dashboard Trainingsübersicht:', e)
|
||||
setTrainingHomeErr(e.message || 'Konnte Trainingsdaten nicht laden')
|
||||
setTrainingHome(null)
|
||||
}
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [user?.id])
|
||||
|
||||
const loadData = async () => {
|
||||
try {
|
||||
const [versionData, profileData] = await Promise.all([
|
||||
@@ -52,6 +120,101 @@ function Dashboard() {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{user?.id && (
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(auto-fit, minmax(min(100%, 280px), 1fr))',
|
||||
gap: '1rem',
|
||||
marginBottom: '1.5rem'
|
||||
}}
|
||||
>
|
||||
<div className="card">
|
||||
<h3 style={{ fontSize: '1.05rem', marginBottom: '0.65rem' }}>Deine nächsten Trainings</h3>
|
||||
{trainingHomeErr ? (
|
||||
<p style={{ color: 'var(--danger)', fontSize: '0.9rem' }}>{trainingHomeErr}</p>
|
||||
) : trainingHome?.upcoming?.length ? (
|
||||
<ul style={{ margin: 0, paddingLeft: '1.15rem', color: 'var(--text2)', fontSize: '0.9rem', lineHeight: 1.55 }}>
|
||||
{trainingHome.upcoming.map((u) => (
|
||||
<li key={u.id} style={{ marginBottom: '0.35rem' }}>
|
||||
<Link to={`/planning/run/${u.id}`} style={{ fontWeight: 600, color: 'var(--accent-dark)' }}>
|
||||
{unitWhenLabel(u)}
|
||||
</Link>
|
||||
{u.group_name ? (
|
||||
<span style={{ color: 'var(--text3)' }}>{` — ${u.group_name}`}</span>
|
||||
) : null}
|
||||
{u.lead_trainer_name ? (
|
||||
<span style={{ display: 'block', fontSize: '0.82rem', color: 'var(--text3)', marginTop: '2px' }}>
|
||||
Leitung: {u.lead_trainer_name}
|
||||
</span>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.9rem', margin: 0 }}>
|
||||
Keine anstehenden Termine mit dir als Leitung oder Co‑Trainer. Unter{' '}
|
||||
<Link to="/planning" style={{ color: 'var(--accent-dark)' }}>
|
||||
Trainingsplanung
|
||||
</Link>{' '}
|
||||
kannst du den Vereins‑ oder Gruppen‑Zeitraum einblenden.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<h3 style={{ fontSize: '1.05rem', marginBottom: '0.65rem' }}>Vermerk / Hinweise (anstehend)</h3>
|
||||
{trainingHomeErr ? (
|
||||
<p style={{ color: 'var(--danger)', fontSize: '0.9rem' }}>{trainingHomeErr}</p>
|
||||
) : trainingHome?.plannedWithNotes?.length ? (
|
||||
<ul style={{ margin: 0, paddingLeft: '1.15rem', color: 'var(--text2)', fontSize: '0.88rem', lineHeight: 1.5 }}>
|
||||
{trainingHome.plannedWithNotes.map((u) => {
|
||||
const snippet = (u.trainer_notes || u.notes || '').trim().slice(0, 120)
|
||||
return (
|
||||
<li key={`n-${u.id}`} style={{ marginBottom: '0.5rem' }}>
|
||||
<Link to={`/planning/run/${u.id}`} style={{ fontWeight: 600, color: 'var(--accent-dark)' }}>
|
||||
{unitWhenLabel(u)}
|
||||
</Link>
|
||||
{u.group_name ? <span style={{ color: 'var(--text3)' }}>{` · ${u.group_name}`}</span> : null}
|
||||
<div style={{ color: 'var(--text2)', marginTop: '4px' }}>
|
||||
{snippet}
|
||||
{(u.trainer_notes || u.notes || '').trim().length > 120 ? '…' : ''}
|
||||
</div>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
) : (
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.9rem', margin: 0 }}>
|
||||
Keine Einträge mit Allgemein‑ oder Trainer‑Notizen in deinen nächsten geplanten Terminen.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<h3 style={{ fontSize: '1.05rem', marginBottom: '0.65rem' }}>Rückschau (durchgeführt)</h3>
|
||||
{trainingHomeErr ? (
|
||||
<p style={{ color: 'var(--danger)', fontSize: '0.9rem' }}>{trainingHomeErr}</p>
|
||||
) : trainingHome?.recent?.length ? (
|
||||
<ul style={{ margin: 0, paddingLeft: '1.15rem', color: 'var(--text2)', fontSize: '0.9rem', lineHeight: 1.55 }}>
|
||||
{trainingHome.recent.map((u) => (
|
||||
<li key={`r-${u.id}`} style={{ marginBottom: '0.35rem' }}>
|
||||
<Link to={`/planning/run/${u.id}`} style={{ fontWeight: 600, color: 'var(--accent-dark)' }}>
|
||||
{(u.actual_date || u.planned_date || '').toString().slice(0, 10) || 'Datum'}
|
||||
</Link>
|
||||
{u.group_name ? (
|
||||
<span style={{ color: 'var(--text3)' }}>{` — ${u.group_name}`}</span>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.9rem', margin: 0 }}>Noch keine abgeschlossenen Einheiten in der Kurzliste.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Status Grid */}
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
|
||||
@@ -105,6 +105,8 @@ function TrainingPlanningPage() {
|
||||
const [endDate, setEndDate] = useState(thirtyDaysLater)
|
||||
const [planView, setPlanView] = useState('list')
|
||||
const [calendarMonthStr, setCalendarMonthStr] = useState(() => today.slice(0, 7))
|
||||
const [planScope, setPlanScope] = useState('group')
|
||||
const [assignedToMeOnly, setAssignedToMeOnly] = useState(false)
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
group_id: '',
|
||||
@@ -162,17 +164,37 @@ function TrainingPlanningPage() {
|
||||
start = r.gridStart
|
||||
end = r.gridEnd
|
||||
}
|
||||
const gid = parseInt(selectedGroupId, 10)
|
||||
const groupRow = groups.find((g) => g.id === gid)
|
||||
const clubId = groupRow?.club_id
|
||||
try {
|
||||
const unitsData = await api.listTrainingUnits({
|
||||
group_id: selectedGroupId,
|
||||
const filters = {
|
||||
start_date: start,
|
||||
end_date: end
|
||||
})
|
||||
}
|
||||
if (assignedToMeOnly) {
|
||||
filters.assigned_to_me = true
|
||||
}
|
||||
if (planScope === 'club' && clubId) {
|
||||
filters.club_id = clubId
|
||||
} else {
|
||||
filters.group_id = gid
|
||||
}
|
||||
const unitsData = await api.listTrainingUnits(filters)
|
||||
setUnits(unitsData)
|
||||
} catch (err) {
|
||||
console.error('Failed to load units:', err)
|
||||
}
|
||||
}, [selectedGroupId, startDate, endDate, planView, calendarMonthStr])
|
||||
}, [
|
||||
selectedGroupId,
|
||||
groups,
|
||||
startDate,
|
||||
endDate,
|
||||
planView,
|
||||
calendarMonthStr,
|
||||
planScope,
|
||||
assignedToMeOnly
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
loadData()
|
||||
@@ -455,6 +477,16 @@ function TrainingPlanningPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const handleTakeLead = async (unit) => {
|
||||
if (!user?.id) return
|
||||
try {
|
||||
await api.updateTrainingUnit(unit.id, { lead_trainer_profile_id: user.id })
|
||||
await loadUnits()
|
||||
} catch (err) {
|
||||
alert(err.message || 'Leitung konnte nicht übernommen werden')
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (unit) => {
|
||||
if (!confirm(`Trainingseinheit vom ${unit.planned_date} wirklich löschen?`)) return
|
||||
try {
|
||||
@@ -759,6 +791,93 @@ function TrainingPlanningPage() {
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div
|
||||
style={{
|
||||
gridColumn: '1 / -1',
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
alignItems: 'center',
|
||||
gap: '12px',
|
||||
}}
|
||||
>
|
||||
<span className="form-label" style={{ marginBottom: 0, alignSelf: 'center' }}>
|
||||
Einblenden
|
||||
</span>
|
||||
<div
|
||||
role="group"
|
||||
aria-label="Gruppe oder ganzer Verein"
|
||||
style={{
|
||||
display: 'inline-flex',
|
||||
borderRadius: '10px',
|
||||
border: '1.5px solid var(--border2)',
|
||||
overflow: 'hidden',
|
||||
background: 'var(--surface2)',
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={planScope === 'group'}
|
||||
disabled={!selectedGroupId}
|
||||
onClick={() => setPlanScope('group')}
|
||||
style={{
|
||||
border: 'none',
|
||||
padding: '8px 14px',
|
||||
fontWeight: 600,
|
||||
fontSize: '0.85rem',
|
||||
cursor: selectedGroupId ? 'pointer' : 'not-allowed',
|
||||
opacity: selectedGroupId ? 1 : 0.55,
|
||||
background: planScope === 'group' ? 'var(--accent-dark)' : 'transparent',
|
||||
color: planScope === 'group' ? '#fff' : 'var(--text1)',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
Nur diese Gruppe
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={planScope === 'club'}
|
||||
disabled={!selectedGroupId}
|
||||
onClick={() => setPlanScope('club')}
|
||||
style={{
|
||||
border: 'none',
|
||||
borderLeft: '1.5px solid var(--border2)',
|
||||
padding: '8px 14px',
|
||||
fontWeight: 600,
|
||||
fontSize: '0.85rem',
|
||||
cursor: selectedGroupId ? 'pointer' : 'not-allowed',
|
||||
opacity: selectedGroupId ? 1 : 0.55,
|
||||
background: planScope === 'club' ? 'var(--accent-dark)' : 'transparent',
|
||||
color: planScope === 'club' ? '#fff' : 'var(--text1)',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
Ganzer Verein
|
||||
</button>
|
||||
</div>
|
||||
<label
|
||||
style={{
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
gap: '8px',
|
||||
fontSize: '0.88rem',
|
||||
color: 'var(--text2)',
|
||||
cursor: selectedGroupId ? 'pointer' : 'default',
|
||||
opacity: selectedGroupId ? 1 : 0.65,
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={assignedToMeOnly}
|
||||
disabled={!selectedGroupId}
|
||||
onChange={(e) => setAssignedToMeOnly(e.target.checked)}
|
||||
/>
|
||||
Nur meine Zuordnung (Leitung / Co)
|
||||
</label>
|
||||
<span style={{ fontSize: '0.78rem', color: 'var(--text3)', lineHeight: 1.4, flex: '1 1 200px' }}>
|
||||
„Ganzer Verein“ nutzt den Verein der gewählten Gruppe; neue Termine unten gelten weiter für die gewählte Gruppe.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{selectedGroup && (
|
||||
@@ -950,7 +1069,9 @@ function TrainingPlanningPage() {
|
||||
type="button"
|
||||
onClick={() => handleEdit(unit)}
|
||||
title={[
|
||||
planScope === 'club' && unit.group_name ? unit.group_name : '',
|
||||
unit.planned_time_start?.slice(0, 5) || '',
|
||||
unit.lead_trainer_name?.trim(),
|
||||
unit.planned_focus?.trim(),
|
||||
unit.status === 'completed'
|
||||
? 'Durchgeführt'
|
||||
@@ -986,6 +1107,18 @@ function TrainingPlanningPage() {
|
||||
? `${unit.planned_time_start.slice(0, 5)}`
|
||||
: 'Ganztags'}
|
||||
</span>
|
||||
{planScope === 'club' && (unit.group_name || '').trim() ? (
|
||||
<span style={{ display: 'block', fontWeight: 500, color: 'var(--text1)' }}>
|
||||
{(unit.group_name || '').trim().length > 22
|
||||
? `${(unit.group_name || '').trim().slice(0, 22)}…`
|
||||
: unit.group_name}
|
||||
</span>
|
||||
) : null}
|
||||
{unit.lead_trainer_name?.trim() ? (
|
||||
<span style={{ display: 'block', color: 'var(--text3)', fontWeight: 400, fontSize: '0.62rem' }}>
|
||||
{unit.lead_trainer_name.trim().split(/\s+/).slice(-1)[0] || unit.lead_trainer_name.trim()}
|
||||
</span>
|
||||
) : null}
|
||||
{unit.planned_focus?.trim() ? (
|
||||
<span style={{ display: 'block', color: 'var(--text2)', fontWeight: 400 }}>
|
||||
{(unit.planned_focus || '').trim().length > 24
|
||||
@@ -1017,6 +1150,13 @@ function TrainingPlanningPage() {
|
||||
<div style={{ display: 'grid', gap: '1rem' }}>
|
||||
{units.map((unit) => {
|
||||
const lineage = unit.origin_framework_slot_id ? frameworkLineageText(unit) : null
|
||||
const uid = user?.id != null ? Number(user.id) : null
|
||||
const effLead =
|
||||
unit.effective_lead_trainer_profile_id != null
|
||||
? Number(unit.effective_lead_trainer_profile_id)
|
||||
: null
|
||||
const showTakeLead =
|
||||
unit.status === 'planned' && uid != null && effLead != null && effLead !== uid
|
||||
return (
|
||||
<div key={unit.id} className="card">
|
||||
<div
|
||||
@@ -1035,6 +1175,20 @@ function TrainingPlanningPage() {
|
||||
{unit.planned_time_start &&
|
||||
` · ${unit.planned_time_start.slice(0, 5)} - ${unit.planned_time_end?.slice(0, 5)}`}
|
||||
</h3>
|
||||
{planScope === 'club' && (unit.group_name || '').trim() ? (
|
||||
<p
|
||||
style={{
|
||||
fontSize: '0.85rem',
|
||||
color: 'var(--text3)',
|
||||
margin: '0 0 0.35rem',
|
||||
}}
|
||||
>
|
||||
{unit.group_name}
|
||||
</p>
|
||||
) : null}
|
||||
<p style={{ fontSize: '0.82rem', color: 'var(--text2)', margin: '0 0 0.5rem' }}>
|
||||
Leitung: {(unit.lead_trainer_name || '').trim() || '—'}
|
||||
</p>
|
||||
{unit.planned_focus && (
|
||||
<p
|
||||
style={{
|
||||
@@ -1134,6 +1288,11 @@ function TrainingPlanningPage() {
|
||||
<button className="btn btn-secondary" onClick={() => handleEdit(unit)}>
|
||||
Bearbeiten
|
||||
</button>
|
||||
{showTakeLead ? (
|
||||
<button type="button" className="btn btn-secondary" onClick={() => handleTakeLead(unit)}>
|
||||
Ich übernehme
|
||||
</button>
|
||||
) : null}
|
||||
<button
|
||||
className="btn"
|
||||
style={{ background: 'var(--danger)', color: 'white', border: 'none' }}
|
||||
|
||||
Reference in new issue
Block a user