Update FamilyDetail.tsx

This commit is contained in:
2025-12-12 19:25:48 +01:00
committed by GitHub
parent e2c66d63db
commit 7950d2f025

View File

@@ -144,12 +144,17 @@ export const FamilyDetail: React.FC = () => {
if (!family || !id) return; if (!family || !id) return;
setIsSubmitting(true); setIsSubmitting(true);
try { try {
// Format date to SQL compatible string: YYYY-MM-DD HH:mm:ss
// This is safe for both MySQL (Strict Mode) and PostgreSQL
const now = new Date();
const sqlDate = now.toISOString().slice(0, 19).replace('T', ' ');
const payment = await CondoService.addPayment({ const payment = await CondoService.addPayment({
familyId: id, familyId: id,
amount: newPaymentAmount, amount: newPaymentAmount,
forMonth: newPaymentMonth, forMonth: newPaymentMonth,
forYear: selectedYear, forYear: selectedYear,
datePaid: new Date().toISOString(), datePaid: sqlDate,
notes: details ? `Pagato con PayPal (ID: ${details.id})` : '' notes: details ? `Pagato con PayPal (ID: ${details.id})` : ''
}); });
@@ -169,7 +174,17 @@ export const FamilyDetail: React.FC = () => {
} }
} catch (e: any) { } catch (e: any) {
console.error("Failed to add payment", e); console.error("Failed to add payment", e);
alert(`Errore durante il salvataggio del pagamento: ${e.message || "Errore sconosciuto"}`); // Clean error message if it's a JSON string from backend
let msg = e.message || "Errore sconosciuto";
try {
const parsed = JSON.parse(msg);
if (parsed.error && parsed.error.includes("Incorrect datetime")) {
msg = "Errore data sistema (DB strict mode). Contatta l'assistenza.";
} else if (parsed.error) {
msg = parsed.error;
}
} catch {}
alert(`Errore durante il salvataggio: ${msg}`);
} finally { } finally {
setIsSubmitting(false); setIsSubmitting(false);
} }