Prevent double submit in new client form (#30438)

Closes #20371

Signed-off-by: Ahana Mallik <ahanamallik@gmail.com>
This commit is contained in:
Ahana Mallik 2024-06-25 20:37:08 +02:00 committed by GitHub
parent bc38b5db1b
commit 4be058a3dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,6 +21,7 @@ import { toClients } from "../routes/Clients";
import { CapabilityConfig } from "./CapabilityConfig";
import { GeneralSettings } from "./GeneralSettings";
import { LoginSettings } from "./LoginSettings";
import { useState } from "react";
const NewClientFooter = (newClientForm: any) => {
const { t } = useTranslation();
@ -54,6 +55,7 @@ export default function NewClientForm() {
const { t } = useTranslation();
const { realm } = useRealm();
const navigate = useNavigate();
const [saving, setSaving] = useState<boolean>(false);
const { addAlert, addError } = useAlerts();
const form = useForm<FormFields>({
@ -78,6 +80,8 @@ export default function NewClientForm() {
const protocol = watch("protocol");
const save = async () => {
if (saving) return;
setSaving(true);
const client = convertFormValuesToObject(getValues());
try {
const newClient = await adminClient.clients.create({
@ -88,6 +92,8 @@ export default function NewClientForm() {
navigate(toClient({ realm, clientId: newClient.id, tab: "settings" }));
} catch (error) {
addError("createClientError", error);
} finally {
setSaving(false);
}
};