// routes/tenant/settings/index.tsx import { define } from "../../../utils.ts"; import { page } from "fresh"; import { getUser } from "../../../services/userService.ts"; import { User } from "../../../db/interfaces.ts"; import TenantSettings from "../../../islands/TenantSettings.tsx"; interface SettingsPageData { user: User; error?: string; } export const handler = define.handlers({ async GET(ctx) { const { user_id } = ctx.state.data; if (!user_id) { return new Response("", { status: 302, headers: { Location: "/auth/login" }, }); } try { const user = await getUser(user_id); if (!user) { return page({ user: {} as User, error: "User profile not found.", }); } // Parse JSON fields for the island component const notificationPreferences = user.notification_preferences_json ? JSON.parse(user.notification_preferences_json as string) : {}; const paymentPreferences = user.payment_preferences_json ? JSON.parse(user.payment_preferences_json as string) : {}; // Pass parsed objects back to the page component user.notification_preferences_json = notificationPreferences; user.payment_preferences_json = paymentPreferences; return page({ user, }); } catch (error) { console.error("Error loading settings:", error); return page({ user: {} as User, error: "Failed to load settings.", }); } }, }); export default define.page(function TenantSettingsPage({ data }: { data: SettingsPageData }) { const { user, error } = data as SettingsPageData; if (error) { return (

Error

{error}

); } return (
{/* Header */}

Tenant Settings

Manage your notification and payment preferences.

{/* Main Content */}
); });