import React, { useState } from 'react' import DashboardLayout from '@/components/layout/DashboardLayout' import { useSession } from 'next-auth/react' import { MagnifyingGlassIcon, FunnelIcon, EllipsisHorizontalIcon, CalendarIcon, BanknotesIcon, ClockIcon, ExclamationTriangleIcon, DocumentTextIcon, } from '@heroicons/react/24/outline' import { Menu, Transition } from '@headlessui/react' import { Fragment } from 'react' type LoanStatus = 'Active' | 'Pending Approval' | 'Overdue' | 'Completed' | 'Defaulted' | 'Restructured' type LoanType = 'Business Expansion' | 'Working Capital' | 'Asset Financing' | 'Invoice Discounting' | 'Emergency Loan' type RepaymentFrequency = 'Daily' | 'Weekly' | 'Monthly' | 'Quarterly' interface Loan { id: string clientName: string businessName: string loanType: LoanType amount: number interestRate: number disbursementDate: string dueDate: string status: LoanStatus repaymentFrequency: RepaymentFrequency totalRepaid: number remainingBalance: number nextPaymentDate: string nextPaymentAmount: number collateral?: { type: string value: number description: string } guarantors: string[] latePayments: number restructured: boolean documents: { offerLetter: boolean contract: boolean collateralDocs: boolean guarantorForms: boolean } } const sampleLoans: Loan[] = [ { id: 'L001', clientName: 'Wanjiku Kamau', businessName: 'Kamau Fresh Produce', loanType: 'Working Capital', amount: 250000, interestRate: 15, disbursementDate: '2024-01-15', dueDate: '2024-07-15', status: 'Active', repaymentFrequency: 'Monthly', totalRepaid: 100000, remainingBalance: 150000, nextPaymentDate: '2024-03-15', nextPaymentAmount: 25000, collateral: { type: 'Land', value: 1000000, description: '2 Acres Agricultural Land in Nyeri' }, guarantors: ['John Mwangi', 'Grace Njeri'], latePayments: 0, restructured: false, documents: { offerLetter: true, contract: true, collateralDocs: true, guarantorForms: true } }, { id: 'L002', clientName: 'Odhiambo Otieno', businessName: 'Quick Shuttle Services', loanType: 'Asset Financing', amount: 500000, interestRate: 18, disbursementDate: '2024-02-01', dueDate: '2025-02-01', status: 'Active', repaymentFrequency: 'Monthly', totalRepaid: 50000, remainingBalance: 450000, nextPaymentDate: '2024-03-01', nextPaymentAmount: 50000, collateral: { type: 'Vehicle', value: 800000, description: '2020 Toyota Hiace' }, guarantors: ['Peter Ouko', 'Sarah Akinyi'], latePayments: 1, restructured: false, documents: { offerLetter: true, contract: true, collateralDocs: true, guarantorForms: true } }, { id: 'L003', clientName: 'Amina Hassan', businessName: 'Amina Beauty Shop', loanType: 'Business Expansion', amount: 150000, interestRate: 15, disbursementDate: '2024-02-10', dueDate: '2024-08-10', status: 'Pending Approval', repaymentFrequency: 'Monthly', totalRepaid: 0, remainingBalance: 150000, nextPaymentDate: '2024-03-10', nextPaymentAmount: 30000, guarantors: ['Fatuma Ali'], latePayments: 0, restructured: false, documents: { offerLetter: true, contract: false, collateralDocs: false, guarantorForms: true } }, { id: 'L004', clientName: 'Kipchoge Kiprotich', businessName: 'Tech Solutions Kenya', loanType: 'Working Capital', amount: 300000, interestRate: 15, disbursementDate: '2023-08-15', dueDate: '2024-02-15', status: 'Defaulted', repaymentFrequency: 'Monthly', totalRepaid: 100000, remainingBalance: 200000, nextPaymentDate: '2024-02-15', nextPaymentAmount: 60000, guarantors: ['William Ruto', 'David Kimani'], latePayments: 3, restructured: true, documents: { offerLetter: true, contract: true, collateralDocs: false, guarantorForms: true } }, { id: 'L005', clientName: 'Njeri Muthoni', businessName: 'Njeri Cereals & Supplies', loanType: 'Invoice Discounting', amount: 450000, interestRate: 12, disbursementDate: '2023-06-20', dueDate: '2023-12-20', status: 'Completed', repaymentFrequency: 'Monthly', totalRepaid: 450000, remainingBalance: 0, nextPaymentDate: '2023-12-20', nextPaymentAmount: 0, collateral: { type: 'Commercial Property', value: 2000000, description: 'Shop Space in Nakuru CBD' }, guarantors: ['James Kariuki', 'Mary Wangari'], latePayments: 0, restructured: false, documents: { offerLetter: true, contract: true, collateralDocs: true, guarantorForms: true } } ] const statusColors: Record = { 'Active': 'bg-green-100 text-green-800', 'Pending Approval': 'bg-yellow-100 text-yellow-800', 'Overdue': 'bg-orange-100 text-orange-800', 'Completed': 'bg-blue-100 text-blue-800', 'Defaulted': 'bg-red-100 text-red-800', 'Restructured': 'bg-purple-100 text-purple-800' } export default function LoansPage() { const { data: session, status } = useSession() const [searchTerm, setSearchTerm] = useState('') const [selectedStatus, setSelectedStatus] = useState<'all' | LoanStatus>('all') const [selectedLoanType, setSelectedLoanType] = useState<'all' | LoanType>('all') if (status === 'loading') { return
Loading...
} if (!session) { return null } const filteredLoans = sampleLoans.filter(loan => { const matchesSearch = loan.clientName.toLowerCase().includes(searchTerm.toLowerCase()) || loan.businessName.toLowerCase().includes(searchTerm.toLowerCase()) || loan.id.toLowerCase().includes(searchTerm.toLowerCase()) const matchesStatus = selectedStatus === 'all' || loan.status === selectedStatus const matchesType = selectedLoanType === 'all' || loan.loanType === selectedLoanType return matchesSearch && matchesStatus && matchesType }) return (

Loan Management

Monitor active loans, process applications, and manage repayments.

{/* Filters and Search */}
setSearchTerm(e.target.value)} />
{/* Loans Table */}
{filteredLoans.map((loan) => ( ))}
Loan Details Client Information Payment Status Documents Actions
{loan.id} - {loan.loanType}
KES {loan.amount.toLocaleString()} @ {loan.interestRate}%
Disbursed: {loan.disbursementDate}
Due: {loan.dueDate}
{loan.clientName}
{loan.businessName}
{loan.guarantors.length} Guarantor{loan.guarantors.length !== 1 ? 's' : ''}
{loan.collateral && (
Collateral: {loan.collateral.type}
)}
{loan.status}
Repaid: KES {loan.totalRepaid.toLocaleString()}
Balance: KES {loan.remainingBalance.toLocaleString()}
Next: KES {loan.nextPaymentAmount.toLocaleString()}
Due: {loan.nextPaymentDate}
{loan.latePayments > 0 && (
{loan.latePayments} late payment{loan.latePayments !== 1 ? 's' : ''}
)} {loan.restructured && (
Restructured
)}
Offer Letter
Contract
Collateral Docs
Guarantor Forms
Open options
{({ active }) => ( View Details )} {({ active }) => ( Payment Schedule )} {({ active }) => ( Generate Statement )} {({ active }) => ( Download Documents )} {loan.status === 'Active' && ( {({ active }) => ( Mark as Defaulted )} )}
) }