Skip to content

Commit

Permalink
Fixed useCertificateCreateDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-slobodian committed Jun 6, 2024
1 parent d5bf840 commit ba30300
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 51 deletions.
9 changes: 2 additions & 7 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function App() {
currentCertificatDelete,
currentCertificateViewerValue,
handleCertificatesDataReload,
handleAddCSRToList,
handleProviderChange,
handleCertificatesSearch,
handleCertificateDeleteDialogOpen,
Expand All @@ -49,12 +48,8 @@ export function App() {
providers,
currentProviderId,
fortifyClient,
onSuccess: (type, providerId, certRaw, label) => {
if (type === "x509") {
handleCertificatesDataReload(providerId);
} else if (type === "csr") {
handleAddCSRToList(providerId, certRaw, label);
}
onSuccess: (providerId) => {
handleCertificatesDataReload(providerId);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ import { CertificateType } from "../../types";
export function useCertificateCreateDialog(props: {
providers: IProviderInfo[];
currentProviderId?: string;
fortifyClient: FortifyAPI | null;
onSuccess: (
type: CertificateType,
providerId: string,
certRaw: ArrayBuffer,
label: string
) => void;
fortifyClient?: FortifyAPI | null;
onSuccess: (providerId: string) => void;
}) {
const { providers, currentProviderId, fortifyClient, onSuccess } = props;
const { addToast } = useToast();
Expand All @@ -38,6 +33,9 @@ export function useCertificateCreateDialog(props: {
const dialogType = useRef<CertificateType>("x509");

const handleCertificateCreate = async (data: CertificateCreateDataProps) => {
if (!fortifyClient) {
return;
}
if (!localCurrentProviderId?.current) {
localCurrentProviderId.current = currentProviderId;
}
Expand All @@ -47,7 +45,7 @@ export function useCertificateCreateDialog(props: {
try {
let newCert;
if (type === "x509") {
newCert = await fortifyClient?.createX509(
newCert = await fortifyClient.createX509(
localCurrentProviderId.current as string,
{
subjectName: subject,
Expand All @@ -56,7 +54,7 @@ export function useCertificateCreateDialog(props: {
}
);
} else if (type === "csr") {
newCert = await fortifyClient?.createPKCS10(
newCert = await fortifyClient.createPKCS10(
localCurrentProviderId.current as string,
{
subjectName: subject,
Expand All @@ -66,12 +64,7 @@ export function useCertificateCreateDialog(props: {
);
}
if (newCert) {
onSuccess(
type,
localCurrentProviderId.current as string,
newCert.der,
data.subject.CN
);
onSuccess(localCurrentProviderId.current as string);
setIsOpen(false);
addToast({
message: t("certificates.dialog.create.success-message"),
Expand Down
29 changes: 0 additions & 29 deletions src/hooks/app/useApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,34 +217,6 @@ export function useApp() {
}
};

const handleAddCSRToList = (
providerId: string,
certRaw: ArrayBuffer,
label: string
) => {
setCurrentProviderId(providerId);

const today = new Date();
const nextYear = new Date(
today.getFullYear() + 1,
today.getMonth(),
today.getDate()
);

setCertificates([
...certificates,
{
id: today.getTime(),
notAfter: nextYear,
notBefore: today,
raw: certRaw,
serialNumber: "01",
type: "csr" as unknown as "x509",
label,
} as unknown as ICertificate,
]);
};

const handleCertificatesSearch = (value: string) => {
// TODO: add logic
console.log(value);
Expand Down Expand Up @@ -296,7 +268,6 @@ export function useApp() {
currentCertificatDelete,
currentCertificateViewerValue,
handleCertificatesDataReload,
handleAddCSRToList,
handleProviderChange,
handleCertificatesSearch,
handleCertificateDeleteDialogOpen,
Expand Down

0 comments on commit ba30300

Please sign in to comment.