import { useState } from "react"; import { Modal, Button, Form, Alert } from "react-bootstrap"; import { generateMockData, DayIndex } from "../../../../types"; type Props = { isOpen: boolean; onClose: () => void; currentDayIndex?: number; }; const DAY_NAMES = ['Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek']; /** Modální dialog pro generování mock dat (pouze DEV). */ export default function GenerateMockDataModal({ isOpen, onClose, currentDayIndex }: Readonly) { const [dayIndex, setDayIndex] = useState(currentDayIndex); const [count, setCount] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const handleGenerate = async () => { setError(null); setLoading(true); try { const body: any = {}; if (dayIndex !== undefined) { body.dayIndex = dayIndex as DayIndex; } if (count && count.trim() !== '') { const countNum = parseInt(count, 10); if (isNaN(countNum) || countNum < 1 || countNum > 100) { setError('Počet musí být číslo mezi 1 a 100'); setLoading(false); return; } body.count = countNum; } const response = await generateMockData({ body }); if (response.error) { setError((response.error as any).error || 'Nastala chyba při generování dat'); } else { setSuccess(true); setTimeout(() => { onClose(); setSuccess(false); setCount(''); }, 1500); } } catch (e: any) { setError(e.message || 'Nastala chyba při generování dat'); } finally { setLoading(false); } }; const handleClose = () => { setError(null); setSuccess(false); setCount(''); onClose(); }; return (

Generovat mock data

{success ? ( Mock data byla úspěšně vygenerována! ) : ( <> DEV režim - Tato funkce je dostupná pouze ve vývojovém prostředí. {error && ( setError(null)} dismissible> {error} )} Den setDayIndex(e.target.value === '' ? undefined : parseInt(e.target.value, 10))} > {DAY_NAMES.map((name, index) => ( ))} Pokud není vybráno, použije se aktuální den. Počet záznamů setCount(e.target.value)} min={1} max={100} onKeyDown={e => e.stopPropagation()} /> Pokud není zadáno, vybere se náhodný počet 5-20. )} {!success && ( <> )} {success && ( )}
); }