feat: support removing certificates

This commit is contained in:
Fu Diwei
2025-01-16 21:53:51 +08:00
parent 831f0ee5d9
commit 3a2baba746
17 changed files with 48 additions and 30 deletions

View File

@@ -130,7 +130,7 @@ const AccessList = () => {
});
}, []);
const { loading } = useRequest(
const { loading, run: refreshTableData } = useRequest(
() => {
const startIndex = (page - 1) * pageSize;
const endIndex = startIndex + pageSize;
@@ -157,6 +157,7 @@ const AccessList = () => {
// TODO: 有关联数据的不允许被删除
try {
await deleteAccess(data);
refreshTableData();
} catch (err) {
console.error(err);
notificationApi.error({ message: t("common.text.request_error"), description: getErrMsg(err) });

View File

@@ -4,13 +4,13 @@ import { useNavigate, useSearchParams } from "react-router-dom";
import { DeleteOutlined as DeleteOutlinedIcon, SelectOutlined as SelectOutlinedIcon } from "@ant-design/icons";
import { PageHeader } from "@ant-design/pro-components";
import { useRequest } from "ahooks";
import { Button, Divider, Empty, Menu, type MenuProps, Radio, Space, Table, type TableProps, Tooltip, Typography, notification, theme } from "antd";
import { Button, Divider, Empty, Menu, type MenuProps, Modal, Radio, Space, Table, type TableProps, Tooltip, Typography, notification, theme } from "antd";
import dayjs from "dayjs";
import { ClientResponseError } from "pocketbase";
import CertificateDetailDrawer from "@/components/certificate/CertificateDetailDrawer";
import { CERTIFICATE_SOURCES, type CertificateModel } from "@/domain/certificate";
import { type ListCertificateRequest, list as listCertificate } from "@/repository/certificate";
import { type ListCertificateRequest, list as listCertificate, remove as removeCertificate } from "@/repository/certificate";
import { getErrMsg } from "@/utils/error";
const CertificateList = () => {
@@ -21,6 +21,7 @@ const CertificateList = () => {
const { token: themeToken } = theme.useToken();
const [modalApi, ModalContextHolder] = Modal.useModal();
const [notificationApi, NotificationContextHolder] = notification.useNotification();
const tableColumns: TableProps<CertificateModel>["columns"] = [
@@ -169,14 +170,7 @@ const CertificateList = () => {
/>
<Tooltip title={t("certificate.action.delete")}>
<Button
color="danger"
icon={<DeleteOutlinedIcon />}
variant="text"
onClick={() => {
alert("TODO: 暂时不支持删除证书");
}}
/>
<Button color="danger" icon={<DeleteOutlinedIcon />} variant="text" onClick={() => handleDeleteClick(record)} />
</Tooltip>
</Button.Group>
),
@@ -194,7 +188,7 @@ const CertificateList = () => {
const [page, setPage] = useState<number>(() => parseInt(+searchParams.get("page")! + "") || 1);
const [pageSize, setPageSize] = useState<number>(() => parseInt(+searchParams.get("perPage")! + "") || 10);
const { loading } = useRequest(
const { loading, run: refreshTableData } = useRequest(
() => {
return listCertificate({
page: page,
@@ -219,8 +213,28 @@ const CertificateList = () => {
}
);
const handleDeleteClick = (certificate: CertificateModel) => {
modalApi.confirm({
title: t("certificate.action.delete"),
content: t("certificate.action.delete.confirm"),
onOk: async () => {
try {
const resp = await removeCertificate(certificate);
if (resp) {
setTableData((prev) => prev.filter((item) => item.id !== certificate.id));
refreshTableData();
}
} catch (err) {
console.error(err);
notificationApi.error({ message: t("common.text.request_error"), description: getErrMsg(err) });
}
},
});
};
return (
<div className="p-4">
{ModalContextHolder}
{NotificationContextHolder}
<PageHeader title={t("certificate.page.title")} />

View File

@@ -251,10 +251,10 @@ const Dashboard = () => {
{t("dashboard.quick_actions.change_login_password")}
</Button>
<Button block size="large" icon={<SendOutlined />} onClick={() => navigate("/settings/notification")}>
{t("dashboard.quick_actions.notification_settings")}
{t("dashboard.quick_actions.cofigure_notification")}
</Button>
<Button block size="large" icon={<ApiOutlined />} onClick={() => navigate("/settings/ssl-provider")}>
{t("dashboard.quick_actions.certificate_authority_configuration")}
{t("dashboard.quick_actions.configure_ca")}
</Button>
</Space>
</Card>

View File

@@ -109,7 +109,7 @@ const WorkflowDetail = () => {
content: t("workflow.action.delete.confirm"),
onOk: async () => {
try {
const resp: boolean = await removeWorkflow(workflow);
const resp = await removeWorkflow(workflow);
if (resp) {
navigate("/workflows", { replace: true });
}

View File

@@ -240,7 +240,7 @@ const WorkflowList = () => {
const [page, setPage] = useState<number>(() => parseInt(+searchParams.get("page")! + "") || 1);
const [pageSize, setPageSize] = useState<number>(() => parseInt(+searchParams.get("perPage")! + "") || 10);
const { loading } = useRequest(
const { loading, run: refreshTableData } = useRequest(
() => {
return listWorkflow({
page: page,
@@ -302,9 +302,10 @@ const WorkflowList = () => {
content: t("workflow.action.delete.confirm"),
onOk: async () => {
try {
const resp: boolean = await removeWorkflow(workflow);
const resp = await removeWorkflow(workflow);
if (resp) {
setTableData((prev) => prev.filter((item) => item.id !== workflow.id));
refreshTableData();
}
} catch (err) {
console.error(err);