@@ -18,6 +18,9 @@ import {
1818 ChartTooltipContent ,
1919} from '@/components/ui/chart'
2020import { Analysis } from '@/lib/types/analysis'
21+ import { useSearchParams } from 'next/navigation'
22+ import { useMemo } from 'react'
23+ import { format , parse } from 'date-fns'
2124
2225export function TopMembershipChart ( { data } : { data : Analysis [ 'membership' ] } ) {
2326 const chartConfig = data . reduce ( ( acc , { name } , index ) => {
@@ -34,13 +37,28 @@ export function TopMembershipChart({ data }: { data: Analysis['membership'] }) {
3437 fill : chartConfig [ name ] . color ,
3538 } ) )
3639
40+ const params = useSearchParams ( )
41+ const paramFrom = params . get ( 'from' ) as string
42+ const paramTo = params . get ( 'to' ) as string
43+
44+ const [ from , to ] = useMemo ( ( ) => {
45+ const from = format (
46+ parse ( paramFrom , 'dd-MM-yyyy' , new Date ( ) ) ,
47+ 'LLL dd, yyyy'
48+ )
49+ const to = format ( parse ( paramTo , 'dd-MM-yyyy' , new Date ( ) ) , 'LLL dd, yyyy' )
50+ return [ from , to ]
51+ } , [ paramFrom , paramTo ] )
52+
3753 return (
3854 < Card className = "flex flex-col" >
39- < CardHeader className = "items-center pb-0" >
55+ < CardHeader >
4056 < CardTitle > Top Purchased Membership</ CardTitle >
41- < CardDescription > January - June 2024</ CardDescription >
57+ < CardDescription >
58+ { from } - { to }
59+ </ CardDescription >
4260 </ CardHeader >
43- < CardContent className = "flex-1 pb-0 " >
61+ < CardContent className = "flex-1" >
4462 < ChartContainer
4563 config = { chartConfig }
4664 className = "mx-auto aspect-square max-h-[250px] pb-0 [&_.recharts-pie-label-text]:fill-foreground"
@@ -51,12 +69,12 @@ export function TopMembershipChart({ data }: { data: Analysis['membership'] }) {
5169 </ PieChart >
5270 </ ChartContainer >
5371 </ CardContent >
54- < CardFooter className = "flex-col gap-2 text-sm" >
72+ < CardFooter className = "flex-col items-start gap-2 text-sm" >
5573 { /* <div className="flex items-center gap-2 font-medium leading-none">
5674 Trending up by 5.2% this month <TrendingUp className="h-4 w-4" />
5775 </div> */ }
5876 < div className = "leading-none text-muted-foreground" >
59- Showing top most purchased membership
77+ Showing top purchased membership
6078 </ div >
6179 </ CardFooter >
6280 </ Card >
0 commit comments