diff --git a/src/components/pages/dashboard/admins/ActivityTable.tsx b/src/components/pages/dashboard/admins/ActivityTable.tsx new file mode 100644 index 0000000..d675805 --- /dev/null +++ b/src/components/pages/dashboard/admins/ActivityTable.tsx @@ -0,0 +1,107 @@ +import React, { useState } from "react"; +import { Activity } from "../channels/ActivityTableData"; + +interface ActivityTableProps { + data: Activity[]; +} + +const ActivityTable: React.FC = ({ data }) => { + const [isModalOpen, setModalOpen] = useState(false); + + const toggleModal = () => { + setModalOpen(!isModalOpen); + }; + + // Split data into two parts + const visibleData = data.slice(0, 5); // First 5 items + const modalData = data.slice(); // Remaining items + + return ( +
+ {/* Table */} +
+ + + + + + + + + + {visibleData.map((activity, index) => ( + + + + + + ))} + +
Channel NameReachTimestamp
{activity.channelName} + {activity.reach} + {activity.timestamp}
+
+ + {/* View More Button */} + {modalData.length > 0 && ( +
+

View More

+
+ )} + + {/* Modal */} + {isModalOpen && ( +
+
+ {/* Close Button */} + + + {/* Modal Table */} +
+ + + + + + + + + + {modalData.map((activity, index) => ( + + + + + + ))} + +
+ Channel Name + Reach + Timestamp +
{activity.channelName} + {activity.reach} + {activity.timestamp}
+
+
+
+ )} +
+ ); +}; + +export default ActivityTable; diff --git a/src/components/pages/dashboard/admins/ManageAdmins.tsx b/src/components/pages/dashboard/admins/ManageAdmins.tsx index 3a4e995..33e6706 100644 --- a/src/components/pages/dashboard/admins/ManageAdmins.tsx +++ b/src/components/pages/dashboard/admins/ManageAdmins.tsx @@ -1,10 +1,10 @@ import React, { useState, useContext } from "react"; import { AuthContext } from "@/context/AuthContext"; -import { activityData } from "../channels/ActivityTableData"; import { pendingChannelsData } from "../channels/pendingChannelData"; -import AdminTable from "@/components/tables/AdminTable"; import DeleteModal from "@/components/modals/actionPrompts/DeleteModal"; -import ViewMoreModal from "../channels/ViewMoreModal"; +import PendingChannels from "@/components/pages/dashboard/admins/PendingChannelData"; +import ActivityTable from "@/components/pages/dashboard/admins/ActivityTable"; +import { activityData } from "../channels/ActivityTableData"; import axios from "axios"; import apiUrl from "@/data/axios"; @@ -12,73 +12,16 @@ const ManageAdmins: React.FC = () => { const { userData } = useContext(AuthContext); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [activeModalData, setActiveModalData] = useState(""); - const [isViewMoreActivityOpen, setIsViewMoreActivityOpen] = useState(false); - const [isViewMorePendingOpen, setIsViewMorePendingOpen] = useState(false); - const [visibleActivityItems, setVisibleActivityItems] = useState(5); - const [visiblePendingItems, setVisiblePendingItems] = useState(5); - const API_URL = apiUrl("production"); - const openDeleteModal = (channelName: string) => { - setActiveModalData(channelName); - setIsDeleteModalOpen(true); - }; - - const closeDeleteModal = () => setIsDeleteModalOpen(false); - - const activityTableHeadings: string[] = [ - "Channel Name", - "Reach", - "Timestamp" - ]; - - const pendingTableHeadings: string[] = [ + const pendingTableHeadings = [ "Email Address", "Channel Name", "Category", - "Actions" + "Actions", ]; - const displayedActivities = activityData.slice(0, 5); - const displayedPendingChannels = pendingChannelsData.slice(0, 5); - - const modalActivities = activityData.slice(0, visibleActivityItems); - const modalPendingChannels = pendingChannelsData.slice(0, visiblePendingItems); - - const handleActivityScroll = (e: React.UIEvent) => { - const { scrollTop, scrollHeight, clientHeight } = e.currentTarget; - if (scrollHeight - scrollTop <= clientHeight * 1.5) { - if (visibleActivityItems < activityData.length) { - setVisibleActivityItems(prev => Math.min(prev + 5, activityData.length)); - } - } - }; - - const handlePendingScroll = (e: React.UIEvent) => { - const { scrollTop, scrollHeight, clientHeight } = e.currentTarget; - if (scrollHeight - scrollTop <= clientHeight * 1.5) { - if (visiblePendingItems < pendingChannelsData.length) { - setVisiblePendingItems(prev => Math.min(prev + 5, pendingChannelsData.length)); - } - } - }; - - const handleDelete = async (channelName: string) => { - try { - const response = await axios.delete(`${API_URL}/api/channel/${channelName}`); - if (response.status === 200) { - alert(`Deleted channel ${channelName} successfully.`); - closeDeleteModal(); - } else { - alert(`Failed to delete channel ${channelName}.`); - } - } catch (error) { - console.error(error); - alert(`An error occurred while deleting channel ${channelName}.`); - } - }; - const handleResend = async (email: string) => { try { const response = await axios.post( @@ -90,7 +33,6 @@ const ManageAdmins: React.FC = () => { }, } ); - if (response.status === 200) { alert("Invitation resent successfully."); } else { @@ -102,121 +44,41 @@ const ManageAdmins: React.FC = () => { } }; - const resetModalState = () => { - setVisibleActivityItems(15); - setVisiblePendingItems(15); + const openDeleteModal = (channelName: string) => { + setActiveModalData(channelName); + setIsDeleteModalOpen(true); }; - const handleModalClose = (type: 'activity' | 'pending') => { - if (type === 'activity') { - setIsViewMoreActivityOpen(false); - } else { - setIsViewMorePendingOpen(false); + const closeDeleteModal = () => setIsDeleteModalOpen(false); + + const handleDelete = async (channelName: string) => { + try { + const response = await axios.delete(`${API_URL}/api/channel/${channelName}`); + if (response.status === 200) { + alert(`Deleted channel ${channelName} successfully.`); + closeDeleteModal(); + } else { + alert(`Failed to delete channel ${channelName}.`); + } + } catch (error) { + console.error(error); + alert(`An error occurred while deleting channel ${channelName}.`); } - resetModalState(); }; return (
-

Activity

- {/* Activity Tale */} -
-
- - <> - {displayedActivities.map((activity, index) => ( - - - {activity.channelName} - - - {activity.reach} - - - {activity.timestamp} - - - ))} - - -
-
- {activityData.length > 5 && ( -
- -
- )} - - {/* Pending Channels Table */} -

Pending Channels

-
-
- - <> - {displayedPendingChannels.map((channel, index) => ( - - - {channel.email} - - - {channel.channelName} - - - {channel.category} - - - - - - - ))} - - -
+
+

Activity Table

+
- {pendingChannelsData.length > 5 && ( -
- -
- )} - - {/* View More Modals */} - handleModalClose('activity')} - data={modalActivities} - type="activity" - onScroll={handleActivityScroll} - /> - handleModalClose('pending')} - data={modalPendingChannels} - type="pending" - onDelete={handleDelete} + {/* Pending Channels */} + {/* Delete Modal */} diff --git a/src/components/pages/dashboard/admins/PendingChannelData.tsx b/src/components/pages/dashboard/admins/PendingChannelData.tsx new file mode 100644 index 0000000..4f10cac --- /dev/null +++ b/src/components/pages/dashboard/admins/PendingChannelData.tsx @@ -0,0 +1,136 @@ +import React, { useState } from "react"; +import AdminTable from "@/components/tables/AdminTable"; + +interface PendingChannel { + email: string; + channelName: string; + category: string; +} + +interface PendingChannelsProps { + pendingChannels: PendingChannel[]; + onResend: (email: string) => void; + onDelete: (channelName: string) => void; + headings: string[]; +} + +const PendingChannels: React.FC = ({ + pendingChannels, + onResend, + onDelete, + headings, +}) => { + const [isModalOpen, setModalOpen] = useState(false); + + const toggleModal = () => { + setModalOpen(!isModalOpen); + }; + + // Split data into visible and modal data + const visibleChannels = pendingChannels.slice(0, 5); // First 5 items + const modalChannels = pendingChannels.slice(); // Remaining items + + return ( + <> +

Pending Channels

+
+
+ {/* Table for Visible Data */} + + {visibleChannels.map((channel, index) => ( + + + {channel.email} + + + {channel.channelName} + + + {channel.category} + + + + + + + ))} + +
+
+ + {/* View More Button */} + {modalChannels.length > 0 && ( +
+

+ View More +

+
+ )} + + {/* Modal */} + {isModalOpen && ( +
+
+ {/* Close Button */} + + +

All Pending Channels

+ + {/* Table for Modal Data */} +
+ + {modalChannels.map((channel, index) => ( + + + {channel.email} + + + {channel.channelName} + + + {channel.category} + + + + + + + ))} + +
+
+
+ )} + + ); +}; + +export default PendingChannels; diff --git a/src/components/pages/dashboard/channels/ActivityTableData.ts b/src/components/pages/dashboard/channels/ActivityTableData.ts index e7fa7f2..5c9d997 100644 --- a/src/components/pages/dashboard/channels/ActivityTableData.ts +++ b/src/components/pages/dashboard/channels/ActivityTableData.ts @@ -1,59 +1,59 @@ // ActivityTableData.ts export interface Activity { channelName: string; - reach: number; + reach: string; timestamp: string; } export const activityData: Activity[] = [ { channelName: "Channel 1", - reach: 1200, + reach: "Public", timestamp: "2024-10-01 10:30 AM", }, { channelName: "Channel 2", - reach: 950, + reach: "Institution", timestamp: "2024-10-02 02:15 PM", }, { channelName: "Channel 3", - reach: 875, + reach: "Public", timestamp: "2024-10-03 08:45 AM", }, { channelName: "Channel 4", - reach: 1870, + reach: "Public", timestamp: "2024-12-01 09:30 AM", }, { channelName: "Channel 5", - reach: 950, + reach: "Public", timestamp: "2024-13-02 02:30 PM", }, { channelName: "Channel 6", - reach: 300, + reach: "Institution", timestamp: "2024-13-03 02:45 AM", }, { channelName: "Channel 7", - reach: 1200, + reach: "Institution", timestamp: "2024-14-01 08:30 PM", }, { channelName: "Channel 8", - reach: 950, + reach: "Public", timestamp: "2024-18-02 02:15 PM", }, { channelName: "Channel 9", - reach: 875, + reach: "Institution", timestamp: "2024-18-03 08:45 AM", }, { channelName: "Channel 10", - reach: 1200, + reach: "Public", timestamp: "2024-18-01 10:30 AM", }, ]; \ No newline at end of file diff --git a/src/components/tables/AdminTable.tsx b/src/components/tables/AdminTable.tsx index 0949309..e8ca26a 100644 --- a/src/components/tables/AdminTable.tsx +++ b/src/components/tables/AdminTable.tsx @@ -9,7 +9,7 @@ const AdminTable: React.FC = ({headers, children}) => { return ( - + {headers.map((header) => (