Files
bedolaga-cabinet/src/components/PromoDiscountBadge.tsx

35 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useQuery } from '@tanstack/react-query';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { promoApi } from '../api/promo';
export default function PromoDiscountBadge() {
const { t } = useTranslation();
const { data: activeDiscount } = useQuery({
queryKey: ['active-discount'],
queryFn: promoApi.getActiveDiscount,
staleTime: 30000,
refetchInterval: 60000,
});
// Don't render if no active discount
if (!activeDiscount || !activeDiscount.is_active || !activeDiscount.discount_percent) {
return null;
}
return (
<Link
to="/subscription"
state={{ scrollToExtend: true }}
className="group relative flex items-center gap-1.5 rounded-lg bg-gradient-to-r from-success-500/20 to-accent-500/15 px-2.5 py-1.5 transition-all hover:from-success-500/30 hover:to-accent-500/25"
title={t('promo.activeDiscount', 'Active discount')}
>
<span className="text-base">🏷</span>
<span className="text-sm font-bold text-success-400">
-{activeDiscount.discount_percent}%
</span>
</Link>
);
}