feat: add Purge CDN button and confirmation UI to CA management

This commit is contained in:
dyzulk
2026-01-07 11:07:04 +07:00
parent a1c38e4ab2
commit 2867288706
4 changed files with 69 additions and 4 deletions

View File

@@ -31,6 +31,8 @@ export default function RootCaManagementClient() {
const [isPromoting, setIsPromoting] = useState(false);
const [confirmRenewUuid, setConfirmRenewUuid] = useState<string | null>(null);
const [showBulkRenewConfirm, setShowBulkRenewConfirm] = useState(false);
const [showPurgeConfirm, setShowPurgeConfirm] = useState(false);
const [isPurging, setIsPurging] = useState(false);
// Redirect if not admin or owner (double security, backend also checks)
const { isAdminOrOwner } = useAuth();
@@ -82,6 +84,21 @@ export default function RootCaManagementClient() {
}
};
const handlePurgeCdn = async () => {
setIsPurging(true);
try {
const response = await axios.post("/api/admin/ca-certificates/purge-cdn");
addToast(response.data.message || t("toast_purge_success"), "success");
setShowPurgeConfirm(false);
mutate(); // Refresh local list to see 'Local Only' status
} catch (err: any) {
console.error(err);
addToast(err.response?.data?.message || t("toast_purge_failed"), "error");
} finally {
setIsPurging(false);
}
};
const handlePromote = async (uuid: string) => {
setIsPromoting(true);
try {
@@ -182,8 +199,9 @@ export default function RootCaManagementClient() {
{/* CDN Synchronization Controls */}
<CdnManagementCard
onSync={handleSyncCdn}
onPurge={() => setShowPurgeConfirm(true)}
activeSync={activeSync}
disabled={isLoading || isPromoting}
disabled={isLoading || isPromoting || isPurging}
/>
{/* Full-width Archive History */}
@@ -232,6 +250,18 @@ export default function RootCaManagementClient() {
variant="warning"
requiredInput="RENEW-ALL"
/>
<ConfirmationModal
isOpen={showPurgeConfirm}
onClose={() => setShowPurgeConfirm(false)}
onConfirm={handlePurgeCdn}
title={t("purge_modal_title")}
message={t("purge_modal_msg")}
isLoading={isPurging}
confirmLabel={t("purge_confirm_label")}
variant="error"
requiredInput="PURGE"
/>
</div>
);
}