import { RequestBadgesComposer } from '@nitrots/nitro-renderer'; import { FC, useEffect, useEffectEvent } from 'react'; import { LocalizeText, NotificationBubbleItem, SendMessageComposer } from '../../../../api'; import { Flex, LayoutNotificationBubbleView, LayoutNotificationBubbleViewProps, Text } from '../../../../common'; import { useInventoryBadges } from '../../../../hooks'; export interface NotificationBadgeReceivedBubbleViewProps extends LayoutNotificationBubbleViewProps { item: NotificationBubbleItem; } export const NotificationBadgeReceivedBubbleView: FC = props => { const { item = null, onClose = null, ...rest } = props; const { activeBadgeCodes = [], toggleBadge = null, isWearingBadge = null, canWearBadges = null } = useInventoryBadges(); const requestBadgesIfEmpty = useEffectEvent(() => { if(activeBadgeCodes.length === 0) SendMessageComposer(new RequestBadgesComposer()); }); useEffect(() => { requestBadgesIfEmpty(); }, []); const badgeCode = item?.linkUrl ?? null; const isLoaded = activeBadgeCodes.length > 0; const alreadyWearing = !!badgeCode && !!isWearingBadge && isWearingBadge(badgeCode); const slotsAvailable = !!canWearBadges && canWearBadges(); const canShowWearButton = !!badgeCode && isLoaded && !alreadyWearing && slotsAvailable; const handleWear = (event: React.MouseEvent) => { event.stopPropagation(); if(canShowWearButton && toggleBadge) toggleBadge(badgeCode); if(onClose) onClose(); }; const handleDismiss = (event: React.MouseEvent) => { event.stopPropagation(); if(onClose) onClose(); }; return (
e.stopPropagation() }> { item.iconUrl && } { item.senderName ? LocalizeText('notifications.text.received.badge', [ 'user_name' ], [ item.senderName ]) : LocalizeText('prereg.reward.you.received') } { item.message } { canShowWearButton && } { LocalizeText('notifications.button.later') }
); };