11import { AlertTriangle , ArrowRight } from "lucide-react" ;
22import Link from "next/link" ;
33import { useCurrentSite } from "../../../../api/admin/sites" ;
4- import { Alert , AlertDescription , AlertTitle } from "../../../../components/ui/alert" ;
54import { Button } from "../../../../components/ui/button" ;
65
76export function UsageBanners ( ) {
@@ -14,88 +13,67 @@ export function UsageBanners() {
1413 return num . toLocaleString ( ) ;
1514 } ;
1615
16+ // Get current month name
17+ const currentMonth = new Date ( ) . toLocaleString ( "en-US" , { month : "long" } ) ;
18+
1719 // Calculate usage percentage
1820 const getUsagePercentage = ( ) => {
1921 if ( ! subscription ?. eventLimit || ! subscription . monthlyEventCount ) return 0 ;
2022 return ( subscription . monthlyEventCount / subscription . eventLimit ) * 100 ;
2123 } ;
2224
2325 const usagePercentage = getUsagePercentage ( ) ;
24- const isNearLimit = usagePercentage >= 90 && ! subscription ?. overMonthlyLimit ;
2526
2627 if (
2728 subscription ?. monthlyEventCount &&
2829 subscription ?. eventLimit &&
2930 subscription . monthlyEventCount > subscription . eventLimit
3031 ) {
3132 return (
32- < Alert variant = "destructive" className = "p-4 mt-4" >
33- < div className = "flex items-start space-x-3" >
34- < AlertTriangle className = "h-5 w-5 mt-0.5" />
35- < div className = "flex-1" >
36- < AlertTitle className = "text-base font-semibold mb-1" > Event Limit Exceeded</ AlertTitle >
37- < div className = "mb-2 text-sm" >
38- < strong > { formatNumber ( subscription . monthlyEventCount || 0 ) } </ strong > events used of{ " " }
39- < strong > { formatNumber ( subscription . eventLimit ) } </ strong >
40- </ div >
41-
42- { site . isOwner ? (
43- < div className = "flex flex-col space-y-2 sm:flex-row sm:space-y-0 sm:space-x-2 items-start sm:items-center" >
44- < AlertDescription className = "text-sm" >
45- Upgrade your plan to continue collecting analytics.
46- </ AlertDescription >
47- < Button variant = "success" asChild size = "sm" >
48- < Link href = "/subscribe" >
49- Upgrade Plan < ArrowRight className = "ml-1 h-3 w-3" />
50- </ Link >
51- </ Button >
52- </ div >
53- ) : (
54- < AlertDescription className = "text-sm" >
55- This site has exceeded its monthly event limit. Please contact your organization owner to upgrade the
56- plan.
57- </ AlertDescription >
58- ) }
59- </ div >
33+ < div className = "mt-4 px-4 py-3 rounded-lg border border-red-200 dark:border-red-400/30 bg-red-50/80 dark:bg-red-900/20 text-sm flex gap-4 items-center" >
34+ < AlertTriangle className = "h-5 w-5 text-red-600 dark:text-red-400 flex-shrink-0" />
35+ < div className = "flex-1" >
36+ < span className = "text-red-700 dark:text-red-300 font-medium" >
37+ Monthly event limit exceeded: < strong > { formatNumber ( subscription . monthlyEventCount || 0 ) } </ strong > of{ " " }
38+ < strong > { formatNumber ( subscription . eventLimit ) } </ strong > events used.{ " " }
39+ { site . isOwner
40+ ? "Upgrade your plan to continue collecting analytics."
41+ : "Please contact your organization owner to upgrade." }
42+ </ span >
6043 </ div >
61- </ Alert >
44+ { site . isOwner && (
45+ < Button variant = "success" size = "sm" asChild >
46+ < Link href = "/settings/organization/subscription" >
47+ Upgrade < ArrowRight className = "ml-1 h-3 w-3" />
48+ </ Link >
49+ </ Button >
50+ ) }
51+ </ div >
6252 ) ;
6353 }
6454
65- // If approaching limit (>90%), show warning banner
66- if ( isNearLimit ) {
55+ // Approaching limit (90-100%)
56+ if ( usagePercentage <= 90 ) {
6757 return (
68- < Alert className = "mt-4 p-4 bg-amber-50 border-amber-200 dark:bg-amber-900/20 dark:border-amber-800" >
69- < div className = "flex items-start space-x-3" >
70- < AlertTriangle className = "h-5 w-5 mt-0.5 text-amber-500" />
71- < div className = "flex-1" >
72- < AlertTitle className = "text-base font-semibold mb-1 text-amber-700 dark:text-amber-400" >
73- Approaching Event Limit
74- </ AlertTitle >
75- < div className = "mb-2 text-sm text-amber-700 dark:text-amber-400" >
76- < strong > { formatNumber ( subscription ?. monthlyEventCount || 0 ) } </ strong > events used of{ " " }
77- < strong > { formatNumber ( subscription ?. eventLimit || 0 ) } </ strong >
78- </ div >
79-
80- { site . isOwner ? (
81- < div className = "flex flex-col space-y-2 sm:flex-row sm:space-y-0 sm:space-x-2 items-start sm:items-center" >
82- < AlertDescription className = "text-sm text-amber-700 dark:text-amber-400" >
83- Consider upgrading your plan to avoid interruptions.
84- </ AlertDescription >
85- < Button asChild variant = "success" size = "sm" >
86- < Link href = "/subscribe" >
87- Upgrade Plan < ArrowRight className = "ml-1 h-3 w-3" />
88- </ Link >
89- </ Button >
90- </ div >
91- ) : (
92- < AlertDescription className = "text-sm text-amber-700 dark:text-amber-400" >
93- This site is approaching its monthly event limit. You may want to notify your organization owner.
94- </ AlertDescription >
95- ) }
96- </ div >
58+ < div className = "mt-4 px-4 py-3 rounded-lg border border-amber-200 dark:border-amber-400/30 bg-amber-50/80 dark:bg-amber-900/20 text-sm flex gap-4 items-center" >
59+ < AlertTriangle className = "h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0" />
60+ < div className = "flex-1" >
61+ < span className = "text-amber-700 dark:text-amber-300 font-medium" >
62+ Approaching monthly event limit: < strong > { formatNumber ( subscription ?. monthlyEventCount || 0 ) } </ strong > of{ " " }
63+ < strong > { formatNumber ( subscription ?. eventLimit || 0 ) } </ strong > events used.{ " " }
64+ { site . isOwner
65+ ? "Consider upgrading to avoid interruptions."
66+ : "You may want to notify your organization owner." }
67+ </ span >
9768 </ div >
98- </ Alert >
69+ { site . isOwner && (
70+ < Button variant = "success" size = "sm" asChild >
71+ < Link href = "/settings/organization/subscription" >
72+ Upgrade < ArrowRight className = "ml-1 h-3 w-3" />
73+ </ Link >
74+ </ Button >
75+ ) }
76+ </ div >
9977 ) ;
10078 }
10179
0 commit comments