fix: anti double submit in form
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { PageActionType } from '@/config/types';
|
||||
import useSubmitLock from '@/hooks/use-submit-lock';
|
||||
import { ModalFooter } from '@gpustack/core-ui';
|
||||
import { useRef } from 'react';
|
||||
import FormDrawer from '../../../_components/form-drawer';
|
||||
@@ -26,9 +27,10 @@ const AddModal: React.FC<AddModalProps> = ({
|
||||
storageClassList
|
||||
}) => {
|
||||
const form = useRef<any>(null);
|
||||
const { loading, guard, run, release } = useSubmitLock();
|
||||
|
||||
const handleSubmit = () => {
|
||||
form.current?.submit();
|
||||
guard(() => form.current?.submit());
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
@@ -37,9 +39,11 @@ const AddModal: React.FC<AddModalProps> = ({
|
||||
};
|
||||
|
||||
const onFinish = async (values: FormData) => {
|
||||
onOk({
|
||||
...values
|
||||
});
|
||||
await run(() =>
|
||||
onOk({
|
||||
...values
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -53,6 +57,7 @@ const AddModal: React.FC<AddModalProps> = ({
|
||||
<ModalFooter
|
||||
onOk={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
loading={loading}
|
||||
style={{
|
||||
padding: '16px 24px 8px',
|
||||
display: 'flex',
|
||||
@@ -67,6 +72,7 @@ const AddModal: React.FC<AddModalProps> = ({
|
||||
action={action}
|
||||
currentData={data}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={release}
|
||||
open={open}
|
||||
/>
|
||||
</FormContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user