Update FamilyDetail.tsx
This commit is contained in:
@@ -144,12 +144,17 @@ export const FamilyDetail: React.FC = () => {
|
||||
if (!family || !id) return;
|
||||
setIsSubmitting(true);
|
||||
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({
|
||||
familyId: id,
|
||||
amount: newPaymentAmount,
|
||||
forMonth: newPaymentMonth,
|
||||
forYear: selectedYear,
|
||||
datePaid: new Date().toISOString(),
|
||||
datePaid: sqlDate,
|
||||
notes: details ? `Pagato con PayPal (ID: ${details.id})` : ''
|
||||
});
|
||||
|
||||
@@ -169,7 +174,17 @@ export const FamilyDetail: React.FC = () => {
|
||||
}
|
||||
} catch (e: any) {
|
||||
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 {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user