-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from Kodylow/current-service-in-header
- Loading branch information
Showing
2 changed files
with
29 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import { useLocation } from 'react-router-dom'; | ||
|
||
export const useActiveService = () => { | ||
export const useActiveService = (): { | ||
type: 'guardian' | 'gateway'; | ||
id: string; | ||
} => { | ||
const location = useLocation(); | ||
const [type, id] = location.pathname.split('/').filter(Boolean); | ||
|
||
if (type !== 'guardian' && type !== 'gateway') { | ||
throw new Error('Invalid service type'); | ||
} | ||
return { | ||
activeServiceId: type && id ? `${type}/${id}` : null, | ||
serviceType: type as 'guardian' | 'gateway' | null, | ||
serviceId: id || null, | ||
type, | ||
id, | ||
}; | ||
}; |