mirror of
https://github.com/dyzulk/trustlab.git
synced 2026-01-26 13:32:06 +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 { addToast } = useToast();
|
||||||
const { data, error, mutate, isLoading } = useSWR("/api/admin/ca-certificates", fetcher);
|
const { data, error, mutate, isLoading } = useSWR("/api/admin/ca-certificates", fetcher);
|
||||||
const [isRenewing, setIsRenewing] = useState(false);
|
const [isRenewing, setIsRenewing] = useState(false);
|
||||||
|
const [isSettingUp, setIsSettingUp] = useState(false);
|
||||||
const [isBulkRenewing, setIsBulkRenewing] = useState(false);
|
const [isBulkRenewing, setIsBulkRenewing] = useState(false);
|
||||||
const [activeSync, setActiveSync] = useState<string | null>(null);
|
const [activeSync, setActiveSync] = useState<string | null>(null);
|
||||||
const [isPromoting, setIsPromoting] = useState(false);
|
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>;
|
if (error) return <div className="p-10 text-center text-error-500">{t("load_failed")}</div>;
|
||||||
|
|
||||||
const certificates = data?.data || [];
|
const certificates = data?.data || [];
|
||||||
@@ -124,16 +139,29 @@ export default function RootCaManagementClient() {
|
|||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="flex flex-col md:flex-row md:items-center justify-between mb-2 gap-4">
|
<div className="flex flex-col md:flex-row md:items-center justify-between mb-2 gap-4">
|
||||||
<PageBreadcrumb pageTitle={t("management_title")} />
|
<PageBreadcrumb pageTitle={t("management_title")} />
|
||||||
|
<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
|
<Button
|
||||||
variant="warning"
|
variant="warning"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => setShowBulkRenewConfirm(true)}
|
onClick={() => setShowBulkRenewConfirm(true)}
|
||||||
loading={isBulkRenewing}
|
loading={isBulkRenewing}
|
||||||
disabled={isLoading || isRenewing || isPromoting}
|
disabled={isLoading || isRenewing || isPromoting || certificates.length === 0}
|
||||||
>
|
>
|
||||||
{t("renew_all_button")}
|
{t("renew_all_button")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
{/* Main CA Management Table */}
|
{/* Main CA Management Table */}
|
||||||
|
|||||||
@@ -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>;
|
if (error) return <div className="p-10 text-center text-error-500">{t("load_failed")}</div>;
|
||||||
|
|
||||||
const certificates = data?.data?.data || [];
|
const certificates = data?.data?.data || [];
|
||||||
@@ -86,22 +72,19 @@ export default function CertificatesClient() {
|
|||||||
<span className="text-xs text-yellow-700 dark:text-yellow-300">
|
<span className="text-xs text-yellow-700 dark:text-yellow-300">
|
||||||
{t("ca_missing_msg", { missing: caStatus?.missing?.join(", ").replace(/_/g, " ") })}
|
{t("ca_missing_msg", { missing: caStatus?.missing?.join(", ").replace(/_/g, " ") })}
|
||||||
</span>
|
</span>
|
||||||
{!isAdmin && (
|
{!isAdmin ? (
|
||||||
<span className="mt-1 text-xs font-medium text-yellow-800 dark:text-yellow-200">
|
<span className="mt-1 text-xs font-medium text-yellow-800 dark:text-yellow-200">
|
||||||
{t("contact_admin_msg")}
|
{t("contact_admin_msg")}
|
||||||
</span>
|
</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>
|
</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>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -651,6 +651,7 @@
|
|||||||
"toast_bulk_renew_failed": "Bulk renewal failed",
|
"toast_bulk_renew_failed": "Bulk renewal failed",
|
||||||
"toast_renew_success": "CA Certificate renewed successfully.",
|
"toast_renew_success": "CA Certificate renewed successfully.",
|
||||||
"toast_renew_failed": "Failed to renew CA certificate",
|
"toast_renew_failed": "Failed to renew CA certificate",
|
||||||
|
"btn_initialize_ca": "Initialize Root CA",
|
||||||
"load_failed": "Failed to load CA certificates. Admin access required.",
|
"load_failed": "Failed to load CA certificates. Admin access required.",
|
||||||
"processing": "Processing...",
|
"processing": "Processing...",
|
||||||
"info_title": "Information",
|
"info_title": "Information",
|
||||||
@@ -675,7 +676,7 @@
|
|||||||
"self_signed": "Self-Signed",
|
"self_signed": "Self-Signed",
|
||||||
"renew_button": "Renew Now",
|
"renew_button": "Renew Now",
|
||||||
"no_ca_search": "No CAs matched \"{term}\"",
|
"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": {
|
"SmtpTester": {
|
||||||
"page_title": "SMTP Tester",
|
"page_title": "SMTP Tester",
|
||||||
@@ -821,6 +822,7 @@
|
|||||||
"ca_not_setup_title": "CA Not Fully Setup",
|
"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.",
|
"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.",
|
"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_setup_ca": "Setup CA Now",
|
||||||
"btn_generate_new": "Generate New",
|
"btn_generate_new": "Generate New",
|
||||||
"processing": "Processing...",
|
"processing": "Processing...",
|
||||||
|
|||||||
@@ -651,7 +651,8 @@
|
|||||||
"toast_bulk_renew_failed": "Pembaruan massal gagal",
|
"toast_bulk_renew_failed": "Pembaruan massal gagal",
|
||||||
"toast_renew_success": "Sertifikat CA berhasil diperbarui.",
|
"toast_renew_success": "Sertifikat CA berhasil diperbarui.",
|
||||||
"toast_renew_failed": "Gagal memperbarui sertifikat CA",
|
"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...",
|
"processing": "Memproses...",
|
||||||
"info_title": "Informasi",
|
"info_title": "Informasi",
|
||||||
"info_point_1": "Memperbarui sertifikat CA menghasilkan sertifikat publik baru dengan masa berlaku 10 tahun.",
|
"info_point_1": "Memperbarui sertifikat CA menghasilkan sertifikat publik baru dengan masa berlaku 10 tahun.",
|
||||||
@@ -675,7 +676,7 @@
|
|||||||
"self_signed": "Self-Signed",
|
"self_signed": "Self-Signed",
|
||||||
"renew_button": "Perbarui",
|
"renew_button": "Perbarui",
|
||||||
"no_ca_search": "Tidak ada CA yang cocok dengan \"{term}\"",
|
"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": {
|
"SmtpTester": {
|
||||||
"page_title": "Pengetes SMTP",
|
"page_title": "Pengetes SMTP",
|
||||||
@@ -820,8 +821,9 @@
|
|||||||
"load_failed": "Gagal memuat sertifikat.",
|
"load_failed": "Gagal memuat sertifikat.",
|
||||||
"ca_not_setup_title": "CA Belum Teratur Sepenuhnya",
|
"ca_not_setup_title": "CA Belum Teratur Sepenuhnya",
|
||||||
"ca_missing_msg": "Sistem Otoritas Sertifikasi kehilangan: {missing}. Sertifikat tidak dapat dibuat sampai pengaturan selesai.",
|
"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.",
|
"contact_admin_msg": "Silakan hubungi administrator Anda untuk menginisialisasi Certification Authority.",
|
||||||
"btn_setup_ca": "Atur CA Sekarang",
|
"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",
|
"btn_generate_new": "Terbitkan Baru",
|
||||||
"processing": "Memproses...",
|
"processing": "Memproses...",
|
||||||
"delete_title": "Hapus Sertifikat",
|
"delete_title": "Hapus Sertifikat",
|
||||||
|
|||||||
Reference in New Issue
Block a user