-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into account-on-hold-error-screen
- Loading branch information
Showing
8 changed files
with
116 additions
and
35 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 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 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,42 @@ | ||
import { useMemo } from 'react'; | ||
import { useAtomValue } from 'jotai'; | ||
import { matchPath, useLocation } from 'react-router-dom'; | ||
import { chromeModulesAtom } from '../state/atoms/chromeModuleAtom'; | ||
import { ModuleRoute, SupportCaseConfig } from '../@types/types'; | ||
import { activeModuleAtom } from '../state/atoms/activeModuleAtom'; | ||
|
||
function findRouteSupportCaseData(routes: ModuleRoute[], currentPathname: string): SupportCaseConfig | undefined { | ||
const sortedModules = routes.sort((a, b) => b.pathname.length - a.pathname.length); | ||
const matchedRoute = sortedModules.find(({ pathname }) => { | ||
return matchPath( | ||
{ | ||
path: pathname, | ||
end: false, | ||
}, | ||
currentPathname | ||
); | ||
}); | ||
|
||
return matchedRoute?.supportCaseData; | ||
} | ||
|
||
const useSupportCaseData = (): SupportCaseConfig | undefined => { | ||
const scope = useAtomValue(activeModuleAtom); | ||
const location = useLocation(); | ||
const modules = useAtomValue(chromeModulesAtom); | ||
const moduleConfig = useMemo(() => (scope ? modules[scope] : undefined), [modules, scope]); | ||
const supportCaseData = useMemo(() => { | ||
if (!moduleConfig?.modules) { | ||
return undefined; | ||
} | ||
const routeCaseData = findRouteSupportCaseData( | ||
moduleConfig.modules.flatMap(({ routes }) => routes), | ||
location.pathname | ||
); | ||
return routeCaseData ?? moduleConfig?.config?.supportCaseData; | ||
}, [moduleConfig, location]); | ||
|
||
return supportCaseData; | ||
}; | ||
|
||
export default useSupportCaseData; |
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