import React, { ComponentType, MouseEventHandler, useCallback } from 'react'; import clsx from 'clsx'; import { Link } from 'react-router-dom'; import { FormattedMessage as Message } from 'react-intl'; import { PseudoAvatar } from 'app/components/ui'; import { Button } from 'app/components/ui/form'; import { Account } from 'app/components/accounts/reducer'; import messages from 'app/components/accounts/accountSwitcher.intl'; import styles from './accountSwitcher.scss'; interface Props { activeAccount: Account; accounts: ReadonlyArray; onAccountClick?: (account: Account) => void; onRemoveClick?: (account: Account) => void; onLoginClick?: MouseEventHandler; } const AccountSwitcher: ComponentType = ({ activeAccount, accounts, onAccountClick = () => {}, onRemoveClick = () => {}, onLoginClick, }) => { const available = accounts.filter((account) => account.id !== activeAccount.id); const onAccountClickCallback = useCallback( (account: Account): MouseEventHandler => (event) => { event.preventDefault(); onAccountClick(account); }, [onAccountClick], ); const onAccountRemoveCallback = useCallback( (account: Account): MouseEventHandler => (event) => { event.preventDefault(); event.stopPropagation(); onRemoveClick(account); }, [onRemoveClick], ); return (
{activeAccount.username}
{activeAccount.email}
{available.map((account, index) => (
{account.username}
{account.email}
))}
); }; export default AccountSwitcher;