feat(fronend): wip org prefixed routing

This commit is contained in:
2026-01-04 17:54:58 +00:00
parent 86e90af5c2
commit 0c02929019
32 changed files with 835 additions and 519 deletions

View File

@@ -0,0 +1,32 @@
import { queryOptions, skipToken } from "@tanstack/react-query"
import { fetchApi } from "@/lib/api"
import { Organization } from "./organization"
import { Drive } from "@/drive/drive"
export const organizationQuery = (orgSlug: string | null) =>
queryOptions({
queryKey: ["organizations", orgSlug],
queryFn: orgSlug
? () =>
fetchApi("GET", `/organizations/${orgSlug}`, {
returns: Organization,
}).then(([, data]) => data)
: skipToken,
})
export const listOrganizationsQuery = queryOptions({
queryKey: ["organizations"],
queryFn: () =>
fetchApi("GET", "/users/me/organizations", {
returns: Organization.array(),
}).then(([, data]) => data),
})
export const listOrganizationDrivesQuery = (orgSlug: string) =>
queryOptions({
queryKey: ["organizations", orgSlug, "drives"],
queryFn: () =>
fetchApi("GET", `/${orgSlug}/drives`, {
returns: Drive.array(),
}).then(([, data]) => data),
})

View File

@@ -0,0 +1,16 @@
import { createContext, useContext } from "react"
import type { Organization } from "./organization"
export const OrganizationContext = createContext<Organization>(
null as unknown as Organization,
)
export function useCurrentOrganization() {
const org = useContext(OrganizationContext)
if (!org) {
throw new Error(
"useCurrentOrganization must be used under /$orgSlug routes",
)
}
return org
}

View File

@@ -0,0 +1,18 @@
import { type } from "arktype"
export const ORGANIZATION_KIND = {
personal: "personal",
team: "team",
} as const
export type OrganizationKind =
(typeof ORGANIZATION_KIND)[keyof typeof ORGANIZATION_KIND]
export const Organization = type({
id: "string",
kind: type.valueOf(ORGANIZATION_KIND),
name: "string",
slug: "string",
createdAt: "string.date.iso.parse",
updatedAt: "string.date.iso.parse",
})
export type Organization = typeof Organization.infer