Phase 0a Mandantenfähigkeit
This commit is contained in:
1 parent
0748990328
commit
0c044249d9
15 files changed
+982
-193
No files matched your search
@@ -16,10 +16,26 @@ function ClubsPage() {
|
||||
// Form state
|
||||
const [formData, setFormData] = useState({})
|
||||
|
||||
const isAdmin = user?.role === 'admin' || user?.role === 'superadmin'
|
||||
const isTrainer = user?.role === 'trainer' || isAdmin
|
||||
const canCreateClub = ['admin', 'superadmin', 'trainer', 'user'].includes(user?.role)
|
||||
const isPlatformAdmin = user?.role === 'admin' || user?.role === 'superadmin'
|
||||
const isSuperAdmin = user?.role === 'superadmin'
|
||||
const clubAdminClubIds = new Set(
|
||||
(user?.clubs || [])
|
||||
.filter((c) => (c.roles || []).includes('club_admin'))
|
||||
.map((c) => c.id)
|
||||
)
|
||||
const canManageClub = (clubId) => isPlatformAdmin || clubAdminClubIds.has(clubId)
|
||||
const canCreateClub = isPlatformAdmin
|
||||
const canManageOrgSomewhere = isPlatformAdmin || clubAdminClubIds.size > 0
|
||||
const canCreateTrainingGroup =
|
||||
isPlatformAdmin || (Array.isArray(user?.clubs) && user.clubs.length > 0)
|
||||
|
||||
const canEditGroup = (g) =>
|
||||
isPlatformAdmin ||
|
||||
clubAdminClubIds.has(g.club_id) ||
|
||||
g.trainer_id === user?.id ||
|
||||
(Array.isArray(g.co_trainer_ids) && g.co_trainer_ids.includes(user?.id))
|
||||
|
||||
const canDeleteGroup = (g) => isPlatformAdmin || clubAdminClubIds.has(g.club_id)
|
||||
useEffect(() => {
|
||||
loadData()
|
||||
}, [])
|
||||
@@ -47,7 +63,13 @@ function ClubsPage() {
|
||||
setModalType(type)
|
||||
|
||||
if (type === 'club') {
|
||||
setFormData({ name: '', abbreviation: '', description: '', status: 'active' })
|
||||
setFormData({
|
||||
name: '',
|
||||
abbreviation: '',
|
||||
description: '',
|
||||
status: 'active',
|
||||
primary_admin_profile_id: user?.id ?? '',
|
||||
})
|
||||
} else if (type === 'division') {
|
||||
setFormData({ club_id: '', name: '', focus_area: '' })
|
||||
} else if (type === 'group') {
|
||||
@@ -102,11 +124,19 @@ function ClubsPage() {
|
||||
e.preventDefault()
|
||||
|
||||
try {
|
||||
if (modalType === 'club') {
|
||||
if (modalType === 'club') {
|
||||
if (editing) {
|
||||
await api.updateClub(editing.id, formData)
|
||||
} else {
|
||||
await api.createClub(formData)
|
||||
const payload = {
|
||||
...formData,
|
||||
primary_admin_profile_id: Number(formData.primary_admin_profile_id),
|
||||
}
|
||||
if (!payload.primary_admin_profile_id) {
|
||||
alert('Hauptverwalter (Profil-ID) ist Pflicht.')
|
||||
return
|
||||
}
|
||||
await api.createClub(payload)
|
||||
}
|
||||
} else if (modalType === 'division') {
|
||||
if (editing) {
|
||||
@@ -235,7 +265,7 @@ function ClubsPage() {
|
||||
{club.status}
|
||||
</span>
|
||||
</div>
|
||||
{isAdmin && (
|
||||
{canManageClub(club.id) && (
|
||||
<div style={{ display: 'flex', gap: '0.5rem' }}>
|
||||
<button
|
||||
className="btn btn-secondary"
|
||||
@@ -243,6 +273,7 @@ function ClubsPage() {
|
||||
>
|
||||
Bearbeiten
|
||||
</button>
|
||||
{isSuperAdmin && (
|
||||
<button
|
||||
className="btn"
|
||||
style={{
|
||||
@@ -254,6 +285,7 @@ function ClubsPage() {
|
||||
>
|
||||
Löschen
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -269,7 +301,7 @@ function ClubsPage() {
|
||||
<>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '1rem' }}>
|
||||
<h2>Sparten</h2>
|
||||
{isAdmin && (
|
||||
{canManageOrgSomewhere && (
|
||||
<button className="btn btn-primary" onClick={() => handleCreate('division')}>
|
||||
+ Neue Sparte
|
||||
</button>
|
||||
@@ -306,7 +338,7 @@ function ClubsPage() {
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{isAdmin && (
|
||||
{canManageClub(division.club_id) && (
|
||||
<div style={{ display: 'flex', gap: '0.5rem' }}>
|
||||
<button
|
||||
className="btn btn-secondary"
|
||||
@@ -340,7 +372,7 @@ function ClubsPage() {
|
||||
<>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '1rem' }}>
|
||||
<h2>Trainingsgruppen</h2>
|
||||
{canCreateClub && (
|
||||
{canCreateTrainingGroup && (
|
||||
<button className="btn btn-primary" onClick={() => handleCreate('group')}>
|
||||
+ Neue Gruppe
|
||||
</button>
|
||||
@@ -377,7 +409,7 @@ function ClubsPage() {
|
||||
{group.age_group && <div>👶 {group.age_group}</div>}
|
||||
</div>
|
||||
|
||||
{(isAdmin || group.trainer_id === user?.id) && (
|
||||
{canEditGroup(group) && (
|
||||
<div style={{ display: 'flex', gap: '0.5rem', marginTop: 'auto' }}>
|
||||
<button
|
||||
className="btn btn-secondary"
|
||||
@@ -386,7 +418,7 @@ function ClubsPage() {
|
||||
>
|
||||
Bearbeiten
|
||||
</button>
|
||||
{isAdmin && (
|
||||
{canDeleteGroup(group) && (
|
||||
<button
|
||||
className="btn"
|
||||
style={{
|
||||
@@ -485,6 +517,28 @@ function ClubsPage() {
|
||||
<option value="inactive">Inaktiv</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{!editing && canCreateClub && (
|
||||
<div className="form-row">
|
||||
<label className="form-label">Hauptverwalter (Profil-ID) *</label>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
className="form-input"
|
||||
value={formData.primary_admin_profile_id ?? ''}
|
||||
onChange={(e) =>
|
||||
updateFormField(
|
||||
'primary_admin_profile_id',
|
||||
e.target.value === '' ? '' : parseInt(e.target.value, 10)
|
||||
)
|
||||
}
|
||||
required
|
||||
/>
|
||||
<p style={{ fontSize: '0.8rem', color: 'var(--text3)', marginTop: '0.35rem' }}>
|
||||
Nur Plattform-Administratoren legen Vereine an. Standard ist deine eigene Profil-ID.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
Reference in new issue
Block a user