-
Notifications
You must be signed in to change notification settings - Fork 477
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 #6417 from coronasafe/develop
Production Release; Oct Week 2
- Loading branch information
Showing
57 changed files
with
1,307 additions
and
716 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { usePath } from "raviger"; | ||
|
||
/** | ||
* Returns the slug from the current path. | ||
* @param prefix The prefix of the slug. | ||
* @returns The slug. | ||
* @example | ||
* // Current path: /consultation/94b9a | ||
* const consultation = useSlug("consultation"); // consultation = "94b9a" | ||
*/ | ||
export default function useSlug(prefix: string) { | ||
const path = usePath() ?? ""; | ||
return findSlug(path.split("/"), prefix); | ||
} | ||
|
||
/** | ||
* Returns the slugs from the current path. | ||
* @param prefix The prefixes of the slug. | ||
* @returns The slugs | ||
* @example | ||
* // Current path: /facility/5b0a/consultation/94b9a | ||
* const [facility, consultation] = useSlug("facility", "consultation"); | ||
* // facility = "5b0a" | ||
* // consultation = "94b9a" | ||
*/ | ||
export const useSlugs = (...prefix: string[]) => { | ||
const path = usePath() ?? ""; | ||
return prefix.map((p) => findSlug(path.split("/"), p)); | ||
}; | ||
|
||
const findSlug = (segments: string[], prefix: string) => { | ||
const index = segments.findIndex((segment) => segment === prefix); | ||
if (index === -1) { | ||
throw new Error( | ||
`Prefix "${prefix}" not found in path "${segments.join("/")}"` | ||
); | ||
} | ||
|
||
const slug = segments[index + 1]; | ||
if (!slug) { | ||
throw new Error(`Slug not found in path "${segments.join("/")}"`); | ||
} | ||
|
||
return slug; | ||
}; |
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
Oops, something went wrong.
ce4154a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
care-storybook – ./
care-storybook-git-master-ohcnetwork.vercel.app
care-storybook-ohcnetwork.vercel.app