Address greptile comments

This commit is contained in:
Carlos Monastyrski
2025-11-10 22:15:16 -03:00
parent 76645ccd23
commit ff07bb643a
5 changed files with 82 additions and 47 deletions
@@ -19,13 +19,17 @@ type Props = {
popUpName: keyof UsePopUpState<["certificateExport"]>,
state?: boolean
) => void;
onFormatSelected: (format: "pem" | "jks", serialNumber: string, options?: ExportOptions) => void;
onFormatSelected: (
format: "pem" | "pkcs12",
serialNumber: string,
options?: ExportOptions
) => void;
};
export type CertificateExportFormat = "pem" | "jks";
export type CertificateExportFormat = "pem" | "pkcs12";
export type ExportOptions = {
jks?: {
pkcs12?: {
password: string;
alias: string;
};
@@ -33,7 +37,7 @@ export type ExportOptions = {
export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelected }: Props) => {
const [selectedFormat, setSelectedFormat] = useState<CertificateExportFormat>("pem");
const [jksOptions, setJksOptions] = useState({
const [pkcs12Options, setPkcs12Options] = useState({
password: "",
alias: ""
});
@@ -45,7 +49,7 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
useEffect(() => {
if (popUp?.certificateExport?.isOpen) {
setSelectedFormat("pem");
setJksOptions({
setPkcs12Options({
password: "",
alias: ""
});
@@ -53,8 +57,8 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
}, [popUp?.certificateExport?.isOpen]);
const isFormValid = () => {
if (selectedFormat === "jks") {
return jksOptions.password.trim() !== "" && jksOptions.alias.trim() !== "";
if (selectedFormat === "pkcs12") {
return pkcs12Options.password.length >= 6 && pkcs12Options.alias.trim() !== "";
}
return true;
};
@@ -63,8 +67,8 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
if (serialNumber && isFormValid()) {
const options: ExportOptions = {};
if (selectedFormat === "jks") {
options.jks = jksOptions;
if (selectedFormat === "pkcs12") {
options.pkcs12 = pkcs12Options;
}
onFormatSelected(selectedFormat, serialNumber, options);
@@ -97,20 +101,28 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
onValueChange={(value) => setSelectedFormat(value as CertificateExportFormat)}
>
<SelectItem value="pem">PEM Format</SelectItem>
<SelectItem value="jks">PKCS12 Format</SelectItem>
<SelectItem value="pkcs12">PKCS12 Format</SelectItem>
</Select>
</FormControl>
{selectedFormat === "jks" && (
{selectedFormat === "pkcs12" && (
<>
<FormControl
label="Keystore Password"
helperText="Password to protect the PKCS12 keystore"
helperText={
pkcs12Options.password.length > 0 && pkcs12Options.password.length < 6
? undefined
: "Password to protect the PKCS12 keystore (minimum 6 characters)"
}
isError={pkcs12Options.password.length > 0 && pkcs12Options.password.length < 6}
errorText="Password must be at least 6 characters long"
>
<Input
placeholder="Enter keystore password"
value={jksOptions.password}
onChange={(e) => setJksOptions((prev) => ({ ...prev, password: e.target.value }))}
value={pkcs12Options.password}
onChange={(e) =>
setPkcs12Options((prev) => ({ ...prev, password: e.target.value }))
}
type="password"
/>
</FormControl>
@@ -121,8 +133,8 @@ export const CertificateExportModal = ({ popUp, handlePopUpToggle, onFormatSelec
>
<Input
placeholder="Enter certificate alias"
value={jksOptions.alias}
onChange={(e) => setJksOptions((prev) => ({ ...prev, alias: e.target.value }))}
value={pkcs12Options.alias}
onChange={(e) => setPkcs12Options((prev) => ({ ...prev, alias: e.target.value }))}
/>
</FormControl>
</>
@@ -53,16 +53,16 @@ export const CertificatesSection = () => {
};
const handleCertificateExport = async (
format: "pem" | "jks",
format: "pem" | "pkcs12",
serialNumber: string,
options?: ExportOptions
) => {
if (format === "pem") {
handlePopUpOpen("certificateCert", { serialNumber });
} else if (format === "jks") {
} else if (format === "pkcs12") {
if (!currentProject?.slug) return;
if (!options?.jks?.password || !options?.jks?.alias) {
if (!options?.pkcs12?.password || !options?.pkcs12?.alias) {
createNotification({
text: "Password and alias are required for PKCS12 export",
type: "error"
@@ -74,17 +74,17 @@ export const CertificatesSection = () => {
await downloadCertPkcs12({
serialNumber,
projectSlug: currentProject.slug,
password: options.jks.password,
alias: options.jks.alias
password: options.pkcs12.password,
alias: options.pkcs12.alias
});
createNotification({
text: "PKCS12 certificate downloaded successfully",
type: "success"
});
} catch {
} catch (error: any) {
createNotification({
text: "Failed to download PKCS12 certificate",
text: error?.message || "Failed to download PKCS12 certificate",
type: "error"
});
}