Improve financial record creation by ensuring data is handled correctly

Refactor createRecordMutation in FinancesPage.tsx to handle fetch responses properly.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: ff0be73b-afdd-4747-978b-bb8301fb0a82
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9777c70b-fc38-4831-8d6b-78dfffe041b0/1999d076-38ec-4633-8667-1740c231dafc.jpg
This commit is contained in:
ghaddaditw
2025-06-08 00:06:16 +00:00
parent fe0aa91ca9
commit 56f2f98a5e
+10 -3
View File
@@ -35,14 +35,21 @@ export default function FinancesPage() {
const summary = (summaryResponse as any)?.summary || { income: 0, expenses: 0, net: 0 }; const summary = (summaryResponse as any)?.summary || { income: 0, expenses: 0, net: 0 };
const createRecordMutation = useMutation({ const createRecordMutation = useMutation({
mutationFn: (record: typeof newRecord) => mutationFn: async (record: typeof newRecord) => {
apiRequest("/api/financial/records", { const response = await fetch("/api/financial/records", {
method: "POST", method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
...record, ...record,
amount: parseFloat(record.amount), amount: parseFloat(record.amount),
}), }),
}), credentials: "include",
});
if (!response.ok) throw new Error("Failed to create record");
return response.json();
},
onSuccess: () => { onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["/api/financial/records"] }); queryClient.invalidateQueries({ queryKey: ["/api/financial/records"] });
queryClient.invalidateQueries({ queryKey: ["/api/financial/summary"] }); queryClient.invalidateQueries({ queryKey: ["/api/financial/summary"] });