-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
109 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { createContext, useContext } from "react"; | ||
import { PluginConfigType } from "./useConfig"; | ||
import { INavItem } from "@core/Components/Common/Sidebar/Sidebar"; | ||
|
||
type CareAppsContextType = PluginConfigType[]; | ||
|
||
export const CareAppsContext = createContext<CareAppsContextType | null>(null); | ||
|
||
export const useCareApps = () => { | ||
const ctx = useContext(CareAppsContext); | ||
if (!ctx) { | ||
throw new Error( | ||
"'useCareApps' must be used within 'CareAppsProvider' only", | ||
); | ||
} | ||
return ctx; | ||
}; | ||
|
||
export const useCareAppNavItems = () => { | ||
const careApps = useCareApps(); | ||
const navItems = careApps.reduce<INavItem[]>((acc, plugin) => { | ||
if (typeof plugin === "string") { | ||
return acc; | ||
} | ||
return [...acc, ...(plugin.navItems || [])]; | ||
}, []); | ||
return navItems; | ||
}; | ||
|
||
// If required; Reduce plugin.routes to a single pluginRoutes object of type Record<string, () => JSX.Element> | ||
export function usePluginRoutes() { | ||
const careApps = useCareApps(); | ||
const routes = careApps.reduce((acc, plugin) => { | ||
if (typeof plugin === "string") { | ||
return acc; | ||
} | ||
return { ...acc, ...plugin.routes }; | ||
}, {}); | ||
if (!routes) { | ||
throw new Error("'usePluginRoutes' must be used within 'AppRouter' only"); | ||
} | ||
return routes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters