import { useState } from "react"; import { Modal, Button, Alert } from "react-bootstrap"; import { clearMockData, 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 smazání mock dat (pouze DEV). */ export default function ClearMockDataModal({ isOpen, onClose, currentDayIndex }: Readonly) { const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const handleClear = async () => { setError(null); setLoading(true); try { const body: any = {}; if (currentDayIndex !== undefined) { body.dayIndex = currentDayIndex as DayIndex; } const response = await clearMockData({ body }); if (response.error) { setError((response.error as any).error || 'Nastala chyba při mazání dat'); } else { setSuccess(true); setTimeout(() => { onClose(); setSuccess(false); }, 1500); } } catch (e: any) { setError(e.message || 'Nastala chyba při mazání dat'); } finally { setLoading(false); } }; const handleClose = () => { setError(null); setSuccess(false); onClose(); }; const dayName = currentDayIndex !== undefined ? DAY_NAMES[currentDayIndex] : 'aktuální den'; return (

Smazat data

{success ? ( Data byla úspěšně smazána! ) : ( <> DEV režim - Tato funkce je dostupná pouze ve vývojovém prostředí. {error && ( setError(null)} dismissible> {error} )}

Opravdu chcete smazat všechny volby stravování pro {dayName}?

Tato akce je nevratná.

)}
{!success && ( <> )} {success && ( )}
); }