g1t/apps/sudo/app/routes/legacy-accounts.tsx
| 1 | import { data, redirect } from "react-router"; |
| 2 | |
| 3 | import type { Route } from "./+types/legacy-accounts"; |
| 4 | import { requireStaff } from "~/lib/staff"; |
| 5 | import { legacyAccountPath } from "~/lib/workspaces"; |
| 6 | |
| 7 | /** |
| 8 | * Old links: `/accounts` was the list, `/accounts/ws_<slug>` a workspace's |
| 9 | * own account and `/accounts/ent_…` an enterprise. |
| 10 | */ |
| 11 | export async function loader({ request, params, context }: Route.LoaderArgs) { |
| 12 | requireStaff(context); |
| 13 | const id = (params["*"] ?? "").replace(/\/+$/, ""); |
| 14 | if (!id) return redirect(`/workspaces${new URL(request.url).search}`, 301); |
| 15 | const path = legacyAccountPath(id); |
| 16 | if (!path) throw data("That is not a workspace or an enterprise.", { status: 404 }); |
| 17 | return redirect(path, 301); |
| 18 | } |
| 19 | |
| 20 | export default function LegacyAccounts() { |
| 21 | return null; |
| 22 | } |