import { Key } from 'react'; import { Text, Icon, Button, Popup, Menu, Item, PopupTrigger, Flexbox } from 'react-basics'; import classNames from 'classnames'; import Icons from '@/components/icons'; import { useLogin, useMessages, useTeams, useTeamUrl } from '@/components/hooks'; import styles from './TeamsButton.module.css'; export function TeamsButton({ className, showText = true, onChange, }: { className?: string; showText?: boolean; onChange?: (value: string) => void; }) { const { user } = useLogin(); const { formatMessage, labels } = useMessages(); const { result } = useTeams(user.id); const { teamId } = useTeamUrl(); const team = result?.data?.find(({ id }) => id === teamId); const handleSelect = (close: () => void, id: Key) => { onChange?.((id !== user.id ? id : '') as string); close(); }; if (!result?.count) { return null; } return ( {(close: () => void) => (
{formatMessage(labels.myAccount)}
{user.username}
{formatMessage(labels.team)}
{result?.data?.map(({ id, name }) => ( {name} ))}
)}
); } export default TeamsButton;