import { getKeyValue, Table, TableBody, TableCell, TableColumn, TableHeader, TableRow, Button, Tooltip, } from "@nextui-org/react"; import { useEffect, useState } from "react"; import instance from "../security/http"; import config from "../config"; import { popErrorToast, popToast } from "../utilities"; import { ArchiveBoxIcon, ClipboardDocumentIcon, LifebuoyIcon } from "../icons"; export default function UsersManagement() { const [userInformationlist, setUserInformationList] = useState([]); const columns = [ { key: "firstName", label: "FISRT NAME", }, { key: "lastName", label: "LAST NAME", }, { key: "email", label: "EMAIL ADDRESS", }, { key: "phoneNumber", label: "TELEPHONE", }, { key: "townCouncil", label: "TOWN COUNCIL", }, { key: "accountType", label: "ACCOUNT TYPE", }, { key: "isArchived", label: "STATUS", }, { key: "actions", label: "ACTIONS", }, ]; const populateUserInformationList = () => { instance .get(`${config.serverAddress}/users/all`) .then((response) => { setUserInformationList(response.data); console.log(userInformationlist); }) .catch((error) => { popErrorToast(error); }); }; useEffect(() => { populateUserInformationList(); }, []); const handleCopyID = (userId: string, firstName: string) => { navigator.clipboard.writeText(userId); popToast(firstName + "'s User ID has been copied!", 1); }; const handleArchiveToggle = (userId: string, isArchived: boolean) => { instance .put( `${config.serverAddress}/users/${ isArchived ? "unarchive" : "archive" }/${userId}` ) .then(() => { window.location.reload(); }) .catch((error) => { popErrorToast(error); }); }; return (
{userInformationlist && (

Users Onboard

{(column) => ( {column.label} )} {(userEntry: any) => ( {(columnKey) => ( {columnKey === "accountType" ? ( (() => { const accountType = getKeyValue(userEntry, columnKey); switch (accountType) { case 0: return "User"; case 1: return "Karang Guni"; case 2: return "Admin"; default: return ""; } })() ) : columnKey === "actions" ? (
) : columnKey == "isArchived" ? ( getKeyValue(userEntry, columnKey) ? ( "Archived" ) : ( "Active" ) ) : (

{getKeyValue(userEntry, columnKey)}

)}
)}
)}
)}
); }