From 84622698f6c0e9d76ebe434c00df587908a37015 Mon Sep 17 00:00:00 2001 From: Biswa Kalyan Bhuyan Date: Sat, 26 Apr 2025 01:05:59 +0530 Subject: finance/frontend: fix: updated the pages and layouts to be compatible with the backend --- frontend/src/app/(auth)/login/page.tsx | 4 +-- frontend/src/app/(main)/loans/page.tsx | 47 +++++++++++++++++++++++++++++++--- 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(null); const [selectedLoan, setSelectedLoan] = useState(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() { + {/* Delete Confirmation Dialog */} + + + + Confirm Deletion + +
+

Are you sure you want to delete this loan? This action cannot be undone.

+
+
+ + +
+
+
+ {data && data.length > 0 ? ( 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 ( - + -- cgit v1.2.3-59-g8ed1b