| 1 | import { data } from "react-router"; |
| 2 | |
| 3 | import type { Route } from "./+types/spend-pill"; |
| 4 | import { managesBilling, requireUser, roleIn } from "../../lib/session.server"; |
| 5 | import { loadPill } from "../../lib/spend.server"; |
| 6 | |
| 7 | /** |
| 8 | * The top bar's spend pill, read after the page draws (components/spend.tsx |
| 9 | * `SpendPill`): the viewer's month, and the workspace's for owners and |
| 10 | * billing managers. |
| 11 | */ |
| 12 | export async function loader({ params, context, request }: Route.LoaderArgs) { |
| 13 | const viewer = requireUser(context, request); |
| 14 | const slug = params.owner.toLowerCase(); |
| 15 | if (!roleIn(viewer, slug)) throw data(null, { status: 404 }); |
| 16 | return data(await loadPill(viewer, slug, managesBilling(viewer, slug)), { headers: { "Cache-Control": "private, no-store" } }); |
| 17 | } |