@dovetail-v2/refine 0.3.30-alpha.1 → 0.3.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,5 +32,7 @@ export type UseFormProps<TQueryFnData extends BaseRecord = BaseRecord, TError ex
32
32
  transformInitValues?: (values: Record<string, unknown>) => DefaultValues<TVariables>;
33
33
  beforeSubmit?: (values: TVariables, setErrors: (errors: string[]) => void) => Promise<TVariables>;
34
34
  onBeforeSubmitError?: (errors: string[]) => void;
35
+ onSubmitStart?: () => void;
36
+ onSubmitAbort?: () => void;
35
37
  } & UseHookFormProps<TVariables, TContext>;
36
- export declare const useForm: <TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TVariables extends FieldValues = FieldValues, TContext extends object = object, TData extends BaseRecord = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError>({ refineCoreProps, warnWhenUnsavedChanges: warnWhenUnsavedChangesProp, disableServerSideValidation: disableServerSideValidationProp, transformApplyValues, transformInitValues, beforeSubmit, onBeforeSubmitError, ...rest }?: UseFormProps<TQueryFnData, TError, TVariables, TContext, TData, TResponse, TResponseError>) => UseFormReturnType<TQueryFnData, TError, TVariables, TContext, TData, TResponse, TResponseError>;
38
+ export declare const useForm: <TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TVariables extends FieldValues = FieldValues, TContext extends object = object, TData extends BaseRecord = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError>({ refineCoreProps, warnWhenUnsavedChanges: warnWhenUnsavedChangesProp, disableServerSideValidation: disableServerSideValidationProp, transformApplyValues, transformInitValues, beforeSubmit, onBeforeSubmitError, onSubmitStart, onSubmitAbort, ...rest }?: UseFormProps<TQueryFnData, TError, TVariables, TContext, TData, TResponse, TResponseError>) => UseFormReturnType<TQueryFnData, TError, TVariables, TContext, TData, TResponse, TResponseError>;
@@ -3,6 +3,8 @@ import { UseFormProps } from './useReactHookForm';
3
3
  interface UseRefineFormOptions {
4
4
  initialValues?: Record<string, unknown>;
5
5
  onBeforeSubmitError?: (errors: string[]) => void;
6
+ onSubmitStart?: () => void;
7
+ onSubmitAbort?: () => void;
6
8
  }
