mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-18 17:39:24 +00:00
80 lines
3.1 KiB
TypeScript
80 lines
3.1 KiB
TypeScript
![]() |
import React, { useEffect } from "react";
|
||
|
import { useTranslation } from "react-i18next";
|
||
|
import { useEndpointEnabled } from "../hooks/useEndpointConfig";
|
||
|
import { useFileContext } from "../contexts/FileContext";
|
||
|
import { useToolFileSelection } from "../contexts/FileSelectionContext";
|
||
|
|
||
|
import { createToolFlow } from "../components/tools/shared/createToolFlow";
|
||
|
|
||
|
import { useRemoveCertificateSignParameters } from "../hooks/tools/removeCertificateSign/useRemoveCertificateSignParameters";
|
||
|
import { useRemoveCertificateSignOperation } from "../hooks/tools/removeCertificateSign/useRemoveCertificateSignOperation";
|
||
|
import { BaseToolProps } from "../types/tool";
|
||
|
|
||
|
const RemoveCertificateSign = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
||
|
const { t } = useTranslation();
|
||
|
const { setCurrentMode } = useFileContext();
|
||
|
const { selectedFiles } = useToolFileSelection();
|
||
|
|
||
|
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");
|
||
|
setCurrentMode("viewer");
|
||
|
};
|
||
|
|
||
|
const handleSettingsReset = () => {
|
||
|
removeCertificateSignOperation.resetResults();
|
||
|
onPreviewFile?.(null);
|
||
|
setCurrentMode("removeCertificateSign");
|
||
|
};
|
||
|
|
||
|
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,
|
||
|
},
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export default RemoveCertificateSign;
|