Skip to content

Commit 3990ceb

Browse files
committed
Add error boundary to Retention warnings
1 parent 7a57f34 commit 3990ceb

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useTranslation } from '@rocket.chat/ui-contexts';
44
import React from 'react';
55

66
import { usePruneWarningMessage } from '../../hooks/usePruneWarningMessage';
7+
import { withErrorBoundary } from '../withErrorBoundary';
78

89
const RetentionPolicyCallout = ({ room }: { room: IRoom }) => {
910
const message = usePruneWarningMessage(room);
@@ -18,4 +19,4 @@ const RetentionPolicyCallout = ({ room }: { room: IRoom }) => {
1819
);
1920
};
2021

21-
export default RetentionPolicyCallout;
22+
export default withErrorBoundary(RetentionPolicyCallout);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { ComponentType, ReactNode, ComponentProps } from 'react';
2+
import React from 'react';
3+
import { ErrorBoundary } from 'react-error-boundary';
4+
5+
function withErrorBoundary<T extends object>(Component: ComponentType<T>, fallback: ReactNode = null) {
6+
const WrappedComponent = function (props: ComponentProps<typeof Component>) {
7+
return (
8+
<ErrorBoundary fallback={<>{fallback}</>}>
9+
<Component {...props} />
10+
</ErrorBoundary>
11+
);
12+
};
13+
14+
WrappedComponent.displayName = `withErrorBoundary(${Component.displayName ?? Component.name ?? 'Component'})`;
15+
16+
return WrappedComponent;
17+
}
18+
19+
export { withErrorBoundary };

apps/meteor/client/views/room/body/RetentionPolicyWarning.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useTranslation } from '@rocket.chat/ui-contexts';
44
import type { ReactElement } from 'react';
55
import React from 'react';
66

7+
import { withErrorBoundary } from '../../../components/withErrorBoundary';
78
import { usePruneWarningMessage } from '../../../hooks/usePruneWarningMessage';
89

910
const RetentionPolicyWarning = ({ room }: { room: IRoom }): ReactElement => {
@@ -23,4 +24,4 @@ const RetentionPolicyWarning = ({ room }: { room: IRoom }): ReactElement => {
2324
);
2425
};
2526

26-
export default RetentionPolicyWarning;
27+
export default withErrorBoundary(RetentionPolicyWarning);

0 commit comments

Comments
 (0)