import { useState } from 'react' import apiClient from '../api/client' import MealTypeSelect from './MealTypeSelect' import { parseDecimal } from '../utils/numbers' export default function EditLogModal({ log, onSaved, onClose }) { const [amountG, setAmountG] = useState(String(log.amount_g)) const [mealType, setMealType] = useState(log.meal_type) const [error, setError] = useState('') const [isSubmitting, setIsSubmitting] = useState(false) async function handleSubmit(e) { e.preventDefault() setError('') setIsSubmitting(true) try { await apiClient.put(`/api/logs/${log.id}`, { amount_g: parseDecimal(amountG), meal_type: mealType, }) onSaved() } catch { setError('Eintrag konnte nicht gespeichert werden.') } finally { setIsSubmitting(false) } } return (
Eintrag bearbeiten