diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index c293c83..91d37d5 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -87,6 +87,22 @@ const chartConfig2 = { }, } satisfies ChartConfig; + +const barChartConfig = { + category: { + label: "category", + color: "hsl(var(--chart-1))", + }, + count: { + label: "count", + color: "hsl(var(--chart-2))", + }, + label: { + color: "hsl(var(--background))", + }, +} satisfies ChartConfig; + + const chartConfig = { visitors: { label: "Visitors", @@ -113,6 +129,12 @@ const chartConfig = { }, } satisfies ChartConfig; +const categoryChartConfig = { + label: { + color: "hsl(var(--background))", + }, +}; + const totalAttendeesData = [ { name: "Online", value: 1200 }, { name: "In-person", value: 800 }, @@ -152,8 +174,12 @@ export default function Page() { const [organisedEvent, setOrganisedEvent]: any = useState([]); const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); + const [totalEventCount, setTotalEventCount] = useState(0); + const [totalAttendees, setTotalAttendees] = useState([]); + const [totalAttendeesByEvent, setTotalAttendeesByEvent] = useState([]); const [chartData, setChartData] = useState([]); + const [formatChartData, setFormatChartData] = useState([]); const [eventcount, seteventCount] = useState(""); const {getPermission} = useKindeBrowserClient(); @@ -183,17 +209,77 @@ export default function Page() { if (error) { console.log(error); } - { - // console.log(organised_events); + else { + // Calculate total events + setTotalEventCount(organised_events?.length || 0); + // Count the occurrences of each event category + const categoryCounts: any = organised_events?.reduce>( + (acc, curr) => { + acc[curr.event_category] = (acc[curr.event_category] || 0) + 1; + return acc; + }, {} + ); + + // Prepare chart data for the pie chart + const formattedChartData: any= Object.entries(categoryCounts).map( + ([category, count]) => ({ + category, + eventcount: count, + fill: categoryColors[category as keyof typeof categoryColors] || "var(--color-other)", + }) + ); + setFormatChartData(formattedChartData); setLoading(true); setOrganisedEvent(organised_events); setLoading(false); } }; - organizeEvents(); }, [user]); + /* Total participants grouped by event category */ + useEffect(() => { + const eventCategory: any = async () => { + const { data, error } = await supabase.from('event_participants') + .select(` + event_id, + event_details (event_category, event_title) + `); + + if (error) { + console.error('Error fetching participants:', error); + } else { + + // Process the data to count participants per category + const counts = data.reduce((acc: any, participant: any) => { + const category = participant.event_details.event_category; + acc[category] = (acc[category] || 0) + 1; + return acc; + }, {}); + + const participantsByCategory = Object.entries(counts).map(([category, count]) => ({ + category, + count, + })); + setTotalAttendees(participantsByCategory); + + // Process the data to count participants per event title + const countsByEvent = data.reduce((acc: any, participant: any) => { + const title = participant.event_details.event_title; + acc[title] = (acc[title] || 0) + 1; + return acc; + }, {}); + + const participantsByTitle = Object.entries(countsByEvent).map(([title, count]) => ({ + title, + count, + })); + setTotalAttendeesByEvent(participantsByTitle); + } + } + eventCategory(); + }, []); + useEffect(() => { const fetchEventStats = async () => { setLoading(true); @@ -327,7 +413,7 @@ export default function Page() { y={viewBox.cy} className="fill-white text-3xl font-bold" > - {eventcount.toLocaleString()} + {totalEventCount} +{/* @@ -399,66 +486,104 @@ export default function Page() { +*/} - - - Average Rating - - - - - - value.slice(0, 3)} - hide - /> - - - } - /> - - - - - - - + + + Participants By Event + + + + + + value} // Return the full value + /> + + + } + /> + + + + + + + + + + + + Participants By Category + + + + + + value} // Return the full value + /> + + + } + /> + + + + + +