Files
outline/app/hooks/useCurrentTeam.ts
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

24 lines
741 B
TypeScript

import invariant from "invariant";
import type Team from "~/models/Team";
import useStores from "./useStores";
/**
* Returns the current team, or undefined if there is no current team and `rejectOnEmpty` is set to
* false.
*
* @param options.rejectOnEmpty - If true, throws an error if there is no current team. Defaults to true.
*/
function useCurrentTeam(options: { rejectOnEmpty: false }): Team | undefined;
function useCurrentTeam(options?: { rejectOnEmpty: true }): Team;
function useCurrentTeam({
rejectOnEmpty = true,
}: { rejectOnEmpty?: boolean } = {}) {
const { auth } = useStores();
if (rejectOnEmpty) {
invariant(auth.team, "team required");
}
return auth.team || undefined;
}
export default useCurrentTeam;