diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index 687ff6c..6e36c04 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -23,12 +23,25 @@ interface Event { is_approved: boolean | null; // Include the approval status } +interface Community { + id: string; + community_name: string; + community_description: string; + community_location: string; + community_category: string; + community_members_count: number; + community_image: string; + community_creation_date: string; + is_approved: boolean | null; // Include the approval status + } + export default function Admin() { const router = useRouter(); const { isAuthenticated, isLoading } = useKindeBrowserClient(); const [user, setUser] = useState(null); const [events, setEvents] = useState([]); + const [communities, setCommunities] = useState([]); // State to hold communities const [loading, setLoading] = useState(true); useEffect(() => { @@ -44,23 +57,34 @@ export default function Admin() { }, []); useEffect(() => { - const organizeEvents = async () => { + const fetchEventsAndCommunities = async () => { if (!user) return; setLoading(true); - const { data: organised_events, error } = await supabase + + // Fetch events + const { data: organised_events, error: eventError } = await supabase .from("event_details") .select("*"); - // .eq("organizer_email", user.email); - - if (error) { - console.log(error); + if (eventError) { + console.log(eventError); } + setEvents(organised_events || []); + + // Fetch communities + const { data: communities_data, error: communityError } = await supabase + .from("communities") // Assuming you have a 'communities' table + .select("*"); + if (communityError) { + console.log(communityError); + } + + setCommunities(communities_data || []); setLoading(false); }; - organizeEvents(); + fetchEventsAndCommunities(); }, [user]); const handleEventStatusChange = async ( @@ -75,7 +99,6 @@ export default function Admin() { if (error) { console.error(`Error changing event approval status:`, error); } else { - // Update local state to reflect the change setEvents((prevEvents) => prevEvents.map((event) => event.id === eventId ? { ...event, is_approved: isApproved } : event @@ -87,6 +110,32 @@ export default function Admin() { } }; + const handleCommunityStatusChange = async ( + communityId: string, + isApproved: boolean + ) => { + const { error } = await supabase + .from("communities") + .update({ is_approved: isApproved }) + .eq("id", communityId); + + if (error) { + console.error(`Error changing community approval status:`, error); + } else { + // Update local state to reflect the change + setCommunities((prevCommunities) => + prevCommunities.map((community) => + community.id === communityId + ? { ...community, is_approved: isApproved } + : community + ) + ); + toast.success( + `Community ${isApproved ? "approved" : "rejected"} successfully.` + ); + } + }; + if (isLoading) { return ; } @@ -99,27 +148,28 @@ export default function Admin() {

- Administer Events + Administer Events & Communities

+ + {/* Events Section */}
+

+ Events +

{events.map((event) => ( - + {event.event_title}

{event.event_description}

- {/* Display the current approval status */}

Status:{" "} {event.is_approved === null ? "Pending" : event.is_approved - ? "Approved" - : "Rejected"} + ? "Approved" + : "Rejected"}

+ + {/* Communities Section */} +
+

+ Communities +

+ {communities.map((community) => ( + + + {community.community_name} + + +

{community.community_description}

+

+ Status:{" "} + {community.is_approved === null + ? "Pending" + : community.is_approved + ? "Approved" + : "Rejected"} +

+
+ + +
+
+
+ ))} +
)}