@pisell/private-materials 6.12.405 → 6.12.407
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/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/meta.js +1 -1
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +2 -2
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +2 -2
- package/es/components/appointmentBooking/components/Cart/ContinueButton/index.js +13 -6
- package/es/components/appointmentBooking/components/Cart/ContinueButton/index.less +6 -0
- package/es/components/appointmentBooking/components/Date/index.js +103 -35
- package/es/components/appointmentBooking/components/Services/index.js +123 -58
- package/es/components/appointmentBooking/context.js +72 -10
- package/es/components/appointmentBooking/hooks.js +227 -172
- package/es/components/appointmentBooking/index.js +3 -2
- package/es/components/appointmentBooking/locales.js +10 -0
- package/es/components/bigSale/components/BookingFloatingPanel/useBookingPanelController.js +0 -1
- package/es/components/bigSale/components/ProductList/index.js +0 -1
- package/es/components/bigSale/components/TimeBar/index.js +0 -1
- package/es/components/bigSale/dialog.js +0 -1
- package/es/components/bigSale/hooks/useBigSaleContext.js +0 -1
- package/es/components/bigSale/hooks/useSelectFloorMapResourceForBigSale.js +0 -1
- package/es/components/bigSale/index.js +0 -1
- package/es/components/bigSale/templates/Kiosk/index.js +0 -1
- package/es/components/sharedSecondaryBigSale/SharedSecondaryBigSaleReceiver.js +0 -1
- package/es/components/vendingMachine/README.md +1 -1
- package/es/components/vendingMachine/customer.less +2 -20
- package/es/components/vendingMachine/dispense.less +1 -3
- package/es/components/vendingMachine/redeem.less +1 -1
- package/es/components/vendingMachine/vendingBottomBar.less +2 -2
- package/es/components/venueBookingSales/checkout/useVenueBookingCheckout.js +0 -1
- package/es/index.js +0 -2
- package/es/plus/multiCurrencySettlement/index.js +1 -1
- package/es/plus/pisellReservation/data/bookingToReservationTables.js +1 -1
- package/es/plus/pisellReservation/floorMap/floorPlanApi.js +1 -1
- package/es/plus/pisellReservation/floorMap/reservationMock.js +1 -1
- package/es/plus/saleDetail/Base.js +0 -1
- package/es/plus/saleDetail/components/Client/hooks/useClientSelectorProps.js +0 -1
- package/es/plus/saleDetail/components/DetailActions/PrintAction.js +0 -1
- package/es/plus/saleDetail/components/DetailActions/index.js +0 -1
- package/es/plus/saleDetail/components/SummaryFinancialSections/index.js +0 -1
- package/es/plus/saleDetail/index.js +0 -1
- package/es/plus/saleDetail/tmpl/B/components/Dish/index.js +0 -1
- package/es/plus/saleDetail/tmpl/B/index.js +0 -1
- package/es/plus/salesSdk/utils/addProductWithFlowDebounced.js +1 -1
- package/es/plus/salesSdk/utils/bookingDate.js +1 -1
- package/es/plus/salesSdk/utils/enrichCartLineHolderDisplay.js +1 -1
- package/es/private-materials/lowcode/authmodal/meta.d.ts +1 -0
- package/es/pro/Login2.0/AuthModal.d.ts +1 -1
- package/es/pro/Login2.0/index.d.ts +2 -2
- package/es/pro/Login2.0/shared/types.d.ts +1 -1
- package/lib/components/appointmentBooking/components/Cart/ContinueButton/index.js +13 -6
- package/lib/components/appointmentBooking/components/Cart/ContinueButton/index.less +6 -0
- package/lib/components/appointmentBooking/components/Date/index.js +102 -34
- package/lib/components/appointmentBooking/components/Services/index.js +122 -57
- package/lib/components/appointmentBooking/context.js +71 -9
- package/lib/components/appointmentBooking/hooks.js +227 -172
- package/lib/components/appointmentBooking/index.js +2 -1
- package/lib/components/appointmentBooking/locales.js +10 -0
- package/lib/components/vendingMachine/README.md +1 -1
- package/lib/components/vendingMachine/customer.less +2 -20
- package/lib/components/vendingMachine/dispense.less +1 -3
- package/lib/components/vendingMachine/redeem.less +1 -1
- package/lib/components/vendingMachine/vendingBottomBar.less +2 -2
- package/package.json +3 -3
- package/es/components/vendingMachine/assets/Bricolage-Grotesque-OFL.txt +0 -93
- package/es/components/vendingMachine/assets/DM-Sans-OFL.txt +0 -93
- package/es/components/vendingMachine/assets/bricolage-grotesque-latin.woff2 +0 -0
- package/es/components/vendingMachine/assets/dm-sans-latin.woff2 +0 -0
- package/es/plus/pisellReservation/index.js +0 -17
- package/es/plus/salesSdk/index.js +0 -54
- package/lib/components/vendingMachine/assets/Bricolage-Grotesque-OFL.txt +0 -93
- package/lib/components/vendingMachine/assets/DM-Sans-OFL.txt +0 -93
- package/lib/components/vendingMachine/assets/bricolage-grotesque-latin.woff2 +0 -0
- package/lib/components/vendingMachine/assets/dm-sans-latin.woff2 +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import useEngineContext from "../../../../../hooks/useEngineContext.js";
|
|
2
2
|
import { _asyncToGenerator } from "../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
|
|
3
|
+
import useInitLocalesOnce from "../../../../../hooks/useInitLocalesOnce.js";
|
|
4
|
+
import locales_default from "../../../locales.js";
|
|
3
5
|
import { formatAppointmentCartSummary, sendAppointmentBookingLog } from "../../../utils.js";
|
|
4
6
|
import { useAppointmentBookingAccount, useAppointmentBookingLogin, useAppointmentBookingSetting } from "../../../hooks.js";
|
|
5
7
|
import { useAppointmentBookingContext } from "../../../context.js";
|
|
@@ -10,11 +12,13 @@ import { Button } from "@pisell/materials";
|
|
|
10
12
|
import "./index.less";
|
|
11
13
|
//#region src/components/appointmentBooking/components/Cart/ContinueButton/index.tsx
|
|
12
14
|
const ContinueButton = ({ onNext }) => {
|
|
13
|
-
var _appointmentBooking$s2, _currentStep$step2;
|
|
14
|
-
const
|
|
15
|
+
var _context$engine, _appointmentBooking$s2, _currentStep$step2;
|
|
16
|
+
const context = useEngineContext();
|
|
17
|
+
useInitLocalesOnce(locales_default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
|
|
18
|
+
const utils = context.appHelper.utils || {};
|
|
15
19
|
const { isLogin, openLoginModal } = useAppointmentBookingLogin();
|
|
16
20
|
const { accountLists, getHolders, checkAccount } = useAppointmentBookingAccount();
|
|
17
|
-
const { currentStep, carts, appointmentBooking, setCarts, loading, setIsErrorHolder, isLastStep } = useAppointmentBookingContext();
|
|
21
|
+
const { currentStep, carts, appointmentBooking, setCarts, loading, availabilityError, setIsErrorHolder, isLastStep } = useAppointmentBookingContext();
|
|
18
22
|
const { isFormSubject, isRetailTemplate } = useAppointmentBookingSetting();
|
|
19
23
|
const lastButtonStatusRef = useRef();
|
|
20
24
|
useMemo(() => {
|
|
@@ -79,13 +83,16 @@ const ContinueButton = ({ onNext }) => {
|
|
|
79
83
|
if (isLastStep) return locales.getText("pisell2.event.checkout");
|
|
80
84
|
else return locales.getText("pisell2.event.close.continue");
|
|
81
85
|
}, [isLastStep]);
|
|
82
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
83
|
-
|
|
86
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, availabilityError && /* @__PURE__ */ React.createElement("div", {
|
|
87
|
+
role: "alert",
|
|
88
|
+
className: "appointment-continue-error"
|
|
89
|
+
}, locales.getText("pisell2.appointment.availability.load.failed")), /* @__PURE__ */ React.createElement(Button, {
|
|
90
|
+
disabled: !(carts === null || carts === void 0 ? void 0 : carts.length) || loading,
|
|
84
91
|
size: "large",
|
|
85
92
|
type: "primary",
|
|
86
93
|
onClick: () => handleContinue(),
|
|
87
94
|
loading
|
|
88
|
-
}, continueText));
|
|
95
|
+
}, availabilityError ? locales.getText("pisell2.appointment.retry") : continueText));
|
|
89
96
|
};
|
|
90
97
|
//#endregion
|
|
91
98
|
export { ContinueButton as default };
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import useEngineContext from "../../../../hooks/useEngineContext.js";
|
|
2
2
|
import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
|
|
3
3
|
import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
|
|
4
|
+
import useInitLocalesOnce from "../../../../hooks/useInitLocalesOnce.js";
|
|
5
|
+
import locales_default from "../../locales.js";
|
|
4
6
|
import { Toast } from "../../utils.js";
|
|
5
7
|
import { useAppointmentBookingSetting, useAppointmentBookingStep } from "../../hooks.js";
|
|
6
8
|
import { useAppointmentBookingContext } from "../../context.js";
|
|
7
9
|
import { localeTypes } from "./state.js";
|
|
8
10
|
import dayjs from "dayjs";
|
|
9
11
|
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
10
|
-
import { Skeleton } from "antd";
|
|
12
|
+
import { Button, Skeleton } from "antd";
|
|
11
13
|
import { isMobile, locales } from "@pisell/utils";
|
|
12
14
|
import classNames from "classnames";
|
|
13
15
|
import { CaretLeftOutlined, CaretRightOutlined } from "@ant-design/icons";
|
|
@@ -16,9 +18,13 @@ import "./index.less";
|
|
|
16
18
|
//#region src/components/appointmentBooking/components/Date/index.tsx
|
|
17
19
|
dayjs.extend(isSameOrBefore);
|
|
18
20
|
const Date = forwardRef((props, ref) => {
|
|
19
|
-
var _context$
|
|
21
|
+
var _context$engine, _context$engine3, _Dayjs$locale;
|
|
20
22
|
const isFetchingDates = useRef(false);
|
|
21
|
-
const
|
|
23
|
+
const requestIdRef = useRef(0);
|
|
24
|
+
const mountedRef = useRef(false);
|
|
25
|
+
const readyMonthRef = useRef("");
|
|
26
|
+
const loadStateRef = useRef("loading");
|
|
27
|
+
const [loadState, setLoadState] = useState("loading");
|
|
22
28
|
const [currentDate, setCurrentDate] = useState();
|
|
23
29
|
const [dateMonthList, setDateMonthList] = useState([]);
|
|
24
30
|
const [currentMonth, setCurrentMonth] = useState();
|
|
@@ -26,6 +32,11 @@ const Date = forwardRef((props, ref) => {
|
|
|
26
32
|
const { isDateSelectedFirst, customPageId, channel } = useAppointmentBookingSetting();
|
|
27
33
|
const { nextStep } = useAppointmentBookingStep();
|
|
28
34
|
const context = useEngineContext();
|
|
35
|
+
useInitLocalesOnce(locales_default, context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale);
|
|
36
|
+
const updateLoadState = (state) => {
|
|
37
|
+
loadStateRef.current = state;
|
|
38
|
+
setLoadState(state);
|
|
39
|
+
};
|
|
29
40
|
useImperativeHandle(ref, () => ({ next: handleNext }));
|
|
30
41
|
/**
|
|
31
42
|
* @title: 处理进入下一步的逻辑
|
|
@@ -36,9 +47,13 @@ const Date = forwardRef((props, ref) => {
|
|
|
36
47
|
*/
|
|
37
48
|
const handleNext = function() {
|
|
38
49
|
var _ref = _asyncToGenerator(function* () {
|
|
50
|
+
var _data$;
|
|
51
|
+
if (loadStateRef.current !== "success" || readyMonthRef.current !== (currentMonth === null || currentMonth === void 0 ? void 0 : currentMonth.format("YYYY-MM"))) return;
|
|
52
|
+
const requestId = requestIdRef.current;
|
|
39
53
|
const data = yield appointmentBooking.getDateRange();
|
|
40
|
-
if (!
|
|
41
|
-
|
|
54
|
+
if (!mountedRef.current || requestId !== requestIdRef.current) return;
|
|
55
|
+
if (!(data === null || data === void 0 ? void 0 : data.length) || !currentDate || ((_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.date) !== currentDate) return Toast(locales.getText("pisell2.appointment.unselect.date"));
|
|
56
|
+
yield nextStep();
|
|
42
57
|
});
|
|
43
58
|
return function handleNext() {
|
|
44
59
|
return _ref.apply(this, arguments);
|
|
@@ -56,21 +71,33 @@ const Date = forwardRef((props, ref) => {
|
|
|
56
71
|
const startingColumn = 0;
|
|
57
72
|
const columns = Array.from({ length: 7 }, (_, index) => (index + 7 - startingColumn) % 7);
|
|
58
73
|
useEffect(() => {
|
|
74
|
+
mountedRef.current = true;
|
|
75
|
+
const requestId = ++requestIdRef.current;
|
|
59
76
|
(function() {
|
|
60
77
|
var _ref2 = _asyncToGenerator(function* () {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
try {
|
|
79
|
+
var _data$2;
|
|
80
|
+
const data = yield appointmentBooking.getDateRange();
|
|
81
|
+
if (!mountedRef.current || requestId !== requestIdRef.current) return;
|
|
82
|
+
const selectedMonth = dayjs(data === null || data === void 0 || (_data$2 = data[0]) === null || _data$2 === void 0 ? void 0 : _data$2.date);
|
|
83
|
+
setCurrentMonth(selectedMonth.isValid() ? selectedMonth : dayjs());
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (mountedRef.current && requestId === requestIdRef.current) updateLoadState("error");
|
|
86
|
+
}
|
|
64
87
|
});
|
|
65
88
|
return function getCurrentMonthData() {
|
|
66
89
|
return _ref2.apply(this, arguments);
|
|
67
90
|
};
|
|
68
91
|
})()();
|
|
92
|
+
return () => {
|
|
93
|
+
mountedRef.current = false;
|
|
94
|
+
requestIdRef.current += 1;
|
|
95
|
+
};
|
|
69
96
|
}, []);
|
|
70
97
|
const locale = useMemo(() => {
|
|
71
|
-
var _context$
|
|
72
|
-
return localeTypes[context === null || context === void 0 || (_context$
|
|
73
|
-
}, [context === null || context === void 0 || (_context$
|
|
98
|
+
var _context$engine2;
|
|
99
|
+
return localeTypes[context === null || context === void 0 || (_context$engine2 = context.engine) === null || _context$engine2 === void 0 || (_context$engine2 = _context$engine2.props) === null || _context$engine2 === void 0 ? void 0 : _context$engine2.locale] || "en";
|
|
100
|
+
}, [context === null || context === void 0 || (_context$engine3 = context.engine) === null || _context$engine3 === void 0 || (_context$engine3 = _context$engine3.props) === null || _context$engine3 === void 0 ? void 0 : _context$engine3.locale]);
|
|
74
101
|
/**
|
|
75
102
|
* @title: 获取当前月日期
|
|
76
103
|
* @description:
|
|
@@ -115,7 +142,6 @@ const Date = forwardRef((props, ref) => {
|
|
|
115
142
|
*/
|
|
116
143
|
const getDateData = function() {
|
|
117
144
|
var _ref3 = _asyncToGenerator(function* (params) {
|
|
118
|
-
console.log(isDateSelectedFirst, customPageId, params, channel, "wh7868");
|
|
119
145
|
if (isDateSelectedFirst) return appointmentBooking.loadScheduleAvailableDate(_objectSpread2(_objectSpread2({}, params), {}, {
|
|
120
146
|
custom_page_id: customPageId,
|
|
121
147
|
channel
|
|
@@ -127,24 +153,40 @@ const Date = forwardRef((props, ref) => {
|
|
|
127
153
|
};
|
|
128
154
|
}();
|
|
129
155
|
const getDates = function() {
|
|
130
|
-
var _ref4 = _asyncToGenerator(function* (date) {
|
|
156
|
+
var _ref4 = _asyncToGenerator(function* (date, retryAborted = true) {
|
|
157
|
+
const requestId = ++requestIdRef.current;
|
|
158
|
+
const isCurrentRequest = () => mountedRef.current && requestId === requestIdRef.current;
|
|
159
|
+
readyMonthRef.current = "";
|
|
160
|
+
updateLoadState("loading");
|
|
161
|
+
setCurrentDate(void 0);
|
|
131
162
|
try {
|
|
132
163
|
const data = yield getDateData({
|
|
133
164
|
startDate: dayjs(date).startOf("month").format("YYYY-MM-DD"),
|
|
134
|
-
endDate: dayjs(date).endOf("month").format("YYYY-MM-DD")
|
|
165
|
+
endDate: dayjs(date).endOf("month").format("YYYY-MM-DD"),
|
|
166
|
+
assertCurrent: () => {
|
|
167
|
+
if (!isCurrentRequest()) {
|
|
168
|
+
const error = /* @__PURE__ */ new Error("Calendar request superseded");
|
|
169
|
+
error.name = "AbortError";
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
135
173
|
});
|
|
136
|
-
|
|
174
|
+
if (!isCurrentRequest()) return;
|
|
175
|
+
if (!Array.isArray(data)) throw new Error("Invalid availability response");
|
|
176
|
+
const firstAvailableDate = data.find((d) => d.status === "available");
|
|
137
177
|
if (!firstAvailableDate && !isFetchingDates.current) {
|
|
138
178
|
isFetchingDates.current = true;
|
|
139
179
|
setCurrentMonth(dayjs(date).add(1, "month"));
|
|
140
|
-
setLoading(true);
|
|
141
180
|
return;
|
|
142
181
|
}
|
|
143
182
|
const selected = yield appointmentBooking.getDateRange();
|
|
144
|
-
|
|
183
|
+
if (!isCurrentRequest()) return;
|
|
145
184
|
if ((selected === null || selected === void 0 ? void 0 : selected.length) > 0) {
|
|
146
|
-
|
|
147
|
-
|
|
185
|
+
const selectedDay = data.find((day) => {
|
|
186
|
+
var _selected$;
|
|
187
|
+
return day.date === ((_selected$ = selected[0]) === null || _selected$ === void 0 ? void 0 : _selected$.date);
|
|
188
|
+
});
|
|
189
|
+
setCurrentDate(selectedDay && selectedDay.status !== "unavailable" ? selectedDay.date : void 0);
|
|
148
190
|
} else if (!isDateSelectedFirst) {
|
|
149
191
|
if (date.format("YYYY-MM") === dayjs().format("YYYY-MM") || isFetchingDates.current) {
|
|
150
192
|
if (firstAvailableDate) {
|
|
@@ -153,16 +195,21 @@ const Date = forwardRef((props, ref) => {
|
|
|
153
195
|
}
|
|
154
196
|
}
|
|
155
197
|
}
|
|
156
|
-
|
|
198
|
+
setDateMonthList(getMonthData(date.format("YYYY-MM")).map((day) => {
|
|
157
199
|
const matchedDay = data.find((d) => d.date === day.date);
|
|
158
200
|
if (matchedDay) return _objectSpread2(_objectSpread2(_objectSpread2({}, day), matchedDay), {}, { disabled: matchedDay.status === "unavailable" });
|
|
159
|
-
return day;
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
|
|
201
|
+
return _objectSpread2(_objectSpread2({}, day), {}, { disabled: true });
|
|
202
|
+
}));
|
|
203
|
+
readyMonthRef.current = date.format("YYYY-MM");
|
|
204
|
+
updateLoadState("success");
|
|
163
205
|
} catch (error) {
|
|
164
|
-
|
|
165
|
-
|
|
206
|
+
if (!isCurrentRequest()) return;
|
|
207
|
+
if ((error === null || error === void 0 ? void 0 : error.name) === "AbortError") {
|
|
208
|
+
if (retryAborted) return getDates(date, false);
|
|
209
|
+
updateLoadState("idle");
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
updateLoadState("error");
|
|
166
213
|
}
|
|
167
214
|
});
|
|
168
215
|
return function getDates(_x2) {
|
|
@@ -172,7 +219,27 @@ const Date = forwardRef((props, ref) => {
|
|
|
172
219
|
useEffect(() => {
|
|
173
220
|
if (!currentMonth) return;
|
|
174
221
|
getDates(currentMonth);
|
|
175
|
-
|
|
222
|
+
return () => {
|
|
223
|
+
requestIdRef.current += 1;
|
|
224
|
+
};
|
|
225
|
+
}, [
|
|
226
|
+
currentMonth,
|
|
227
|
+
isDateSelectedFirst,
|
|
228
|
+
customPageId,
|
|
229
|
+
channel,
|
|
230
|
+
appointmentBooking
|
|
231
|
+
]);
|
|
232
|
+
const changeMonth = (month) => {
|
|
233
|
+
requestIdRef.current += 1;
|
|
234
|
+
readyMonthRef.current = "";
|
|
235
|
+
updateLoadState("loading");
|
|
236
|
+
setCurrentMonth(month);
|
|
237
|
+
};
|
|
238
|
+
const retry = () => {
|
|
239
|
+
if (loadStateRef.current === "loading") return;
|
|
240
|
+
if (currentMonth) getDates(currentMonth);
|
|
241
|
+
else changeMonth(dayjs());
|
|
242
|
+
};
|
|
176
243
|
/**
|
|
177
244
|
* @title: 切换上个月
|
|
178
245
|
* @description:
|
|
@@ -182,7 +249,7 @@ const Date = forwardRef((props, ref) => {
|
|
|
182
249
|
* @Date: 2024-02-01 19:15
|
|
183
250
|
*/
|
|
184
251
|
const lastMonth = () => {
|
|
185
|
-
|
|
252
|
+
changeMonth(dayjs(currentMonth === null || currentMonth === void 0 ? void 0 : currentMonth.format("YYYY-MM")).subtract(1, "month"));
|
|
186
253
|
};
|
|
187
254
|
/**
|
|
188
255
|
* @title: 切换下个月
|
|
@@ -193,8 +260,7 @@ const Date = forwardRef((props, ref) => {
|
|
|
193
260
|
* @Date: 2024-02-01 19:15
|
|
194
261
|
*/
|
|
195
262
|
const nextMonth = () => {
|
|
196
|
-
|
|
197
|
-
setLoading(true);
|
|
263
|
+
changeMonth(dayjs(currentMonth === null || currentMonth === void 0 ? void 0 : currentMonth.format("YYYY-MM")).add(1, "month"));
|
|
198
264
|
};
|
|
199
265
|
/**
|
|
200
266
|
* @title: 点击某一天日期
|
|
@@ -206,12 +272,15 @@ const Date = forwardRef((props, ref) => {
|
|
|
206
272
|
* @Date: 2025-04-24 18:36
|
|
207
273
|
*/
|
|
208
274
|
const handleClick = (day, date) => {
|
|
209
|
-
if (day === null || day === void 0 ? void 0 : day.disabled) return;
|
|
275
|
+
if ((day === null || day === void 0 ? void 0 : day.disabled) || loadStateRef.current !== "success") return;
|
|
210
276
|
setCurrentDate(date);
|
|
211
277
|
appointmentBooking.setDateRange([day]);
|
|
212
|
-
if (isDateSelectedFirst)
|
|
278
|
+
if (isDateSelectedFirst) nextStep();
|
|
213
279
|
};
|
|
214
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
280
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
281
|
+
className: `calendar-date-box ${isMobile() ? "calendar-date-mobile-box" : ""}`,
|
|
282
|
+
"aria-busy": loadState === "loading"
|
|
283
|
+
}, loadState === "error" || loadState === "idle" ? /* @__PURE__ */ React.createElement("div", null, loadState === "error" && /* @__PURE__ */ React.createElement("p", { role: "alert" }, locales.getText("pisell2.appointment.availability.load.failed")), /* @__PURE__ */ React.createElement(Button, { onClick: retry }, locales.getText("pisell2.appointment.retry"))) : loadState === "loading" || !currentMonth ? /* @__PURE__ */ React.createElement(Skeleton, {
|
|
215
284
|
loading: true,
|
|
216
285
|
active: true,
|
|
217
286
|
style: { paddingTop: "16px" }
|
|
@@ -235,8 +304,7 @@ const Date = forwardRef((props, ref) => {
|
|
|
235
304
|
className: classNames("calendar-days-items", {
|
|
236
305
|
["disabledDate"]: day === null || day === void 0 ? void 0 : day.disabled,
|
|
237
306
|
["selectDate"]: currentDate === date,
|
|
238
|
-
["other-month-days"]: !isCurrentMonth
|
|
239
|
-
["loading-item"]: loading
|
|
307
|
+
["other-month-days"]: !isCurrentMonth
|
|
240
308
|
}),
|
|
241
309
|
onClick: () => handleClick(day, date)
|
|
242
310
|
}, isCurrentMonth && /* @__PURE__ */ React.createElement("div", { className: classNames("day-text") }, dayjs(day.date).format("D")));
|
|
@@ -1,42 +1,58 @@
|
|
|
1
1
|
import useEngineContext from "../../../../hooks/useEngineContext.js";
|
|
2
2
|
import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
|
|
3
3
|
import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
|
|
4
|
+
import useInitLocalesOnce from "../../../../hooks/useInitLocalesOnce.js";
|
|
4
5
|
import ProductSelect from "../../../../plus/productSelect/index.js";
|
|
6
|
+
import locales_default from "../../locales.js";
|
|
5
7
|
import { Toast } from "../../utils.js";
|
|
6
8
|
import { useAppointmentBooking, useAppointmentBookingProduct, useAppointmentBookingSetting, useAppointmentBookingStep } from "../../hooks.js";
|
|
7
9
|
import { useAppointmentBookingContext } from "../../context.js";
|
|
8
10
|
import dayjs from "dayjs";
|
|
9
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from "react";
|
|
11
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
12
|
+
import { Alert, Button } from "antd";
|
|
10
13
|
import { isMobile, locales } from "@pisell/utils";
|
|
11
14
|
import "./index.less";
|
|
12
15
|
//#region src/components/appointmentBooking/components/Services/index.tsx
|
|
13
16
|
const Services = forwardRef((props, ref) => {
|
|
17
|
+
var _context$engine;
|
|
14
18
|
const context = useEngineContext();
|
|
19
|
+
useInitLocalesOnce(locales_default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
|
|
15
20
|
const { utils } = context.appHelper || {};
|
|
16
21
|
const appointmentBooking = useAppointmentBooking();
|
|
17
22
|
const { isDateSelectedFirst, isRetailTemplate } = useAppointmentBookingSetting();
|
|
18
23
|
const { getProducts, checkProductType } = useAppointmentBookingProduct();
|
|
19
24
|
const { removeStep, nextStep } = useAppointmentBookingStep();
|
|
20
|
-
const {
|
|
25
|
+
const { setLoading, carts, setAvailabilityError, bookingPreparationRef, runBookingPreparation, stepTransitionRef } = useAppointmentBookingContext();
|
|
21
26
|
const [products, setProducts] = useState(null);
|
|
22
27
|
const [productLoading, setProductLoading] = useState(false);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
setLoading(false);
|
|
28
|
-
}, 500);
|
|
29
|
-
} }));
|
|
28
|
+
const [productError, setProductError] = useState(false);
|
|
29
|
+
const retryProductRef = useRef(null);
|
|
30
|
+
const openingRequestRef = useRef(0);
|
|
31
|
+
const mountedRef = useRef(true);
|
|
30
32
|
useEffect(() => {
|
|
33
|
+
mountedRef.current = true;
|
|
34
|
+
return () => {
|
|
35
|
+
mountedRef.current = false;
|
|
36
|
+
openingRequestRef.current += 1;
|
|
37
|
+
};
|
|
38
|
+
}, [appointmentBooking]);
|
|
39
|
+
useImperativeHandle(ref, () => ({ next: nextStep }));
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
let active = true;
|
|
31
42
|
setProductLoading(true);
|
|
32
43
|
getProducts().then((res) => {
|
|
44
|
+
if (!active) return;
|
|
33
45
|
setProducts(res || []);
|
|
34
46
|
setProductLoading(false);
|
|
35
47
|
}).catch(() => {
|
|
48
|
+
if (!active) return;
|
|
36
49
|
setProducts([]);
|
|
37
50
|
setProductLoading(false);
|
|
38
51
|
});
|
|
39
|
-
|
|
52
|
+
return () => {
|
|
53
|
+
active = false;
|
|
54
|
+
};
|
|
55
|
+
}, [isDateSelectedFirst, appointmentBooking]);
|
|
40
56
|
/**
|
|
41
57
|
* @description: 是否显示商品详情页面的步进器
|
|
42
58
|
* @param {*} useMemo
|
|
@@ -47,15 +63,36 @@ const Services = forwardRef((props, ref) => {
|
|
|
47
63
|
return productModuleParams === null || productModuleParams === void 0 ? void 0 : productModuleParams.isShowProductDetailStepper;
|
|
48
64
|
}, [appointmentBooking === null || appointmentBooking === void 0 ? void 0 : appointmentBooking.otherParams]);
|
|
49
65
|
const handleSelectProduct = function() {
|
|
50
|
-
var
|
|
66
|
+
var _ref3 = _asyncToGenerator(function* (item, clickType) {
|
|
67
|
+
const requestId = ++openingRequestRef.current;
|
|
68
|
+
setProductError(false);
|
|
69
|
+
setProductLoading(true);
|
|
51
70
|
let type = "";
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
try {
|
|
72
|
+
yield runBookingPreparation();
|
|
73
|
+
if (!mountedRef.current || requestId !== openingRequestRef.current) return;
|
|
74
|
+
if (!isRetailTemplate) {
|
|
75
|
+
yield appointmentBooking.openProductDetail(item.id);
|
|
76
|
+
type = yield checkProductType(item.id);
|
|
77
|
+
}
|
|
78
|
+
if (!mountedRef.current || requestId !== openingRequestRef.current) return;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (mountedRef.current && requestId === openingRequestRef.current && (error === null || error === void 0 ? void 0 : error.name) !== "AbortError") {
|
|
81
|
+
appointmentBooking.closeProductDetail();
|
|
82
|
+
retryProductRef.current = () => {
|
|
83
|
+
handleSelectProduct(item, clickType);
|
|
84
|
+
};
|
|
85
|
+
setProductError(true);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
} finally {
|
|
89
|
+
if (mountedRef.current && requestId === openingRequestRef.current) setProductLoading(false);
|
|
55
90
|
}
|
|
91
|
+
let added = false;
|
|
56
92
|
utils === null || utils === void 0 || utils.action({
|
|
57
93
|
type: "pisell1.productDetail",
|
|
58
94
|
data: {
|
|
95
|
+
bookingRead: !isRetailTemplate,
|
|
59
96
|
detail: _objectSpread2(_objectSpread2({}, item), {}, { open_deposit: 1 }),
|
|
60
97
|
setting: {
|
|
61
98
|
can_input: true,
|
|
@@ -64,75 +101,96 @@ const Services = forwardRef((props, ref) => {
|
|
|
64
101
|
}
|
|
65
102
|
},
|
|
66
103
|
callback: function() {
|
|
67
|
-
var
|
|
104
|
+
var _ref2 = _asyncToGenerator(function* (data) {
|
|
105
|
+
if (added || !mountedRef.current || requestId !== openingRequestRef.current) return;
|
|
68
106
|
if (data.isCancel) {
|
|
107
|
+
openingRequestRef.current += 1;
|
|
69
108
|
appointmentBooking.closeProductDetail();
|
|
70
109
|
return;
|
|
71
110
|
}
|
|
72
111
|
const product = _objectSpread2(_objectSpread2({}, data), {}, { options: (data === null || data === void 0 ? void 0 : data.option) || [] });
|
|
73
112
|
delete product.option;
|
|
74
|
-
if (isRetailTemplate) {
|
|
75
|
-
if (data === null || data === void 0 ? void 0 : data.isCancel) return;
|
|
76
|
-
const res = appointmentBooking.storeProduct(product);
|
|
77
|
-
if (!res.success && res.errorCode === "not_enough_stock") return Toast(locales.getText("pisell2.appointment.unuse.stock"));
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
113
|
const session = data === null || data === void 0 ? void 0 : data.session;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
114
|
+
let result;
|
|
115
|
+
if (isRetailTemplate) result = appointmentBooking.storeProduct(product);
|
|
116
|
+
else if (session) {
|
|
117
|
+
const startDate = dayjs(session.start_at).format("YYYY-MM-DD");
|
|
118
|
+
const endDate = dayjs(session.end_at).format("YYYY-MM-DD");
|
|
119
|
+
result = appointmentBooking.addProductToCart({
|
|
85
120
|
product: _objectSpread2({}, product),
|
|
86
121
|
date: {
|
|
87
|
-
startTime: `${startDate} ${session
|
|
88
|
-
endTime: `${endDate} ${session
|
|
122
|
+
startTime: `${startDate} ${session.start_time}`,
|
|
123
|
+
endTime: `${endDate} ${session.end_time}`
|
|
89
124
|
}
|
|
90
125
|
});
|
|
91
|
-
if (!res.success && res.errorCode === "not_enough_stock") return Toast(locales.getText("pisell2.appointment.unuse.stock"));
|
|
92
|
-
appointmentBooking.closeProductDetail();
|
|
93
|
-
yield appointmentBooking.getAvailableDate({
|
|
94
|
-
startDate,
|
|
95
|
-
endDate
|
|
96
|
-
});
|
|
97
126
|
} else {
|
|
98
127
|
var _data$origin;
|
|
99
|
-
if (!((data === null || data === void 0 || (_data$origin = data.origin) === null || _data$origin === void 0 || (_data$origin = _data$origin.product_resource) === null || _data$origin === void 0 ? void 0 : _data$origin.resources) || []).
|
|
100
|
-
|
|
101
|
-
if (!res.success && res.errorCode === "not_enough_stock") return Toast(locales.getText("pisell2.appointment.unuse.stock"));
|
|
102
|
-
if (type === "duration") yield appointmentBooking.getAvailableDate();
|
|
128
|
+
if (!((data === null || data === void 0 || (_data$origin = data.origin) === null || _data$origin === void 0 || (_data$origin = _data$origin.product_resource) === null || _data$origin === void 0 ? void 0 : _data$origin.resources) || []).some((resource) => resource.status === 1) && !appointmentBooking.isTargetNormalProduct(data === null || data === void 0 ? void 0 : data.origin)) return Toast(locales.getText("pisell2.appointment.no.available.service"));
|
|
129
|
+
result = appointmentBooking.storeProduct(product);
|
|
103
130
|
}
|
|
131
|
+
if (!(result === null || result === void 0 ? void 0 : result.success)) return Toast(locales.getText((result === null || result === void 0 ? void 0 : result.errorCode) === "not_enough_stock" ? "pisell2.appointment.unuse.stock" : "pisell2.appointment.no.available.service"));
|
|
132
|
+
added = true;
|
|
104
133
|
appointmentBooking.closeProductDetail();
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
134
|
+
if (isRetailTemplate) return;
|
|
135
|
+
const cartIdentity = () => JSON.stringify(appointmentBooking.getCart().map((cart) => cart._id).sort());
|
|
136
|
+
const addedCartIdentity = cartIdentity();
|
|
137
|
+
const job = {
|
|
138
|
+
module: appointmentBooking,
|
|
139
|
+
pending: null,
|
|
140
|
+
run: function() {
|
|
141
|
+
var _ref = _asyncToGenerator(function* () {
|
|
142
|
+
if (cartIdentity() !== addedCartIdentity) return;
|
|
143
|
+
yield appointmentBooking.prepareResourcesForCurrentSelection();
|
|
144
|
+
if (cartIdentity() !== addedCartIdentity) return;
|
|
145
|
+
if (bookingPreparationRef.current !== job) {
|
|
146
|
+
const error = /* @__PURE__ */ new Error("Booking preparation superseded");
|
|
147
|
+
error.name = "AbortError";
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
if (isDateSelectedFirst) if (type === "duration" || appointmentBooking.isCartHasDurationProduct()) {
|
|
151
|
+
if (appointmentBooking.getStepList().some((step) => step.key === "select-resource")) {
|
|
152
|
+
var _appointmentBooking$g;
|
|
153
|
+
appointmentBooking.addStep({
|
|
154
|
+
index: ((_appointmentBooking$g = appointmentBooking.getCurrentStep()) === null || _appointmentBooking$g === void 0 ? void 0 : _appointmentBooking$g.index) + 2,
|
|
155
|
+
key: "select-time",
|
|
156
|
+
description: locales.getText("pisell2.appointment.select.time")
|
|
157
|
+
}, "select-resource");
|
|
158
|
+
}
|
|
159
|
+
} else removeStep("select-time");
|
|
160
|
+
else if (type === "session") {
|
|
161
|
+
removeStep("select-date");
|
|
162
|
+
removeStep("select-time");
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return function run() {
|
|
166
|
+
return _ref.apply(this, arguments);
|
|
167
|
+
};
|
|
168
|
+
}()
|
|
169
|
+
};
|
|
170
|
+
bookingPreparationRef.current = job;
|
|
171
|
+
setAvailabilityError(false);
|
|
172
|
+
setLoading(true);
|
|
173
|
+
try {
|
|
174
|
+
yield runBookingPreparation();
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (mountedRef.current && (error === null || error === void 0 ? void 0 : error.name) !== "AbortError") setAvailabilityError(true);
|
|
177
|
+
} finally {
|
|
178
|
+
if (mountedRef.current && !stepTransitionRef.current.pending) setLoading(false);
|
|
121
179
|
}
|
|
122
180
|
});
|
|
123
181
|
return function callback(_x) {
|
|
124
|
-
return
|
|
182
|
+
return _ref2.apply(this, arguments);
|
|
125
183
|
};
|
|
126
184
|
}()
|
|
127
185
|
});
|
|
128
186
|
});
|
|
129
187
|
return function handleSelectProduct(_x2, _x3) {
|
|
130
|
-
return
|
|
188
|
+
return _ref3.apply(this, arguments);
|
|
131
189
|
};
|
|
132
190
|
}();
|
|
133
191
|
const productListSetting = useMemo(() => {
|
|
134
|
-
var _context$
|
|
135
|
-
const { customPageData } = ((_context$
|
|
192
|
+
var _context$engine2;
|
|
193
|
+
const { customPageData } = ((_context$engine2 = context.engine) === null || _context$engine2 === void 0 ? void 0 : _context$engine2.props) || {};
|
|
136
194
|
let productListBlock;
|
|
137
195
|
if (Array.isArray(customPageData === null || customPageData === void 0 ? void 0 : customPageData.block)) productListBlock = customPageData.block.find((b) => "product_list" === b.type);
|
|
138
196
|
return (productListBlock === null || productListBlock === void 0 ? void 0 : productListBlock.setting) || {};
|
|
@@ -141,7 +199,14 @@ const Services = forwardRef((props, ref) => {
|
|
|
141
199
|
if (typeof isMobile === "function") return isMobile();
|
|
142
200
|
return isMobile;
|
|
143
201
|
}, [isMobile]);
|
|
144
|
-
return /* @__PURE__ */ React.createElement("div", { className: "appointment-service-wrap" }, /* @__PURE__ */ React.createElement(
|
|
202
|
+
return /* @__PURE__ */ React.createElement("div", { className: "appointment-service-wrap" }, productError && /* @__PURE__ */ React.createElement(Alert, {
|
|
203
|
+
type: "error",
|
|
204
|
+
message: locales.getText("pisell2.appointment.availability.load.failed"),
|
|
205
|
+
action: /* @__PURE__ */ React.createElement(Button, { onClick: () => {
|
|
206
|
+
var _retryProductRef$curr;
|
|
207
|
+
return (_retryProductRef$curr = retryProductRef.current) === null || _retryProductRef$curr === void 0 ? void 0 : _retryProductRef$curr.call(retryProductRef);
|
|
208
|
+
} }, locales.getText("pisell2.appointment.retry"))
|
|
209
|
+
}), /* @__PURE__ */ React.createElement(ProductSelect, {
|
|
145
210
|
dataSource: products,
|
|
146
211
|
onChange: handleSelectProduct,
|
|
147
212
|
scrollDom: _isMobile ? ".parallel-content-wrap" : ".parallel-booking-wrap",
|