-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathroutePaths.ts
More file actions
19 lines (14 loc) · 849 Bytes
/
Copy pathroutePaths.ts
File metadata and controls
19 lines (14 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { matchPath } from 'react-router-dom'
// Kept out of web/routes, which imports App: reading a path from there in a
// component is a cycle, and it took the app down once.
export const ORGANISATIONS = '/organisations'
export const ORGANISATION_USAGE = '/organisation/:organisationId/usage'
// A blocked organisation keeps the organisations list, to switch away, and the
// usage page, which explains the block.
const ALLOWED_WHILE_BLOCKED = [ORGANISATIONS, ORGANISATION_USAGE]
const matches = (pathname: string, path: string): boolean =>
!!matchPath(pathname, { exact: true, path, strict: false })
export const isAllowedWhileBlocked = (pathname: string): boolean =>
ALLOWED_WHILE_BLOCKED.some((path) => matches(pathname, path))
export const isOrganisationUsage = (pathname: string): boolean =>
matches(pathname, ORGANISATION_USAGE)