forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #72 from arshad-rao-deriv/Arshad/WEBREL-178/ts-mig…
…ration-routes Arshad/WEBREL-178/TS-Migration CFD routes
- Loading branch information
Showing
10 changed files
with
120 additions
and
110 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,24 @@ | ||
import React from 'react'; | ||
import { Switch } from 'react-router-dom'; | ||
import { Localize } from '@deriv/translations'; | ||
import getRoutesConfig from '../../Constants/routes-config'; | ||
import { TBinaryRoutes } from '../../types/common-prop-types'; | ||
import RouteWithSubRoutes from './route-with-sub-routes'; | ||
|
||
const Loading = () => ( | ||
<div> | ||
<Localize i18n_default_text='Loading...' /> | ||
</div> | ||
); | ||
|
||
const BinaryRoutes = (props: TBinaryRoutes) => ( | ||
<React.Suspense fallback={<Loading />}> | ||
<Switch> | ||
{getRoutesConfig().map(route => ( | ||
<RouteWithSubRoutes key={route.path} {...route} {...props} /> | ||
))} | ||
</Switch> | ||
</React.Suspense> | ||
); | ||
|
||
export default BinaryRoutes; |
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,39 @@ | ||
import { matchPath } from 'react-router'; | ||
import { routes } from '@deriv/shared'; | ||
import { TRouteConfig } from '../../types/common-prop-types'; | ||
|
||
export const normalizePath = (path: string) => (/^\//.test(path) ? path : `/${path || ''}`); // Default to '/' | ||
|
||
export const findRouteByPath = (path: string, routes_config: TRouteConfig[]) => { | ||
let result: TRouteConfig | undefined; | ||
|
||
routes_config.some(route_info => { | ||
let match_path; | ||
try { | ||
match_path = matchPath(path, route_info); | ||
} catch (e) { | ||
if (/undefined/.test((e as Error).message)) { | ||
return undefined; | ||
} | ||
} | ||
|
||
if (match_path) { | ||
result = route_info; | ||
return true; | ||
} else if (route_info.routes) { | ||
result = findRouteByPath(path, route_info.routes); | ||
return result; | ||
} | ||
return false; | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
export const isRouteVisible = (route: TRouteConfig, is_logged_in: boolean) => | ||
!(route && route.is_authenticated && !is_logged_in); | ||
|
||
export const getPath = (route_path: string, params: { [x: string]: string } = {}) => | ||
Object.keys(params).reduce((p, name) => p.replace(`:${name}`, params[name]), route_path); | ||
|
||
export const getContractPath = (contract_id: string) => getPath(routes.contract, { contract_id }); |
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,8 @@ | ||
import BinaryLink from './binary-link'; | ||
import BinaryRoutes from './binary-routes'; | ||
import RouteWithSubRoutes from './route-with-sub-routes'; | ||
|
||
export { BinaryLink }; | ||
export default BinaryRoutes; | ||
export * from './helpers'; | ||
export { RouteWithSubRoutes }; |
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,21 @@ | ||
import { Redirect } from 'react-router-dom'; | ||
|
||
export type TRoute = { | ||
exact?: boolean; | ||
path: string; | ||
default?: boolean; | ||
to?: string; | ||
component?: ((props?: any) => JSX.Element) | typeof Redirect | React.LazyExoticComponent<() => JSX.Element>; | ||
getTitle?: () => string; | ||
subroutes?: TRoute[]; | ||
}; | ||
|
||
export type TRouteConfig = TRoute & { | ||
is_authenticated?: boolean; | ||
routes?: TRoute[]; | ||
}; | ||
|
||
export type TBinaryRoutes = { | ||
is_logged_in: boolean; | ||
is_logging_in: boolean; | ||
}; |