Skip to content

Commit

Permalink
refactor: remove import react (#50)
Browse files Browse the repository at this point in the history
* refactor: remove import react

affects: @medly/create-app, @medly/create-component

* refactor: add space after import

affects: @medly/create-app
  • Loading branch information
Manish-Ranjan authored Nov 17, 2021
1 parent c329b0e commit 502a2d3
Show file tree
Hide file tree
Showing 32 changed files with 63 additions and 80 deletions.
5 changes: 2 additions & 3 deletions packages/app/template/common/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { ErrorBoundary, Header, PageLayout, SideNav } from '@components';
import { CssBaseline, ToastContainer } from '@medly-components/core';
import Routes from '@routes';
import { defaultTheme } from '@theme';
import React from 'react';
import type { FC } from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';

const App: React.FC = () => (
const App: FC = () => (
<ThemeProvider theme={defaultTheme}>
<>
<CssBaseline />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { renderWithRouter } from '@test-utils';
import React from 'react';
import PageContent from '../PageContent';
import ErrorBoundary from './ErrorBoundary';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { PureComponent } from 'react';
import { RouteComponentProps, withRouter } from 'react-router-dom';

class ErrorBoundary extends React.PureComponent<RouteComponentProps> {
class ErrorBoundary extends PureComponent<RouteComponentProps> {
public componentDidCatch() {
this.props.history.push('/');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render } from '@test-utils';
import React from 'react';
import { Header } from './Header';

describe('Header', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Avatar, Text } from '@medly-components/core';
import { WithStyle } from '@medly-components/utils';
import React from 'react';
import type { FC } from 'react';
import * as Styled from './Header.styled';

export const Header: React.FC & WithStyle = () => {
const Component: FC = () => {
return (
<Styled.Header>
<Styled.LeftSide>
Expand All @@ -18,5 +18,5 @@ export const Header: React.FC & WithStyle = () => {
);
};

Header.displayName = 'Header';
Header.Style = Styled.Header;
Component.displayName = 'Header';
export const Header: FC & WithStyle = Object.assign(Component, { Style: Styled.Header });
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render } from '@test-utils';
import React from 'react';
import { PageContent } from './PageContent';

describe('PageContent component', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CircleLoader } from '@medly-components/loaders';
import { WithStyle } from '@medly-components/utils';
import React from 'react';
import type { FC } from 'react';
import * as Styled from './PageContent.styled';
import { Props } from './types';

export const PageContent: React.FC<Props> & WithStyle = props => {
const Component: FC<Props> = props => {
return (
<Styled.PageContent {...props}>
{props.isLoading && (
Expand All @@ -17,5 +17,7 @@ export const PageContent: React.FC<Props> & WithStyle = props => {
);
};

PageContent.displayName = 'PageContent';
PageContent.Style = Styled.PageContent;
Component.displayName = 'PageContent';
export const PageContent: FC<Props> & WithStyle = Object.assign(Component, {
Style: Styled.PageContent
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render } from '@test-utils';
import React from 'react';
import Header from '../Header';
import PageContent from '../PageContent';
import { PageLayout } from './PageLayout';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { HTMLProps } from 'react';
import { FC, HTMLProps, memo } from 'react';
import { PageLayoutStyled } from './PageLayout.styled';

export const PageLayout: React.FC<HTMLProps<HTMLDivElement>> = React.memo(({ children }) => {
export const PageLayout: FC<HTMLProps<HTMLDivElement>> = memo(({ children }) => {
return <PageLayoutStyled>{children}</PageLayoutStyled>;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { renderWithRouter } from '@test-utils';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { SideNav } from './SideNav';

const mockHistoryPush = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Text } from '@medly-components/core';
import { DashboardIcon } from '@medly-components/icons';
import { MedlySidenavHeader, SideNav as MedlySideNav } from '@medly-components/layout';
import React, { useCallback } from 'react';
import type { FC } from 'react';
import { memo, useCallback } from 'react';
import { useHistory, useLocation } from 'react-router-dom';

const Component: React.FC = React.memo(() => {
const Component: FC = memo(() => {
const { pathname } = useLocation(),
history = useHistory(),
handlePathChange = useCallback((page: string) => history.push(page), [history]);
Expand Down
5 changes: 2 additions & 3 deletions packages/app/template/common/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import { render } from 'react-dom';
import 'regenerator-runtime/runtime';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));
render(<App />, document.getElementById('root'));
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render } from '@test-utils';
import React from 'react';
import Dashboard from './';

describe('Dashboard', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PageContent } from '@components/layout';
import { Text } from '@medly-components/core';
import React from 'react';
import type { FC } from 'react';
import { DashboardProps } from './types';

export const Dashboard: React.FC<DashboardProps> = ({ isLoading }) => (
export const Dashboard: FC<DashboardProps> = ({ isLoading }) => (
<PageContent isLoading={isLoading}>
<Text textWeight="Strong" textVariant="body1">
Dashboard Content
Expand Down
1 change: 0 additions & 1 deletion packages/app/template/common/src/routes/Routes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { renderWithRouter } from '@test-utils';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { Routes } from './Routes';

Expand Down
4 changes: 2 additions & 2 deletions packages/app/template/common/src/routes/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { lazy, Suspense } from 'react';
import { FC, lazy, Suspense } from 'react';
import { Route, Switch } from 'react-router-dom';

const Dashboard = lazy(() => import(/* webpackChunkName: "Dashboard" */ /* webpackPrefetch: true */ '@pages/Dashboard'));

export const Routes: React.FC = () => (
export const Routes: FC = () => (
<Suspense fallback={<span>Loading ...</span>}>
<Switch>
<Route exact path="/" component={Dashboard} />
Expand Down
5 changes: 2 additions & 3 deletions packages/app/template/common/src/utils/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { render, RenderOptions, RenderResult } from '@testing-library/react';
import { defaultTheme } from '@theme';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import React from 'react';
import type { FC } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';

export const mockAxios = new MockAdapter(axios);

const WithThemeProvider: React.FunctionComponent = props => (
const WithThemeProvider: FC = props => (
<ThemeProvider theme={defaultTheme}>
<>
<ToastContainer position="top-end" />
Expand Down
2 changes: 1 addition & 1 deletion packages/app/template/common/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"axios@latest",
"react@latest",
"react-dom@latest",
"react-router-dom@latest",
"react-router-dom@5.3.0",
"styled-components@latest"
],
"devDependencies": [
Expand Down
5 changes: 2 additions & 3 deletions packages/app/template/stateManagers/context/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { CssBaseline, ToastContainer } from '@medly-components/core';
import Routes from '@routes';
import { defaultTheme } from '@theme';
import { UserProvider } from 'context';
import React from 'react';
import type { FC } from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';

const App: React.FC = () => (
const App: FC = () => (
<ThemeProvider theme={defaultTheme}>
<>
<CssBaseline />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mockAxios, renderWithUserProvider, screen } from '@test-utils';
import React from 'react';
import { Header } from './Header';

const mockResponse = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useUser } from '@context';
import { Avatar, Text } from '@medly-components/core';
import { WithStyle } from '@medly-components/utils';
import React, { useMemo } from 'react';
import type { FC } from 'react';
import { useMemo } from 'react';
import * as Styled from './Header.styled';

export const Header: React.FC & WithStyle = () => {
const Component: FC = () => {
const {
state: { firstName, lastName }
} = useUser();
Expand All @@ -24,6 +25,5 @@ export const Header: React.FC & WithStyle = () => {
</Styled.Header>
);
};

Header.displayName = 'Header';
Header.Style = Styled.Header;
Component.displayName = 'Header';
export const Header: FC & WithStyle = Object.assign(Component, { Style: Styled.Header });
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mockAxios, renderWithUserProvider } from '@test-utils';
import React from 'react';
import Header from '../Header';
import PageContent from '../PageContent';
import { PageLayout } from './PageLayout';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { addToast } from '@medly-components/core';
import axios from 'axios';
import React, { createContext, useContext, useEffect, useReducer } from 'react';
import type { FC } from 'react';
import { createContext, useContext, useEffect, useReducer } from 'react';
import { Dispatch, User, UserActions, UserActionTypes } from './types';

const FETCH_USER_URL = 'https://run.mocky.io/v3/7937982d-ac84-4657-a1f2-e4fcf5f6d375';

export const initialState: User = {
Expand Down Expand Up @@ -31,7 +31,7 @@ export const userReducer = (state: User, { type, ...payload }: UserActions) => {
}
};

const UserProvider: React.FC = ({ children }) => {
const UserProvider: FC = ({ children }) => {
const [state, dispatch] = useReducer(userReducer, initialState);
const value = { state, dispatch };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { render, RenderOptions, RenderResult } from '@testing-library/react';
import { defaultTheme } from '@theme';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import React from 'react';
import type { FC, ReactElement } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';

export const mockAxios = new MockAdapter(axios);

const WithThemeProvider: React.FunctionComponent = props => (
const WithThemeProvider: FC = props => (
<ThemeProvider theme={defaultTheme}>
<>
<ToastContainer position="top-end" />
Expand All @@ -19,27 +18,26 @@ const WithThemeProvider: React.FunctionComponent = props => (
</ThemeProvider>
);

const WithRouter: React.FunctionComponent = props => (
const WithRouter: FC = props => (
<MemoryRouter>
<WithThemeProvider>{props.children}</WithThemeProvider>
</MemoryRouter>
);

const WithUserProvider: React.FC = props => {
const WithUserProvider: FC = props => {
return (
<WithRouter>
<UserProvider {...props} />
</WithRouter>
);
};

const customRender = (ui: React.ReactElement, options?: RenderOptions): RenderResult =>
render(ui, { wrapper: WithThemeProvider, ...options });
const customRender = (ui: ReactElement, options?: RenderOptions): RenderResult => render(ui, { wrapper: WithThemeProvider, ...options });

export const renderWithUserProvider = (ui: React.ReactElement, options?: RenderOptions): RenderResult =>
export const renderWithUserProvider = (ui: ReactElement, options?: RenderOptions): RenderResult =>
render(ui, { wrapper: WithUserProvider, ...options });

export const renderWithRouter = (ui: React.ReactElement, options?: RenderOptions): RenderResult =>
export const renderWithRouter = (ui: ReactElement, options?: RenderOptions): RenderResult =>
render(ui, { wrapper: WithRouter, ...options });

// re-export everything
Expand Down
4 changes: 2 additions & 2 deletions packages/app/template/stateManagers/redux/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { CssBaseline, ToastContainer } from '@medly-components/core';
import Routes from '@routes';
import { store } from '@store';
import { defaultTheme } from '@theme';
import React from 'react';
import type { FC } from 'react';
import { Provider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';

const App: React.FC = () => (
const App: FC = () => (
<Provider store={store}>
<ThemeProvider theme={defaultTheme}>
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { initialState } from '@store';
import { mockAxios, render, screen } from '@test-utils';
import { user } from '@testData';
import React from 'react';
import { Provider } from 'react-redux';
import reduxMockStore from 'redux-mock-store';
import Header from './Header.container';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Avatar, Text } from '@medly-components/core';
import { WithStyle } from '@medly-components/utils';
import React, { useEffect, useMemo } from 'react';
import type { FC } from 'react';
import { useEffect, useMemo } from 'react';
import * as Styled from './Header.styled';
import { HeaderProps } from './types';

export const Header: React.FC<HeaderProps> & WithStyle = ({ fetchUser, firstName, lastName }) => {
const Component: FC<HeaderProps> = ({ fetchUser, firstName, lastName }) => {
const nameInitials = useMemo(() => (firstName && lastName ? `${firstName[0]}${lastName[0]}`.toUpperCase() : ''), [firstName, lastName]);

useEffect(() => {
Expand All @@ -25,5 +26,5 @@ export const Header: React.FC<HeaderProps> & WithStyle = ({ fetchUser, firstName
);
};

Header.displayName = 'Header';
Header.Style = Styled.Header;
Component.displayName = 'Header';
export const Header: FC<HeaderProps> & WithStyle = Object.assign(Component, { Style: Styled.Header });
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mockAxios, renderWithStore } from '@test-utils';
import React from 'react';
import Header from '../Header';
import PageContent from '../PageContent';
import { PageLayout } from './PageLayout';
Expand Down
Loading

0 comments on commit 502a2d3

Please sign in to comment.