import { RouteManager } from './RouteManager'; import { GroupsTabs } from './GroupsTabs'; import { apiFetch } from '../_lib/api'; interface Group { id: string; name: string; platform: string; platformId: string; isActive: boolean; accountId: string | null; tenantId: string | null; } interface SharedGroup extends Group { sharedByTenantName: string; } interface Route { id: string; sourceGroupId: string; targetGroupId: string; sourceGroup: { name: string }; targetGroup: { name: string }; } type FetchResult = { ok: true; data: T } | { ok: false; status: number; error: string }; async function fetchJson(path: string): Promise> { let res: Response; try { res = await apiFetch(path); } catch (err) { return { ok: false, status: 0, error: `API unreachable: ${(err as Error).message}` }; } if (!res.ok) { const body = await res.text().catch(() => ''); return { ok: false, status: res.status, error: body.slice(0, 200) || res.statusText }; } return { ok: true, data: (await res.json()) as T }; } export default async function GroupsPage({ searchParams, }: { searchParams: Promise<{ tab?: 'mine' | 'shared' }>; }) { const { tab: rawTab } = await searchParams; const tab: 'mine' | 'shared' = rawTab === 'shared' ? 'shared' : 'mine'; const [groupsR, sharedR, routesR] = await Promise.all([ fetchJson('/groups'), tab === 'shared' ? fetchJson('/groups/shared') : Promise.resolve(null), fetchJson('/routes'), ]); const groups = groupsR?.ok ? groupsR.data : []; const shared = sharedR && sharedR.ok ? sharedR.data : []; const routes = routesR?.ok ? routesR.data : []; const errors = [groupsR, sharedR, routesR] .filter((r): r is { ok: false; status: number; error: string } => !!r && !r.ok && r.status !== 401) .map((e) => `${e.status === 0 ? 'API unreachable' : `API ${e.status}`}: ${e.error}`); return (

Groups & Routes

{errors.length > 0 && (
Failed to load some data
    {errors.map((e) =>
  • {e}
  • )}
)} {tab === 'shared' && (

Shared with me

Groups other tenants have shared with you. You can use them as TARGET groups in your routes.

{shared.length === 0 ? (

No groups shared with you yet.

) : (
    {shared.map((g) => (
  • {g.name} {!g.isActive && (Bot removed)} shared by {g.sharedByTenantName}
  • ))}
)}
)} {tab === 'mine' && (
)}
); }