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:
@@ -35,14 +35,21 @@ export default function FinancesPage() {
|
||||
const summary = (summaryResponse as any)?.summary || { income: 0, expenses: 0, net: 0 };
|
||||
|
||||
const createRecordMutation = useMutation({
|
||||
mutationFn: (record: typeof newRecord) =>
|
||||
apiRequest("/api/financial/records", {
|
||||
mutationFn: async (record: typeof newRecord) => {
|
||||
const response = await fetch("/api/financial/records", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...record,
|
||||
amount: parseFloat(record.amount),
|
||||
}),
|
||||
}),
|
||||
credentials: "include",
|
||||
});
|
||||
if (!response.ok) throw new Error("Failed to create record");
|
||||
return response.json();
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["/api/financial/records"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["/api/financial/summary"] });
|
||||
|
||||
Reference in New Issue
Block a user