diff options
author | 2025-04-26 01:05:59 +0530 | |
---|---|---|
committer | 2025-04-26 01:05:59 +0530 | |
commit | 84622698f6c0e9d76ebe434c00df587908a37015 (patch) | |
tree | bd36294b36de67fc182bae088ca34943d14ff129 | |
parent | b08baa708e58bffcaed00525ccfc2a704102dc90 (diff) | |
download | finance-84622698f6c0e9d76ebe434c00df587908a37015.tar.gz finance-84622698f6c0e9d76ebe434c00df587908a37015.tar.bz2 finance-84622698f6c0e9d76ebe434c00df587908a37015.zip |
finance/frontend: fix: updated the pages and layouts to be compatible with the backend
-rw-r--r-- | frontend/src/app/(auth)/login/page.tsx | 4 | ||||
-rw-r--r-- | frontend/src/app/(main)/loans/page.tsx | 47 | ||||
-rw-r--r-- | frontend/src/app/layout.tsx | 4 |
3 files changed, 47 insertions, 8 deletions
diff --git a/frontend/src/app/(auth)/login/page.tsx b/frontend/src/app/(auth)/login/page.tsx index 23cdd24..9c6c4b1 100644 --- a/frontend/src/app/(auth)/login/page.tsx +++ b/frontend/src/app/(auth)/login/page.tsx @@ -37,8 +37,8 @@ export default function LoginPage() { setIsLoading(true); try { - const response = await login(email, password); - showNotification('success', `Welcome back, ${response?.user?.Name || 'user'}! You've been successfully logged in.`); + await login(email, password); + showNotification('success', `Welcome back! You've been successfully logged in.`); router.push('/dashboard'); } catch (err: any) { setError(err.message || 'Login failed'); diff --git a/frontend/src/app/(main)/loans/page.tsx b/frontend/src/app/(main)/loans/page.tsx index 07c1428..ef263fd 100644 --- a/frontend/src/app/(main)/loans/page.tsx +++ b/frontend/src/app/(main)/loans/page.tsx @@ -13,6 +13,8 @@ import { loanApi, Loan, LoanInput } from '@/lib/api'; export default function LoansPage() { const queryClient = useQueryClient(); const [isAddDialogOpen, setIsAddDialogOpen] = useState(false); + const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false); + const [loanToDelete, setLoanToDelete] = useState<number | null>(null); const [selectedLoan, setSelectedLoan] = useState<Loan | null>(null); // Form state @@ -29,7 +31,15 @@ export default function LoansPage() { queryKey: ['loans'], queryFn: async () => { const response = await loanApi.getLoans(); - return response.loans as Loan[]; + console.log('API Response:', response); // Debug the response structure + + // The response might be the array directly rather than nested under a 'loans' property + if (Array.isArray(response)) { + return response as Loan[]; + } + + // Or it might be nested under a 'loans' or 'data' property + return (response.loans || response.data || []) as Loan[]; } }); @@ -51,6 +61,8 @@ export default function LoansPage() { mutationFn: (id: number) => loanApi.deleteLoan(id), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['loans'] }); + setIsDeleteDialogOpen(false); + setLoanToDelete(null); } }); @@ -92,8 +104,13 @@ export default function LoansPage() { }; const handleDeleteLoan = (id: number) => { - if (window.confirm('Are you sure you want to delete this loan?')) { - deleteLoanMutation.mutate(id); + setLoanToDelete(id); + setIsDeleteDialogOpen(true); + }; + + const confirmDeleteLoan = () => { + if (loanToDelete !== null) { + deleteLoanMutation.mutate(loanToDelete); } }; @@ -221,6 +238,30 @@ export default function LoansPage() { </Dialog> </div> + {/* Delete Confirmation Dialog */} + <Dialog open={isDeleteDialogOpen} onOpenChange={setIsDeleteDialogOpen}> + <DialogContent className="sm:max-w-md"> + <DialogHeader> + <DialogTitle>Confirm Deletion</DialogTitle> + </DialogHeader> + <div className="space-y-4 py-4"> + <p>Are you sure you want to delete this loan? This action cannot be undone.</p> + </div> + <div className="flex justify-end space-x-2"> + <Button variant="outline" onClick={() => setIsDeleteDialogOpen(false)}> + Cancel + </Button> + <Button + variant="destructive" + onClick={confirmDeleteLoan} + disabled={deleteLoanMutation.isPending} + > + {deleteLoanMutation.isPending ? 'Deleting...' : 'Delete Loan'} + </Button> + </div> + </DialogContent> + </Dialog> + {data && data.length > 0 ? ( <Card> <CardHeader> diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index f746389..d1442c8 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -27,9 +27,7 @@ export default function RootLayout({ }>) { return ( <html lang="en" suppressHydrationWarning> - <body - className={`${geistSans.variable} ${geistMono.variable} antialiased`} - > + <body suppressHydrationWarning className={`${geistSans.variable} ${geistMono.variable} antialiased`} > <ThemeProvider> <Providers> <NotificationProvider> |