feat(ui/alerts): shared env helper for alerting query hooks
This commit is contained in:
24
ui/src/api/queries/alertMeta.ts
Normal file
24
ui/src/api/queries/alertMeta.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user