Prevent double click on submit of forms.
This commit is contained in:
parent
b481de0a61
commit
1cde87dca7
|
@ -26,6 +26,7 @@ export default function TaskShow() {
|
||||||
const [userTasks, setUserTasks] = useState(null);
|
const [userTasks, setUserTasks] = useState(null);
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [disabled, setDisabled] = useState(false);
|
||||||
|
|
||||||
const { addError, removeError } = useAPIError();
|
const { addError, removeError } = useAPIError();
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ export default function TaskShow() {
|
||||||
|
|
||||||
const processSubmitResult = (result: any) => {
|
const processSubmitResult = (result: any) => {
|
||||||
removeError();
|
removeError();
|
||||||
|
setDisabled(false);
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
navigate(`/tasks`);
|
navigate(`/tasks`);
|
||||||
} else if (result.process_instance_id) {
|
} else if (result.process_instance_id) {
|
||||||
|
@ -68,13 +70,20 @@ export default function TaskShow() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFormSubmit = (event: any) => {
|
const handleFormSubmit = (event: any) => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setDisabled(true);
|
||||||
removeError();
|
removeError();
|
||||||
const dataToSubmit = event.formData;
|
const dataToSubmit = event.formData;
|
||||||
delete dataToSubmit.isManualTask;
|
delete dataToSubmit.isManualTask;
|
||||||
HttpService.makeCallToBackend({
|
HttpService.makeCallToBackend({
|
||||||
path: `/tasks/${params.process_instance_id}/${params.task_id}`,
|
path: `/tasks/${params.process_instance_id}/${params.task_id}`,
|
||||||
successCallback: processSubmitResult,
|
successCallback: processSubmitResult,
|
||||||
failureCallback: addError,
|
failureCallback: (error: any) => {
|
||||||
|
addError(error);
|
||||||
|
setDisabled(false);
|
||||||
|
},
|
||||||
httpMethod: 'PUT',
|
httpMethod: 'PUT',
|
||||||
postBody: dataToSubmit,
|
postBody: dataToSubmit,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue