// routes/landlord/properties/index.tsx import { define } from "../../../utils.ts"; import { SessionCookie } from "../../auth/callback.ts"; import { getPropertiesByUser } from "../../../services/propertyService.ts"; import { page } from "fresh"; import { Property } from "../../../db/interfaces.ts"; import DeletePropertyButton from "../../../islands/DeletePropertyButton.tsx"; export const handler = define.handlers({ async GET(ctx) { const stateData: SessionCookie = ctx.state.data; const { user_id } = stateData; if (!user_id) { return new Response("", { status: 302, headers: { Location: "/auth/login" }, }); } try { const properties = await getPropertiesByUser(user_id); return page({ stateData, properties, }); } catch (error) { console.error("Error loading properties:", error); return page({ stateData, error: "Failed to load properties", }); } }, }); export default define.page(function LandlordProperties({ data }) { const { stateData, properties, error } = data as { stateData: SessionCookie; properties: Property[]; error?: string; }; return (
{/* Header */}

My Properties

Manage your rental properties and listings

{error && (
{error}
)} {properties && properties.length > 0 ? (
{properties.map((property) => (

{property.address_1}

{property.rental_status || "draft"}

{property.city}, {property.state} {property.zip}

{property.bedrooms} bed • {property.bathrooms} bath {property.square_footage && ` • ${property.square_footage.toLocaleString()} sq ft`}

${property.monthly_rent?.toLocaleString() || "N/A"}/month

{property.rental_status === "draft" && ( )}
))}
) : (

No properties

Get started by adding your first rental property.

)}
); });