@pisell/private-materials 6.11.686 → 6.11.687

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.
@@ -659,6 +659,7 @@ function useAdjustTimeModal(options) {
659
659
  if (yield function() {
660
660
  var _ref23 = _asyncToGenerator(function* () {
661
661
  if (mode === "checkout") {
662
+ yield previewQueueRef.current;
662
663
  yield salesSdkCart.waitForCartConsistency();
663
664
  const checkoutResult = yield sales === null || sales === void 0 ? void 0 : sales.openCheckout();
664
665
  const isBackWithPaymentChanged = (checkoutResult === null || checkoutResult === void 0 ? void 0 : checkoutResult.reason) === "back" && (checkoutResult === null || checkoutResult === void 0 ? void 0 : checkoutResult.isChangePaymentNotIncludeVoucher) === true;
@@ -786,9 +787,7 @@ function useAdjustTimeModal(options) {
786
787
  onSave: (result) => {
787
788
  handleSave(result);
788
789
  },
789
- onCheckout: (result) => {
790
- handleCheckout(result);
791
- },
790
+ onCheckout: handleCheckout,
792
791
  onPreviewChange: handlePreviewChange,
793
792
  onTicketCountClick: bookingSelection && bookingSelection.options.length > 1 ? openBookingSelectionFromAdjustTime : void 0
794
793
  }) : null);
@@ -1,4 +1,5 @@
1
1
  import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
+ import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
2
3
  import { useSalesSdk } from "../../hooks/useSalesSdk.js";
3
4
  import { addMinutes, applyTimeToDate, formatTime, getDelayToNextBillableMinuteChange, minutesBetween, resolveBillableMinuteDate, resolveFlexibleBusinessEnd, toDate } from "../utils/time.js";
4
5
  import { resolveDefaultChangeTimeValue } from "../utils/changeTime.js";
@@ -308,6 +309,8 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
308
309
  const start = useMemo(() => toDate(booking.start), [booking.start]);
309
310
  const end = useMemo(() => toDate(booking.end), [booking.end]);
310
311
  const [liveNow, setLiveNow] = useState(() => resolveBillableMinuteDate(/* @__PURE__ */ new Date()));
312
+ const [checkoutPending, setCheckoutPending] = useState(false);
313
+ const checkoutPendingRef = useRef(false);
311
314
  const [manualEndTime, setManualEndTime] = useState(() => getManualDefaultEndTime(end, liveNow));
312
315
  const [manualEndDate, setManualEndDate] = useState(() => resolveDefaultManualEndDate(end, liveNow));
313
316
  const [changeTimeValue, setChangeTimeValue] = useState(() => resolveDefaultChangeTimeValue({
@@ -322,6 +325,7 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
322
325
  const prevOpenRef = useRef(false);
323
326
  const latestOnPreviewChangeRef = useRef();
324
327
  latestOnPreviewChangeRef.current = onPreviewChange;
328
+ const pendingPreviewRef = useRef();
325
329
  /** 重置 Manual Add time 的 Date 和 HH:mm 文本,保持 UI 和计算值一致。 */
326
330
  const resetManualEnd = useCallback((defaultManualEnd) => {
327
331
  setManualEndDate(defaultManualEnd);
@@ -330,10 +334,11 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
330
334
  /** Pay overtime 按分钟计费,只在跨过计费分钟时刷新 controller 派生数据。 */
331
335
  /** 注册调试入口:允许运行时通过事件/localStorage 临时覆盖营业结束时间。 */
332
336
  useEffect(() => {
333
- if (!open) return void 0;
337
+ if (!open || checkoutPending) return void 0;
334
338
  let timeoutId;
335
339
  let intervalId;
336
340
  const tick = () => {
341
+ if (checkoutPendingRef.current) return;
337
342
  const now = resolveBillableMinuteDate(/* @__PURE__ */ new Date());
338
343
  setLiveNow((prev) => prev.getTime() === now.getTime() ? prev : now);
339
344
  };
@@ -346,7 +351,7 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
346
351
  if (timeoutId != null) window.clearTimeout(timeoutId);
347
352
  if (intervalId != null) window.clearInterval(intervalId);
348
353
  };
349
- }, [open]);
354
+ }, [open, checkoutPending]);
350
355
  useEffect(() => {
351
356
  if (typeof window === "undefined") return void 0;
352
357
  const setDebugClosingTime = (time) => {
@@ -636,8 +641,7 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
636
641
  ]);
637
642
  /** action/time/price 变化后通知外层写入 tempOrder 预览;不依赖 previewDueAmount,避免预览回填触发循环。 */
638
643
  useEffect(() => {
639
- var _latestOnPreviewChang2;
640
- if (!open) return;
644
+ if (!open || checkoutPendingRef.current) return;
641
645
  const actionType = isProductAction(activeAction) ? "product" : activeAction;
642
646
  const previewResult = {
643
647
  actionType,
@@ -651,19 +655,30 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
651
655
  manualDueAmount,
652
656
  selectedProductId: scenario.selectedProductId
653
657
  };
658
+ const notifyPreviewChange = () => {
659
+ var _latestOnPreviewChang;
660
+ if (checkoutPendingRef.current) return;
661
+ (_latestOnPreviewChang = latestOnPreviewChangeRef.current) === null || _latestOnPreviewChang === void 0 || _latestOnPreviewChang.call(latestOnPreviewChangeRef, previewResult);
662
+ };
654
663
  if (actionType === "changeTime") {
664
+ pendingPreviewRef.current = previewResult;
655
665
  const timerId = window.setTimeout(() => {
656
- var _latestOnPreviewChang;
657
- (_latestOnPreviewChang = latestOnPreviewChangeRef.current) === null || _latestOnPreviewChang === void 0 || _latestOnPreviewChang.call(latestOnPreviewChangeRef, previewResult);
666
+ if (pendingPreviewRef.current !== previewResult) return;
667
+ pendingPreviewRef.current = void 0;
668
+ notifyPreviewChange();
658
669
  }, 0);
659
- return () => window.clearTimeout(timerId);
670
+ return () => {
671
+ window.clearTimeout(timerId);
672
+ if (pendingPreviewRef.current === previewResult) pendingPreviewRef.current = void 0;
673
+ };
660
674
  }
661
- (_latestOnPreviewChang2 = latestOnPreviewChangeRef.current) === null || _latestOnPreviewChang2 === void 0 || _latestOnPreviewChang2.call(latestOnPreviewChangeRef, previewResult);
675
+ notifyPreviewChange();
662
676
  }, [
663
677
  activeAction,
664
678
  addedMinutes,
665
679
  autoPricing,
666
680
  booking.id,
681
+ checkoutPending,
667
682
  localDueAmount,
668
683
  manualDueAmount,
669
684
  open,
@@ -698,10 +713,23 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
698
713
  changeTimeValue,
699
714
  scenario,
700
715
  handleActionChange,
701
- handleCheckout: useMemoizedFn(() => {
702
- if (checkoutDisabled || previewLoading) return;
703
- onCheckout === null || onCheckout === void 0 || onCheckout(buildSubmitResult());
704
- }),
716
+ handleCheckout: useMemoizedFn(_asyncToGenerator(function* () {
717
+ if (checkoutDisabled || previewLoading || checkoutPendingRef.current) return;
718
+ const pendingPreview = pendingPreviewRef.current;
719
+ pendingPreviewRef.current = void 0;
720
+ checkoutPendingRef.current = true;
721
+ setCheckoutPending(true);
722
+ try {
723
+ if (pendingPreview) {
724
+ var _latestOnPreviewChang2;
725
+ yield (_latestOnPreviewChang2 = latestOnPreviewChangeRef.current) === null || _latestOnPreviewChang2 === void 0 ? void 0 : _latestOnPreviewChang2.call(latestOnPreviewChangeRef, pendingPreview);
726
+ }
727
+ yield onCheckout === null || onCheckout === void 0 ? void 0 : onCheckout(buildSubmitResult());
728
+ } finally {
729
+ checkoutPendingRef.current = false;
730
+ setCheckoutPending(false);
731
+ }
732
+ })),
705
733
  handleSave,
706
734
  handleManualEndTimeChange,
707
735
  handleChangeTimeChange,
@@ -663,6 +663,7 @@ function useAdjustTimeModal(options) {
663
663
  if (yield function() {
664
664
  var _ref23 = require_asyncToGenerator._asyncToGenerator(function* () {
665
665
  if (mode === "checkout") {
666
+ yield previewQueueRef.current;
666
667
  yield salesSdkCart.waitForCartConsistency();
667
668
  const checkoutResult = yield sales === null || sales === void 0 ? void 0 : sales.openCheckout();
668
669
  const isBackWithPaymentChanged = (checkoutResult === null || checkoutResult === void 0 ? void 0 : checkoutResult.reason) === "back" && (checkoutResult === null || checkoutResult === void 0 ? void 0 : checkoutResult.isChangePaymentNotIncludeVoucher) === true;
@@ -790,9 +791,7 @@ function useAdjustTimeModal(options) {
790
791
  onSave: (result) => {
791
792
  handleSave(result);
792
793
  },
793
- onCheckout: (result) => {
794
- handleCheckout(result);
795
- },
794
+ onCheckout: handleCheckout,
796
795
  onPreviewChange: handlePreviewChange,
797
796
  onTicketCountClick: bookingSelection && bookingSelection.options.length > 1 ? openBookingSelectionFromAdjustTime : void 0
798
797
  }) : null);
@@ -1,5 +1,6 @@
1
1
  require("../../../../_virtual/_rolldown/runtime.js");
2
2
  const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
3
+ const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
3
4
  const require_useSalesSdk = require("../../hooks/useSalesSdk.js");
4
5
  const require_time = require("../utils/time.js");
5
6
  const require_changeTime = require("../utils/changeTime.js");
@@ -309,6 +310,8 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
309
310
  const start = (0, react.useMemo)(() => require_time.toDate(booking.start), [booking.start]);
310
311
  const end = (0, react.useMemo)(() => require_time.toDate(booking.end), [booking.end]);
311
312
  const [liveNow, setLiveNow] = (0, react.useState)(() => require_time.resolveBillableMinuteDate(/* @__PURE__ */ new Date()));
313
+ const [checkoutPending, setCheckoutPending] = (0, react.useState)(false);
314
+ const checkoutPendingRef = (0, react.useRef)(false);
312
315
  const [manualEndTime, setManualEndTime] = (0, react.useState)(() => getManualDefaultEndTime(end, liveNow));
313
316
  const [manualEndDate, setManualEndDate] = (0, react.useState)(() => resolveDefaultManualEndDate(end, liveNow));
314
317
  const [changeTimeValue, setChangeTimeValue] = (0, react.useState)(() => require_changeTime.resolveDefaultChangeTimeValue({
@@ -323,6 +326,7 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
323
326
  const prevOpenRef = (0, react.useRef)(false);
324
327
  const latestOnPreviewChangeRef = (0, react.useRef)();
325
328
  latestOnPreviewChangeRef.current = onPreviewChange;
329
+ const pendingPreviewRef = (0, react.useRef)();
326
330
  /** 重置 Manual Add time 的 Date 和 HH:mm 文本,保持 UI 和计算值一致。 */
327
331
  const resetManualEnd = (0, react.useCallback)((defaultManualEnd) => {
328
332
  setManualEndDate(defaultManualEnd);
@@ -331,10 +335,11 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
331
335
  /** Pay overtime 按分钟计费,只在跨过计费分钟时刷新 controller 派生数据。 */
332
336
  /** 注册调试入口:允许运行时通过事件/localStorage 临时覆盖营业结束时间。 */
333
337
  (0, react.useEffect)(() => {
334
- if (!open) return void 0;
338
+ if (!open || checkoutPending) return void 0;
335
339
  let timeoutId;
336
340
  let intervalId;
337
341
  const tick = () => {
342
+ if (checkoutPendingRef.current) return;
338
343
  const now = require_time.resolveBillableMinuteDate(/* @__PURE__ */ new Date());
339
344
  setLiveNow((prev) => prev.getTime() === now.getTime() ? prev : now);
340
345
  };
@@ -347,7 +352,7 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
347
352
  if (timeoutId != null) window.clearTimeout(timeoutId);
348
353
  if (intervalId != null) window.clearInterval(intervalId);
349
354
  };
350
- }, [open]);
355
+ }, [open, checkoutPending]);
351
356
  (0, react.useEffect)(() => {
352
357
  if (typeof window === "undefined") return void 0;
353
358
  const setDebugClosingTime = (time) => {
@@ -637,8 +642,7 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
637
642
  ]);
638
643
  /** action/time/price 变化后通知外层写入 tempOrder 预览;不依赖 previewDueAmount,避免预览回填触发循环。 */
639
644
  (0, react.useEffect)(() => {
640
- var _latestOnPreviewChang2;
641
- if (!open) return;
645
+ if (!open || checkoutPendingRef.current) return;
642
646
  const actionType = isProductAction(activeAction) ? "product" : activeAction;
643
647
  const previewResult = {
644
648
  actionType,
@@ -652,19 +656,30 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
652
656
  manualDueAmount,
653
657
  selectedProductId: scenario.selectedProductId
654
658
  };
659
+ const notifyPreviewChange = () => {
660
+ var _latestOnPreviewChang;
661
+ if (checkoutPendingRef.current) return;
662
+ (_latestOnPreviewChang = latestOnPreviewChangeRef.current) === null || _latestOnPreviewChang === void 0 || _latestOnPreviewChang.call(latestOnPreviewChangeRef, previewResult);
663
+ };
655
664
  if (actionType === "changeTime") {
665
+ pendingPreviewRef.current = previewResult;
656
666
  const timerId = window.setTimeout(() => {
657
- var _latestOnPreviewChang;
658
- (_latestOnPreviewChang = latestOnPreviewChangeRef.current) === null || _latestOnPreviewChang === void 0 || _latestOnPreviewChang.call(latestOnPreviewChangeRef, previewResult);
667
+ if (pendingPreviewRef.current !== previewResult) return;
668
+ pendingPreviewRef.current = void 0;
669
+ notifyPreviewChange();
659
670
  }, 0);
660
- return () => window.clearTimeout(timerId);
671
+ return () => {
672
+ window.clearTimeout(timerId);
673
+ if (pendingPreviewRef.current === previewResult) pendingPreviewRef.current = void 0;
674
+ };
661
675
  }
662
- (_latestOnPreviewChang2 = latestOnPreviewChangeRef.current) === null || _latestOnPreviewChang2 === void 0 || _latestOnPreviewChang2.call(latestOnPreviewChangeRef, previewResult);
676
+ notifyPreviewChange();
663
677
  }, [
664
678
  activeAction,
665
679
  addedMinutes,
666
680
  autoPricing,
667
681
  booking.id,
682
+ checkoutPending,
668
683
  localDueAmount,
669
684
  manualDueAmount,
670
685
  open,
@@ -699,10 +714,23 @@ const useAdjustTimeModalController = ({ open, booking, products, resourceEndTime
699
714
  changeTimeValue,
700
715
  scenario,
701
716
  handleActionChange,
702
- handleCheckout: (0, ahooks.useMemoizedFn)(() => {
703
- if (checkoutDisabled || previewLoading) return;
704
- onCheckout === null || onCheckout === void 0 || onCheckout(buildSubmitResult());
705
- }),
717
+ handleCheckout: (0, ahooks.useMemoizedFn)(require_asyncToGenerator._asyncToGenerator(function* () {
718
+ if (checkoutDisabled || previewLoading || checkoutPendingRef.current) return;
719
+ const pendingPreview = pendingPreviewRef.current;
720
+ pendingPreviewRef.current = void 0;
721
+ checkoutPendingRef.current = true;
722
+ setCheckoutPending(true);
723
+ try {
724
+ if (pendingPreview) {
725
+ var _latestOnPreviewChang2;
726
+ yield (_latestOnPreviewChang2 = latestOnPreviewChangeRef.current) === null || _latestOnPreviewChang2 === void 0 ? void 0 : _latestOnPreviewChang2.call(latestOnPreviewChangeRef, pendingPreview);
727
+ }
728
+ yield onCheckout === null || onCheckout === void 0 ? void 0 : onCheckout(buildSubmitResult());
729
+ } finally {
730
+ checkoutPendingRef.current = false;
731
+ setCheckoutPending(false);
732
+ }
733
+ })),
706
734
  handleSave,
707
735
  handleManualEndTimeChange,
708
736
  handleChangeTimeChange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.11.686",
3
+ "version": "6.11.687",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -73,8 +73,8 @@
73
73
  "use-sync-external-store": "^1.6.0",
74
74
  "@pisell/pi-payment-sdk": "0.0.3",
75
75
  "@pisell/utils": "3.0.7",
76
- "@pisell/icon": "0.0.11",
77
76
  "@pisell/materials": "6.11.266",
77
+ "@pisell/icon": "0.0.11",
78
78
  "@pisell/date-picker": "3.0.12"
79
79
  },
80
80
  "peerDependencies": {