// routes/tenant/applications/index.tsx import { define } from "../../../utils.ts"; import { page } from "fresh"; import { getApplicationsByApplicant } from "../../../services/tenantApplicationService.ts"; import { TenantApplication } from "../../../db/interfaces.ts"; import { AlertMessage } from "../maintenance/new/components/AlertMessage.tsx"; interface ApplicationsPageData { applications: TenantApplication[]; error?: string; } export const handler = define.handlers({ async GET(ctx) { const { user_id } = ctx.state.data; try { const applications = await getApplicationsByApplicant( user_id, ) as TenantApplication[]; return page({ applications: applications || [], }); } catch (error) { console.error("Error loading tenant applications:", error); return page({ applications: [], error: "Failed to load applications.", }); } }, }); function ApplicationStatusPill({ status }: { status: string }) { let colorClass = "bg-gray-100 text-gray-800"; switch (status.toLowerCase()) { case "submitted": case "pending": colorClass = "bg-yellow-100 text-yellow-800"; break; case "approved": colorClass = "bg-green-100 text-green-800"; break; case "rejected": colorClass = "bg-red-100 text-red-800"; break; } return ( {status} ); } export default define.page(function TenantApplicationsPage({ data }) { const { applications, error } = data as ApplicationsPageData; return (
{/* Header */}

My Applications

View the status of your submitted rental applications.

New Application
{/* Main Content */}
{error && }
{applications.length === 0 ? ( ) : ( applications.map((app) => ( )) )}
Application ID Submitted On Status View
No applications submitted yet.
{app.id.substring(0, 8)}... {app.submitted_on ? new Date(app.submitted_on) .toLocaleDateString() : "N/A"} View Details
); });