mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* refactor: use dependency injection for InsightsRoutingService * remove unused getter * clean up * Revert "clean up" This reverts commit a95b83d5dfd4c3236e44268df40bab935237101e. * Update insightsRoutingDI.ts * Revert "Update insightsRoutingDI.ts" This reverts commit 39ead809fa8dabfc17da043c6416bbc6d1fed58d. --------- Co-authored-by: Alex van Andel <[email protected]>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { useSession } from "next-auth/react";
|
|
import { useContext } from "react";
|
|
|
|
import { InsightsOrgTeamsContext } from "../context/InsightsOrgTeamsProvider";
|
|
|
|
export function useInsightsOrgTeams() {
|
|
const context = useContext(InsightsOrgTeamsContext);
|
|
if (!context) {
|
|
throw new Error("useInsightsOrgTeams must be used within a InsightsOrgTeamsProvider");
|
|
}
|
|
const session = useSession();
|
|
const currentOrgId = session.data?.user.org?.id;
|
|
const { orgTeamsType, selectedTeamId, setOrgTeamsType, setSelectedTeamId } = context;
|
|
const isAll = orgTeamsType === "org";
|
|
const teamId = orgTeamsType === "org" ? currentOrgId : orgTeamsType === "team" ? selectedTeamId : undefined;
|
|
const userId = orgTeamsType === "yours" ? session.data?.user.id : undefined;
|
|
|
|
// Adding `scope` for InsightsRoutingBaseService
|
|
// (renaming 'yours' to 'user')
|
|
const scope: "org" | "team" | "user" = orgTeamsType === "yours" ? "user" : orgTeamsType;
|
|
|
|
return {
|
|
orgTeamsType,
|
|
setOrgTeamsType,
|
|
selectedTeamId,
|
|
setSelectedTeamId,
|
|
isAll,
|
|
teamId,
|
|
userId,
|
|
scope,
|
|
};
|
|
}
|