Browse Source

Add error boundary to UserDropdown. For #2811

pull/2815/head
Gabe Kangas 2 years ago
parent
commit
02ca54d810
No known key found for this signature in database
GPG Key ID: 4345B2060657F330
  1. 19
      web/components/common/UserDropdown/UserDropdown.tsx

19
web/components/common/UserDropdown/UserDropdown.tsx

@ -4,6 +4,7 @@ import { useRecoilState, useRecoilValue } from 'recoil';
import { FC, useState } from 'react'; import { FC, useState } from 'react';
import { useHotkeys } from 'react-hotkeys-hook'; import { useHotkeys } from 'react-hotkeys-hook';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { ErrorBoundary } from 'react-error-boundary';
import { import {
chatVisibleToggleAtom, chatVisibleToggleAtom,
currentUserAtom, currentUserAtom,
@ -11,6 +12,7 @@ import {
} from '../../stores/ClientConfigStore'; } from '../../stores/ClientConfigStore';
import styles from './UserDropdown.module.scss'; import styles from './UserDropdown.module.scss';
import { AppStateOptions } from '../../stores/application-state'; import { AppStateOptions } from '../../stores/application-state';
import { ComponentError } from '../../ui/ComponentError/ComponentError';
// Lazy loaded components // Lazy loaded components
@ -109,6 +111,16 @@ export const UserDropdown: FC<UserDropdownProps> = ({ username: defaultUsername
); );
return ( return (
<ErrorBoundary
// eslint-disable-next-line react/no-unstable-nested-components
fallbackRender={({ error, resetErrorBoundary }) => (
<ComponentError
componentName="UserDropdown"
message={error.message}
retryFunction={resetErrorBoundary}
/>
)}
>
<div id="user-menu" className={`${styles.root}`}> <div id="user-menu" className={`${styles.root}`}>
<Dropdown overlay={menu} trigger={['click']}> <Dropdown overlay={menu} trigger={['click']}>
<Button type="primary" icon={<UserOutlined className={styles.userIcon} />}> <Button type="primary" icon={<UserOutlined className={styles.userIcon} />}>
@ -123,9 +135,14 @@ export const UserDropdown: FC<UserDropdownProps> = ({ username: defaultUsername
> >
<NameChangeModal /> <NameChangeModal />
</Modal> </Modal>
<Modal title="Authenticate" open={showAuthModal} handleCancel={() => setShowAuthModal(false)}> <Modal
title="Authenticate"
open={showAuthModal}
handleCancel={() => setShowAuthModal(false)}
>
<AuthModal /> <AuthModal />
</Modal> </Modal>
</div> </div>
</ErrorBoundary>
); );
}; };

Loading…
Cancel
Save