Add error boundary to segments/segments.jsx

[MAILPOET-4706]
This commit is contained in:
Sam Najian
2022-11-28 14:23:37 +01:00
committed by Aschepikov
parent d8ea29423d
commit b218663e7e
7 changed files with 27 additions and 12 deletions

View File

@ -10,7 +10,7 @@ import {
} from 'react-router-dom';
import { noop } from 'lodash';
import { Tabs, Props as TabProps } from './tabs';
import { Props as TabProps, Tabs } from './tabs';
function RouterAwareTabs(
props: TabProps & {
@ -105,4 +105,6 @@ function RoutedTabs({
);
}
RoutedTabs.displayName = 'RoutedTabs';
export { RoutedTabs };

View File

@ -1,13 +1,14 @@
import {
useState,
useRef,
ReactNode,
useCallback,
useEffect,
useLayoutEffect,
ReactNode,
useRef,
useState,
} from 'react';
import ReactDOM from 'react-dom';
import { MailPoet } from 'mailpoet';
import { withBoundary } from 'common';
type Props = {
type: 'success' | 'info' | 'warning' | 'error';
@ -86,6 +87,7 @@ function Notice({
document.getElementById('mailpoet_notices'),
);
}
Notice.defaultProps = {
timeout: 10000,
scroll: false,
@ -94,5 +96,6 @@ Notice.defaultProps = {
onDisplay: undefined,
onClose: undefined,
};
export { Notice };
Notice.displayName = 'Notice';
const NoticeWithBoundary = withBoundary(Notice);
export { NoticeWithBoundary as Notice };

View File

@ -40,3 +40,4 @@ export function Editor(): JSX.Element {
</>
);
}
Editor.displayName = 'SegmentEditor';

View File

@ -225,4 +225,6 @@ DynamicSegmentListComponent.propTypes = {
}).isRequired,
};
DynamicSegmentListComponent.displayName = 'DynamicSegmentList';
export const DynamicSegmentList = withRouter(DynamicSegmentListComponent);

View File

@ -78,4 +78,6 @@ SegmentForm.propTypes = {
}).isRequired,
};
SegmentForm.displayName = 'SegmentForm';
export { SegmentForm };

View File

@ -374,4 +374,6 @@ SegmentListComponent.propTypes = {
}).isRequired,
};
SegmentListComponent.displayName = 'SegmentList';
export const SegmentList = withRouter(SegmentListComponent);

View File

@ -8,6 +8,7 @@ import { SegmentList } from 'segments/list.jsx';
import { SegmentForm } from 'segments/form.jsx';
import { GlobalContext, useGlobalContextValue } from 'context/index.jsx';
import { Notices } from 'notices/notices.jsx';
import { withBoundary } from 'common';
import { Editor } from './dynamic/editor';
import { DynamicSegmentList } from './dynamic/list.jsx';
import { ListHeading } from './heading';
@ -39,6 +40,8 @@ function Tabs() {
);
}
Tabs.displayName = 'SegmentTabs';
function App() {
return (
<GlobalContext.Provider value={useGlobalContextValue(window)}>
@ -46,12 +49,12 @@ function App() {
<Notices />
<Switch>
<Route exact path="/" render={() => <Redirect to="/lists" />} />
<Route path="/new" component={SegmentForm} />
<Route path="/edit/:id" component={SegmentForm} />
<Route path="/new-segment" component={Editor} />
<Route path="/edit-segment/:id" component={Editor} />
<Route path="/segments/(.*)?" component={Tabs} />
<Route path="/lists/(.*)?" component={Tabs} />
<Route path="/new" render={withBoundary(SegmentForm)} />
<Route path="/edit/:id" render={withBoundary(SegmentForm)} />
<Route path="/new-segment" render={withBoundary(Editor)} />
<Route path="/edit-segment/:id" render={withBoundary(Editor)} />
<Route path="/segments/(.*)?" render={withBoundary(Tabs)} />
<Route path="/lists/(.*)?" render={withBoundary(Tabs)} />
</Switch>
</HashRouter>
</GlobalContext.Provider>