Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Add members page (#1840)

Luke Vella72059dc31f2f
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index d33df96c2..e4af0f74d 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -299,11 +299,8 @@
"commandMenuNoResults": "No results",
"commandMenu": "Command Menu",
"commandMenuDescription": "Select a command",
- "eventsPageDesc": "View and manage your scheduled events",
- "homeDashboardDesc": "Manage your polls, events, and account settings",
"homeNavTitle": "Navigation",
"account": "Account",
- "pollsPageDesc": "View and manage all your scheduling polls",
"signOut": "Sign Out",
"paginationItems": "Showing {startItem}–{endItem} of {totalItems}",
"paginationPrevious": "Previous",
@@ -401,5 +398,15 @@
"createSpaceDescription": "Create a new space to organize your polls and events.",
"createSpaceLoading": "Creating space...",
"createSpaceSuccess": "Space created successfully",
- "createSpaceError": "Failed to create space"
+ "createSpaceError": "Failed to create space",
+ "members": "Members",
+ "noMembers": "No members found",
+ "noMembersDescription": "Try adjusting your search",
+ "searchMembers": "Search members",
+ "actionErrorTooManyRequests": "You are making too many requests",
+ "owner": "Owner",
+ "member": "Member",
+ "allMembers": "All",
+ "inviteMember": "Invite member",
+ "content": "Content"
}
diff --git a/apps/web/src/app/[locale]/(space)/account/layout.tsx b/apps/web/src/app/[locale]/(space)/account/layout.tsx
index f8f4093b1..086db0a27 100644
--- a/apps/web/src/app/[locale]/(space)/account/layout.tsx
+++ b/apps/web/src/app/[locale]/(space)/account/layout.tsx
@@ -4,6 +4,8 @@ import {
PageContainer,
PageContent,
PageHeader,
+ PageHeaderActions,
+ PageHeaderContent,
PageTitle,
} from "@/app/components/page-layout";
import { Trans } from "@/components/trans";
@@ -19,16 +21,14 @@ export default async function ProfileLayout({
return (
<PageContainer>
<PageHeader>
- <div className="flex items-start gap-4">
- <div className="flex-1">
- <PageTitle>
- <Trans i18nKey="settings" />
- </PageTitle>
- </div>
- <div className="flex items-center gap-2">
- <SignOutButton />
- </div>
- </div>
+ <PageHeaderContent>
+ <PageTitle>
+ <Trans i18nKey="settings" />
+ </PageTitle>
+ </PageHeaderContent>
+ <PageHeaderActions>
+ <SignOutButton />
+ </PageHeaderActions>
</PageHeader>
<PageContent>
<SettingsLayout>{children}</SettingsLayout>
diff --git a/apps/web/src/app/[locale]/(space)/components/sidebar/space-sidebar-menu.tsx b/apps/web/src/app/[locale]/(space)/components/sidebar/space-sidebar-menu.tsx
index 35ebeac11..fe6d1a493 100644
--- a/apps/web/src/app/[locale]/(space)/components/sidebar/space-sidebar-menu.tsx
+++ b/apps/web/src/app/[locale]/(space)/components/sidebar/space-sidebar-menu.tsx
@@ -2,51 +2,52 @@
import { Icon } from "@rallly/ui/icon";
import {
+ SidebarGroup,
+ SidebarGroupContent,
+ SidebarGroupLabel,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
} from "@rallly/ui/sidebar";
-import { BarChart2Icon, CalendarIcon, HomeIcon } from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation";
-import { useTranslation } from "@/i18n/client";
-
-const useSpaceMenuItems = () => {
- const { t } = useTranslation();
- return [
- {
- href: "/",
- icon: <HomeIcon />,
- label: t("home", { defaultValue: "Home" }),
- },
- {
- href: "/polls",
- icon: <BarChart2Icon />,
- label: t("polls", { defaultValue: "Polls" }),
- },
- {
- href: "/events",
- icon: <CalendarIcon />,
- label: t("events", { defaultValue: "Events" }),
- },
- ];
-};
+import { useSpaceMenu } from "@/features/navigation/config";
export function SpaceSidebarMenu() {
- const items = useSpaceMenuItems();
+ const { config } = useSpaceMenu();
const pathname = usePathname();
return (
- <SidebarMenu>
- {items.map((item) => (
- <SidebarMenuItem key={item.href}>
- <SidebarMenuButton asChild isActive={pathname === item.href}>
- <Link href={item.href}>
- <Icon>{item.icon}</Icon>
- {item.label}
- </Link>
- </SidebarMenuButton>
- </SidebarMenuItem>
- ))}
- </SidebarMenu>
+ <>
+ {config.sections.map((section) => {
+ return (
+ <SidebarGroup key={section.id}>
+ {section.title && (
+ <SidebarGroupLabel>{section.title}</SidebarGroupLabel>
+ )}
+ <SidebarGroupContent>
+ <SidebarMenu>
+ {section.items.map((item) => {
+ return (
+ <SidebarMenuItem key={item.id}>
+ <SidebarMenuButton
+ asChild
+ isActive={pathname === item.href}
+ >
+ <Link href={item.href}>
+ <Icon>
+ <item.icon />
+ </Icon>
+ {item.label}
+ </Link>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ );
+ })}
+ </SidebarMenu>
+ </SidebarGroupContent>
+ </SidebarGroup>
+ );
+ })}
+ </>
);
}
diff --git a/apps/web/src/app/[locale]/(space)/components/sidebar/space-sidebar.tsx b/apps/web/src/app/[locale]/(space)/components/sidebar/space-sidebar.tsx
index bd50fdaf2..2484fdc31 100644
--- a/apps/web/src/app/[locale]/(space)/components/sidebar/space-sidebar.tsx
+++ b/apps/web/src/app/[locale]/(space)/components/sidebar/space-sidebar.tsx
@@ -4,7 +4,6 @@ import {
Sidebar,
SidebarContent,
SidebarFooter,
- SidebarGroup,
SidebarHeader,
SidebarSeparator,
} from "@rallly/ui/sidebar";
@@ -46,28 +45,6 @@ export async function SpaceSidebar({
return (
<Sidebar variant="inset" {...props}>
<SidebarHeader>
- <div className="flex items-center justify-between p-1">
- <div className="flex items-center gap-2">
- <LogoLink />
- </div>
- <div className="flex items-center gap-1">
- <FeedbackToggle />
- <Tooltip>
- <TooltipTrigger asChild>
- <Button variant="ghost" size="icon" asChild>
- <Link href="/new">
- <Icon>
- <PlusIcon />
- </Icon>
- </Link>
- </Button>
- </TooltipTrigger>
- <TooltipContent>
- <Trans i18nKey="create" />
- </TooltipContent>
- </Tooltip>
- </div>
- </div>
{isSpacesEnabled ? (
<div>
<SpaceDropdown spaces={spaces} activeSpaceId={activeSpace.id}>
@@ -85,12 +62,33 @@ export async function SpaceSidebar({
</Button>
</SpaceDropdown>
</div>
- ) : null}
+ ) : (
+ <div className="flex items-center justify-between p-1">
+ <div className="flex items-center gap-2">
+ <LogoLink />
+ </div>
+ <div className="flex items-center gap-1">
+ <FeedbackToggle />
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button variant="ghost" size="icon" asChild>
+ <Link href="/new">
+ <Icon>
+ <PlusIcon />
+ </Icon>
+ </Link>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>
+ <Trans i18nKey="create" />
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </div>
+ )}
</SidebarHeader>
<SidebarContent>
- <SidebarGroup>
- <SpaceSidebarMenu />
- </SidebarGroup>
+ <SpaceSidebarMenu />
</SidebarContent>
<SidebarFooter>
{!user.isPro ? (
diff --git a/apps/web/src/app/[locale]/(space)/events/page.tsx b/apps/web/src/app/[locale]/(space)/events/page.tsx
index 0ba2164ee..d63bf5bb8 100644
--- a/apps/web/src/app/[locale]/(space)/events/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/events/page.tsx
@@ -4,7 +4,6 @@ import type { Params } from "@/app/[locale]/types";
import {
PageContainer,
PageContent,
- PageDescription,
PageHeader,
PageTitle,
} from "@/app/components/page-layout";
@@ -123,12 +122,6 @@ export default async function Page(props: {
<PageTitle>
<Trans i18nKey="events" defaults="Events" />
</PageTitle>
- <PageDescription>
- <Trans
- i18nKey="eventsPageDesc"
- defaults="View and manage your scheduled events"
- />
- </PageDescription>
</PageHeader>
<PageContent>
<div className="space-y-4">
@@ -164,7 +157,6 @@ export default async function Page(props: {
{totalPages > 1 && (
<Pagination
currentPage={page}
- totalPages={totalPages}
totalItems={totalCount}
pageSize={pageSize}
/>
diff --git a/apps/web/src/app/[locale]/(space)/members/components/header.tsx b/apps/web/src/app/[locale]/(space)/members/components/header.tsx
new file mode 100644
index 000000000..722bd5895
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/members/components/header.tsx
@@ -0,0 +1,35 @@
+"use client";
+
+import { Button } from "@rallly/ui/button";
+import { Icon } from "@rallly/ui/icon";
+import { UserPlusIcon } from "lucide-react";
+import {
+ PageHeader,
+ PageHeaderActions,
+ PageTitle,
+} from "@/app/components/page-layout";
+import { SearchInput } from "@/app/components/search-input";
+import { Trans } from "@/components/trans";
+import { useTranslation } from "@/i18n/client";
+
+export function MembersHeader() {
+ const { t } = useTranslation();
+ return (
+ <PageHeader>
+ <PageTitle>
+ <Trans i18nKey="members" defaults="Members" />
+ </PageTitle>
+ <PageHeaderActions>
+ <SearchInput
+ placeholder={t("searchMembers", { defaultValue: "Search members" })}
+ />
+ <Button variant="primary">
+ <Icon>
+ <UserPlusIcon />
+ </Icon>
+ <Trans i18nKey="inviteMember" defaults="Invite member" />
+ </Button>
+ </PageHeaderActions>
+ </PageHeader>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(space)/members/components/tabs.tsx b/apps/web/src/app/[locale]/(space)/members/components/tabs.tsx
new file mode 100644
index 000000000..08b046fb0
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/members/components/tabs.tsx
@@ -0,0 +1,36 @@
+import {
+ PageTabs,
+ PageTabsContent,
+ PageTabsList,
+ PageTabsTrigger,
+} from "@/app/components/page-tabs";
+import { Trans } from "@/components/trans";
+import type { SpaceMemberRole } from "@/features/spaces/schema";
+
+export const MembersTabs = ({
+ value = "all",
+ children,
+}: {
+ value?: "all" | SpaceMemberRole;
+ children: React.ReactNode;
+}) => {
+ return (
+ <PageTabs name="role" value={value}>
+ <PageTabsList>
+ <PageTabsTrigger value="all">
+ <Trans i18nKey="allMembers" defaults="All" />
+ </PageTabsTrigger>
+ <PageTabsTrigger value="member">
+ <Trans i18nKey="member" defaults="Member" />
+ </PageTabsTrigger>
+ <PageTabsTrigger value="admin">
+ <Trans i18nKey="admin" defaults="Admin" />
+ </PageTabsTrigger>
+ <PageTabsTrigger value="owner">
+ <Trans i18nKey="owner" defaults="Owner" />
+ </PageTabsTrigger>
+ </PageTabsList>
+ <PageTabsContent value={value}>{children}</PageTabsContent>
+ </PageTabs>
+ );
+};
diff --git a/apps/web/src/app/[locale]/(space)/members/page.tsx b/apps/web/src/app/[locale]/(space)/members/page.tsx
new file mode 100644
index 000000000..12d988134
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/members/page.tsx
@@ -0,0 +1,105 @@
+import { UserSearchIcon } from "lucide-react";
+import type { Metadata } from "next";
+import { MembersHeader } from "@/app/[locale]/(space)/members/components/header";
+import { MembersTabs } from "@/app/[locale]/(space)/members/components/tabs";
+import { PageContainer, PageContent } from "@/app/components/page-layout";
+import {
+ EmptyState,
+ EmptyStateDescription,
+ EmptyStateIcon,
+ EmptyStateTitle,
+} from "@/components/empty-state";
+import { OptimizedAvatarImage } from "@/components/optimized-avatar-image";
+import { Pagination } from "@/components/pagination";
+import { StackedList, StackedListItem } from "@/components/stacked-list";
+import { Trans } from "@/components/trans";
+import { loadMembers } from "@/data/space";
+import { SpaceRole } from "@/features/spaces/components/space-role";
+import { getTranslation } from "@/i18n/server";
+import { searchParamsSchema } from "./schema";
+
+export default async function MembersPage({
+ searchParams,
+}: {
+ searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
+}) {
+ const { page, pageSize, q, role } = searchParamsSchema.parse(
+ await searchParams,
+ );
+
+ const members = await loadMembers({
+ page,
+ pageSize,
+ q,
+ role,
+ });
+
+ return (
+ <PageContainer>
+ <MembersHeader />
+ <PageContent className="space-y-4">
+ <MembersTabs value={role}>
+ {members.data.length === 0 ? (
+ <EmptyState>
+ <EmptyStateIcon>
+ <UserSearchIcon />
+ </EmptyStateIcon>
+ <EmptyStateTitle>
+ <Trans i18nKey="noMembers" defaults="No members found" />
+ </EmptyStateTitle>
+ <EmptyStateDescription>
+ <Trans
+ i18nKey="noMembersDescription"
+ defaults="Try adjusting your search"
+ />
+ </EmptyStateDescription>
+ </EmptyState>
+ ) : (
+ <>
+ <StackedList>
+ {members.data.map((member) => (
+ <StackedListItem key={member.id}>
+ <div className="flex flex-1 items-center gap-4">
+ <OptimizedAvatarImage
+ src={member.image ?? undefined}
+ name={member.name}
+ size="md"
+ />
+ <div className="text-sm">
+ <div className="font-semibold">{member.name}</div>
+ <div className="text-muted-foreground">
+ {member.email}
+ </div>
+ </div>
+ </div>
+ <div className="text-sm capitalize">
+ <SpaceRole role={member.role} />
+ </div>
+ </StackedListItem>
+ ))}
+ </StackedList>
+ <div>
+ {members.total > pageSize ? (
+ <Pagination
+ currentPage={page}
+ totalItems={members.total}
+ pageSize={pageSize}
+ />
+ ) : null}
+ </div>
+ </>
+ )}
+ </MembersTabs>
+ </PageContent>
+ </PageContainer>
+ );
+}
+
+export async function generateMetadata(): Promise<Metadata> {
+ const { t } = await getTranslation();
+ return {
+ title: t("members", {
+ defaultValue: "Members",
+ }),
+ };
+}
diff --git a/apps/web/src/app/[locale]/(space)/members/schema.ts b/apps/web/src/app/[locale]/(space)/members/schema.ts
new file mode 100644
index 000000000..be5784916
--- /dev/null
+++ b/apps/web/src/app/[locale]/(space)/members/schema.ts
@@ -0,0 +1,8 @@
+import { z } from "zod";
+
+export const searchParamsSchema = z.object({
+ page: z.coerce.number().min(1).default(1),
+ pageSize: z.coerce.number().min(1).default(10),
+ q: z.string().optional(),
+ role: z.enum(["all", "member", "admin", "owner"]).optional().catch("all"),
+});
diff --git a/apps/web/src/app/[locale]/(space)/page.tsx b/apps/web/src/app/[locale]/(space)/page.tsx
index 17bd71b14..723f3ae36 100644
--- a/apps/web/src/app/[locale]/(space)/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/page.tsx
@@ -13,7 +13,6 @@ import {
import {
PageContainer,
PageContent,
- PageDescription,
PageHeader,
PageTitle,
} from "@/app/components/page-layout";
@@ -53,12 +52,6 @@ export default async function Page() {
<PageTitle>
<Trans i18nKey="home" defaults="Home" />
</PageTitle>
- <PageDescription>
- <Trans
- i18nKey="homeDashboardDesc"
- defaults="Manage your polls, events, and account settings"
- />
- </PageDescription>
</PageHeader>
<PageContent className="space-y-8">
<IfCloudHosted>
diff --git a/apps/web/src/app/[locale]/(space)/polls/page.tsx b/apps/web/src/app/[locale]/(space)/polls/page.tsx
index 223631f5e..26bbdf5a3 100644
--- a/apps/web/src/app/[locale]/(space)/polls/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/polls/page.tsx
@@ -8,8 +8,9 @@ import Link from "next/link";
import {
PageContainer,
PageContent,
- PageDescription,
PageHeader,
+ PageHeaderActions,
+ PageHeaderContent,
PageTitle,
} from "@/app/components/page-layout";
import {
@@ -105,26 +106,20 @@ export default async function Page(props: {
return (
<PageContainer>
- <div className="flex gap-4">
- <PageHeader className="flex-1">
+ <PageHeader>
+ <PageHeaderContent>
<PageTitle>
<Trans i18nKey="polls" defaults="Polls" />
</PageTitle>
- <PageDescription>
- <Trans
- i18nKey="pollsPageDesc"
- defaults="View and manage all your scheduling polls"
- />
- </PageDescription>
- </PageHeader>
- <div className="flex items-start gap-2">
- <Button size="sm" asChild>
+ </PageHeaderContent>
+ <PageHeaderActions>
+ <Button variant="primary" asChild>
<Link href="/new">
<Trans i18nKey="create" defaults="Create" />
</Link>
</Button>
- </div>
- </div>
+ </PageHeaderActions>
+ </PageHeader>
<PageContent className="space-y-4">
<SearchInput
placeholder={t("searchPollsPlaceholder", {
@@ -152,7 +147,6 @@ export default async function Page(props: {
{totalPages > 1 ? (
<Pagination
currentPage={page}
- totalPages={totalPages}
totalItems={total}
pageSize={pageSize}
className="mt-4"
diff --git a/apps/web/src/app/[locale]/control-panel/users/page.tsx b/apps/web/src/app/[locale]/control-panel/users/page.tsx
index 5053dd5c7..1be0af568 100644
--- a/apps/web/src/app/[locale]/control-panel/users/page.tsx
+++ b/apps/web/src/app/[locale]/control-panel/users/page.tsx
@@ -111,8 +111,7 @@ export default async function AdminPage(props: {
role: roleSchema.parse(searchParams.role),
});
- const totalPages = Math.ceil(totalUsers / pageSize);
- const totalItems = allUsers.length;
+ const totalItems = totalUsers;
return (
<FullWidthLayout>
@@ -147,7 +146,6 @@ export default async function AdminPage(props: {
</StackedList>
<Pagination
currentPage={page}
- totalPages={totalPages}
totalItems={totalItems}
pageSize={pageSize}
/>
diff --git a/apps/web/src/app/components/page-layout.tsx b/apps/web/src/app/components/page-layout.tsx
index bf273e341..948ba006e 100644
--- a/apps/web/src/app/components/page-layout.tsx
+++ b/apps/web/src/app/components/page-layout.tsx
@@ -33,7 +33,7 @@ export function PageTitle({
);
}
-export function PageDescription({
+export function PageHeader({
children,
className,
}: {
@@ -41,21 +41,39 @@ export function PageDescription({
className?: string;
}) {
return (
- <p className={cn("mt-2 text-muted-foreground text-sm", className)}>
+ <div
+ className={cn(
+ "flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",
+ className,
+ )}
+ >
{children}
- </p>
+ </div>
);
}
-export function PageHeader({
+export function PageHeaderContent({
children,
className,
}: {
children?: React.ReactNode;
className?: string;
- variant?: "default" | "ghost";
}) {
- return <div className={cn(className)}>{children}</div>;
+ return <div className={cn("min-w-0 flex-1", className)}>{children}</div>;
+}
+
+export function PageHeaderActions({
+ children,
+ className,
+}: {
+ children?: React.ReactNode;
+ className?: string;
+}) {
+ return (
+ <div className={cn("flex items-center gap-2 sm:flex-shrink-0", className)}>
+ {children}
+ </div>
+ );
}
export function PageSection({ children }: { children?: React.ReactNode }) {
@@ -85,7 +103,6 @@ export function PageSkeleton() {
<PageTitle>
<Skeleton className="h-6 w-32" />
</PageTitle>
- <Skeleton className="mt-2 h-4 w-64" />
</PageHeader>
<PageContent>
<div className="space-y-8">
diff --git a/apps/web/src/app/components/page-tabs.tsx b/apps/web/src/app/components/page-tabs.tsx
new file mode 100644
index 000000000..90b42cb90
--- /dev/null
+++ b/apps/web/src/app/components/page-tabs.tsx
@@ -0,0 +1,65 @@
+"use client";
+import { cn } from "@rallly/ui";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@rallly/ui/page-tabs";
+import { useRouter, useSearchParams } from "next/navigation";
+import React from "react";
+
+export function PageTabs({
+ children,
+ value,
+ name,
+}: {
+ name: string;
+ value?: string;
+ children: React.ReactNode;
+}) {
+ const searchParams = useSearchParams();
+ const router = useRouter();
+ const [isPending, startTransition] = React.useTransition();
+ const [tab, setTab] = React.useState(value);
+ const handleTabChange = React.useCallback(
+ (value: string) => {
+ const params = new URLSearchParams(searchParams);
+ params.set(name, value);
+
+ params.delete("page");
+
+ setTab(value);
+
+ startTransition(() => {
+ const newUrl = `?${params.toString()}`;
+ router.replace(newUrl, { scroll: false });
+ });
+ },
+ [router, searchParams, name],
+ );
+
+ return (
+ <Tabs
+ className={cn(
+ "transition-opacity",
+ isPending ? "pointer-events-none opacity-50 delay-200" : "",
+ )}
+ value={tab}
+ onValueChange={handleTabChange}
+ >
+ {children}
+ </Tabs>
+ );
+}
+export const PageTabsList = TabsList;
+export const PageTabsTrigger = TabsTrigger;
+
+export function PageTabsContent({
+ value,
+ children,
+}: {
+ value: string;
+ children: React.ReactNode;
+}) {
+ return (
+ <TabsContent tabIndex={-1} value={value}>
+ {children}
+ </TabsContent>
+ );
+}
diff --git a/apps/web/src/components/optimized-avatar-image.tsx b/apps/web/src/components/optimized-avatar-image.tsx
index b02319e9c..d16ff4388 100644
--- a/apps/web/src/components/optimized-avatar-image.tsx
+++ b/apps/web/src/components/optimized-avatar-image.tsx
@@ -35,14 +35,7 @@ export function OptimizedAvatarImage({
)
) : null}
{!src || !isLoaded ? (
- <AvatarFallback
- seed={name}
- className={cn("shrink-0", {
- "text-[10px]": size === "sm",
- "text-[12px]": size === "md",
- "text-md": size === "lg",
- })}
- >
+ <AvatarFallback seed={name} className={cn("shrink-0")}>
{name?.[0]?.toUpperCase()}
</AvatarFallback>
) : null}
diff --git a/apps/web/src/components/pagination.tsx b/apps/web/src/components/pagination.tsx
index ecdd56ac9..4b8140e8d 100644
--- a/apps/web/src/components/pagination.tsx
+++ b/apps/web/src/components/pagination.tsx
@@ -10,7 +10,6 @@ import { Trans } from "@/components/trans";
interface PaginationProps {
currentPage: number;
- totalPages: number;
totalItems: number;
pageSize: number;
className?: string;
@@ -18,7 +17,6 @@ interface PaginationProps {
export function Pagination({
currentPage,
- totalPages,
totalItems,
pageSize,
className,
@@ -30,6 +28,8 @@ export function Pagination({
const startItem = (currentPage - 1) * pageSize + 1;
const endItem = Math.min(currentPage * pageSize, totalItems);
+ const totalPages = Math.ceil(totalItems / pageSize);
+
const navigateToPage = (page: number) => {
const params = new URLSearchParams(searchParams);
params.set("page", page.toString());
diff --git a/apps/web/src/data/space.ts b/apps/web/src/data/space.ts
index 5eaf26b2f..e6e3b614d 100644
--- a/apps/web/src/data/space.ts
+++ b/apps/web/src/data/space.ts
@@ -1,8 +1,10 @@
import { accessibleBy } from "@casl/prisma";
-import type { SpaceMemberRole } from "@rallly/database";
+import type { Prisma } from "@rallly/database";
import { prisma } from "@rallly/database";
import { cache } from "react";
import { loadUserAbility } from "@/data/user";
+import type { SpaceMemberRole } from "@/features/spaces/schema";
+import { fromDBRole, toDBRole } from "@/features/spaces/utils";
export type SpaceDTO = {
id: string;
@@ -45,7 +47,7 @@ export const loadSpaces = cache(async () => {
name: space.name,
ownerId: space.ownerId,
isPro: Boolean(space.subscription?.active),
- role,
+ role: fromDBRole(role),
} satisfies SpaceDTO;
})
.filter(Boolean) as SpaceDTO[];
@@ -127,3 +129,95 @@ export const loadPaymentMethods = cache(async () => {
return paymentMethods;
});
+
+type MemberDTO = {
+ id: string;
+ name: string;
+ email: string;
+ image?: string;
+ role: SpaceMemberRole;
+};
+
+export const loadMembers = cache(
+ async ({
+ page = 1,
+ pageSize = 10,
+ q,
+ role,
+ }: {
+ page?: number;
+ pageSize?: number;
+ q?: string;
+ role?: "all" | SpaceMemberRole;
+ }) => {
+ const space = await loadActiveSpace();
+
+ const whereClause: Prisma.SpaceMemberWhereInput = {
+ spaceId: space.id,
+ ...(q
+ ? {
+ user: {
+ OR: [
+ {
+ name: {
+ contains: q,
+ mode: "insensitive",
+ },
+ },
+ {
+ email: {
+ contains: q,
+ mode: "insensitive",
+ },
+ },
+ ],
+ },
+ }
+ : {}),
+ ...(role && role !== "all"
+ ? {
+ role: toDBRole(role),
+ }
+ : {}),
+ };
+
+ const [members, totalCount] = await Promise.all([
+ prisma.spaceMember.findMany({
+ where: whereClause,
+ select: {
+ id: true,
+ userId: true,
+ role: true,
+ user: {
+ select: {
+ id: true,
+ name: true,
+ email: true,
+ image: true,
+ },
+ },
+ },
+ skip: (page - 1) * pageSize,
+ take: pageSize,
+ }),
+ prisma.spaceMember.count({
+ where: whereClause,
+ }),
+ ]);
+
+ return {
+ total: totalCount,
+ data: members.map(
+ (member) =>
+ ({
+ id: member.id,
+ name: member.user.name,
+ email: member.user.email,
+ image: member.user.image ?? undefined,
+ role: fromDBRole(member.role),
+ }) satisfies MemberDTO,
+ ),
+ hasNextPage: page * pageSize < totalCount,
+ };
+ },
+);
diff --git a/apps/web/src/features/navigation/config.tsx b/apps/web/src/features/navigation/config.tsx
new file mode 100644
index 000000000..af5929a6d
--- /dev/null
+++ b/apps/web/src/features/navigation/config.tsx
@@ -0,0 +1,96 @@
+"use client";
+
+import type { LucideIcon } from "lucide-react";
+import { BarChart2Icon, CalendarIcon, HomeIcon, UsersIcon } from "lucide-react";
+import { usePathname } from "next/navigation";
+import React from "react";
+import { useTranslation } from "@/i18n/client";
+
+export interface NavigationItem {
+ id: string;
+ label: string;
+ href: string;
+ icon: LucideIcon;
+ badge?: string | number;
+ children?: NavigationItem[];
+ isActive?: boolean;
+ external?: boolean;
+}
+
+export interface NavigationSection {
+ id: string;
+ title?: string;
+ items: NavigationItem[];
+}
+
+export interface NavigationConfig {
+ sections: NavigationSection[];
+}
+
+export const useSpaceMenu = () => {
+ const { t } = useTranslation();
+ const pathname = usePathname();
+ const config = React.useMemo<NavigationConfig>(
+ () => ({
+ sections: [
+ {
+ id: "home",
+ items: [
+ {
+ id: "home",
+ label: t("home", { defaultValue: "Home" }),
+ href: "/",
+ icon: HomeIcon,
+ isActive: pathname === "/",
+ },
+ ],
+ },
+ {
+ id: "content",
+ title: t("content", { defaultValue: "Content" }),
+ items: [
+ {
+ id: "polls",
+ label: t("polls", { defaultValue: "Polls" }),
+ href: "/polls",
+ icon: BarChart2Icon,
+ isActive: pathname === "/polls",
+ },
+ {
+ id: "events",
+ label: t("events", { defaultValue: "Events" }),
+ href: "/events",
+ icon: CalendarIcon,
+ isActive: pathname === "/events",
+ },
+ ],
+ },
+ ...(process.env.NODE_ENV === "development"
+ ? [
+ {
+ id: "manage",
+ title: t("manage", { defaultValue: "Manage" }),
+ items: [
+ {
+ id: "members",
+ label: t("members", { defaultValue: "Members" }),
+ href: "/members",
+ icon: UsersIcon,
+ isActive: pathname === "/members",
+ },
+ ],
+ },
+ ]
+ : []),
+ ],
+ }),
+ [pathname, t],
+ );
+
+ return React.useMemo(
+ () => ({
+ config,
+ }),
+ [config],
+ );
+};
diff --git a/apps/web/src/features/spaces/components/space-role.tsx b/apps/web/src/features/spaces/components/space-role.tsx
new file mode 100644
index 000000000..600426f82
--- /dev/null
+++ b/apps/web/src/features/spaces/components/space-role.tsx
@@ -0,0 +1,15 @@
+"use client";
+
+import { Trans } from "@/components/trans";
+import type { SpaceMemberRole } from "@/features/spaces/schema";
+
+export const SpaceRole = ({ role }: { role: SpaceMemberRole }) => {
+ switch (role) {
+ case "owner":
+ return <Trans i18nKey="owner" defaults="Owner" />;
+ case "admin":
+ return <Trans i18nKey="admin" defaults="Admin" />;
+ case "member":
+ return <Trans i18nKey="member" defaults="Member" />;
+ }
+};
diff --git a/apps/web/src/features/spaces/schema.ts b/apps/web/src/features/spaces/schema.ts
new file mode 100644
index 000000000..d92787385
--- /dev/null
+++ b/apps/web/src/features/spaces/schema.ts
@@ -0,0 +1,4 @@
+import { z } from "zod";
+
+export const spaceMemberRoleSchema = z.enum(["member", "admin", "owner"]);
+export type SpaceMemberRole = z.infer<typeof spaceMemberRoleSchema>;
diff --git a/apps/web/src/features/spaces/utils.ts b/apps/web/src/features/spaces/utils.ts
new file mode 100644
index 000000000..f080e05d8
--- /dev/null
+++ b/apps/web/src/features/spaces/utils.ts
@@ -0,0 +1,24 @@
+import type { SpaceMemberRole as PrismaSpaceMemberRole } from "@prisma/client";
+import type { SpaceMemberRole } from "@/features/spaces/schema";
+
+export const toDBRole = (role: SpaceMemberRole): PrismaSpaceMemberRole => {
+ switch (role) {
+ case "member":
+ return "MEMBER";
+ case "admin":
+ return "ADMIN";
+ case "owner":
+ return "OWNER";
+ }
+};
+
+export const fromDBRole = (role: PrismaSpaceMemberRole): SpaceMemberRole => {
+ switch (role) {
+ case "MEMBER":
+ return "member";
+ case "ADMIN":
+ return "admin";
+ case "OWNER":
+ return "owner";
+ }
+};
diff --git a/packages/ui/src/avatar.tsx b/packages/ui/src/avatar.tsx
index a651528b6..2d3734787 100644
--- a/packages/ui/src/avatar.tsx
+++ b/packages/ui/src/avatar.tsx
@@ -12,7 +12,7 @@ const avatarVariants = cva("relative flex shrink-0 overflow-hidden", {
xl: "size-12 rounded-md text-xl",
lg: "size-12 rounded-md text-lg",
md: "size-9 rounded-md text-base",
- sm: "size-5 rounded-md text-xs",
+ sm: "size-5 rounded-md text-[10px]",
},
},
defaultVariants: {