Admin: przebudowa modalu wlascicieli silowni (awatarskie kafelki, pusty stan, inline formularz nadania)
This commit is contained in:
@@ -2,12 +2,15 @@ import { useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import {
|
||||
Crown,
|
||||
Dumbbell,
|
||||
Image as ImageIcon,
|
||||
MapPin,
|
||||
Pencil,
|
||||
ShieldCheck,
|
||||
Star,
|
||||
UserPlus,
|
||||
UserX,
|
||||
Users,
|
||||
Wrench,
|
||||
X,
|
||||
@@ -17,7 +20,7 @@ import { api } from '../../api/client';
|
||||
import { AuthImage } from '../../components/AuthImage';
|
||||
import { UserPicker } from '../../components/UserPicker';
|
||||
import { useAdminUsers } from '../users/user-queries';
|
||||
import type { Equipment, Gym, GymException, GymPhoto } from '../../api/types';
|
||||
import type { Equipment, Gym, GymException, GymOwner, GymPhoto } from '../../api/types';
|
||||
import { formatEquipmentSpec, formatGymEquipment } from '../../lib/equipment';
|
||||
import {
|
||||
BackButton,
|
||||
@@ -27,10 +30,7 @@ import {
|
||||
ConfirmDialog,
|
||||
ErrorText,
|
||||
Field,
|
||||
H3,
|
||||
Input,
|
||||
Label,
|
||||
ListRow,
|
||||
Loading,
|
||||
Modal,
|
||||
Muted,
|
||||
@@ -415,57 +415,80 @@ function OwnersSection({ gym, onChanged }: { gym: Gym; onChanged: () => void })
|
||||
}
|
||||
};
|
||||
|
||||
const initials = (o: GymOwner) =>
|
||||
`${o.firstName?.[0] ?? ''}${o.lastName?.[0] ?? ''}`.toUpperCase() || o.email.slice(0, 2).toUpperCase();
|
||||
|
||||
return (
|
||||
<>
|
||||
<SectionHeader
|
||||
title="Właściciele (OWNER)"
|
||||
description="Osoby zarządzające siłownią w aplikacji. Tylko admin może nadać lub odebrać tę rolę."
|
||||
/>
|
||||
<div className="divide-y divide-line">
|
||||
{owners.length === 0 && (
|
||||
<Muted>Brak właściciela — wyznacz go, aby użytkownik mógł zarządzać siłownią.</Muted>
|
||||
)}
|
||||
{owners.map((o) => (
|
||||
<ListRow
|
||||
key={o.id}
|
||||
title={[o.firstName, o.lastName].filter(Boolean).join(' ') || o.email}
|
||||
meta={o.email}
|
||||
actions={
|
||||
<Button
|
||||
variant="danger"
|
||||
size="sm"
|
||||
<div className="space-y-4">
|
||||
{owners.length === 0 ? (
|
||||
<div className="rounded-xl border border-dashed border-line px-4 py-8 text-center">
|
||||
<div className="mx-auto mb-3 flex h-11 w-11 items-center justify-center rounded-full bg-accent/10 text-accent-text">
|
||||
<Crown className="h-5 w-5" />
|
||||
</div>
|
||||
<p className="mb-1 font-semibold">Brak właściciela</p>
|
||||
<Muted className="text-[0.875rem]">
|
||||
Wyznacz osobę, która będzie zarządzać siłownią w aplikacji.
|
||||
</Muted>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{owners.map((o) => (
|
||||
<div
|
||||
key={o.id}
|
||||
className="flex items-center gap-3 rounded-xl border border-line bg-input px-3.5 py-2.5"
|
||||
>
|
||||
<span
|
||||
aria-hidden
|
||||
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-accent/10 text-[0.8rem] font-bold text-accent-text"
|
||||
>
|
||||
{initials(o)}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex min-w-0 items-center gap-1.5">
|
||||
<span className="truncate text-[0.95rem] font-semibold">
|
||||
{[o.firstName, o.lastName].filter(Boolean).join(' ') || o.email}
|
||||
</span>
|
||||
<Crown aria-hidden className="h-3.5 w-3.5 shrink-0 text-accent-text" />
|
||||
</div>
|
||||
<Muted className="block truncate text-[0.8rem]">{o.email}</Muted>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Odbierz rolę"
|
||||
title="Odbierz rolę właściciela"
|
||||
disabled={busy}
|
||||
onClick={() => void remove(o.id)}
|
||||
className="shrink-0 cursor-pointer rounded-lg p-2 text-dim transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-50"
|
||||
>
|
||||
Odbierz rolę
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-4 border-t border-line pt-4">
|
||||
<H3>Nadaj właściciela</H3>
|
||||
<div className="grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2">
|
||||
<div>
|
||||
<Label>Użytkownik</Label>
|
||||
<UserX className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="border-t border-line pt-4">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<div className="min-w-0 flex-1">
|
||||
<UserPicker
|
||||
users={availableUsers}
|
||||
value={pick}
|
||||
onChange={setPick}
|
||||
ariaLabel="Szukaj przyszłego właściciela"
|
||||
emptyLabel="Brak użytkowników"
|
||||
emptyLabel="Brak kandydatów — wszyscy użytkownicy są już właścicielami"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-end">
|
||||
<Button variant="secondary" onClick={() => void add()} disabled={!pick || busy}>
|
||||
{busy ? 'Zapisywanie…' : 'Nadaj właściciela'}
|
||||
</Button>
|
||||
</div>
|
||||
<Button onClick={() => void add()} disabled={!pick || busy} className="shrink-0">
|
||||
<UserPlus className="h-4 w-4" />
|
||||
{busy ? 'Nadawanie…' : 'Nadaj właściciela'}
|
||||
</Button>
|
||||
</div>
|
||||
<Muted className="mt-2 block text-[0.8rem]">
|
||||
Właściciel zarządza siłownią w aplikacji: urządzeniami, galerią i harmonogramem.
|
||||
</Muted>
|
||||
{error && <ErrorText>{error}</ErrorText>}
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -711,7 +734,12 @@ export default function GymDetail() {
|
||||
>
|
||||
<EquipmentSection key={gym.id} gym={gym} onChanged={() => void invalidate()} />
|
||||
</Modal>
|
||||
<Modal open={ownersOpen} onClose={() => setOwnersOpen(false)} title="Zarządzaj właścicielami">
|
||||
<Modal
|
||||
open={ownersOpen}
|
||||
onClose={() => setOwnersOpen(false)}
|
||||
title="Zarządzaj właścicielami"
|
||||
className="sm:max-w-lg"
|
||||
>
|
||||
<OwnersSection key={gym.id} gym={gym} onChanged={() => void invalidate()} />
|
||||
</Modal>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user