diff --git a/frontend/src/components/patient/CreatePatientForm.js b/frontend/src/components/patient/CreatePatientForm.js
index c7280ab03e..b83c4e0150 100644
--- a/frontend/src/components/patient/CreatePatientForm.js
+++ b/frontend/src/components/patient/CreatePatientForm.js
@@ -1,11 +1,7 @@
import React, { useState, useRef, useEffect, useContext } from "react";
import { FormattedMessage, injectIntl, useIntl } from "react-intl";
import "../Style.css";
-import {
- getFromOpenElisServer,
- getFromOpenElisServerSync,
- postToOpenElisServer,
-} from "../utils/Utils";
+import { getFromOpenElisServer, postToOpenElisServer } from "../utils/Utils";
import { nationalityList } from "../data/countries";
import format from "date-fns/format";
import {
@@ -66,6 +62,9 @@ function CreatePatientForm(props) {
const [subjectNo, setSubjectNo] = useState(
props.selectedPatient.subjectNumber,
);
+
+ const [isSubmitting, setIsSubmitting] = useState(false);
+
const handleNationalIdChange = (event) => {
const newValue = event.target.value;
setNationalId(newValue);
@@ -308,6 +307,13 @@ function CreatePatientForm(props) {
};
const handleSubmit = async (values, { resetForm }) => {
+ // Prevent multiple submissions.
+ if (isSubmitting) {
+ return;
+ }
+
+ setIsSubmitting(true);
+
if ("years" in values) {
delete values.years;
}
@@ -330,7 +336,9 @@ function CreatePatientForm(props) {
days: "",
});
},
- );
+ ).then(() => {
+ setIsSubmitting(false);
+ });
};
const handlePost = (status) => {
@@ -1007,7 +1015,7 @@ function CreatePatientForm(props) {
{props.showActionsButton && (
<>
-
@@ -1015,6 +1023,7 @@ function CreatePatientForm(props) {
{
resetForm({ values: CreatePatientFormValues });
setHealthDistricts([]);
diff --git a/frontend/src/components/utils/Utils.js b/frontend/src/components/utils/Utils.js
index b59895d595..5335d0daab 100644
--- a/frontend/src/components/utils/Utils.js
+++ b/frontend/src/components/utils/Utils.js
@@ -35,7 +35,7 @@ export const postToOpenElisServer = (
callback,
extraParams,
) => {
- fetch(
+ return fetch(
config.serverBaseUrl + endPoint,
{