fix(provider-form): prevent duplicate submissions on rapid button clicks (#1352)

Make ProviderForm.handleSubmit async and await onSubmit so react-hook-form's
isSubmitting state is tracked. Disable submit buttons in AddProviderDialog and
EditProviderDialog while submission is in flight via onSubmittingChange callback.
This commit is contained in:
Hexi
2026-03-15 15:24:17 +08:00
committed by GitHub
parent d8a7bc32db
commit 5c03de53f7
3 changed files with 18 additions and 4 deletions
@@ -48,6 +48,7 @@ export function AddProviderDialog({
const [universalFormOpen, setUniversalFormOpen] = useState(false);
const [selectedUniversalPreset, setSelectedUniversalPreset] =
useState<UniversalProviderPreset | null>(null);
const [isFormSubmitting, setIsFormSubmitting] = useState(false);
const handleUniversalProviderSave = useCallback(
async (provider: UniversalProvider) => {
@@ -247,6 +248,7 @@ export function AddProviderDialog({
<Button
type="submit"
form="provider-form"
disabled={isFormSubmitting}
className="bg-primary text-primary-foreground hover:bg-primary/90"
>
<Plus className="h-4 w-4 mr-2" />
@@ -299,6 +301,7 @@ export function AddProviderDialog({
submitLabel={t("common.add")}
onSubmit={handleSubmit}
onCancel={() => onOpenChange(false)}
onSubmittingChange={setIsFormSubmitting}
showButtons={false}
/>
</TabsContent>
@@ -314,6 +317,7 @@ export function AddProviderDialog({
submitLabel={t("common.add")}
onSubmit={handleSubmit}
onCancel={() => onOpenChange(false)}
onSubmittingChange={setIsFormSubmitting}
showButtons={false}
/>
)}