import { MembersList } from "./components/membersList"; import { getOrgMembers } from "@/actions"; import { isServiceError } from "@/lib/utils"; import { getOrgFromDomain } from "@/data/org"; import { InviteMemberCard } from "./components/inviteMemberCard"; import { Tabs, TabsContent } from "@/components/ui/tabs"; import { TabSwitcher } from "@/components/ui/tab-switcher"; import { InvitesList } from "./components/invitesList"; import { getOrgInvites, getMe, getOrgAccountRequests } from "@/actions"; import { IS_BILLING_ENABLED } from "@/ee/features/billing/stripe"; import { ServiceErrorException } from "@/lib/serviceError"; import { getSeats, SOURCEBOT_UNLIMITED_SEATS } from "@sourcebot/shared"; import { RequestsList } from "./components/requestsList"; import { OrgRole } from "@prisma/client"; import { redirect } from "next/navigation"; import { NotificationDot } from "../../components/notificationDot"; import { Badge } from "@/components/ui/badge"; interface MembersSettingsPageProps { params: Promise<{ domain: string }>, searchParams: Promise<{ tab?: string }> } export default async function MembersSettingsPage(props: MembersSettingsPageProps) { const searchParams = await props.searchParams; const { tab } = searchParams; const params = await props.params; const { domain } = params; const org = await getOrgFromDomain(domain); if (!org) { throw new Error("Organization not found"); } const me = await getMe(); if (isServiceError(me)) { throw new ServiceErrorException(me); } const userRoleInOrg = me.memberships.find((membership) => membership.id === org.id)?.role; if (!userRoleInOrg) { throw new Error("User role not found"); } if (userRoleInOrg !== OrgRole.OWNER) { redirect(`/${domain}/settings`); } const members = await getOrgMembers(domain); if (isServiceError(members)) { throw new ServiceErrorException(members); } const invites = await getOrgInvites(domain); if (isServiceError(invites)) { throw new ServiceErrorException(invites); } const requests = await getOrgAccountRequests(domain); if (isServiceError(requests)) { throw new ServiceErrorException(requests); } const currentTab = tab || "members"; const seats = getSeats(); const usedSeats = members.length const seatsAvailable = seats === SOURCEBOT_UNLIMITED_SEATS || usedSeats < seats; return (
Invite and manage members of your organization.