From 1cde87dca745da1a789099f439ea7a96759c5a96 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 3 Feb 2023 13:25:05 -0500 Subject: [PATCH] Prevent double click on submit of forms. --- spiffworkflow-frontend/src/routes/TaskShow.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index 83e5df3f0..d68bd3da9 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -26,6 +26,7 @@ export default function TaskShow() { const [userTasks, setUserTasks] = useState(null); const params = useParams(); const navigate = useNavigate(); + const [disabled, setDisabled] = useState(false); const { addError, removeError } = useAPIError(); @@ -58,6 +59,7 @@ export default function TaskShow() { const processSubmitResult = (result: any) => { removeError(); + setDisabled(false); if (result.ok) { navigate(`/tasks`); } else if (result.process_instance_id) { @@ -68,13 +70,20 @@ export default function TaskShow() { }; const handleFormSubmit = (event: any) => { + if (disabled) { + return; + } + setDisabled(true); removeError(); const dataToSubmit = event.formData; delete dataToSubmit.isManualTask; HttpService.makeCallToBackend({ path: `/tasks/${params.process_instance_id}/${params.task_id}`, successCallback: processSubmitResult, - failureCallback: addError, + failureCallback: (error: any) => { + addError(error); + setDisabled(false); + }, httpMethod: 'PUT', postBody: dataToSubmit, });