Silownie: przegladne zarzadzanie urzadzeniami w panelu (modal wide, listy wierszy; parametry pozycji zawsze reczne bez domyslnych z katalogu; widoczny przycisk dodawania zdjec z podgladem)
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
Pencil,
|
||||
ShieldCheck,
|
||||
Star,
|
||||
Trash2,
|
||||
UserPlus,
|
||||
UserX,
|
||||
Users,
|
||||
@@ -35,10 +36,8 @@ import {
|
||||
EMPTY_SPEC_FIELDS,
|
||||
LOAD_RANGE_KINDS,
|
||||
MAX_LOAD_KINDS,
|
||||
formatEquipmentSpec,
|
||||
formatGymEquipment,
|
||||
hasSpecFields,
|
||||
specFieldsFrom,
|
||||
specFromFields,
|
||||
type SpecFields,
|
||||
} from '../../lib/equipment';
|
||||
@@ -46,7 +45,6 @@ import {
|
||||
BackButton,
|
||||
Button,
|
||||
Card,
|
||||
Chip,
|
||||
ConfirmDialog,
|
||||
ErrorText,
|
||||
Field,
|
||||
@@ -795,6 +793,7 @@ export default function GymDetail() {
|
||||
open={equipmentOpen}
|
||||
onClose={() => setEquipmentOpen(false)}
|
||||
title="Zarządzaj urządzeniami"
|
||||
className="sm:max-w-2xl"
|
||||
>
|
||||
<EquipmentSection key={gym.id} gym={gym} onChanged={() => void invalidate()} />
|
||||
</Modal>
|
||||
@@ -1024,16 +1023,15 @@ function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [addId, setAddId] = useState('');
|
||||
const [addQty, setAddQty] = useState('1');
|
||||
const [addCustom, setAddCustom] = useState(false);
|
||||
const [addFields, setAddFields] = useState<SpecFields>(EMPTY_SPEC_FIELDS);
|
||||
|
||||
const addItem = catalog.find((e) => e.id === addId) ?? null;
|
||||
|
||||
// Parametry każdej pozycji admin wpisuje zawsze sam — bez podpowiedzi z katalogu.
|
||||
const selectAdd = (id: string) => {
|
||||
setAddId(id);
|
||||
const item = catalog.find((e) => e.id === id);
|
||||
setAddFields(item ? specFieldsFrom(item.spec) : EMPTY_SPEC_FIELDS);
|
||||
setAddCustom(false);
|
||||
setAddFields(EMPTY_SPEC_FIELDS);
|
||||
setError('');
|
||||
};
|
||||
|
||||
const add = async () => {
|
||||
@@ -1041,14 +1039,14 @@ function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void
|
||||
const quantity = parseInt(addQty, 10) || 1;
|
||||
setError('');
|
||||
let spec: EquipmentSpec | null = null;
|
||||
if (addCustom && hasSpecFields(addItem.kind)) {
|
||||
if (hasSpecFields(addItem.kind)) {
|
||||
const result = specFromFields(addItem.kind, addFields);
|
||||
if ('error' in result) {
|
||||
setError(result.error);
|
||||
return;
|
||||
}
|
||||
if (result.spec == null) {
|
||||
setError('Uzupełnij parametry lub wyłącz ich własną wartość.');
|
||||
setError('Podaj parametry urządzenia (prędkość lub nachylenie).');
|
||||
return;
|
||||
}
|
||||
spec = result.spec;
|
||||
@@ -1061,7 +1059,6 @@ function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void
|
||||
});
|
||||
setAddId('');
|
||||
setAddQty('1');
|
||||
setAddCustom(false);
|
||||
setAddFields(EMPTY_SPEC_FIELDS);
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
@@ -1098,96 +1095,115 @@ function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void
|
||||
.reduce((sum, e) => sum + e.quantity, 0);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SectionHeader
|
||||
title="Urządzenia"
|
||||
description="Maszyny i urządzenia dostępne w tej siłowni (z katalogu). Każde dodanie tworzy osobną pozycję — możesz ustawić jej parametry (np. stały ciężar lub zakres regulacji)."
|
||||
/>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{gym.equipment.length === 0 && (
|
||||
<span className="text-[0.875rem] text-dim">Brak urządzeń.</span>
|
||||
<div className="space-y-5">
|
||||
{/* POZYCJE NA STANIE: wiersz = nazwa/spec + ilość + usuwanie */}
|
||||
<div>
|
||||
<div className="mb-2 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Pozycje na stanie ({gym.equipment.length})
|
||||
</div>
|
||||
{gym.equipment.length === 0 ? (
|
||||
<div className="rounded-[10px] border border-dashed border-line px-4 py-6 text-center text-[0.875rem] text-dim">
|
||||
Brak urządzeń — dodaj pierwsze z katalogu poniżej.
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{gym.equipment.map((e) => (
|
||||
<div
|
||||
key={e.id}
|
||||
className="flex items-center gap-2.5 rounded-[10px] border border-line bg-card/50 px-3 py-2"
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate text-[0.875rem] font-semibold">
|
||||
{formatGymEquipment(e)}
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={10000}
|
||||
defaultValue={e.quantity}
|
||||
aria-label={`Ilość: ${e.equipment.name}`}
|
||||
className="w-16 shrink-0 rounded-[10px] border border-line bg-input px-2 py-1 text-center text-[0.875rem] text-ink focus:border-accent-text focus:outline-none"
|
||||
onBlur={(ev) => {
|
||||
const value = parseInt(ev.target.value, 10);
|
||||
if (Number.isFinite(value) && value >= 1 && value !== e.quantity) {
|
||||
void changeQty(e.id, value);
|
||||
} else {
|
||||
ev.target.value = String(e.quantity);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(ev) => {
|
||||
if (ev.key === 'Enter') (ev.target as HTMLInputElement).blur();
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void remove(e.id)}
|
||||
aria-label={`Usuń ${e.equipment.name}`}
|
||||
title={`Usuń ${e.equipment.name}`}
|
||||
className="shrink-0 cursor-pointer rounded-lg p-1.5 text-dim transition-colors hover:bg-danger/10 hover:text-danger"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{gym.equipment.map((e) => (
|
||||
<Chip key={e.id} onRemove={() => remove(e.id)} removeLabel={`Usuń ${e.equipment.name}`}>
|
||||
{formatGymEquipment(e)}
|
||||
<input
|
||||
</div>
|
||||
|
||||
{/* DODAWANIE z katalogu: pozycja zawsze z własnymi parametrami (zdjęcia pozycji zarządza właściciel w apce) */}
|
||||
<div className="rounded-xl border border-line bg-input/40 p-3.5">
|
||||
<div className="mb-2.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Dodaj urządzenie z katalogu
|
||||
</div>
|
||||
<div className="flex flex-wrap items-end gap-2.5">
|
||||
<div className="min-w-0 flex-1 basis-52">
|
||||
<Select
|
||||
value={addId}
|
||||
onChange={(e) => selectAdd(e.target.value)}
|
||||
aria-label="Dodaj urządzenie"
|
||||
>
|
||||
<option value="">Wybierz urządzenie…</option>
|
||||
{catalog.map((e) => {
|
||||
const qty = totalQty(e.id);
|
||||
return (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name}
|
||||
{qty > 0 ? ` (na stanie: ${qty})` : ''}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</div>
|
||||
<Field label="Ilość" className="w-20 shrink-0">
|
||||
<Input
|
||||
type="number"
|
||||
size="sm"
|
||||
min={1}
|
||||
max={10000}
|
||||
defaultValue={e.quantity}
|
||||
aria-label={`Ilość: ${e.equipment.name}`}
|
||||
className="w-14 border border-line bg-card rounded-md px-1.5 py-0.5 text-center text-[0.875rem]"
|
||||
onBlur={(ev) => {
|
||||
const value = parseInt(ev.target.value, 10);
|
||||
if (Number.isFinite(value) && value >= 1 && value !== e.quantity) {
|
||||
void changeQty(e.id, value);
|
||||
} else {
|
||||
ev.target.value = String(e.quantity);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(ev) => {
|
||||
if (ev.key === 'Enter') (ev.target as HTMLInputElement).blur();
|
||||
}}
|
||||
value={addQty}
|
||||
onChange={(e) => setAddQty(e.target.value)}
|
||||
aria-label="Ilość"
|
||||
/>
|
||||
</Chip>
|
||||
))}
|
||||
</div>
|
||||
<div className="mt-4 flex flex-wrap items-center gap-2">
|
||||
<Select
|
||||
value={addId}
|
||||
onChange={(e) => selectAdd(e.target.value)}
|
||||
className="max-w-xs"
|
||||
aria-label="Dodaj urządzenie"
|
||||
>
|
||||
<option value="">+ dodaj urządzenie…</option>
|
||||
{catalog.map((e) => {
|
||||
const qty = totalQty(e.id);
|
||||
const spec = formatEquipmentSpec(e.spec);
|
||||
return (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name}
|
||||
{spec ? ` · ${spec}` : ''}
|
||||
{qty > 0 ? ` (${qty} szt.)` : ''}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={10000}
|
||||
value={addQty}
|
||||
onChange={(e) => setAddQty(e.target.value)}
|
||||
className="w-20"
|
||||
aria-label="Ilość"
|
||||
/>
|
||||
<Button size="sm" onClick={add} disabled={!addId || busy} aria-label="Dodaj urządzenie">
|
||||
{busy ? 'Dodawanie…' : 'Dodaj'}
|
||||
</Button>
|
||||
</div>
|
||||
{addItem && hasSpecFields(addItem.kind) && (
|
||||
<div className="mt-3">
|
||||
<label className="mb-2 flex cursor-pointer items-center gap-2 text-[0.875rem]">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={addCustom}
|
||||
onChange={(e) => setAddCustom(e.target.checked)}
|
||||
className="h-4 w-4 accent-accent"
|
||||
/>
|
||||
Ustaw własne parametry (domyślne: {formatEquipmentSpec(addItem.spec) ?? 'brak'})
|
||||
</label>
|
||||
{addCustom && (
|
||||
</Field>
|
||||
<Button onClick={add} disabled={!addId || busy} className="shrink-0">
|
||||
{busy ? 'Dodawanie…' : 'Dodaj'}
|
||||
</Button>
|
||||
</div>
|
||||
{addItem && hasSpecFields(addItem.kind) && (
|
||||
<div className="mt-3.5 border-t border-line pt-3.5">
|
||||
<div className="mb-2 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Parametry
|
||||
</div>
|
||||
<AddSpecFields
|
||||
kind={addItem.kind}
|
||||
values={addFields}
|
||||
onChange={(patch) => setAddFields({ ...addFields, ...patch })}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{error && <ErrorText>{error}</ErrorText>}
|
||||
{isLoading && <Loading />}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -166,14 +166,21 @@ describe('admin GymDetail page', () => {
|
||||
fireEvent.click(actionButton('Urządzenia'));
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
|
||||
// select pokazuje cały katalog ze specyfikacją — sprzęt już dodany jest oznaczony bieżącą ilością
|
||||
// select pokazuje cały katalog — sprzęt już dodany jest oznaczony bieżącą ilością
|
||||
expect(
|
||||
await within(dialog).findByRole('option', { name: 'hantle · 2.5–25 kg (2 szt.)' }),
|
||||
await within(dialog).findByRole('option', { name: 'hantle (na stanie: 2)' }),
|
||||
).toBeInTheDocument();
|
||||
fireEvent.change(within(dialog).getByRole('combobox', { name: 'Dodaj urządzenie' }), {
|
||||
target: { value: 'eq-2' },
|
||||
});
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: 'Dodaj urządzenie' }));
|
||||
// pozycja z katalogu DUMBBELL wymaga własnych parametrów — zawsze wpisywanych przez admina
|
||||
fireEvent.change(within(dialog).getByRole('spinbutton', { name: 'Min. obciążenie (kg)' }), {
|
||||
target: { value: '2.5' },
|
||||
});
|
||||
fireEvent.change(within(dialog).getByRole('spinbutton', { name: 'Max. obciążenie (kg)' }), {
|
||||
target: { value: '25' },
|
||||
});
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: 'Dodaj', exact: true }));
|
||||
|
||||
// każde dodanie = POST tworzący NOWĄ instancję (bez PATCH-a ilości istniejącej)
|
||||
await waitFor(() =>
|
||||
@@ -183,7 +190,7 @@ describe('admin GymDetail page', () => {
|
||||
);
|
||||
expect(
|
||||
calls.find((c) => c.method === 'POST' && c.url.endsWith('/admin/gyms/g1/equipment'))?.body,
|
||||
).toEqual({ equipmentId: 'eq-2', quantity: 1 });
|
||||
).toEqual({ equipmentId: 'eq-2', quantity: 1, spec: { minKg: 2.5, maxKg: 25 } });
|
||||
expect(calls.some((c) => c.method === 'PATCH')).toBe(false);
|
||||
});
|
||||
|
||||
@@ -210,9 +217,7 @@ describe('admin GymDetail page', () => {
|
||||
fireEvent.click(await within(dialog).findByRole('option', { name: /Jan Kowalski/ }));
|
||||
fireEvent.click(within(dialog).getByRole('button', { name: 'Nadaj właściciela' }));
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
calls.find((c) => c.method === 'POST' && c.url.endsWith('/owners')),
|
||||
).toBeTruthy(),
|
||||
expect(calls.find((c) => c.method === 'POST' && c.url.endsWith('/owners'))).toBeTruthy(),
|
||||
);
|
||||
expect(calls.find((c) => c.method === 'POST' && c.url.endsWith('/owners'))?.body).toEqual({
|
||||
userId: 'u1',
|
||||
|
||||
@@ -44,7 +44,7 @@ test('ponowne dodanie tego samego typu tworzy osobną instancję (bez inkrementa
|
||||
(req) => req.url().endsWith('/admin/gyms/gym-1/equipment') && req.method() === 'POST',
|
||||
);
|
||||
await page.getByRole('combobox', { name: 'Dodaj urządzenie' }).selectOption('eq-2');
|
||||
await page.getByRole('button', { name: 'Dodaj urządzenie' }).click();
|
||||
await page.getByRole('button', { name: 'Dodaj', exact: true }).click();
|
||||
expect((await addReq).postDataJSON()).toMatchObject({ equipmentId: 'eq-2', quantity: 1 });
|
||||
|
||||
// dotychczasowa instancja bez zmian, nowa instancja to osobny chip (×1 = bez licznika)
|
||||
@@ -63,9 +63,8 @@ test('dodanie urządzenia z własnymi parametrami wysyła spec w POST', async ({
|
||||
(req) => req.url().endsWith('/admin/gyms/gym-1/equipment') && req.method() === 'POST',
|
||||
);
|
||||
await page.getByRole('combobox', { name: 'Dodaj urządzenie' }).selectOption('eq-1');
|
||||
await page.getByRole('checkbox', { name: /Ustaw własne parametry/ }).check();
|
||||
await page.getByLabel('Maksymalne obciążenie (kg)').fill('80');
|
||||
await page.getByRole('button', { name: 'Dodaj urządzenie' }).click();
|
||||
await page.getByRole('button', { name: 'Dodaj', exact: true }).click();
|
||||
expect((await addReq).postDataJSON()).toEqual({
|
||||
equipmentId: 'eq-1',
|
||||
quantity: 1,
|
||||
|
||||
@@ -667,6 +667,7 @@ export default function GymDetail() {
|
||||
<GymGallery gym={gym} canManage={canManage} onChanged={() => {}} />
|
||||
</Modal>
|
||||
<Modal
|
||||
wide
|
||||
open={equipmentOpen}
|
||||
onClose={() => setEquipmentOpen(false)}
|
||||
title="Zarządzaj urządzeniami"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Check, Dumbbell, ImageIcon, Trash2, X } from 'lucide-react';
|
||||
import {
|
||||
addEquipmentPhotos,
|
||||
addGymEquipment,
|
||||
@@ -14,14 +15,13 @@ import {
|
||||
EMPTY_SPEC_FIELDS,
|
||||
LOAD_RANGE_KINDS,
|
||||
MAX_LOAD_KINDS,
|
||||
formatEquipmentSpec,
|
||||
formatGymEquipment,
|
||||
hasSpecFields,
|
||||
specFieldsFrom,
|
||||
specFromFields,
|
||||
type SpecFields,
|
||||
} from '../../lib/equipment';
|
||||
import { Button, Chip, Field, Input, Loading, SectionHeader, Select } from '../../components/ui';
|
||||
import { Button, Field, Input, Loading, Select } from '../../components/ui';
|
||||
import { AuthImage } from '../../components/AuthImage';
|
||||
import { useToast } from '../../components/toast';
|
||||
import { AvailabilityEditor } from '../../components/AvailabilityEditor';
|
||||
@@ -151,34 +151,59 @@ function PhotoPicker({
|
||||
}) {
|
||||
const { push } = useToast();
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
type="file"
|
||||
multiple
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
aria-label={label}
|
||||
className="text-[0.8125rem] text-dim"
|
||||
onChange={(e) => {
|
||||
const picked = Array.from(e.target.files ?? []);
|
||||
e.target.value = '';
|
||||
if (picked.length === 0) return;
|
||||
if (files.length + picked.length > MAX_EQUIPMENT_PHOTO_FILES) {
|
||||
push(`Maksymalnie ${MAX_EQUIPMENT_PHOTO_FILES} zdjęć na urządzenie`, 'error');
|
||||
return;
|
||||
}
|
||||
if (picked.some((f) => !EQUIPMENT_PHOTO_TYPES.includes(f.type))) {
|
||||
push('Dozwolone formaty: JPG, PNG, WebP', 'error');
|
||||
return;
|
||||
}
|
||||
if (picked.some((f) => f.size > MAX_EQUIPMENT_PHOTO_SIZE)) {
|
||||
push('Maksymalny rozmiar zdjęcia to 5 MB', 'error');
|
||||
return;
|
||||
}
|
||||
onChange([...files, ...picked]);
|
||||
}}
|
||||
/>
|
||||
<div>
|
||||
<div className="flex flex-wrap items-center gap-2.5">
|
||||
<label className="inline-flex cursor-pointer items-center gap-1.5 rounded-[10px] border border-line bg-card px-3 py-1.5 text-[0.85rem] font-semibold text-dim transition-colors hover:border-accent/55 hover:text-accent-text">
|
||||
<ImageIcon className="h-4 w-4" aria-hidden="true" />
|
||||
Dodaj zdjęcia
|
||||
<input
|
||||
type="file"
|
||||
multiple
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
aria-label={label}
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const picked = Array.from(e.target.files ?? []);
|
||||
e.target.value = '';
|
||||
if (picked.length === 0) return;
|
||||
if (files.length + picked.length > MAX_EQUIPMENT_PHOTO_FILES) {
|
||||
push(`Maksymalnie ${MAX_EQUIPMENT_PHOTO_FILES} zdjęć na urządzenie`, 'error');
|
||||
return;
|
||||
}
|
||||
if (picked.some((f) => !EQUIPMENT_PHOTO_TYPES.includes(f.type))) {
|
||||
push('Dozwolone formaty: JPG, PNG, WebP', 'error');
|
||||
return;
|
||||
}
|
||||
if (picked.some((f) => f.size > MAX_EQUIPMENT_PHOTO_SIZE)) {
|
||||
push('Maksymalny rozmiar zdjęcia to 5 MB', 'error');
|
||||
return;
|
||||
}
|
||||
onChange([...files, ...picked]);
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<span className="text-[0.8125rem] text-dim">JPG, PNG lub WebP · maks. 5 MB</span>
|
||||
</div>
|
||||
{files.length > 0 && (
|
||||
<span className="text-[0.8125rem] text-dim">{files.map((f) => f.name).join(', ')}</span>
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{files.map((f, i) => (
|
||||
<span key={`${f.name}-${i}`} className="relative inline-block">
|
||||
<img
|
||||
src={URL.createObjectURL(f)}
|
||||
alt={f.name}
|
||||
className="h-16 w-16 rounded-[8px] border border-line object-cover"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange(files.filter((_, j) => j !== i))}
|
||||
aria-label={`Usuń ${f.name}`}
|
||||
className="absolute -top-1.5 -right-1.5 grid h-5 w-5 cursor-pointer place-items-center rounded-full border border-line bg-card text-danger"
|
||||
>
|
||||
<X className="h-3 w-3" aria-hidden="true" />
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -275,15 +300,14 @@ export function EquipmentSection({ gym }: { gym: Gym }) {
|
||||
const { data: eqData, isLoading } = useEquipment();
|
||||
const catalog = eqData?.equipment ?? [];
|
||||
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [addId, setAddId] = useState('');
|
||||
const [addQty, setAddQty] = useState('1');
|
||||
const [addCustom, setAddCustom] = useState(false);
|
||||
const [addFields, setAddFields] = useState<SpecFields>(EMPTY_SPEC_FIELDS);
|
||||
const [addFiles, setAddFiles] = useState<File[]>([]);
|
||||
const [addBusy, setAddBusy] = useState(false);
|
||||
const [addPhotosOpen, setAddPhotosOpen] = useState(false);
|
||||
|
||||
const [editingId, setEditingId] = useState<string | null>(null);
|
||||
const [editCustom, setEditCustom] = useState(false);
|
||||
const [editFields, setEditFields] = useState<SpecFields>(EMPTY_SPEC_FIELDS);
|
||||
const [editFiles, setEditFiles] = useState<File[]>([]);
|
||||
const [savingEdit, setSavingEdit] = useState(false);
|
||||
@@ -296,33 +320,42 @@ export function EquipmentSection({ gym }: { gym: Gym }) {
|
||||
queryClient.invalidateQueries({ queryKey: ['gym', gym.id] }),
|
||||
]);
|
||||
|
||||
// Parametry każdej pozycji właściciel wpisuje sam — bez podpowiedzi z katalogu.
|
||||
const selectAdd = (id: string) => {
|
||||
setAddId(id);
|
||||
const item = catalog.find((e) => e.id === id);
|
||||
setAddFields(item ? specFieldsFrom(item.spec) : EMPTY_SPEC_FIELDS);
|
||||
setAddCustom(false);
|
||||
setAddFields(EMPTY_SPEC_FIELDS);
|
||||
setAddFiles([]);
|
||||
setAddPhotosOpen(false);
|
||||
};
|
||||
|
||||
const resetAdd = () => {
|
||||
setAddId('');
|
||||
setAddQty('1');
|
||||
setAddFields(EMPTY_SPEC_FIELDS);
|
||||
setAddFiles([]);
|
||||
setAddPhotosOpen(false);
|
||||
};
|
||||
|
||||
const add = async () => {
|
||||
if (!addItem) return;
|
||||
const quantity = parseInt(addQty, 10) || 1;
|
||||
let spec: EquipmentSpec | null = null;
|
||||
if (addCustom && hasSpecFields(addItem.kind)) {
|
||||
if (hasSpecFields(addItem.kind)) {
|
||||
const result = specFromFields(addItem.kind, addFields);
|
||||
if ('error' in result) {
|
||||
push(result.error, 'error');
|
||||
return;
|
||||
}
|
||||
if (result.spec == null) {
|
||||
push('Uzupełnij parametry lub wyłącz ich własną wartość.', 'error');
|
||||
push('Podaj parametry urządzenia (prędkość lub nachylenie).', 'error');
|
||||
return;
|
||||
}
|
||||
spec = result.spec;
|
||||
}
|
||||
setBusy(true);
|
||||
setAddBusy(true);
|
||||
try {
|
||||
const { instance } = await addGymEquipment(gym.id, addItem.id, quantity, spec);
|
||||
if (addFiles.length > 0) {
|
||||
if (addPhotosOpen && addFiles.length > 0) {
|
||||
try {
|
||||
await addEquipmentPhotos(gym.id, instance.id, addFiles);
|
||||
} catch {
|
||||
@@ -330,16 +363,12 @@ export function EquipmentSection({ gym }: { gym: Gym }) {
|
||||
}
|
||||
}
|
||||
push('Sprzęt dodany', 'success');
|
||||
setAddId('');
|
||||
setAddQty('1');
|
||||
setAddCustom(false);
|
||||
setAddFields(EMPTY_SPEC_FIELDS);
|
||||
setAddFiles([]);
|
||||
resetAdd();
|
||||
await invalidate();
|
||||
} catch (err) {
|
||||
push((err as Error).message, 'error');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
setAddBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -367,7 +396,6 @@ export function EquipmentSection({ gym }: { gym: Gym }) {
|
||||
|
||||
const openEdit = (ge: GymEquipment) => {
|
||||
setEditingId(ge.id);
|
||||
setEditCustom(ge.spec != null);
|
||||
setEditFields(specFieldsFrom(ge.spec ?? ge.equipment.spec));
|
||||
setEditFiles([]);
|
||||
};
|
||||
@@ -379,26 +407,24 @@ export function EquipmentSection({ gym }: { gym: Gym }) {
|
||||
|
||||
const saveEdit = async () => {
|
||||
if (!editing) return;
|
||||
let specBody: EquipmentSpec | null | undefined;
|
||||
if (editCustom && hasSpecFields(editing.equipment.kind)) {
|
||||
let specBody: EquipmentSpec | null = null;
|
||||
if (hasSpecFields(editing.equipment.kind)) {
|
||||
const result = specFromFields(editing.equipment.kind, editFields);
|
||||
if ('error' in result) {
|
||||
push(result.error, 'error');
|
||||
return;
|
||||
}
|
||||
if (result.spec == null) {
|
||||
push('Uzupełnij parametry lub wróć do specyfikacji katalogu.', 'error');
|
||||
push('Podaj parametry lub przywróć specyfikację katalogu.', 'error');
|
||||
return;
|
||||
}
|
||||
specBody = result.spec;
|
||||
} else if (!editCustom && editing.spec != null) {
|
||||
} else if (editing.spec != null) {
|
||||
specBody = null;
|
||||
}
|
||||
setSavingEdit(true);
|
||||
try {
|
||||
if (specBody !== undefined) {
|
||||
await updateGymEquipment(gym.id, editing.id, { spec: specBody });
|
||||
}
|
||||
await updateGymEquipment(gym.id, editing.id, { spec: specBody });
|
||||
if (editFiles.length > 0) {
|
||||
try {
|
||||
await addEquipmentPhotos(gym.id, editing.id, editFiles);
|
||||
@@ -416,6 +442,21 @@ export function EquipmentSection({ gym }: { gym: Gym }) {
|
||||
}
|
||||
};
|
||||
|
||||
const restoreCatalogSpec = async () => {
|
||||
if (!editing) return;
|
||||
setSavingEdit(true);
|
||||
try {
|
||||
await updateGymEquipment(gym.id, editing.id, { spec: null });
|
||||
push('Przywrócono specyfikację katalogu', 'success');
|
||||
closeEdit();
|
||||
await invalidate();
|
||||
} catch (err) {
|
||||
push((err as Error).message, 'error');
|
||||
} finally {
|
||||
setSavingEdit(false);
|
||||
}
|
||||
};
|
||||
|
||||
const removePhoto = async (ge: GymEquipment, photoId: string) => {
|
||||
try {
|
||||
await deleteEquipmentPhoto(gym.id, ge.id, photoId);
|
||||
@@ -431,205 +472,240 @@ export function EquipmentSection({ gym }: { gym: Gym }) {
|
||||
.reduce((sum, e) => sum + e.quantity, 0);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SectionHeader
|
||||
title="Urządzenia"
|
||||
description="Maszyny i urządzenia dostępne w tej siłowni (z katalogu). Każde dodanie tworzy osobną pozycję — możesz ustawić jej parametry (np. stały ciężar lub zakres regulacji) i dodać zdjęcia. Kliknij pozycję, aby ją edytować."
|
||||
/>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{gym.equipment.length === 0 && (
|
||||
<span className="text-[0.875rem] text-dim">Brak urządzeń.</span>
|
||||
)}
|
||||
{gym.equipment.map((e) => (
|
||||
<Chip
|
||||
key={e.id}
|
||||
onRemove={() => remove(e.id, e.equipment.name)}
|
||||
removeLabel={`Usuń ${e.equipment.name}`}
|
||||
className={editingId === e.id ? 'border-accent' : undefined}
|
||||
>
|
||||
{e.photos && e.photos.length > 0 && (
|
||||
<AuthImage
|
||||
src={e.photos[0].url}
|
||||
alt={e.equipment.name}
|
||||
className="h-6 w-6 rounded-full object-cover"
|
||||
/>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => (editingId === e.id ? closeEdit() : openEdit(e))}
|
||||
aria-label={`Edytuj ${e.equipment.name}`}
|
||||
className="cursor-pointer text-inherit hover:text-accent-text"
|
||||
>
|
||||
{formatGymEquipment(e)}
|
||||
</button>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={10000}
|
||||
defaultValue={e.quantity}
|
||||
aria-label={`Ilość: ${e.equipment.name}`}
|
||||
className="w-14 border border-line bg-card rounded-md px-1.5 py-0.5 text-center text-[0.875rem]"
|
||||
onBlur={(ev) => {
|
||||
const value = parseInt(ev.target.value, 10);
|
||||
if (Number.isFinite(value) && value >= 1 && value !== e.quantity) {
|
||||
void changeQty(e.id, value);
|
||||
} else {
|
||||
ev.target.value = String(e.quantity);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(ev) => {
|
||||
if (ev.key === 'Enter') (ev.target as HTMLInputElement).blur();
|
||||
}}
|
||||
/>
|
||||
</Chip>
|
||||
))}
|
||||
</div>
|
||||
{editing && (
|
||||
<div className="mt-4 rounded-[10px] border border-line bg-card/50 p-3">
|
||||
<div className="mb-3 flex items-center justify-between gap-2">
|
||||
<span className="font-display text-[0.9rem] font-bold">
|
||||
{editing.equipment.name} — edycja
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={closeEdit}
|
||||
aria-label="Zamknij edycję"
|
||||
className="text-[0.8125rem] text-dim hover:text-ink cursor-pointer"
|
||||
>
|
||||
Zamknij
|
||||
</button>
|
||||
<div className="space-y-5">
|
||||
{isLoading && <Loading />}
|
||||
{/* POZYCJE NA STANIE: wiersz = miniatura + nazwa/spec + ilość + akcje */}
|
||||
<div>
|
||||
<div className="mb-2 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Pozycje na stanie ({gym.equipment.length})
|
||||
</div>
|
||||
{gym.equipment.length === 0 ? (
|
||||
<div className="rounded-[10px] border border-dashed border-line px-4 py-6 text-center text-[0.875rem] text-dim">
|
||||
Brak urządzeń — dodaj pierwsze z katalogu poniżej.
|
||||
</div>
|
||||
{hasSpecFields(editing.equipment.kind) && (
|
||||
<div className="mb-3">
|
||||
<label className="mb-2 flex cursor-pointer items-center gap-2 text-[0.875rem]">
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{gym.equipment.map((e) => (
|
||||
<div
|
||||
key={e.id}
|
||||
className={`flex items-center gap-2.5 rounded-[10px] border bg-card/50 px-3 py-2 ${
|
||||
editingId === e.id ? 'border-accent/55' : 'border-line'
|
||||
}`}
|
||||
>
|
||||
{e.photos && e.photos.length > 0 ? (
|
||||
<AuthImage
|
||||
src={e.photos[0].url}
|
||||
alt={e.equipment.name}
|
||||
className="h-9 w-9 shrink-0 rounded-[8px] border border-line object-cover"
|
||||
/>
|
||||
) : (
|
||||
<span className="grid h-9 w-9 shrink-0 place-items-center rounded-[8px] border border-line bg-input text-dim">
|
||||
<Dumbbell className="h-4 w-4" aria-hidden="true" />
|
||||
</span>
|
||||
)}
|
||||
<span className="min-w-0 flex-1 truncate text-[0.875rem] font-semibold">
|
||||
{formatGymEquipment(e)}
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={editCustom}
|
||||
onChange={(e) => setEditCustom(e.target.checked)}
|
||||
className="h-4 w-4 accent-accent"
|
||||
type="number"
|
||||
min={1}
|
||||
max={10000}
|
||||
defaultValue={e.quantity}
|
||||
aria-label={`Ilość: ${e.equipment.name}`}
|
||||
className="w-16 shrink-0 rounded-[10px] border border-line bg-input px-2 py-1 text-center text-[0.875rem] text-ink focus:border-accent-text focus:outline-none"
|
||||
onBlur={(ev) => {
|
||||
const value = parseInt(ev.target.value, 10);
|
||||
if (Number.isFinite(value) && value >= 1 && value !== e.quantity) {
|
||||
void changeQty(e.id, value);
|
||||
} else {
|
||||
ev.target.value = String(e.quantity);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(ev) => {
|
||||
if (ev.key === 'Enter') (ev.target as HTMLInputElement).blur();
|
||||
}}
|
||||
/>
|
||||
Własne parametry (domyślne: {formatEquipmentSpec(editing.equipment.spec) ?? 'brak'})
|
||||
</label>
|
||||
{editCustom && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => (editingId === e.id ? closeEdit() : openEdit(e))}
|
||||
aria-label={`Edytuj ${e.equipment.name}`}
|
||||
className="shrink-0"
|
||||
>
|
||||
{editingId === e.id ? 'Zamknij' : 'Edytuj'}
|
||||
</Button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void remove(e.id, e.equipment.name)}
|
||||
aria-label={`Usuń ${e.equipment.name}`}
|
||||
title={`Usuń ${e.equipment.name}`}
|
||||
className="shrink-0 cursor-pointer rounded-lg p-1.5 text-dim transition-colors hover:bg-danger/10 hover:text-danger"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{editing && (
|
||||
<div className="mt-2 rounded-[10px] border border-accent/55 bg-card/50 p-3.5">
|
||||
<div className="mb-3 flex items-center justify-between gap-2">
|
||||
<span className="font-display text-[0.95rem] font-bold">
|
||||
Edycja: {editing.equipment.name}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={closeEdit}
|
||||
aria-label="Zamknij edycję"
|
||||
className="cursor-pointer p-1 text-dim hover:text-ink"
|
||||
>
|
||||
<X className="h-4 w-4" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
{hasSpecFields(editing.equipment.kind) && (
|
||||
<div className="mb-4">
|
||||
<div className="mb-2 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Parametry pozycji
|
||||
</div>
|
||||
<SpecFieldsEditor
|
||||
kind={editing.equipment.kind}
|
||||
values={editFields}
|
||||
onChange={(patch) => setEditFields({ ...editFields, ...patch })}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="mb-3">
|
||||
<div className="mb-1.5 text-[0.8125rem] font-semibold text-dim">
|
||||
Zdjęcia ({editing.photos?.length ?? 0}/{MAX_EQUIPMENT_PHOTO_FILES})
|
||||
</div>
|
||||
{editing.photos && editing.photos.length > 0 && (
|
||||
<div className="mb-2 flex flex-wrap gap-2">
|
||||
{editing.photos.map((p) => (
|
||||
<span key={p.id} className="relative inline-block">
|
||||
<AuthImage
|
||||
src={p.url}
|
||||
alt={editing.equipment.name}
|
||||
className="h-16 w-16 rounded-[8px] border border-line object-cover"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void removePhoto(editing, p.id)}
|
||||
aria-label="Usuń zdjęcie"
|
||||
className="absolute -top-1.5 -right-1.5 grid h-5 w-5 place-items-center rounded-full border border-line bg-card text-danger cursor-pointer"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{(editing.photos?.length ?? 0) < MAX_EQUIPMENT_PHOTO_FILES && (
|
||||
<PhotoPicker
|
||||
files={editFiles}
|
||||
onChange={setEditFiles}
|
||||
label="Dodaj zdjęcia urządzenia"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button size="sm" onClick={saveEdit} disabled={savingEdit}>
|
||||
{savingEdit ? 'Zapisywanie…' : 'Zapisz'}
|
||||
</Button>
|
||||
{editCustom && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
setEditCustom(false);
|
||||
setEditFields(specFieldsFrom(editing.equipment.spec));
|
||||
}}
|
||||
>
|
||||
Przywróć katalog
|
||||
<div className="mb-4">
|
||||
<div className="mb-1.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Zdjęcia ({editing.photos?.length ?? 0}/{MAX_EQUIPMENT_PHOTO_FILES})
|
||||
</div>
|
||||
{editing.photos && editing.photos.length > 0 && (
|
||||
<div className="mb-2 flex flex-wrap gap-2">
|
||||
{editing.photos.map((p) => (
|
||||
<span key={p.id} className="relative inline-block">
|
||||
<AuthImage
|
||||
src={p.url}
|
||||
alt={editing.equipment.name}
|
||||
className="h-16 w-16 rounded-[8px] border border-line object-cover"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void removePhoto(editing, p.id)}
|
||||
aria-label="Usuń zdjęcie"
|
||||
className="absolute -top-1.5 -right-1.5 grid h-5 w-5 place-items-center rounded-full border border-line bg-card text-danger cursor-pointer"
|
||||
>
|
||||
<X className="h-3 w-3" aria-hidden="true" />
|
||||
</button>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{(editing.photos?.length ?? 0) < MAX_EQUIPMENT_PHOTO_FILES && (
|
||||
<PhotoPicker
|
||||
files={editFiles}
|
||||
onChange={setEditFiles}
|
||||
label="Dodaj zdjęcia urządzenia"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button size="sm" onClick={saveEdit} disabled={savingEdit}>
|
||||
{savingEdit ? 'Zapisywanie…' : 'Zapisz'}
|
||||
</Button>
|
||||
)}
|
||||
{editing.spec != null && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={restoreCatalogSpec}
|
||||
disabled={savingEdit}
|
||||
>
|
||||
Przywróć specyfikację katalogu
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-4 flex flex-wrap items-center gap-2">
|
||||
<Select
|
||||
value={addId}
|
||||
onChange={(e) => selectAdd(e.target.value)}
|
||||
className="max-w-xs"
|
||||
aria-label="Dodaj urządzenie"
|
||||
>
|
||||
<option value="">+ dodaj urządzenie…</option>
|
||||
{catalog.map((e) => {
|
||||
const qty = totalQty(e.id);
|
||||
const spec = formatEquipmentSpec(e.spec);
|
||||
return (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name}
|
||||
{spec ? ` · ${spec}` : ''}
|
||||
{qty > 0 ? ` (${qty} szt.)` : ''}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={10000}
|
||||
value={addQty}
|
||||
onChange={(e) => setAddQty(e.target.value)}
|
||||
className="w-20"
|
||||
aria-label="Ilość"
|
||||
/>
|
||||
<Button size="sm" onClick={add} disabled={!addId || busy}>
|
||||
{busy ? 'Dodawanie…' : 'Dodaj'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{addItem && hasSpecFields(addItem.kind) && (
|
||||
<div className="mt-3">
|
||||
<label className="mb-2 flex cursor-pointer items-center gap-2 text-[0.875rem]">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={addCustom}
|
||||
onChange={(e) => setAddCustom(e.target.checked)}
|
||||
className="h-4 w-4 accent-accent"
|
||||
/>
|
||||
Ustaw własne parametry (domyślne: {formatEquipmentSpec(addItem.spec) ?? 'brak'})
|
||||
</label>
|
||||
{addCustom && (
|
||||
<SpecFieldsEditor
|
||||
kind={addItem.kind}
|
||||
values={addFields}
|
||||
onChange={(patch) => setAddFields({ ...addFields, ...patch })}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* DODAWANIE z katalogu: pozycja zawsze z własnymi parametrami i opcjonalnymi zdjęciami */}
|
||||
<div className="rounded-xl border border-line bg-input/40 p-3.5">
|
||||
<div className="mb-2.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Dodaj urządzenie z katalogu
|
||||
</div>
|
||||
)}
|
||||
{addItem && (
|
||||
<div className="mt-3">
|
||||
<PhotoPicker files={addFiles} onChange={setAddFiles} label="Zdjęcia urządzenia" />
|
||||
<div className="flex flex-wrap items-end gap-2.5">
|
||||
<div className="min-w-0 flex-1 basis-52">
|
||||
<Select
|
||||
value={addId}
|
||||
onChange={(e) => selectAdd(e.target.value)}
|
||||
aria-label="Dodaj urządzenie"
|
||||
>
|
||||
<option value="">Wybierz urządzenie…</option>
|
||||
{catalog.map((e) => {
|
||||
const qty = totalQty(e.id);
|
||||
return (
|
||||
<option key={e.id} value={e.id}>
|
||||
{e.name}
|
||||
{qty > 0 ? ` (na stanie: ${qty})` : ''}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</div>
|
||||
<Field label="Ilość" className="w-20 shrink-0">
|
||||
<Input
|
||||
type="number"
|
||||
size="sm"
|
||||
min={1}
|
||||
max={10000}
|
||||
value={addQty}
|
||||
onChange={(e) => setAddQty(e.target.value)}
|
||||
aria-label="Ilość"
|
||||
/>
|
||||
</Field>
|
||||
<Button onClick={add} disabled={!addId || addBusy} className="shrink-0">
|
||||
{addBusy ? 'Dodawanie…' : 'Dodaj'}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{isLoading && <Loading />}
|
||||
</>
|
||||
{addItem && (
|
||||
<div className="mt-3.5 border-t border-line pt-3.5">
|
||||
{hasSpecFields(addItem.kind) && (
|
||||
<div className="mb-3.5">
|
||||
<div className="mb-2 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Parametry
|
||||
</div>
|
||||
<SpecFieldsEditor
|
||||
kind={addItem.kind}
|
||||
values={addFields}
|
||||
onChange={(patch) => setAddFields({ ...addFields, ...patch })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={addPhotosOpen}
|
||||
onClick={() => setAddPhotosOpen(!addPhotosOpen)}
|
||||
className="inline-flex cursor-pointer items-center gap-1.5 text-[0.85rem] font-semibold text-dim hover:text-accent-text"
|
||||
>
|
||||
<span
|
||||
aria-hidden
|
||||
className={`grid h-4 w-4 place-items-center rounded border ${
|
||||
addPhotosOpen
|
||||
? 'border-accent bg-accent text-accent-ink'
|
||||
: 'border-line bg-input'
|
||||
}`}
|
||||
>
|
||||
{addPhotosOpen && <Check className="h-3 w-3" />}
|
||||
</span>
|
||||
Dodaj zdjęcia do tej pozycji (opcjonalnie)
|
||||
</button>
|
||||
{addPhotosOpen && (
|
||||
<PhotoPicker files={addFiles} onChange={setAddFiles} label="Zdjęcia urządzenia" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,8 +130,10 @@ test('ponowne dodanie tego samego typu tworzy osobną instancję urządzenia', a
|
||||
// zarządzanie sprzętem z menu kontekstowego (grupa „Urządzenia” → modal)
|
||||
await page.locator('button[data-slot="button"]', { hasText: 'Urządzenia' }).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
// każde dodanie = NOWA instancja (osobny chip), bez inkrementacji ilości
|
||||
// każde dodanie = NOWA instancja z własnymi parametrami (bez inkrementacji ilości)
|
||||
await dialog.getByLabel('Dodaj urządzenie').selectOption('eq-2');
|
||||
await dialog.getByLabel('Min. obciążenie (kg)').fill('2.5');
|
||||
await dialog.getByLabel('Max. obciążenie (kg)').fill('25');
|
||||
await dialog.getByRole('button', { name: 'Dodaj', exact: true }).click();
|
||||
await expect(dialog.getByText('Hantle · 2.5–25 kg', { exact: true })).toBeVisible();
|
||||
await expect(dialog.getByText('Hantle ×2 · 2.5–25 kg', { exact: true })).toBeVisible();
|
||||
@@ -170,7 +172,6 @@ test('właściciel może nadać instancji własne parametry (nadpisanie speca)',
|
||||
|
||||
// panel edycji instancji Hantle: własny zakres 5–5 kg = ciężar stały „5 kg”
|
||||
await dialog.getByRole('button', { name: 'Edytuj Hantle' }).click();
|
||||
await dialog.getByRole('checkbox', { name: /Własne parametry/ }).check();
|
||||
await dialog.getByLabel('Min. obciążenie (kg)').fill('5');
|
||||
await dialog.getByLabel('Max. obciążenie (kg)').fill('5');
|
||||
await dialog.getByRole('button', { name: 'Zapisz' }).click();
|
||||
|
||||
Reference in New Issue
Block a user