import Link from "next/link" import { redirect } from "next/navigation" import { and, desc, eq, ne } from "drizzle-orm" import { db } from "@/lib/db" import { account_members, profiles } from "@/lib/db/schema" import { getSessionUser } from "@/lib/session" import { getAccountContext } from "@/lib/account" import { PLAN_LIMITS } from "@/lib/stripe/plans" import { TeamManager, type TeamMember } from "@/components/dashboard/team-manager" import { Users } from "lucide-react" import type { Plan } from "@/types" export const metadata = { title: "Team Access" } export default async function TeamSettingsPage() { const user = await getSessionUser() if (!user) redirect("/login") const ctx = await getAccountContext(user.id) // If the user is a MEMBER of someone else's account, show a read-only note // instead of management UI — they can't manage the owner's team. if (!ctx.isOwner) { const owner = await db.query.profiles.findFirst({ where: eq(profiles.id, ctx.ownerId), columns: { full_name: true, company_name: true, email: true }, }) const ownerName = owner?.company_name || owner?.full_name || owner?.email || "another landlord" return (
You're a {ctx.role} of {ownerName}'s account
You're working inside {ownerName}'s portfolio.{" "} {ctx.canWrite ? "You can view and edit their data." : "You have read-only access to their data."}{" "} Only the account owner can manage team members.
Invite staff or co-managers to access your portfolio with the Landlord or Lifetime plan. Members can help manage your properties, and viewers get read-only access.
Upgrade your planInvite people to help manage your property portfolio