Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.6 KB
Raw Blame
'use client';

import { Button, Center } from '@lobehub/ui';
import { type FC } from 'react';
import { useTranslation } from 'react-i18next';
import { Outlet, useNavigate } from 'react-router';

import { RouteLoading } from '@/components/Skeleton/RouteSegment';

import { useWorkspaceFromSlug } from './useWorkspaceFromSlug';

/**
 * Layout boundary for the `/:workspaceSlug` subtree.
 *
 * - Calls `useWorkspaceFromSlug` to resolve the slug β†’ status.
 * - Renders a 404-style empty state when the slug doesn't match any workspace.
 * - Renders the route's own skeleton while the workspace list is in flight.
 * - Renders `<Outlet />` when the workspace is found.
 *
 * A billing-inactive workspace is intentionally NOT blocked here β€” the member
 * should still be able to browse shared content. The "subscription inactive"
 * banner lives in the UserPanel and the chat-level error card surfaces when a
 * spend operation is attempted.
 */
const WorkspaceSlugBoundary: FC = () => {
  const { t } = useTranslation('error');
  const navigate = useNavigate();
  const result = useWorkspaceFromSlug();

  if (result.status === 'loading') return <RouteLoading />;

  if (result.status === 'not-found') {
    return (
      <Center gap={16} height={'100%'} style={{ flexDirection: 'column' }} width={'100%'}>
        <div style={{ fontSize: 48 }}>πŸ”</div>
        <div style={{ fontWeight: 600, fontSize: 20 }}>{t('notFound.title')}</div>
        <div style={{ opacity: 0.6 }}>{t('notFound.check')}</div>
        <Button onClick={() => navigate('/')}>{t('notFound.backHome')}</Button>
      </Center>
    );
  }

  return <Outlet />;
};

export default WorkspaceSlugBoundary;