import { useRef, useState } from "react"; import { Modal, Button, Alert, Form } from "react-bootstrap"; type Props = { isOpen: boolean; onClose: () => void; }; /** Modální dialog pro přenačtení menu z restaurací. */ export default function RefreshMenuModal({ isOpen, onClose }: Readonly) { const refreshPassRef = useRef(null); const refreshTypeRef = useRef(null); const [refreshLoading, setRefreshLoading] = useState(false); const [refreshMessage, setRefreshMessage] = useState<{ type: 'success' | 'error', text: string } | null>(null); const handleRefresh = async () => { const password = refreshPassRef.current?.value; const type = refreshTypeRef.current?.value; if (!password || !type) { setRefreshMessage({ type: 'error', text: 'Zadejte heslo a typ refresh.' }); return; } setRefreshLoading(true); setRefreshMessage(null); try { const res = await fetch(`/api/food/refresh?type=${type}&heslo=${encodeURIComponent(password)}`); const data = await res.json(); if (res.ok) { setRefreshMessage({ type: 'success', text: 'Uspesny fetch' }); if (refreshPassRef.current) { refreshPassRef.current.value = ''; } } else { setRefreshMessage({ type: 'error', text: data.error || 'Chyba při obnovování jídelníčku.' }); } } catch (error) { console.error('Error refreshing menu:', error); setRefreshMessage({ type: 'error', text: 'Chyba při obnovování jídelníčku.' }); } finally { setRefreshLoading(false); } }; const handleClose = () => { setRefreshMessage(null); onClose(); }; return (

Přenačtení menu

Ruční refresh dat z restaurací.

{refreshMessage && ( {refreshMessage.text} )} Heslo e.stopPropagation()} /> Typ refreshe
); }