mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 00:35:32 +08:00
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:
@@ -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}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user