From 81c43ecc3d17e0dbf7ad1d949b6d977f2c65bd48 Mon Sep 17 00:00:00 2001 From: muhamedsalih-tw <104364298+muhamedsalih-tw@users.noreply.github.com> Date: Thu, 27 Oct 2022 07:13:47 +0530 Subject: fix: 'failed prop' warning in QuickSwitchModal, SettingsNavigation, SettingsWindow and Recipe component tree (#713) * chore: turn off eslint rule @typescript-eslint/no-useless-constructor to initialize dynamic props & state Co-authored-by: Muhamed <> Co-authored-by: Vijay A --- .../settings/navigation/SettingsNavigation.tsx | 203 +++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 src/components/settings/navigation/SettingsNavigation.tsx (limited to 'src/components/settings/navigation/SettingsNavigation.tsx') diff --git a/src/components/settings/navigation/SettingsNavigation.tsx b/src/components/settings/navigation/SettingsNavigation.tsx new file mode 100644 index 000000000..95c69027c --- /dev/null +++ b/src/components/settings/navigation/SettingsNavigation.tsx @@ -0,0 +1,203 @@ +import { Component } from 'react'; +import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; +import { inject, observer } from 'mobx-react'; +import { NavLink } from 'react-router-dom'; +import { StoresProps } from '../../../@types/ferdium-components.types'; +import { + LOCAL_SERVER, + LIVE_FERDIUM_API, + LIVE_FRANZ_API, +} from '../../../config'; +import globalMessages from '../../../i18n/globalMessages'; + +const messages = defineMessages({ + availableServices: { + id: 'settings.navigation.availableServices', + defaultMessage: 'Available services', + }, + yourServices: { + id: 'settings.navigation.yourServices', + defaultMessage: 'Your services', + }, + yourWorkspaces: { + id: 'settings.navigation.yourWorkspaces', + defaultMessage: 'Your workspaces', + }, + account: { + id: 'settings.navigation.account', + defaultMessage: 'Account', + }, + team: { + id: 'settings.navigation.team', + defaultMessage: 'Manage Team', + }, + releaseNotes: { + id: 'settings.navigation.releaseNotes', + defaultMessage: 'Release Notes', + }, + supportFerdium: { + id: 'settings.navigation.supportFerdium', + defaultMessage: 'About Ferdium', + }, + logout: { + id: 'settings.navigation.logout', + defaultMessage: 'Logout', + }, +}); + +interface IProps extends Partial, WrappedComponentProps { + serviceCount: number; + workspaceCount: number; +} + +@inject('stores', 'actions') +@observer +class SettingsNavigation extends Component { + constructor(props: IProps) { + super(props); + } + + handleLogout(): void { + const isUsingWithoutAccount = + this.props.stores!.settings.app.server === LOCAL_SERVER; + + // Remove current auth token + localStorage.removeItem('authToken'); + + if (isUsingWithoutAccount) { + // Reset server back to Ferdium API + this.props.actions!.settings.update({ + type: 'app', + data: { + server: LIVE_FERDIUM_API, + }, + }); + } + this.props.stores!.user.isLoggingOut = true; + + this.props.stores!.router.push('/auth/welcome'); + + // Reload Ferdium, otherwise many settings won't sync correctly with the server + // after logging into another account + window.location.reload(); + } + + render() { + const { serviceCount, workspaceCount, stores, intl } = this.props; + const isUsingWithoutAccount = stores!.settings.app.server === LOCAL_SERVER; + const isUsingFranzServer = stores!.settings.app.server === LIVE_FRANZ_API; + + return ( +
+ + isActive + ? 'settings-navigation__link is-active' + : 'settings-navigation__link' + } + > + {intl.formatMessage(messages.availableServices)} + + + isActive + ? 'settings-navigation__link is-active' + : 'settings-navigation__link' + } + > + {intl.formatMessage(messages.yourServices)}{' '} + {serviceCount} + + + isActive + ? 'settings-navigation__link is-active' + : 'settings-navigation__link' + } + > + {intl.formatMessage(messages.yourWorkspaces)}{' '} + {workspaceCount} + + {!isUsingWithoutAccount && ( + + isActive + ? 'settings-navigation__link is-active' + : 'settings-navigation__link' + } + > + {intl.formatMessage(messages.account)} + + )} + {isUsingFranzServer && ( + + isActive + ? 'settings-navigation__link is-active' + : 'settings-navigation__link' + } + > + {intl.formatMessage(messages.team)} + + )} + + isActive + ? 'settings-navigation__link is-active' + : 'settings-navigation__link' + } + > + {intl.formatMessage(globalMessages.settings)} + {stores!.settings.app.automaticUpdates && + (stores!.ui.showServicesUpdatedInfoBar || + stores!.app.updateStatus === + stores!.app.updateStatusTypes.AVAILABLE || + stores!.app.updateStatus === + stores!.app.updateStatusTypes.DOWNLOADED) && ( + + )} + + + isActive + ? 'settings-navigation__link is-active' + : 'settings-navigation__link' + } + > + {intl.formatMessage(messages.releaseNotes)} + + + isActive + ? 'settings-navigation__link is-active' + : 'settings-navigation__link' + } + > + {intl.formatMessage(messages.supportFerdium)} + + + +
+ ); + } +} + +export default injectIntl(SettingsNavigation); -- cgit v1.2.3-70-g09d2