2025-08-20 11:30:57 +01:00
|
|
|
import React, { useEffect } from "react";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { useEndpointEnabled } from "../hooks/useEndpointConfig";
|
|
|
|
import { useFileContext } from "../contexts/FileContext";
|
2025-08-21 17:30:26 +01:00
|
|
|
import { useNavigationActions } from "../contexts/NavigationContext";
|
|
|
|
import { useFileSelection } from "../contexts/file/fileHooks";
|
2025-08-20 11:30:57 +01:00
|
|
|
|
|
|
|
import { createToolFlow } from "../components/tools/shared/createToolFlow";
|
|
|
|
|
|
|
|
import { useRemoveCertificateSignParameters } from "../hooks/tools/removeCertificateSign/useRemoveCertificateSignParameters";
|
|
|
|
import { useRemoveCertificateSignOperation } from "../hooks/tools/removeCertificateSign/useRemoveCertificateSignOperation";
|
2025-08-22 14:40:27 +01:00
|
|
|
import { BaseToolProps, ToolComponent } from "../types/tool";
|
2025-08-20 11:30:57 +01:00
|
|
|
|
|
|
|
const RemoveCertificateSign = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
|
|
|
const { t } = useTranslation();
|
2025-08-21 17:30:26 +01:00
|
|
|
const { actions } = useNavigationActions();
|
|
|
|
const { selectedFiles } = useFileSelection();
|
2025-08-20 11:30:57 +01:00
|
|
|
|
|
|
|
const removeCertificateSignParams = useRemoveCertificateSignParameters();
|
|
|
|
const removeCertificateSignOperation = useRemoveCertificateSignOperation();
|
|
|
|
|
|
|
|
// Endpoint validation
|
|
|
|
const { enabled: endpointEnabled, loading: endpointLoading } = useEndpointEnabled(removeCertificateSignParams.getEndpointName());
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
removeCertificateSignOperation.resetResults();
|
|
|
|
onPreviewFile?.(null);
|
|
|
|
}, [removeCertificateSignParams.parameters]);
|
|
|
|
|
|
|
|
const handleRemoveSignature = async () => {
|
|
|
|
try {
|
|
|
|
await removeCertificateSignOperation.executeOperation(removeCertificateSignParams.parameters, selectedFiles);
|
|
|
|
if (removeCertificateSignOperation.files && onComplete) {
|
|
|
|
onComplete(removeCertificateSignOperation.files);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
if (onError) {
|
|
|
|
onError(error instanceof Error ? error.message : t("removeCertSign.error.failed", "Remove certificate signature operation failed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleThumbnailClick = (file: File) => {
|
|
|
|
onPreviewFile?.(file);
|
|
|
|
sessionStorage.setItem("previousMode", "removeCertificateSign");
|
2025-08-21 17:30:26 +01:00
|
|
|
actions.setMode("viewer");
|
2025-08-20 11:30:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleSettingsReset = () => {
|
|
|
|
removeCertificateSignOperation.resetResults();
|
|
|
|
onPreviewFile?.(null);
|
|
|
|
};
|
|
|
|
|
|
|
|
const hasFiles = selectedFiles.length > 0;
|
|
|
|
const hasResults = removeCertificateSignOperation.files.length > 0 || removeCertificateSignOperation.downloadUrl !== null;
|
|
|
|
|
|
|
|
return createToolFlow({
|
|
|
|
files: {
|
|
|
|
selectedFiles,
|
|
|
|
isCollapsed: hasFiles || hasResults,
|
|
|
|
placeholder: t("removeCertSign.files.placeholder", "Select a PDF file in the main view to get started"),
|
|
|
|
},
|
|
|
|
steps: [],
|
|
|
|
executeButton: {
|
|
|
|
text: t("removeCertSign.submit", "Remove Signature"),
|
|
|
|
isVisible: !hasResults,
|
|
|
|
loadingText: t("loading"),
|
|
|
|
onClick: handleRemoveSignature,
|
|
|
|
disabled: !removeCertificateSignParams.validateParameters() || !hasFiles || !endpointEnabled,
|
|
|
|
},
|
|
|
|
review: {
|
|
|
|
isVisible: hasResults,
|
|
|
|
operation: removeCertificateSignOperation,
|
|
|
|
title: t("removeCertSign.results.title", "Certificate Removal Results"),
|
|
|
|
onFileClick: handleThumbnailClick,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2025-08-22 14:40:27 +01:00
|
|
|
// Static method to get the operation hook for automation
|
|
|
|
RemoveCertificateSign.tool = () => useRemoveCertificateSignOperation;
|
|
|
|
|
|
|
|
export default RemoveCertificateSign as ToolComponent;
|