Skip to content

Commit

Permalink
chore: ts migration of routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-deriv committed Jan 13, 2023
1 parent ecbb7fd commit e4b6d83
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/reports/src/Components/Errors/error-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PageError, Dialog } from '@deriv/components';
import { routes } from '@deriv/shared';
import { localize } from '@deriv/translations';

type TErrorComponent = {
export type TErrorComponent = {
header: string;
is_dialog: boolean;
message: React.ReactElement | string;
Expand Down
9 changes: 6 additions & 3 deletions packages/reports/src/Components/Routes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export BinaryLink from './binary-link.jsx';
export default from './binary-routes.jsx';
import BinaryLink from './binary-link';
import RouteWithSubRoutes from './route-with-sub-routes';
import BinaryRoutes from './binary-routes';

export * from './helpers';
export RouteWithSubRoutes from './route-with-sub-routes.jsx';
export { BinaryLink, RouteWithSubRoutes };
export default BinaryRoutes;
41 changes: 0 additions & 41 deletions packages/reports/src/Containers/routes.jsx

This file was deleted.

40 changes: 40 additions & 0 deletions packages/reports/src/Containers/routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { withRouter } from 'react-router';
import BinaryRoutes from 'Components/Routes';
import { connect } from 'Stores/connect';
import ErrorComponent from 'Components/Errors';
import RootStore from 'Stores/index';
import { TErrorComponent } from 'Components/Errors/error-component';

type TPassthrough = {
root_store: RootStore;
WS: Record<string, any>;
};

type TRoutes = {
error?: TErrorComponent;
has_error?: boolean;
is_logged_in?: boolean;
is_logging_in?: boolean;
is_virtual?: boolean;
passthrough?: TPassthrough;
};

const Routes = ({ error, has_error, is_logged_in, is_logging_in, is_virtual, passthrough }: TRoutes) => {
if (has_error) {
return <ErrorComponent {...error} />;
}

return <BinaryRoutes is_logged_in={is_logged_in} is_logging_in={is_logging_in} passthrough={passthrough} />;
};

// need to wrap withRouter around connect
// to prevent updates on <BinaryRoutes /> from being blocked
export default withRouter(
connect(({ client, common }: RootStore) => ({
is_logged_in: client.is_logged_in,
is_logging_in: client.is_logging_in,
error: common.error,
has_error: common.has_error,
}))(Routes)
);
2 changes: 1 addition & 1 deletion packages/reports/src/app.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import Routes from 'Containers/routes.jsx';
import Routes from 'Containers/routes';
import { MobxContentProvider } from 'Stores/connect';
import 'Sass/app.scss';
import initStore from './init-store'; // eslint-disable-line import/extensions
Expand Down

0 comments on commit e4b6d83

Please sign in to comment.