Skip to content

Commit

Permalink
Add error boundary to Retention warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed Jun 27, 2024
1 parent c3489db commit 88e4fbe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';

import { usePruneWarningMessage } from '../../hooks/usePruneWarningMessage';
import { withErrorBoundary } from '../withErrorBoundary';

const RetentionPolicyCallout = ({ room }: { room: IRoom }) => {
const message = usePruneWarningMessage(room);
Expand All @@ -18,4 +19,4 @@ const RetentionPolicyCallout = ({ room }: { room: IRoom }) => {
);
};

export default RetentionPolicyCallout;
export default withErrorBoundary(RetentionPolicyCallout);
19 changes: 19 additions & 0 deletions apps/meteor/client/components/withErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { ComponentType, ReactNode, ComponentProps } from 'react';
import React from 'react';
import { ErrorBoundary } from 'react-error-boundary';

function withErrorBoundary<T extends object>(Component: ComponentType<T>, fallback: ReactNode = null) {
const WrappedComponent = function (props: ComponentProps<typeof Component>) {
return (
<ErrorBoundary fallback={<>{fallback}</>}>
<Component {...props} />
</ErrorBoundary>
);
};

WrappedComponent.displayName = `withErrorBoundary(${Component.displayName ?? Component.name ?? 'Component'})`;

return WrappedComponent;
}

export { withErrorBoundary };
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React from 'react';

import { withErrorBoundary } from '../../../components/withErrorBoundary';
import { usePruneWarningMessage } from '../../../hooks/usePruneWarningMessage';

const RetentionPolicyWarning = ({ room }: { room: IRoom }): ReactElement => {
Expand All @@ -23,4 +24,4 @@ const RetentionPolicyWarning = ({ room }: { room: IRoom }): ReactElement => {
);
};

export default RetentionPolicyWarning;
export default withErrorBoundary(RetentionPolicyWarning);

0 comments on commit 88e4fbe

Please sign in to comment.