procode-lowcode-core 1.0.18 → 1.0.19

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.
package/dist/index.esm.js CHANGED
@@ -435,6 +435,20 @@ class FieldValidationDispatcher {
435
435
  }
436
436
  }
437
437
 
438
+ class ApiResultDispatcher {
439
+ static registerHandler(handler) {
440
+ ApiResultDispatcher.handler = handler;
441
+ }
442
+ static dispatch(result) {
443
+ if (ApiResultDispatcher.handler) {
444
+ ApiResultDispatcher.handler(result);
445
+ }
446
+ else {
447
+ console.warn("Api result dispatcher handler not registered.");
448
+ }
449
+ }
450
+ }
451
+
438
452
  function getStatusBaseNotifiType(status) {
439
453
  if (status >= 200 && status < 300)
440
454
  return "SUCCESS";
@@ -497,6 +511,14 @@ class CentralService {
497
511
  const statusRelatedConfig = (responseConfig !== null && responseConfig !== void 0 ? responseConfig : {})[status];
498
512
  const alertType = (statusRelatedConfig === null || statusRelatedConfig === void 0 ? void 0 : statusRelatedConfig.alertType) || AlertType.TOAST;
499
513
  response.data.alertType = alertType;
514
+ // Record the response outcome so post-request flow (e.g. navigation)
515
+ // can short-circuit when the server reported failure regardless of
516
+ // alertType. Success is derived from the HTTP-ish status set by the
517
+ // response formatter (2xx = success).
518
+ ApiResultDispatcher.dispatch({
519
+ success: status >= 200 && status < 300,
520
+ alertType,
521
+ });
500
522
  if (alertType === AlertType.FIELDVALIDATION) {
501
523
  // Structured payload (default convention {propertyName, message}, or
502
524
  // whatever shape the registered fieldErrorMapper recognizes): route to
@@ -18696,6 +18718,7 @@ const initialState$1 = {
18696
18718
  viewModel: { supportiveData: null, screenData: null },
18697
18719
  inProgressCount: 0,
18698
18720
  validation: {},
18721
+ lastApiResult: null,
18699
18722
  };
18700
18723
  const appSlice = createSlice({
18701
18724
  name: "appState",
@@ -18729,6 +18752,9 @@ const appSlice = createSlice({
18729
18752
  const { fieldName, invalidMessages } = action.payload;
18730
18753
  state.validation = Object.assign(Object.assign({}, state.validation), { [fieldName]: invalidMessages || [] });
18731
18754
  },
18755
+ setLastApiResult: (state, action) => {
18756
+ state.lastApiResult = action.payload;
18757
+ },
18732
18758
  },
18733
18759
  });
18734
18760
  const appActions = appSlice.actions;
@@ -18745,6 +18771,17 @@ const hasFieldValidationErrors = (eventService) => {
18745
18771
  return Object.values(validation).some((messages) => Array.isArray(messages) && messages.length > 0);
18746
18772
  };
18747
18773
 
18774
+ // Reads `state.app.lastApiResult` written by CentralService's response
18775
+ // interceptor and returns true if the most recent request failed. Used by
18776
+ // save/update actions to skip navigation when the server reported a
18777
+ // non-success status under any alertType (FIELDVALIDATION already populates
18778
+ // state.validation, but TOAST leaves no trace there).
18779
+ const hasLastApiCallFailed = (eventService) => {
18780
+ const appState = eventService === null || eventService === void 0 ? void 0 : eventService.emit(eventServiceType.APP_STATE);
18781
+ const lastApiResult = appState === null || appState === void 0 ? void 0 : appState.lastApiResult;
18782
+ return lastApiResult ? lastApiResult.success === false : false;
18783
+ };
18784
+
18748
18785
  const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0, void 0, function* () {
18749
18786
  var _a, _b;
18750
18787
  const eventService = actionInvokerProps.eventService;
@@ -18770,6 +18807,11 @@ const handleUpdateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
18770
18807
  // from a form the user still has to fix.
18771
18808
  if (hasFieldValidationErrors(eventService))
18772
18809
  return;
18810
+ // TOAST-alert failures don't populate state.validation, so check the
18811
+ // last API call's success flag too — a toast-only error should still
18812
+ // keep the user on the current screen.
18813
+ if (hasLastApiCallFailed(eventService))
18814
+ return;
18773
18815
  handleNavigation(actionInvokerProps);
18774
18816
  });
18775
18817
 
@@ -18840,6 +18882,11 @@ const handleCreateAndNavigate = (actionInvokerProps) => __awaiter(void 0, void 0
18840
18882
  // from a form the user still has to fix.
18841
18883
  if (hasFieldValidationErrors(eventService))
18842
18884
  return;
18885
+ // TOAST-alert failures don't populate state.validation, so check the
18886
+ // last API call's success flag too — a toast-only error should still
18887
+ // keep the user on the current screen.
18888
+ if (hasLastApiCallFailed(eventService))
18889
+ return;
18843
18890
  handleNavigation(actionInvokerProps);
18844
18891
  });
18845
18892
 
@@ -19798,6 +19845,12 @@ const setupStoreAction = (dispatch, eventService, store) => {
19798
19845
  FieldValidationDispatcher.registerHandler((errors) => {
19799
19846
  dispatch(appActions.loadValidation(errors));
19800
19847
  });
19848
+ // Record the latest server response's success/alertType so flow-control
19849
+ // helpers (e.g. hasLastApiCallFailed) can decide whether to continue with
19850
+ // post-request actions like navigation.
19851
+ ApiResultDispatcher.registerHandler((result) => {
19852
+ dispatch(appActions.setLastApiResult(result));
19853
+ });
19801
19854
  // Register loader handlers for external services
19802
19855
  eventService === null || eventService === void 0 ? void 0 : eventService.subscribe(eventServiceType.REQUEST_START, () => () => {
19803
19856
  dispatch(commonDataActions.updatePendingRequests(LoadingStatus.INPROCESS));
@@ -20698,6 +20751,7 @@ const useCoreInitialization = (coreProps) => {
20698
20751
  requestHeaders: coreProps.requestHeaders,
20699
20752
  getSchemaBySlugService: coreProps.getSchemaBySlugService,
20700
20753
  responseFormatter: coreProps.responseFormatter,
20754
+ fieldErrorMapper: coreProps.fieldErrorMapper,
20701
20755
  });
20702
20756
  };
20703
20757
  const initCustomStorages = () => {