2025-08-15 14:43:30 +01:00
|
|
|
import React, { useEffect } from "react";
|
2025-08-14 14:27:23 +01:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { useEndpointEnabled } from "../hooks/useEndpointConfig";
|
2025-08-18 21:00:19 +01:00
|
|
|
import { useToolFileSelection } from "../contexts/FileContext";
|
|
|
|
import { useNavigationActions } from "../contexts/NavigationContext";
|
2025-08-14 14:27:23 +01:00
|
|
|
|
2025-08-15 14:43:30 +01:00
|
|
|
import { createToolFlow } from "../components/tools/shared/createToolFlow";
|
2025-08-14 14:27:23 +01:00
|
|
|
|
|
|
|
import ChangePermissionsSettings from "../components/tools/changePermissions/ChangePermissionsSettings";
|
|
|
|
|
|
|
|
import { useChangePermissionsParameters } from "../hooks/tools/changePermissions/useChangePermissionsParameters";
|
|
|
|
import { useChangePermissionsOperation } from "../hooks/tools/changePermissions/useChangePermissionsOperation";
|
|
|
|
import { useChangePermissionsTips } from "../components/tooltips/useChangePermissionsTips";
|
|
|
|
import { BaseToolProps } from "../types/tool";
|
|
|
|
|
|
|
|
const ChangePermissions = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
|
|
|
|
const { t } = useTranslation();
|
2025-08-18 21:00:19 +01:00
|
|
|
const { actions } = useNavigationActions();
|
|
|
|
const setCurrentMode = actions.setMode;
|
2025-08-14 14:27:23 +01:00
|
|
|
const { selectedFiles } = useToolFileSelection();
|
|
|
|
|
|
|
|
const changePermissionsParams = useChangePermissionsParameters();
|
|
|
|
const changePermissionsOperation = useChangePermissionsOperation();
|
|
|
|
const changePermissionsTips = useChangePermissionsTips();
|
|
|
|
|
|
|
|
// Endpoint validation
|
|
|
|
const { enabled: endpointEnabled, loading: endpointLoading } = useEndpointEnabled(changePermissionsParams.getEndpointName());
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
changePermissionsOperation.resetResults();
|
|
|
|
onPreviewFile?.(null);
|
2025-08-15 14:43:30 +01:00
|
|
|
}, [changePermissionsParams.parameters]);
|
2025-08-14 14:27:23 +01:00
|
|
|
|
|
|
|
const handleChangePermissions = async () => {
|
|
|
|
try {
|
2025-08-15 14:43:30 +01:00
|
|
|
await changePermissionsOperation.executeOperation(changePermissionsParams.parameters, selectedFiles);
|
2025-08-14 14:27:23 +01:00
|
|
|
if (changePermissionsOperation.files && onComplete) {
|
|
|
|
onComplete(changePermissionsOperation.files);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
if (onError) {
|
2025-08-15 14:43:30 +01:00
|
|
|
onError(
|
|
|
|
error instanceof Error ? error.message : t("changePermissions.error.failed", "Change permissions operation failed")
|
|
|
|
);
|
2025-08-14 14:27:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleThumbnailClick = (file: File) => {
|
|
|
|
onPreviewFile?.(file);
|
2025-08-15 14:43:30 +01:00
|
|
|
sessionStorage.setItem("previousMode", "changePermissions");
|
|
|
|
setCurrentMode("viewer");
|
2025-08-14 14:27:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleSettingsReset = () => {
|
|
|
|
changePermissionsOperation.resetResults();
|
|
|
|
onPreviewFile?.(null);
|
2025-08-15 14:43:30 +01:00
|
|
|
setCurrentMode("changePermissions");
|
2025-08-14 14:27:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const hasFiles = selectedFiles.length > 0;
|
|
|
|
const hasResults = changePermissionsOperation.files.length > 0 || changePermissionsOperation.downloadUrl !== null;
|
2025-08-15 14:43:30 +01:00
|
|
|
const settingsCollapsed = !hasFiles || hasResults;
|
|
|
|
|
|
|
|
return createToolFlow({
|
|
|
|
files: {
|
|
|
|
selectedFiles,
|
|
|
|
isCollapsed: hasFiles || hasResults,
|
|
|
|
},
|
|
|
|
steps: [
|
|
|
|
{
|
|
|
|
title: t("changePermissions.title", "Document Permissions"),
|
|
|
|
isCollapsed: settingsCollapsed,
|
|
|
|
onCollapsedClick: settingsCollapsed ? handleSettingsReset : undefined,
|
|
|
|
tooltip: changePermissionsTips,
|
|
|
|
content: (
|
|
|
|
<ChangePermissionsSettings
|
|
|
|
parameters={changePermissionsParams.parameters}
|
|
|
|
onParameterChange={changePermissionsParams.updateParameter}
|
|
|
|
disabled={endpointLoading}
|
2025-08-14 14:27:23 +01:00
|
|
|
/>
|
2025-08-15 14:43:30 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
executeButton: {
|
|
|
|
text: t("changePermissions.submit", "Change Permissions"),
|
|
|
|
isVisible: !hasResults,
|
|
|
|
loadingText: t("loading"),
|
|
|
|
onClick: handleChangePermissions,
|
|
|
|
disabled: !changePermissionsParams.validateParameters() || !hasFiles || !endpointEnabled,
|
|
|
|
},
|
|
|
|
review: {
|
|
|
|
isVisible: hasResults,
|
|
|
|
operation: changePermissionsOperation,
|
|
|
|
title: t("changePermissions.results.title", "Modified PDFs"),
|
|
|
|
onFileClick: handleThumbnailClick,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2025-08-14 14:27:23 +01:00
|
|
|
|
|
|
|
export default ChangePermissions;
|