@pisell/private-materials 6.12.291 → 6.12.292

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.
@@ -52,7 +52,8 @@ function useBookingEditPetState(open, baseBookingState, setRequest, holderSeed,
52
52
  });
53
53
  useEffect(() => {
54
54
  var _baseBookingState$boo, _baseBookingState$boo2, _baseBookingState$cli;
55
- effectRunRef.current += 1;
55
+ const effectRunId = effectRunRef.current + 1;
56
+ effectRunRef.current = effectRunId;
56
57
  previousDepsRef.current;
57
58
  previousDepsRef.current = {
58
59
  holderSeed,
@@ -67,17 +68,18 @@ function useBookingEditPetState(open, baseBookingState, setRequest, holderSeed,
67
68
  const productHolderFormId = holderSourceFormId;
68
69
  const customerId = (_baseBookingState$cli = baseBookingState.client) === null || _baseBookingState$cli === void 0 || (_baseBookingState$cli = _baseBookingState$cli.value) === null || _baseBookingState$cli === void 0 ? void 0 : _baseBookingState$cli.id;
69
70
  let cancelled = false;
71
+ const isCurrentRequest = () => !cancelled && effectRunRef.current === effectRunId;
70
72
  const syncHolderFormData = function() {
71
73
  var _ref4 = _asyncToGenerator(function* () {
72
74
  try {
73
75
  const holderFormDetail = productHolderFormId ? yield getCachedProductHolderFormDetail(Number(productHolderFormId), platform) : null;
74
- if (cancelled) return;
76
+ if (!isCurrentRequest()) return;
75
77
  const formDataConfig = buildHolderFormDataConfig(holder, stableHolderSource, holderFormDetail);
76
78
  setPet((prev) => _objectSpread2(_objectSpread2({}, prev), formDataConfig ? { formData: [formDataConfig] } : {}));
77
79
  const linkedTableId = getMinorLinkedTableId(formDataConfig);
78
80
  if (linkedTableId) {
79
81
  const waiverForm = yield getCachedWaiverFormDetail(Number(linkedTableId), platform);
80
- if (cancelled) return;
82
+ if (!isCurrentRequest()) return;
81
83
  setPet((prev) => _objectSpread2(_objectSpread2({}, prev), {}, { waiverForm }));
82
84
  }
83
85
  } catch (err) {
@@ -107,11 +109,13 @@ function useBookingEditPetState(open, baseBookingState, setRequest, holderSeed,
107
109
  setPet((prev) => _objectSpread2(_objectSpread2({}, prev), {}, { holders: holderSeed }));
108
110
  return cleanup;
109
111
  }
112
+ setPet((prev) => _objectSpread2(_objectSpread2({}, prev), {}, { holders: void 0 }));
110
113
  getPetsData(params, platform).then((data) => {
114
+ if (!isCurrentRequest()) return;
111
115
  const list = Array.isArray(data === null || data === void 0 ? void 0 : data.list) ? data.list : [];
112
116
  setPet((prev) => _objectSpread2(_objectSpread2({}, prev), {}, { holders: list }));
113
117
  }).catch((err) => {
114
- console.warn("[SalesSdk] load holders failed", err);
118
+ if (isCurrentRequest()) console.warn("[SalesSdk] load holders failed", err);
115
119
  });
116
120
  return cleanup;
117
121
  }, [
@@ -2,7 +2,7 @@ import { isWalkIn } from "../../../components/booking/utils.js";
2
2
  import withResponsive from "../../../responsive/withResponsive.js";
3
3
  import PisellSelectHolder from "../../selectHolder/index.js";
4
4
  import { resolveEffectiveHolderConfig } from "../utils/productHolderConfig.js";
5
- import React, { useCallback, useEffect, useMemo, useState } from "react";
5
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
6
6
  import { locales } from "@pisell/utils";
7
7
  //#region src/plus/salesSdk/components/SalesSdkSelectHolderModal.tsx
8
8
  function buildHolderOptions(holders) {
@@ -30,7 +30,7 @@ function buildDisplayConfig(bookingConfig, holderOptions, maxSelectedCount, prod
30
30
  /**
31
31
  * SalesSdk 专用 Holder 弹窗(从 booking selectHolderModal 复制,props 驱动,无 miniRedux dispatch)。
32
32
  */
33
- const SalesSdkSelectHolderModalContent = ({ open, holders, bookingConfig, productSource, customerId, initialValue, maxSelectedCount = 1, onAddHolder, onConfirm, onValueChange, onCancel, onSkip, isInline = false, className, style, variant }) => {
33
+ const SalesSdkSelectHolderModalContent = ({ open, holders, bookingConfig, productSource, customerId, selectionSessionKey, initialValue, maxSelectedCount = 1, onAddHolder, onConfirm, onValueChange, onCancel, onSkip, isInline = false, className, style, variant }) => {
34
34
  var _holderConfig$form;
35
35
  const [innerOpen, setInnerOpen] = useState(open);
36
36
  const holderOptions = useMemo(() => buildHolderOptions(holders), [holders]);
@@ -40,12 +40,20 @@ const SalesSdkSelectHolderModalContent = ({ open, holders, bookingConfig, produc
40
40
  return [initialValue];
41
41
  }, [initialValue]);
42
42
  const [selectedValues, setSelectedValues] = useState(normalizedInitialValue);
43
+ const previousSelectionSessionKeyRef = useRef(selectionSessionKey);
43
44
  useEffect(() => {
44
45
  setInnerOpen(open);
45
46
  }, [open]);
46
47
  useEffect(() => {
47
- setSelectedValues(normalizedInitialValue);
48
- }, [normalizedInitialValue]);
48
+ if (selectionSessionKey === void 0) {
49
+ setSelectedValues(normalizedInitialValue);
50
+ return;
51
+ }
52
+ if (previousSelectionSessionKeyRef.current !== selectionSessionKey) {
53
+ previousSelectionSessionKeyRef.current = selectionSessionKey;
54
+ setSelectedValues(normalizedInitialValue);
55
+ }
56
+ }, [normalizedInitialValue, selectionSessionKey]);
49
57
  const holderConfig = (bookingConfig === null || bookingConfig === void 0 ? void 0 : bookingConfig.holder) || {};
50
58
  const title = (holderConfig === null || holderConfig === void 0 || (_holderConfig$form = holderConfig.form) === null || _holderConfig$form === void 0 ? void 0 : _holderConfig$form.title) || (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.title) || locales.getText("pisell2.text.holder");
51
59
  const displayConfig = useMemo(() => buildDisplayConfig(bookingConfig, holderOptions, maxSelectedCount, productSource), [
@@ -283,6 +283,7 @@ const SalesSdkProvider = ({ osKey, enableMultiCurrencySettlement = false, soluti
283
283
  isFranchisee: businessUtils === null || businessUtils === void 0 || (_businessUtils$getApp = businessUtils.getAppByModal) === null || _businessUtils$getApp === void 0 ? void 0 : _businessUtils$getApp.call(businessUtils, "franchisee"),
284
284
  rules: rulesHooks ? { hooks: rulesHooks } : void 0
285
285
  }, otherParams || {}), {}, {
286
+ channel: productLoadChannel,
286
287
  enableMultiCurrencySettlement,
287
288
  enableTempOrderPersist
288
289
  }) });
@@ -13,7 +13,7 @@ import { useBookingEditPetState } from "../bookingEditService/useBookingEditPetS
13
13
  import { buildBookingEditDrawerState, resolveBookingEditCustomerId } from "../bookingEditService/buildBookingEditDrawerState.js";
14
14
  import { useSalesSdk } from "../hooks/useSalesSdk.js";
15
15
  import { useSyncExternalStoreCompat } from "../hooks/useSyncExternalStoreCompat.js";
16
- import React, { useEffect, useMemo } from "react";
16
+ import React, { useEffect, useMemo, useRef } from "react";
17
17
  import { message } from "antd";
18
18
  import { locales } from "@pisell/utils";
19
19
  import { useMemoizedFn } from "ahooks";
@@ -25,6 +25,12 @@ const HolderHostRenderer = () => {
25
25
  var _context$appHelper, _payload$productSourc, _payload$customerId, _cacheItem$_extend, _bookingTicket$getOrd, _mergedState$bookingC, _cacheItem$_extend3, _cacheItem$_extend7, _mergedState$pet2, _mergedState$bookingC3, _mergedState$pet4, _mergedState$pet7;
26
26
  const bridge = useSalesSdkHostBridges().holder;
27
27
  const pending = useSyncExternalStoreCompat(bridge.subscribe, bridge.getSnapshot, () => null);
28
+ const observedPendingRef = useRef(pending);
29
+ const holderSelectionSessionRef = useRef(0);
30
+ if (observedPendingRef.current !== pending) {
31
+ observedPendingRef.current = pending;
32
+ if (pending) holderSelectionSessionRef.current += 1;
33
+ }
28
34
  const { bookingTicket, tempOrder } = useSalesSdk();
29
35
  const context = useEngineContext();
30
36
  const platform = usePlatform();
@@ -229,12 +235,13 @@ const HolderHostRenderer = () => {
229
235
  });
230
236
  if (!open || !mergedState || !holdersReady) return null;
231
237
  return /* @__PURE__ */ React.createElement(SalesSdkSelectHolderModal, {
232
- key: `holder:${initialHolderValue.map(String).join(",")}`,
238
+ key: `holder:${holderSelectionSessionRef.current}`,
233
239
  open,
234
240
  holders: ((_mergedState$pet7 = mergedState.pet) === null || _mergedState$pet7 === void 0 ? void 0 : _mergedState$pet7.holders) || [],
235
241
  bookingConfig: mergedState.bookingConfig,
236
242
  productSource: holderSource,
237
243
  customerId,
244
+ selectionSessionKey: holderSelectionSessionRef.current,
238
245
  initialValue: initialHolderValue,
239
246
  maxSelectedCount,
240
247
  onAddHolder: action ? handleAddHolder : void 0,
@@ -53,7 +53,8 @@ function useBookingEditPetState(open, baseBookingState, setRequest, holderSeed,
53
53
  });
54
54
  (0, react.useEffect)(() => {
55
55
  var _baseBookingState$boo, _baseBookingState$boo2, _baseBookingState$cli;
56
- effectRunRef.current += 1;
56
+ const effectRunId = effectRunRef.current + 1;
57
+ effectRunRef.current = effectRunId;
57
58
  previousDepsRef.current;
58
59
  previousDepsRef.current = {
59
60
  holderSeed,
@@ -68,17 +69,18 @@ function useBookingEditPetState(open, baseBookingState, setRequest, holderSeed,
68
69
  const productHolderFormId = holderSourceFormId;
69
70
  const customerId = (_baseBookingState$cli = baseBookingState.client) === null || _baseBookingState$cli === void 0 || (_baseBookingState$cli = _baseBookingState$cli.value) === null || _baseBookingState$cli === void 0 ? void 0 : _baseBookingState$cli.id;
70
71
  let cancelled = false;
72
+ const isCurrentRequest = () => !cancelled && effectRunRef.current === effectRunId;
71
73
  const syncHolderFormData = function() {
72
74
  var _ref4 = require_asyncToGenerator._asyncToGenerator(function* () {
73
75
  try {
74
76
  const holderFormDetail = productHolderFormId ? yield require_productHolderFormDetailCache.getCachedProductHolderFormDetail(Number(productHolderFormId), platform) : null;
75
- if (cancelled) return;
77
+ if (!isCurrentRequest()) return;
76
78
  const formDataConfig = buildHolderFormDataConfig(holder, stableHolderSource, holderFormDetail);
77
79
  setPet((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prev), formDataConfig ? { formData: [formDataConfig] } : {}));
78
80
  const linkedTableId = getMinorLinkedTableId(formDataConfig);
79
81
  if (linkedTableId) {
80
82
  const waiverForm = yield require_waiverFormDetailCache.getCachedWaiverFormDetail(Number(linkedTableId), platform);
81
- if (cancelled) return;
83
+ if (!isCurrentRequest()) return;
82
84
  setPet((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prev), {}, { waiverForm }));
83
85
  }
84
86
  } catch (err) {
@@ -108,11 +110,13 @@ function useBookingEditPetState(open, baseBookingState, setRequest, holderSeed,
108
110
  setPet((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prev), {}, { holders: holderSeed }));
109
111
  return cleanup;
110
112
  }
113
+ setPet((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prev), {}, { holders: void 0 }));
111
114
  require_serve.getPetsData(params, platform).then((data) => {
115
+ if (!isCurrentRequest()) return;
112
116
  const list = Array.isArray(data === null || data === void 0 ? void 0 : data.list) ? data.list : [];
113
117
  setPet((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prev), {}, { holders: list }));
114
118
  }).catch((err) => {
115
- console.warn("[SalesSdk] load holders failed", err);
119
+ if (isCurrentRequest()) console.warn("[SalesSdk] load holders failed", err);
116
120
  });
117
121
  return cleanup;
118
122
  }, [
@@ -32,7 +32,7 @@ function buildDisplayConfig(bookingConfig, holderOptions, maxSelectedCount, prod
32
32
  /**
33
33
  * SalesSdk 专用 Holder 弹窗(从 booking selectHolderModal 复制,props 驱动,无 miniRedux dispatch)。
34
34
  */
35
- const SalesSdkSelectHolderModalContent = ({ open, holders, bookingConfig, productSource, customerId, initialValue, maxSelectedCount = 1, onAddHolder, onConfirm, onValueChange, onCancel, onSkip, isInline = false, className, style, variant }) => {
35
+ const SalesSdkSelectHolderModalContent = ({ open, holders, bookingConfig, productSource, customerId, selectionSessionKey, initialValue, maxSelectedCount = 1, onAddHolder, onConfirm, onValueChange, onCancel, onSkip, isInline = false, className, style, variant }) => {
36
36
  var _holderConfig$form;
37
37
  const [innerOpen, setInnerOpen] = (0, react.useState)(open);
38
38
  const holderOptions = (0, react.useMemo)(() => buildHolderOptions(holders), [holders]);
@@ -42,12 +42,20 @@ const SalesSdkSelectHolderModalContent = ({ open, holders, bookingConfig, produc
42
42
  return [initialValue];
43
43
  }, [initialValue]);
44
44
  const [selectedValues, setSelectedValues] = (0, react.useState)(normalizedInitialValue);
45
+ const previousSelectionSessionKeyRef = (0, react.useRef)(selectionSessionKey);
45
46
  (0, react.useEffect)(() => {
46
47
  setInnerOpen(open);
47
48
  }, [open]);
48
49
  (0, react.useEffect)(() => {
49
- setSelectedValues(normalizedInitialValue);
50
- }, [normalizedInitialValue]);
50
+ if (selectionSessionKey === void 0) {
51
+ setSelectedValues(normalizedInitialValue);
52
+ return;
53
+ }
54
+ if (previousSelectionSessionKeyRef.current !== selectionSessionKey) {
55
+ previousSelectionSessionKeyRef.current = selectionSessionKey;
56
+ setSelectedValues(normalizedInitialValue);
57
+ }
58
+ }, [normalizedInitialValue, selectionSessionKey]);
51
59
  const holderConfig = (bookingConfig === null || bookingConfig === void 0 ? void 0 : bookingConfig.holder) || {};
52
60
  const title = (holderConfig === null || holderConfig === void 0 || (_holderConfig$form = holderConfig.form) === null || _holderConfig$form === void 0 ? void 0 : _holderConfig$form.title) || (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.title) || _pisell_utils.locales.getText("pisell2.text.holder");
53
61
  const displayConfig = (0, react.useMemo)(() => buildDisplayConfig(bookingConfig, holderOptions, maxSelectedCount, productSource), [
@@ -286,6 +286,7 @@ const SalesSdkProvider = ({ osKey, enableMultiCurrencySettlement = false, soluti
286
286
  isFranchisee: businessUtils === null || businessUtils === void 0 || (_businessUtils$getApp = businessUtils.getAppByModal) === null || _businessUtils$getApp === void 0 ? void 0 : _businessUtils$getApp.call(businessUtils, "franchisee"),
287
287
  rules: rulesHooks ? { hooks: rulesHooks } : void 0
288
288
  }, otherParams || {}), {}, {
289
+ channel: productLoadChannel,
289
290
  enableMultiCurrencySettlement,
290
291
  enableTempOrderPersist
291
292
  }) });
@@ -27,6 +27,12 @@ const HolderHostRenderer = () => {
27
27
  var _context$appHelper, _payload$productSourc, _payload$customerId, _cacheItem$_extend, _bookingTicket$getOrd, _mergedState$bookingC, _cacheItem$_extend3, _cacheItem$_extend7, _mergedState$pet2, _mergedState$bookingC3, _mergedState$pet4, _mergedState$pet7;
28
28
  const bridge = require_SalesSdkHostBridgesContext.useSalesSdkHostBridges().holder;
29
29
  const pending = require_useSyncExternalStoreCompat.useSyncExternalStoreCompat(bridge.subscribe, bridge.getSnapshot, () => null);
30
+ const observedPendingRef = (0, react.useRef)(pending);
31
+ const holderSelectionSessionRef = (0, react.useRef)(0);
32
+ if (observedPendingRef.current !== pending) {
33
+ observedPendingRef.current = pending;
34
+ if (pending) holderSelectionSessionRef.current += 1;
35
+ }
30
36
  const { bookingTicket, tempOrder } = require_useSalesSdk.useSalesSdk();
31
37
  const context = require_useEngineContext.default();
32
38
  const platform = require_useEngineContext.usePlatform();
@@ -231,12 +237,13 @@ const HolderHostRenderer = () => {
231
237
  });
232
238
  if (!open || !mergedState || !holdersReady) return null;
233
239
  return /* @__PURE__ */ react.default.createElement(require_SalesSdkSelectHolderModal.SalesSdkSelectHolderModal, {
234
- key: `holder:${initialHolderValue.map(String).join(",")}`,
240
+ key: `holder:${holderSelectionSessionRef.current}`,
235
241
  open,
236
242
  holders: ((_mergedState$pet7 = mergedState.pet) === null || _mergedState$pet7 === void 0 ? void 0 : _mergedState$pet7.holders) || [],
237
243
  bookingConfig: mergedState.bookingConfig,
238
244
  productSource: holderSource,
239
245
  customerId,
246
+ selectionSessionKey: holderSelectionSessionRef.current,
240
247
  initialValue: initialHolderValue,
241
248
  maxSelectedCount,
242
249
  onAddHolder: action ? handleAddHolder : void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.12.291",
3
+ "version": "6.12.292",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -72,10 +72,10 @@
72
72
  "styled-components": "^6.0.0-rc.3",
73
73
  "use-sync-external-store": "^1.6.0",
74
74
  "@pisell/pi-payment-sdk": "0.0.3",
75
- "@pisell/materials": "6.12.75",
76
- "@pisell/date-picker": "3.0.12",
77
75
  "@pisell/utils": "3.0.7",
78
- "@pisell/icon": "0.0.11"
76
+ "@pisell/icon": "0.0.11",
77
+ "@pisell/date-picker": "3.0.12",
78
+ "@pisell/materials": "6.12.75"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "react": "^18.0.0",