import { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { ArchiveRestore, Building2, Landmark } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle, } from "@/shared/common/ui/card"; import { Button } from "@/shared/common/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/shared/common/ui/select"; import { AdvancedTable } from "@/shared/common/ui/table/AdvancedTable"; import { useLocalizedName } from "@/shared/common/localizedName"; import { useOrganizations } from "@/super-admin/hooks/useOrganizations"; import { useArchivedOrganizations, useArchivedUnits, useArchiveActions, } from "@/user-management/hooks/useArchived"; type Tab = "organizations" | "units"; const SuperAdminArchivedPage = () => { const { t } = useTranslation(); const localizedName = useLocalizedName(); const [activeTab, setActiveTab] = useState("organizations"); const { organizationsResponse } = useOrganizations("Org", { take: 300, skip: 0, }); const organizations: any[] = organizationsResponse?.items ?? []; const [selectedOrgId, setSelectedOrgId] = useState(""); if (!selectedOrgId && organizations.length > 0) { setSelectedOrgId(organizations[0].id); } const { data: archivedOrgsData, refetch: refetchArchivedOrgs, } = useArchivedOrganizations(); const { data: archivedUnitsData, refetch: refetchArchivedUnits } = useArchivedUnits(activeTab === "units" ? selectedOrgId || undefined : undefined); const archivedOrgs: any[] = useMemo( () => archivedOrgsData?.items ?? archivedOrgsData ?? [], [archivedOrgsData], ); const archivedUnits: any[] = useMemo( () => archivedUnitsData?.items ?? archivedUnitsData ?? [], [archivedUnitsData], ); const { restoreUnit, isRestoringUnit, restoreOrganization, isRestoringOrganization, } = useArchiveActions(); const orgColumns = [ { id: "name", header: t("organization.name", "Name"), cell: ({ row }: any) => localizedName(row.original?.name) || "—", }, { id: "key", header: t("organization.key", "Key"), accessorKey: "key", }, { id: "actions", header: t("userIncomingretun.Actions", "Actions"), cell: ({ row }: any) => ( ), }, ]; const unitColumns = [ { id: "name", header: t("organization.name", "Name"), cell: ({ row }: any) => localizedName(row.original?.name) || "—", }, { id: "key", header: t("organization.key", "Key"), accessorKey: "key", }, { id: "actions", header: t("userIncomingretun.Actions", "Actions"), cell: ({ row }: any) => ( ), }, ]; return (
{t("archive.archivedItems", "Archived Items")}
{activeTab === "units" && organizations.length > 0 && (
)} {activeTab === "organizations" ? ( {}} nextFunction={() => {}} prevFunction={() => {}} refresh={refetchArchivedOrgs} /> ) : ( {}} nextFunction={() => {}} prevFunction={() => {}} refresh={refetchArchivedUnits} /> )}
); }; export default SuperAdminArchivedPage;