feat(ui/alerts): shared env helper for alerting query hooks

This commit is contained in:
hsiegeln
2026-04-20 13:00:49 +02:00
parent b2066cdb68
commit 1a8b9eb41b

View File

@@ -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 };