7
9
  export declare const useRefineForm: (props: {
8
10
  formConfig?: RefineFormConfig & CommonFormConfig;
@@ -29,6 +29,8 @@ export type UseFormProps<TQueryFnData extends BaseRecord = BaseRecord, TError ex
29
29
  transformApplyValues?: (values: Unstructured) => Unstructured;
30
30
  beforeSubmit?: (values: Unstructured, setErrors: (errors: string[]) => void) => Promise<Unstructured>;
31
31
  onBeforeSubmitError?: (errors: string[]) => void;
32
+ onSubmitStart?: () => void;
33
+ onSubmitAbort?: () => void;
32
34
  rules?: YamlFormRule[];
33
35
  };
34
36
  export type UseFormReturnType<TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TVariables extends object = object, TData extends BaseRecord = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError> = UseFormReturnTypeCore<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError> & {
@@ -53,5 +55,5 @@ declare const useYamlForm: <TQueryFnData extends Unstructured = Unstructured & {
53
55
  [prop: string]: unknown;
54
56
  } = {
55
57
  [prop: string]: unknown;
56
- }, TData extends Unstructured = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError>({ action: actionFromProps, resource, onMutationSuccess: onMutationSuccessProp, onMutationError, submitOnEnter, warnWhenUnsavedChanges: warnWhenUnsavedChangesProp, redirect, successNotification, errorNotification, meta, metaData, queryMeta, mutationMeta, liveMode, liveParams, mutationMode, dataProviderName, onLiveEvent, invalidates, undoableTimeout, queryOptions, createMutationOptions, updateMutationOptions, id: idFromProps, overtimeOptions, editorOptions, initialValuesForCreate, initialValuesForEdit, transformInitValues, transformApplyValues, beforeSubmit, onBeforeSubmitError, rules, }?: UseFormProps<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>) => UseFormReturnType<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>;
58
+ }, TData extends Unstructured = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError>({ action: actionFromProps, resource, onMutationSuccess: onMutationSuccessProp, onMutationError, submitOnEnter, warnWhenUnsavedChanges: warnWhenUnsavedChangesProp, redirect, successNotification, errorNotification, meta, metaData, queryMeta, mutationMeta, liveMode, liveParams, mutationMode, dataProviderName, onLiveEvent, invalidates, undoableTimeout, queryOptions, createMutationOptions, updateMutationOptions, id: idFromProps, overtimeOptions, editorOptions, initialValuesForCreate, initialValuesForEdit, transformInitValues, transformApplyValues, beforeSubmit, onBeforeSubmitError, onSubmitStart, onSubmitAbort, rules, }?: UseFormProps<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>) => UseFormReturnType<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>;
57
59
  export default useYamlForm;
package/dist/refine.cjs CHANGED
@@ -11248,6 +11248,8 @@ const useYamlForm = ({
11248
11248
  transformApplyValues,
11249
11249
  beforeSubmit,
11250
11250
  onBeforeSubmitError,
11251
+ onSubmitStart,
11252
+ onSubmitAbort,
11251
11253
  rules
11252
11254
  } = {}) => {
11253
11255
  var _a;
@@ -11281,6 +11283,7 @@ const useYamlForm = ({
11281
11283
  onMutationSuccess: onMutationSuccessProp ? onMutationSuccessProp : void 0,
11282
11284
  onMutationError: (error, ...restParams) => {
11283
11285
  var _a2;
11286
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11284
11287
  const response = error.response;
11285
11288
  if (response && !(response == null ? void 0 : response.bodyUsed)) {
11286
11289
  (_a2 = response.json) == null ? void 0 : _a2.call(response).then((body) => {
@@ -11417,17 +11420,20 @@ const useYamlForm = ({
11417
11420
  onFinish: async (values) => {
11418
11421
  var _a2, _b;
11419
11422
  setBeforeSubmitErrors([]);
11423
+ onSubmitStart == null ? void 0 : onSubmitStart();
11420
11424
  const errors = [
11421
11425
  !isYamlValid ? t2("dovetail.yaml_format_wrong") : "",
11422
11426
  !isSchemaValid ? t2("dovetail.yaml_value_wrong") : ""
11423
11427
  ].filter((error) => !!error);
11424
11428
  if (errors.length) {
11429
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11425
11430
  setEditorErrors(errors);
11426
11431
  setRulesErrors([]);
11427
11432
  return;
11428
11433
  }
11429
11434
  const rulesErrors2 = await validateRules(((_a2 = editor.current) == null ? void 0 : _a2.getEditorValue()) || "");
11430
11435
  if (Object.keys(rulesErrors2).length) {
11436
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11431
11437
  setRulesErrors(Object.values(rulesErrors2));
11432
11438
  return;
11433
11439
  }
@@ -11446,6 +11452,7 @@ const useYamlForm = ({
11446
11452
  }
11447
11453
  });
11448
11454
  if (hasErrors) {
11455
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11449
11456
  return;
11450
11457
  }
11451
11458
  if (result !== void 0) {
@@ -11457,6 +11464,7 @@ const useYamlForm = ({
11457
11464
  }
11458
11465
  return onFinish(finalValues);
11459
11466
  } catch (error) {
11467
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11460
11468
  if (error instanceof Error) {
11461
11469
  if (error.message === "expected a single document in the stream, but found more") {
11462
11470
  setEditorErrors([t2("dovetail.only_support_one_yaml")]);
@@ -11657,6 +11665,7 @@ function YamlFormContainer({
11657
11665
  const pushModal = eagle.usePushModal();
11658
11666
  const popModal = eagle.usePopModal();
11659
11667
  const hasShownExpiredRef = React.useRef(false);
11668
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11660
11669
  const queryResult = core.useOne({
11661
11670
  resource: resourceConfig.name,
11662
11671
  id,
@@ -11665,18 +11674,19 @@ function YamlFormContainer({
11665
11674
  });
11666
11675
  const isExpired = useResourceVersionCheck({ queryResult });
11667
11676
  React.useEffect(() => {
11668
- if (isExpired && !hasShownExpiredRef.current) {
11669
- hasShownExpiredRef.current = true;
11670
- pushModal({
11671
- component: DataExpiredModal,
11672
- props: {
11673
- onAbandon: () => {
11674
- popModal();
11675
- }
11676
- }
11677
- });
11677
+ if (!isExpired || isSubmitting || hasShownExpiredRef.current) {
11678
+ return;
11678
11679
  }
11679
- }, [isExpired, pushModal, popModal]);
11680
+ hasShownExpiredRef.current = true;
11681
+ pushModal({
11682
+ component: DataExpiredModal,
11683
+ props: {
11684
+ onAbandon: () => {
11685
+ popModal();
11686
+ }
11687
+ }
11688
+ });
11689
+ }, [isExpired, isSubmitting, pushModal, popModal]);
11680
11690
  const { transformInitValues, transformApplyValues } = usePathMap({
11681
11691
  pathMap: formConfig == null ? void 0 : formConfig.pathMap,
11682
11692
  transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
@@ -11696,7 +11706,13 @@ function YamlFormContainer({
11696
11706
  action,
11697
11707
  isShowLayout: false,
11698
11708
  useFormProps: {
11699
- redirect: false
11709
+ redirect: false,
11710
+ onSubmitStart: () => {
11711
+ setIsSubmitting(true);
11712
+ },
11713
+ onSubmitAbort: () => {
11714
+ setIsSubmitting(false);
11715
+ }
11700
11716
  },
11701
11717
  rules: void 0,
11702
11718
  onSaveButtonPropsChange,
@@ -13206,8 +13222,11 @@ function _KeyValueTableForm(props, ref) {
13206
13222
  validator: ({
13207
13223
  value: value22
13208
13224
  }) => {
13209
- if (!value22)
13210
- return t2("dovetail.key_empty_text");
13225
+ if (!value22) {
13226
+ return t2("dovetail.required_field", {
13227
+ label: keyTitle || t2("dovetail.key")
13228
+ });
13229
+ }
13211
13230
  const validate2 = validateKey || validateLabelKey;
13212
13231
  const {
13213
13232
  isValid,
@@ -16879,6 +16898,8 @@ const useForm = ({
16879
16898
  transformInitValues,
16880
16899
  beforeSubmit,
16881
16900
  onBeforeSubmitError,
16901
+ onSubmitStart,
16902
+ onSubmitAbort,
16882
16903
  ...rest
16883
16904
  } = {}) => {
16884
16905
  const { options } = core.useRefineContext();
@@ -16999,6 +17020,7 @@ const useForm = ({
16999
17020
  loading: formLoading || isBeforeSubmitLoading,
17000
17021
  onClick: async (e2) => {
17001
17022
  setBeforeSubmitErrors([]);
17023
+ onSubmitStart == null ? void 0 : onSubmitStart();
17002
17024
  handleSubmit(
17003
17025
  async (v) => {
17004
17026
  let finalValues = transformApplyValues ? transformApplyValues(v) : v;
@@ -17014,18 +17036,25 @@ const useForm = ({
17014
17036
  }
17015
17037
  });
17016
17038
  if (hasErrors) {
17039
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
17017
17040
  return;
17018
17041
  }
17019
17042
  if (result !== void 0) {
17020
17043
  finalValues = result;
17021
17044
  }
17045
+ } catch (error) {
17046
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
17047
+ throw error;
17022
17048
  } finally {
17023
17049
  setIsBeforeSubmitLoading(false);
17024
17050
  }
17025
17051
  }
17026
17052
  return onFinish(finalValues);
17027
17053
  },
17028
- () => false
17054
+ () => {
17055
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
17056
+ return false;
17057
+ }
17029
17058
  )(e2);
17030
17059
  }
17031
17060
  };
@@ -17036,7 +17065,9 @@ const useForm = ({
17036
17065
  onFinish,
17037
17066
  transformApplyValues,
17038
17067
  beforeSubmit,
17039
- onBeforeSubmitError
17068
+ onBeforeSubmitError,
17069
+ onSubmitStart,
17070
+ onSubmitAbort
17040
17071
  ]);
17041
17072
  return {
17042
17073
  ...useHookFormResult,
@@ -17088,6 +17119,8 @@ const useRefineForm = (props) => {
17088
17119
  transformInitValues,
17089
17120
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
17090
17121
  onBeforeSubmitError: options == null ? void 0 : options.onBeforeSubmitError,
17122
+ onSubmitStart: options == null ? void 0 : options.onSubmitStart,
17123
+ onSubmitAbort: options == null ? void 0 : options.onSubmitAbort,
17091
17124
  ...formConfig == null ? void 0 : formConfig.useFormProps
17092
17125
  });
17093
17126
  React.useEffect(() => {
@@ -17127,6 +17160,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17127
17160
  const pushModal = eagle.usePushModal();
17128
17161
  const popModal = eagle.usePopModal();
17129
17162
  const hasShownExpiredRef = React.useRef(false);
17163
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
17130
17164
  const refineFormResult = useRefineForm({
17131
17165
  resourceConfig,
17132
17166
  id,
@@ -17135,6 +17169,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17135
17169
  onSuccess == null ? void 0 : onSuccess(data2);
17136
17170
  },
17137
17171
  onMutationError() {
17172
+ setIsSubmitting(false);
17138
17173
  onError == null ? void 0 : onError();
17139
17174
  },
17140
17175
  redirect: false,
@@ -17148,8 +17183,15 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17148
17183
  ...options,
17149
17184
  onBeforeSubmitError: (errors) => {
17150
17185
  if (errors.length) {
17186
+ setIsSubmitting(false);
17151
17187
  onError == null ? void 0 : onError();
17152
17188
  }
17189
+ },
17190
+ onSubmitStart: () => {
17191
+ setIsSubmitting(true);
17192
+ },
17193
+ onSubmitAbort: () => {
17194
+ setIsSubmitting(false);
17153
17195
  }
17154
17196
  }
17155
17197
  });
@@ -17157,18 +17199,19 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17157
17199
  queryResult: refineFormResult.formResult.refineCore.queryResult
17158
17200
  });
17159
17201
  React.useEffect(() => {
17160
- if (isExpired && !hasShownExpiredRef.current) {
17161
- hasShownExpiredRef.current = true;
17162
- pushModal({
17163
- component: DataExpiredModal,
17164
- props: {
17165
- onAbandon: () => {
17166
- popModal();
17167
- }
17168
- }
17169
- });
17202
+ if (!isExpired || isSubmitting || hasShownExpiredRef.current) {
17203
+ return;
17170
17204
  }
17171
- }, [isExpired, pushModal, popModal]);
17205
+ hasShownExpiredRef.current = true;
17206
+ pushModal({
17207
+ component: DataExpiredModal,
17208
+ props: {
17209
+ onAbandon: () => {
17210
+ popModal();
17211
+ }
17212
+ }
17213
+ });
17214
+ }, [isExpired, isSubmitting, pushModal, popModal]);
17172
17215
  const fieldsConfig = useFieldsConfig(
17173
17216
  resourceConfig,
17174
17217
  { fields: formConfig == null ? void 0 : formConfig.fields },
@@ -17200,7 +17243,13 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17200
17243
  action,
17201
17244
  isShowLayout: false,
17202
17245
  useFormProps: {
17203
- redirect: false
17246
+ redirect: false,
17247
+ onSubmitStart: () => {
17248
+ setIsSubmitting(true);
17249
+ },
17250
+ onSubmitAbort: () => {
17251
+ setIsSubmitting(false);
17252
+ }
17204
17253
  },
17205
17254
  rules: fieldsConfig == null ? void 0 : fieldsConfig.filter(
17206
17255
  (config) => "isSkipValidationInYaml" in config && !config.isSkipValidationInYaml
package/dist/refine.js CHANGED
@@ -11229,6 +11229,8 @@ const useYamlForm = ({
11229
11229
  transformApplyValues,
11230
11230
  beforeSubmit,
11231
11231
  onBeforeSubmitError,
11232
+ onSubmitStart,
11233
+ onSubmitAbort,
11232
11234
  rules
11233
11235
  } = {}) => {
11234
11236
  var _a;
@@ -11262,6 +11264,7 @@ const useYamlForm = ({
11262
11264
  onMutationSuccess: onMutationSuccessProp ? onMutationSuccessProp : void 0,
11263
11265
  onMutationError: (error, ...restParams) => {
11264
11266
  var _a2;
11267
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11265
11268
  const response = error.response;
11266
11269
  if (response && !(response == null ? void 0 : response.bodyUsed)) {
11267
11270
  (_a2 = response.json) == null ? void 0 : _a2.call(response).then((body) => {
@@ -11398,17 +11401,20 @@ const useYamlForm = ({
11398
11401
  onFinish: async (values) => {
11399
11402
  var _a2, _b;
11400
11403
  setBeforeSubmitErrors([]);
11404
+ onSubmitStart == null ? void 0 : onSubmitStart();
11401
11405
  const errors = [
11402
11406
  !isYamlValid ? t2("dovetail.yaml_format_wrong") : "",
11403
11407
  !isSchemaValid ? t2("dovetail.yaml_value_wrong") : ""
11404
11408
  ].filter((error) => !!error);
11405
11409
  if (errors.length) {
11410
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11406
11411
  setEditorErrors(errors);
11407
11412
  setRulesErrors([]);
11408
11413
  return;
11409
11414
  }
11410
11415
  const rulesErrors2 = await validateRules(((_a2 = editor.current) == null ? void 0 : _a2.getEditorValue()) || "");
11411
11416
  if (Object.keys(rulesErrors2).length) {
11417
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11412
11418
  setRulesErrors(Object.values(rulesErrors2));
11413
11419
  return;
11414
11420
  }
@@ -11427,6 +11433,7 @@ const useYamlForm = ({
11427
11433
  }
11428
11434
  });
11429
11435
  if (hasErrors) {
11436
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11430
11437
  return;
11431
11438
  }
11432
11439
  if (result !== void 0) {
@@ -11438,6 +11445,7 @@ const useYamlForm = ({
11438
11445
  }
11439
11446
  return onFinish(finalValues);
11440
11447
  } catch (error) {
11448
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
11441
11449
  if (error instanceof Error) {
11442
11450
  if (error.message === "expected a single document in the stream, but found more") {
11443
11451
  setEditorErrors([t2("dovetail.only_support_one_yaml")]);
@@ -11638,6 +11646,7 @@ function YamlFormContainer({
11638
11646
  const pushModal = usePushModal();
11639
11647
  const popModal = usePopModal();
11640
11648
  const hasShownExpiredRef = useRef(false);
11649
+ const [isSubmitting, setIsSubmitting] = useState(false);
11641
11650
  const queryResult = useOne({
11642
11651
  resource: resourceConfig.name,
11643
11652
  id,
@@ -11646,18 +11655,19 @@ function YamlFormContainer({
11646
11655
  });
11647
11656
  const isExpired = useResourceVersionCheck({ queryResult });
11648
11657
  useEffect(() => {
11649
- if (isExpired && !hasShownExpiredRef.current) {
11650
- hasShownExpiredRef.current = true;
11651
- pushModal({
11652
- component: DataExpiredModal,
11653
- props: {
11654
- onAbandon: () => {
11655
- popModal();
11656
- }
11657
- }
11658
- });
11658
+ if (!isExpired || isSubmitting || hasShownExpiredRef.current) {
11659
+ return;
11659
11660
  }
11660
- }, [isExpired, pushModal, popModal]);
11661
+ hasShownExpiredRef.current = true;
11662
+ pushModal({
11663
+ component: DataExpiredModal,
11664
+ props: {
11665
+ onAbandon: () => {
11666
+ popModal();
11667
+ }
11668
+ }
11669
+ });
11670
+ }, [isExpired, isSubmitting, pushModal, popModal]);
11661
11671
  const { transformInitValues, transformApplyValues } = usePathMap({
11662
11672
  pathMap: formConfig == null ? void 0 : formConfig.pathMap,
11663
11673
  transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
@@ -11677,7 +11687,13 @@ function YamlFormContainer({
11677
11687
  action,
11678
11688
  isShowLayout: false,
11679
11689
  useFormProps: {
11680
- redirect: false
11690
+ redirect: false,
11691
+ onSubmitStart: () => {
11692
+ setIsSubmitting(true);
11693
+ },
11694
+ onSubmitAbort: () => {
11695
+ setIsSubmitting(false);
11696
+ }
11681
11697
  },
11682
11698
  rules: void 0,
11683
11699
  onSaveButtonPropsChange,
@@ -13187,8 +13203,11 @@ function _KeyValueTableForm(props, ref) {
13187
13203
  validator: ({
13188
13204
  value: value22
13189
13205
  }) => {
13190
- if (!value22)
13191
- return t2("dovetail.key_empty_text");
13206
+ if (!value22) {
13207
+ return t2("dovetail.required_field", {
13208
+ label: keyTitle || t2("dovetail.key")
13209
+ });
13210
+ }
13192
13211
  const validate2 = validateKey || validateLabelKey;
13193
13212
  const {
13194
13213
  isValid,
@@ -16860,6 +16879,8 @@ const useForm = ({
16860
16879
  transformInitValues,
16861
16880
  beforeSubmit,
16862
16881
  onBeforeSubmitError,
16882
+ onSubmitStart,
16883
+ onSubmitAbort,
16863
16884
  ...rest
16864
16885
  } = {}) => {
16865
16886
  const { options } = useRefineContext();
@@ -16980,6 +17001,7 @@ const useForm = ({
16980
17001
  loading: formLoading || isBeforeSubmitLoading,
16981
17002
  onClick: async (e2) => {
16982
17003
  setBeforeSubmitErrors([]);
17004
+ onSubmitStart == null ? void 0 : onSubmitStart();
16983
17005
  handleSubmit(
16984
17006
  async (v) => {
16985
17007
  let finalValues = transformApplyValues ? transformApplyValues(v) : v;
@@ -16995,18 +17017,25 @@ const useForm = ({
16995
17017
  }
16996
17018
  });
16997
17019
  if (hasErrors) {
17020
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
16998
17021
  return;
16999
17022
  }
17000
17023
  if (result !== void 0) {
17001
17024
  finalValues = result;
17002
17025
  }
17026
+ } catch (error) {
17027
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
17028
+ throw error;
17003
17029
  } finally {
17004
17030
  setIsBeforeSubmitLoading(false);
17005
17031
  }
17006
17032
  }
17007
17033
  return onFinish(finalValues);
17008
17034
  },
17009
- () => false
17035
+ () => {
17036
+ onSubmitAbort == null ? void 0 : onSubmitAbort();
17037
+ return false;
17038
+ }
17010
17039
  )(e2);
17011
17040
  }
17012
17041
  };
@@ -17017,7 +17046,9 @@ const useForm = ({
17017
17046
  onFinish,
17018
17047
  transformApplyValues,
17019
17048
  beforeSubmit,
17020
- onBeforeSubmitError
17049
+ onBeforeSubmitError,
17050
+ onSubmitStart,
17051
+ onSubmitAbort
17021
17052
  ]);
17022
17053
  return {
17023
17054
  ...useHookFormResult,
@@ -17069,6 +17100,8 @@ const useRefineForm = (props) => {
17069
17100
  transformInitValues,
17070
17101
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
17071
17102
  onBeforeSubmitError: options == null ? void 0 : options.onBeforeSubmitError,
17103
+ onSubmitStart: options == null ? void 0 : options.onSubmitStart,
17104
+ onSubmitAbort: options == null ? void 0 : options.onSubmitAbort,
17072
17105
  ...formConfig == null ? void 0 : formConfig.useFormProps
17073
17106
  });
17074
17107
  useEffect(() => {
@@ -17108,6 +17141,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17108
17141
  const pushModal = usePushModal();
17109
17142
  const popModal = usePopModal();
17110
17143
  const hasShownExpiredRef = useRef(false);
17144
+ const [isSubmitting, setIsSubmitting] = useState(false);
17111
17145
  const refineFormResult = useRefineForm({
17112
17146
  resourceConfig,
17113
17147
  id,
@@ -17116,6 +17150,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17116
17150
  onSuccess == null ? void 0 : onSuccess(data2);
17117
17151
  },
17118
17152
  onMutationError() {
17153
+ setIsSubmitting(false);
17119
17154
  onError == null ? void 0 : onError();
17120
17155
  },
17121
17156
  redirect: false,
@@ -17129,8 +17164,15 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17129
17164
  ...options,
17130
17165
  onBeforeSubmitError: (errors) => {
17131
17166
  if (errors.length) {
17167
+ setIsSubmitting(false);
17132
17168
  onError == null ? void 0 : onError();
17133
17169
  }
17170
+ },
17171
+ onSubmitStart: () => {
17172
+ setIsSubmitting(true);
17173
+ },
17174
+ onSubmitAbort: () => {
17175
+ setIsSubmitting(false);
17134
17176
  }
17135
17177
  }
17136
17178
  });
@@ -17138,18 +17180,19 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17138
17180
  queryResult: refineFormResult.formResult.refineCore.queryResult
17139
17181
  });
17140
17182
  useEffect(() => {
17141
- if (isExpired && !hasShownExpiredRef.current) {
17142
- hasShownExpiredRef.current = true;
17143
- pushModal({
17144
- component: DataExpiredModal,
17145
- props: {
17146
- onAbandon: () => {
17147
- popModal();
17148
- }
17149
- }
17150
- });
17183
+ if (!isExpired || isSubmitting || hasShownExpiredRef.current) {
17184
+ return;
17151
17185
  }
17152
- }, [isExpired, pushModal, popModal]);
17186
+ hasShownExpiredRef.current = true;
17187
+ pushModal({
17188
+ component: DataExpiredModal,
17189
+ props: {
17190
+ onAbandon: () => {
17191
+ popModal();
17192
+ }
17193
+ }
17194
+ });
17195
+ }, [isExpired, isSubmitting, pushModal, popModal]);
17153
17196
  const fieldsConfig = useFieldsConfig(
17154
17197
  resourceConfig,
17155
17198
  { fields: formConfig == null ? void 0 : formConfig.fields },
@@ -17181,7 +17224,13 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17181
17224
  action,
17182
17225
  isShowLayout: false,
17183
17226
  useFormProps: {
17184
- redirect: false
17227
+ redirect: false,
17228
+ onSubmitStart: () => {
17229
+ setIsSubmitting(true);
17230
+ },
17231
+ onSubmitAbort: () => {
17232
+ setIsSubmitting(false);
17233
+ }
17185
17234
  },
17186
17235
  rules: fieldsConfig == null ? void 0 : fieldsConfig.filter(
17187
17236
  (config) => "isSkipValidationInYaml" in config && !config.isSkipValidationInYaml
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dovetail-v2/refine",
3
- "version": "0.3.30-alpha.1",
3
+ "version": "0.3.31",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",