import { useCallback, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { Avatar, Button, Empty, Modal, notification, Space, Table, Tooltip, Typography, type TableProps } from "antd"; import { PageHeader } from "@ant-design/pro-components"; import { Copy as CopyIcon, Pencil as PencilIcon, Plus as PlusIcon, Trash2 as Trash2Icon } from "lucide-react"; import moment from "moment"; import AccessEditDialog from "@/components/certimate/AccessEditDialog"; import { Access as AccessType, accessProvidersMap } from "@/domain/access"; import { remove as removeAccess } from "@/repository/access"; import { useConfigContext } from "@/providers/config"; const AccessList = () => { const { t } = useTranslation(); // a flag to fix the twice-rendering issue in strict mode const mountRef = useRef(true); const [modalApi, ModelContextHolder] = Modal.useModal(); const [notificationApi, NotificationContextHolder] = notification.useNotification(); const [loading, setLoading] = useState(false); const tableColumns: TableProps["columns"] = [ { key: "$index", align: "center", title: "", width: 50, render: (_, __, index) => (page - 1) * pageSize + index + 1, }, { key: "name", title: t("common.text.name"), ellipsis: true, render: (_, record) => <>{record.name}, }, { key: "provider", title: t("common.text.provider"), render: (_, record) => { return ( {t(accessProvidersMap.get(record.configType)?.name ?? "")} ); }, }, { key: "createdAt", title: t("common.text.created_at"), ellipsis: true, render: (_, record) => { return moment(record.created!).format("YYYY-MM-DD HH:mm:ss"); }, }, { key: "updatedAt", title: t("common.text.updated_at"), ellipsis: true, render: (_, record) => { return moment(record.updated!).format("YYYY-MM-DD HH:mm:ss"); }, }, { key: "$action", align: "end", fixed: "right", width: 120, render: (_, record) => ( <> } op="add" />, ]} /> columns={tableColumns} dataSource={tableData} loading={loading} locale={{ emptyText: , }} pagination={{ current: page, pageSize: pageSize, total: tableTotal, onChange: (page, pageSize) => { setPage(page); setPageSize(pageSize); }, onShowSizeChange: (page, pageSize) => { setPage(page); setPageSize(pageSize); }, }} rowKey={(record) => record.id} /> ); }; export default AccessList;