37 lines · 1.6 KBRaw
| 1 | import { AppShell as ShellLayout, type Crumb } from "@refs/design-system"; |
| 2 | import { useRouteLoaderData, useSubmit } from "react-router"; |
| 3 | import type { loader as rootLoader } from "../root"; |
| 4 | import { PendingView, under, useIntendedPath } from "./pending"; |
| 5 | |
| 6 | export { AuthPage, PageHeader } from "@refs/design-system"; |
| 7 | |
| 8 | /** |
| 9 | * The app frame around a page. `keeps` is the path a layout inside this frame stays on screen for; a navigation |
| 10 | * under it is that layout's to show, and every other one replaces the whole page. |
| 11 | */ |
| 12 | export function AppShell({ crumbs, subnav, keeps, full, children }: { crumbs?: Crumb[]; subnav?: React.ReactNode; keeps?: string; full?: boolean; children: React.ReactNode }) { |
| 13 | const root = useRouteLoaderData<typeof rootLoader>("root"); |
| 14 | const pathname = useIntendedPath(); |
| 15 | const submit = useSubmit(); |
| 16 | const state = { |
| 17 | org: root?.org ?? "", |
| 18 | namespace: root?.namespace ?? null, |
| 19 | namespaces: root?.namespaces ?? [], |
| 20 | showWaitlist: root?.can.reviewWaitlist ?? false, |
| 21 | user: root?.user ?? null, |
| 22 | showMembers: root?.can.manageMembers ?? false, |
| 23 | showSecrets: root?.can.manageCiSecrets ?? false, |
| 24 | showLabels: root?.can.manageLabels ?? false, |
| 25 | pathname, |
| 26 | onSignOut: () => submit(null, { method: "post", action: "/logout" }), |
| 27 | onSwitchNamespace: (namespace: string) => submit({ namespace }, { method: "post", action: "/switch" }), |
| 28 | }; |
| 29 | return ( |
| 30 | <ShellLayout state={state} crumbs={crumbs} subnav={subnav} full={full}> |
| 31 | <PendingView top covers={(to) => !keeps || !under(to, keeps)}> |
| 32 | {children} |
| 33 | </PendingView> |
| 34 | </ShellLayout> |
| 35 | ); |
| 36 | } |
| 37 |