import React, { ComponentType, MouseEventHandler, ReactElement, useCallback } from 'react'; import { FormattedMessage as Message } from 'react-intl'; import { Link, useLocation } from 'react-router-dom'; import { useReduxDispatch, useReduxSelector } from 'app/functions'; import { authenticate, revoke } from 'app/components/accounts/actions'; import { Account, getSortedAccounts } from 'app/components/accounts/reducer'; import buttons from 'app/components/ui/buttons.scss'; import LoggedInPanel from 'app/components/userbar/LoggedInPanel'; import * as loader from 'app/services/loader'; import siteName from './siteName.intl'; import styles from './root.scss'; interface Props { account: Account | null; onLogoClick?: MouseEventHandler; } const Toolbar: ComponentType = ({ onLogoClick, account }) => { const dispatch = useReduxDispatch(); const location = useLocation(); const availableAccounts = useReduxSelector(getSortedAccounts); const switchAccount = useCallback((account: Account) => { loader.show(); return dispatch(authenticate(account)).finally(loader.hide); }, []); const removeAccount = useCallback((account: Account) => dispatch(revoke(account)), []); let userBar: ReactElement; if (account) { userBar = ( ); } else if (location.pathname === '/register') { userBar = ( ); } else { userBar = ( ); } return (
{userBar}
); }; export default Toolbar;