diff --git a/ui/src/api/queries/alertMeta.ts b/ui/src/api/queries/alertMeta.ts new file mode 100644 index 00000000..9819fd55 --- /dev/null +++ b/ui/src/api/queries/alertMeta.ts @@ -0,0 +1,24 @@ +import { useEnvironmentStore } from '../environment-store'; +import { api } from '../client'; + +/** Returns the currently selected env slug, throwing if none is selected. + * Alerts routes require an env context — callers should gate on `selectedEnv` + * via `enabled:` before invoking these hooks. + */ +export function useSelectedEnvOrThrow(): string { + const env = useEnvironmentStore((s) => s.environment); + if (!env) { + throw new Error('Alerting requires a selected environment.'); + } + return env; +} + +export function useSelectedEnv(): string | undefined { + return useEnvironmentStore((s) => s.environment); +} + +/** Re-exported openapi-fetch client for alerting query hooks. + * The underlying export in `../client` is named `api`; we re-export as + * `apiClient` so alerting hooks can import it under the plan's canonical name. + */ +export { api as apiClient };