import type { FC, ReactNode } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import classNames from 'classnames'; import AdminIcon from '@/images/icons/icon_admin.svg?react'; import BlockIcon from '@/material-icons/400-24px/block.svg?react'; import GroupsIcon from '@/material-icons/400-24px/group.svg?react'; import PersonIcon from '@/material-icons/400-24px/person.svg?react'; import SmartToyIcon from '@/material-icons/400-24px/smart_toy.svg?react'; import VolumeOffIcon from '@/material-icons/400-24px/volume_off.svg?react'; interface BadgeProps { label: ReactNode; icon?: ReactNode; className?: string; domain?: ReactNode; roleId?: string; } export const Badge: FC = ({ icon = , label, className, domain, roleId, }) => (
{icon} {label} {domain && {domain}}
); export const AdminBadge: FC> = ({ label, ...props }) => ( } label={ label ?? ( ) } {...props} /> ); export const GroupBadge: FC> = ({ label, ...props }) => ( } label={ label ?? ( ) } {...props} /> ); export const AutomatedBadge: FC<{ className?: string }> = ({ className }) => ( } label={ } className={className} /> ); export const MutedBadge: FC< Partial & { expiresAt?: string | null } > = ({ expiresAt, label, ...props }) => { // Format the date, only showing the year if it's different from the current year. const intl = useIntl(); let formattedDate: string | null = null; if (expiresAt) { const expiresDate = new Date(expiresAt); const isCurrentYear = expiresDate.getFullYear() === new Date().getFullYear(); formattedDate = intl.formatDate(expiresDate, { month: 'short', day: 'numeric', ...(isCurrentYear ? {} : { year: 'numeric' }), }); } return ( } label={ label ?? (formattedDate ? ( ) : ( )) } {...props} /> ); }; export const BlockedBadge: FC> = ({ label, ...props }) => ( } label={ label ?? ( ) } {...props} /> );