mirror of
https://github.com/dyzulk/trustlab.git
synced 2026-01-26 05:25:36 +07:00
feat: refine CA setup UX by moving setup button to Admin and adding redirection link
This commit is contained in:
@@ -25,6 +25,7 @@ export default function RootCaManagementClient() {
|
||||
const { addToast } = useToast();
|
||||
const { data, error, mutate, isLoading } = useSWR("/api/admin/ca-certificates", fetcher);
|
||||
const [isRenewing, setIsRenewing] = useState(false);
|
||||
const [isSettingUp, setIsSettingUp] = useState(false);
|
||||
const [isBulkRenewing, setIsBulkRenewing] = useState(false);
|
||||
const [activeSync, setActiveSync] = useState<string | null>(null);
|
||||
const [isPromoting, setIsPromoting] = useState(false);
|
||||
@@ -116,6 +117,20 @@ export default function RootCaManagementClient() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSetupCa = async () => {
|
||||
setIsSettingUp(true);
|
||||
try {
|
||||
await axios.post("/api/ca/setup");
|
||||
mutate();
|
||||
addToast(t("toast_ca_setup_success"), "success");
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
addToast(err.response?.data?.message || t("toast_ca_setup_failed"), "error");
|
||||
} finally {
|
||||
setIsSettingUp(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (error) return <div className="p-10 text-center text-error-500">{t("load_failed")}</div>;
|
||||
|
||||
const certificates = data?.data || [];
|
||||
@@ -124,15 +139,28 @@ export default function RootCaManagementClient() {
|
||||
<div className="space-y-6">
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between mb-2 gap-4">
|
||||
<PageBreadcrumb pageTitle={t("management_title")} />
|
||||
<Button
|
||||
variant="warning"
|
||||
size="sm"
|
||||
onClick={() => setShowBulkRenewConfirm(true)}
|
||||
loading={isBulkRenewing}
|
||||
disabled={isLoading || isRenewing || isPromoting}
|
||||
>
|
||||
{t("renew_all_button")}
|
||||
</Button>
|
||||
<div className="flex items-center gap-2">
|
||||
{certificates.length === 0 && !isLoading && (
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={handleSetupCa}
|
||||
loading={isSettingUp}
|
||||
disabled={isLoading || isRenewing || isPromoting}
|
||||
>
|
||||
{t("btn_initialize_ca")}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="warning"
|
||||
size="sm"
|
||||
onClick={() => setShowBulkRenewConfirm(true)}
|
||||
loading={isBulkRenewing}
|
||||
disabled={isLoading || isRenewing || isPromoting || certificates.length === 0}
|
||||
>
|
||||
{t("renew_all_button")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
|
||||
@@ -44,20 +44,6 @@ export default function CertificatesClient() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSetupCa = async () => {
|
||||
setIsSettingUp(true);
|
||||
try {
|
||||
await axios.post("/api/ca/setup");
|
||||
mutate();
|
||||
addToast(t("toast_ca_setup_success"), "success");
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
addToast(err.response?.data?.message || t("toast_ca_setup_failed"), "error");
|
||||
} finally {
|
||||
setIsSettingUp(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (error) return <div className="p-10 text-center text-error-500">{t("load_failed")}</div>;
|
||||
|
||||
const certificates = data?.data?.data || [];
|
||||
@@ -86,22 +72,19 @@ export default function CertificatesClient() {
|
||||
<span className="text-xs text-yellow-700 dark:text-yellow-300">
|
||||
{t("ca_missing_msg", { missing: caStatus?.missing?.join(", ").replace(/_/g, " ") })}
|
||||
</span>
|
||||
{!isAdmin && (
|
||||
{!isAdmin ? (
|
||||
<span className="mt-1 text-xs font-medium text-yellow-800 dark:text-yellow-200">
|
||||
{t("contact_admin_msg")}
|
||||
</span>
|
||||
) : (
|
||||
<a
|
||||
href="/dashboard/admin/root-ca"
|
||||
className="mt-1 text-xs font-bold text-yellow-800 dark:text-yellow-200 underline decoration-2 underline-offset-2 hover:text-yellow-900 transition-colors"
|
||||
>
|
||||
{t("ca_not_setup_admin_link")}
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<Button
|
||||
onClick={handleSetupCa}
|
||||
size="sm"
|
||||
className="bg-yellow-600 hover:bg-yellow-700 text-white border-none h-auto whitespace-nowrap w-full sm:w-auto"
|
||||
loading={isSettingUp}
|
||||
>
|
||||
{t("btn_setup_ca")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -651,6 +651,7 @@
|
||||
"toast_bulk_renew_failed": "Bulk renewal failed",
|
||||
"toast_renew_success": "CA Certificate renewed successfully.",
|
||||
"toast_renew_failed": "Failed to renew CA certificate",
|
||||
"btn_initialize_ca": "Initialize Root CA",
|
||||
"load_failed": "Failed to load CA certificates. Admin access required.",
|
||||
"processing": "Processing...",
|
||||
"info_title": "Information",
|
||||
@@ -675,7 +676,7 @@
|
||||
"self_signed": "Self-Signed",
|
||||
"renew_button": "Renew Now",
|
||||
"no_ca_search": "No CAs matched \"{term}\"",
|
||||
"no_ca_found": "No Root CA certificates found. Run CA Setup from Certificates page."
|
||||
"no_ca_found": "No Root CA certificates found. Start by initializing the Certification Authority."
|
||||
},
|
||||
"SmtpTester": {
|
||||
"page_title": "SMTP Tester",
|
||||
@@ -821,6 +822,7 @@
|
||||
"ca_not_setup_title": "CA Not Fully Setup",
|
||||
"ca_missing_msg": "The Certification Authority system is missing: {missing}. Certificates cannot be generated until setup is complete.",
|
||||
"contact_admin_msg": "Please contact your administrator to initialize the Certification Authority.",
|
||||
"ca_not_setup_admin_link": "Certification Authority is not setup. Please perform setup in the [Root CA Management] page.",
|
||||
"btn_setup_ca": "Setup CA Now",
|
||||
"btn_generate_new": "Generate New",
|
||||
"processing": "Processing...",
|
||||
|
||||
@@ -651,7 +651,8 @@
|
||||
"toast_bulk_renew_failed": "Pembaruan massal gagal",
|
||||
"toast_renew_success": "Sertifikat CA berhasil diperbarui.",
|
||||
"toast_renew_failed": "Gagal memperbarui sertifikat CA",
|
||||
"load_failed": "Gagal memuat sertifikat CA. Diperlukan akses admin.",
|
||||
"btn_initialize_ca": "Inisialisasi Root CA",
|
||||
"load_failed": "Gagal memuat sertifikat CA. Akses admin diperlukan.",
|
||||
"processing": "Memproses...",
|
||||
"info_title": "Informasi",
|
||||
"info_point_1": "Memperbarui sertifikat CA menghasilkan sertifikat publik baru dengan masa berlaku 10 tahun.",
|
||||
@@ -675,7 +676,7 @@
|
||||
"self_signed": "Self-Signed",
|
||||
"renew_button": "Perbarui",
|
||||
"no_ca_search": "Tidak ada CA yang cocok dengan \"{term}\"",
|
||||
"no_ca_found": "Sertifikat Root CA tidak ditemukan. Jalankan Pengaturan CA dari halaman Sertifikat."
|
||||
"no_ca_found": "Sertifikat Root CA tidak ditemukan. Mulailah dengan menginisialisasi Certification Authority."
|
||||
},
|
||||
"SmtpTester": {
|
||||
"page_title": "Pengetes SMTP",
|
||||
@@ -820,8 +821,9 @@
|
||||
"load_failed": "Gagal memuat sertifikat.",
|
||||
"ca_not_setup_title": "CA Belum Teratur Sepenuhnya",
|
||||
"ca_missing_msg": "Sistem Otoritas Sertifikasi kehilangan: {missing}. Sertifikat tidak dapat dibuat sampai pengaturan selesai.",
|
||||
"contact_admin_msg": "Silakan hubungi administrator Anda untuk menginisialisasi Otoritas Sertifikasi.",
|
||||
"btn_setup_ca": "Atur CA Sekarang",
|
||||
"contact_admin_msg": "Silakan hubungi administrator Anda untuk menginisialisasi Certification Authority.",
|
||||
"ca_not_setup_admin_link": "Certification Authority belum diatur. Silakan lakukan pengaturan di halaman [Manajemen Root CA].",
|
||||
"btn_setup_ca": "Siapkan CA Sekarang",
|
||||
"btn_generate_new": "Terbitkan Baru",
|
||||
"processing": "Memproses...",
|
||||
"delete_title": "Hapus Sertifikat",
|
||||
|
||||
Reference in New Issue
Block a user