Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat(mobile): add team switcher to mobile More menu

Marc Seitz7e1d8b065b89
diff --git a/components/layouts/mobile-more-menu.tsx b/components/layouts/mobile-more-menu.tsx
index 63232a7a..5aee6dc6 100644
--- a/components/layouts/mobile-more-menu.tsx
+++ b/components/layouts/mobile-more-menu.tsx
@@ -17,12 +17,14 @@ import { usePlan } from "@/lib/swr/use-billing";
import useLimits from "@/lib/swr/use-limits";
import { useSlackIntegration } from "@/lib/swr/use-slack-integration";
import { PlanEnum } from "@/ee/stripe/constants";
+import { Team } from "@/lib/types";
import { cn, nFormatter } from "@/lib/utils";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import { Progress } from "@/components/ui/progress";
import { SlackIcon } from "../shared/icons/slack-icon";
+import { MobileTeamSwitcher } from "./mobile-team-switcher";
interface MobileMoreMenuProps {
open: boolean;
@@ -31,7 +33,7 @@ interface MobileMoreMenuProps {
export function MobileMoreMenu({ open, onClose }: MobileMoreMenuProps) {
const router = useRouter();
- const { currentTeam } = useTeam() || {};
+ const { currentTeam, teams, setCurrentTeam } = useTeam() || {};
const { isFree, isTrial } = usePlan();
const { limits } = useLimits();
const { isAdmin } = useIsAdmin();
@@ -42,6 +44,13 @@ export function MobileMoreMenu({ open, onClose }: MobileMoreMenuProps) {
() => router.pathname.includes("settings"),
);
+ const switchTeam = (team: Pick<Team, "id" | "name">) => {
+ const target = teams?.find((t) => t.id === team.id);
+ if (!target || target.id === currentTeam?.id) return;
+ setCurrentTeam?.(target);
+ onClose();
+ };
+
useEffect(() => {
if (open) {
document.body.style.overflow = "hidden";
@@ -87,6 +96,14 @@ export function MobileMoreMenu({ open, onClose }: MobileMoreMenuProps) {
</div>
<div className="min-h-0 flex-1 overflow-y-auto overscroll-y-contain px-4 py-4">
+ {currentTeam && teams && teams.length > 0 && (
+ <MobileTeamSwitcher
+ currentTeam={currentTeam}
+ teams={teams}
+ onSwitch={switchTeam}
+ />
+ )}
+
<div className="space-y-1">
{isFree && !isTrial ? (
<UpgradePlanModal
diff --git a/components/layouts/mobile-team-switcher.tsx b/components/layouts/mobile-team-switcher.tsx
new file mode 100644
index 00000000..1c82f9ce
--- /dev/null
+++ b/components/layouts/mobile-team-switcher.tsx
@@ -0,0 +1,92 @@
+import { useState } from "react";
+
+import { CheckIcon, ChevronDownIcon } from "lucide-react";
+
+import { Team } from "@/lib/types";
+import { cn } from "@/lib/utils";
+
+import { Avatar, AvatarFallback } from "@/components/ui/avatar";
+
+interface MobileTeamSwitcherProps {
+ currentTeam: Pick<Team, "id" | "name">;
+ teams: Pick<Team, "id" | "name">[];
+ onSwitch: (team: Pick<Team, "id" | "name">) => void;
+}
+
+export function MobileTeamSwitcher({
+ currentTeam,
+ teams,
+ onSwitch,
+}: MobileTeamSwitcherProps) {
+ const [expanded, setExpanded] = useState(false);
+
+ if (!currentTeam || !teams || teams.length === 0) return null;
+
+ const hasMultipleTeams = teams.length > 1;
+
+ return (
+ <div className="mb-4">
+ <div className="mb-2 px-3 text-xs font-medium uppercase tracking-wide text-muted-foreground">
+ Team
+ </div>
+ <button
+ type="button"
+ onClick={() => (hasMultipleTeams ? setExpanded((v) => !v) : undefined)}
+ disabled={!hasMultipleTeams}
+ aria-expanded={hasMultipleTeams ? expanded : undefined}
+ className={cn(
+ "flex w-full items-center gap-3 rounded-lg border border-border px-3 py-3 text-left text-sm font-medium transition-colors",
+ hasMultipleTeams ? "hover:bg-muted" : "cursor-default opacity-90",
+ )}
+ >
+ <Avatar className="size-8 shrink-0 rounded">
+ <AvatarFallback className="rounded text-xs">
+ {currentTeam.name?.slice(0, 2).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+ <span className="min-w-0 flex-1 truncate">{currentTeam.name}</span>
+ {hasMultipleTeams && (
+ <ChevronDownIcon
+ className={cn(
+ "h-4 w-4 shrink-0 text-muted-foreground transition-transform",
+ expanded && "rotate-180",
+ )}
+ />
+ )}
+ </button>
+ {expanded && hasMultipleTeams && (
+ <div className="mt-1 space-y-0.5 rounded-lg border border-border p-1">
+ {teams.map((team) => {
+ const isActive = team.id === currentTeam.id;
+ return (
+ <button
+ key={team.id}
+ type="button"
+ onClick={() => {
+ setExpanded(false);
+ if (!isActive) onSwitch(team);
+ }}
+ className={cn(
+ "flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-sm transition-colors",
+ isActive
+ ? "bg-muted font-medium text-foreground"
+ : "text-muted-foreground hover:bg-muted hover:text-foreground",
+ )}
+ >
+ <Avatar className="size-6 shrink-0 rounded text-[11px]">
+ <AvatarFallback className="rounded">
+ {team.name?.slice(0, 2).toUpperCase()}
+ </AvatarFallback>
+ </Avatar>
+ <span className="min-w-0 flex-1 truncate">{team.name}</span>
+ {isActive && (
+ <CheckIcon className="h-4 w-4 shrink-0 text-foreground" />
+ )}
+ </button>
+ );
+ })}
+ </div>
+ )}
+ </div>
+ );
+}