Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go
1.5 KB
Raw Blame
"use client";

import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useQuery } from "@tanstack/react-query";
import { useAuthStore } from "@multica/core/auth";
import { paths } from "@multica/core/paths";
import { workspaceListOptions } from "@multica/core/workspace/queries";
import { InvitationsPage } from "@multica/views/invitations";

export default function InvitationsRoutePage() {
  const router = useRouter();
  const user = useAuthStore((s) => s.user);
  const isLoading = useAuthStore((s) => s.isLoading);
  const { data: wsList = [] } = useQuery({
    ...workspaceListOptions(),
    enabled: !!user,
  });

  // Unauthenticated users have nowhere meaningful to land here — kick them
  // through login and bring them back. The login page will eventually run
  // its own listMyInvitations() check and route them here again.
  useEffect(() => {
    if (!isLoading && !user) {
      router.replace(
        `${paths.login()}?next=${encodeURIComponent(paths.invitations())}`,
      );
    }
  }, [isLoading, user, router]);

  if (isLoading || !user) return null;

  const onBack =
    wsList.length > 0 ? () => router.push(paths.root()) : undefined;

  // The root layout sets `body { overflow: hidden }` (app-shell convention),
  // so the page owns its scroll; otherwise a long invitation list is cut off.
  return (
    <div className="h-full overflow-y-auto bg-background">
      <InvitationsPage onBack={onBack} />
    </div>
  );
}