Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sergei / chore: ts migration of routes #38

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions packages/reports/src/Components/Errors/error-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ import React from 'react';
import { PageError, Dialog } from '@deriv/components';
import { routes } from '@deriv/shared';
import { localize } from '@deriv/translations';

type TErrorComponent = {
header: string;
is_dialog: boolean;
message: React.ReactElement | string;
redirect_label: string;
redirectOnClick: () => void;
should_show_refresh: boolean;
type: string;
};
import { TErrorComponent } from '../../Types';

const ErrorComponent = ({
header,
Expand Down
7 changes: 7 additions & 0 deletions packages/reports/src/Components/Routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import BinaryLink from './binary-link';
import RouteWithSubRoutes from './route-with-sub-routes';
import BinaryRoutes from './binary-routes';

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

This file was deleted.

26 changes: 26 additions & 0 deletions packages/reports/src/Containers/routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 { TRootStore } from 'Stores/index';
import { TRoutes } from '../Types';

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 }: TRootStore) => ({
is_logged_in: client.is_logged_in,
is_logging_in: client.is_logging_in,
error: common.error,
has_error: common.has_error,
}))(Routes)
);
19 changes: 19 additions & 0 deletions packages/reports/src/Types/common-prop.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ export type TRoute = {
exact?: boolean;
};

export type TErrorComponent = {
header: string;
is_dialog: boolean;
message: React.ReactElement | string;
redirect_label: string;
redirectOnClick: () => void;
should_show_refresh: boolean;
type: string;
};

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

export type TRouteConfig = TRoute & {
is_modal?: boolean;
is_authenticated?: boolean;
Expand Down
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