@escapenavigator/hooks 1.10.124 → 1.10.126
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.
|
@@ -63,7 +63,7 @@ const use_players_and_variation_picker_1 = require("../use-players-and-variation
|
|
|
63
63
|
* places with subtle drift. This component is the single source of truth.
|
|
64
64
|
*/
|
|
65
65
|
const PlayersAndVariationPicker = ({ slot, currentTariffId, currentDuration, loadSlotDetails, onVariationChange, onVariationResolved, onDetailsLoaded, players = 0, child = 0, tariff: tariffOverride, currency, minPlayers, maxPlayersLimit, slotDiscount, error, t, onChange, onSave, orderId, }) => {
|
|
66
|
-
var _a, _b
|
|
66
|
+
var _a, _b;
|
|
67
67
|
const { options: pickerOptions, selectedOptionId, selectedVariation, buildVariationChange, selectVariation, details, } = (0, use_players_and_variation_picker_1.usePlayersAndVariationPicker)({
|
|
68
68
|
slot,
|
|
69
69
|
currentTariffId,
|
|
@@ -72,20 +72,32 @@ const PlayersAndVariationPicker = ({ slot, currentTariffId, currentDuration, loa
|
|
|
72
72
|
t: t,
|
|
73
73
|
orderId,
|
|
74
74
|
});
|
|
75
|
+
const onDetailsLoadedRef = (0, react_1.useRef)(onDetailsLoaded);
|
|
76
|
+
const onVariationResolvedRef = (0, react_1.useRef)(onVariationResolved);
|
|
77
|
+
onDetailsLoadedRef.current = onDetailsLoaded;
|
|
78
|
+
onVariationResolvedRef.current = onVariationResolved;
|
|
75
79
|
(0, react_1.useEffect)(() => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
var _a;
|
|
81
|
+
if (!details)
|
|
82
|
+
return;
|
|
83
|
+
(_a = onDetailsLoadedRef.current) === null || _a === void 0 ? void 0 : _a.call(onDetailsLoadedRef, details);
|
|
84
|
+
}, [
|
|
85
|
+
details === null || details === void 0 ? void 0 : details.slotId,
|
|
86
|
+
details === null || details === void 0 ? void 0 : details.isFlex,
|
|
87
|
+
details === null || details === void 0 ? void 0 : details.questroomId,
|
|
88
|
+
details === null || details === void 0 ? void 0 : details.date,
|
|
89
|
+
details === null || details === void 0 ? void 0 : details.start,
|
|
90
|
+
details,
|
|
91
|
+
]);
|
|
79
92
|
const tariff = (0, react_1.useMemo)(() => (tariffOverride || (selectedVariation === null || selectedVariation === void 0 ? void 0 : selectedVariation.tariff) || {}), [tariffOverride, selectedVariation === null || selectedVariation === void 0 ? void 0 : selectedVariation.tariff]);
|
|
80
93
|
(0, react_1.useEffect)(() => {
|
|
81
|
-
|
|
82
|
-
|
|
94
|
+
var _a;
|
|
95
|
+
(_a = onVariationResolvedRef.current) === null || _a === void 0 ? void 0 : _a.call(onVariationResolvedRef, selectedVariation);
|
|
83
96
|
}, [
|
|
84
97
|
selectedVariation === null || selectedVariation === void 0 ? void 0 : selectedVariation.id,
|
|
85
98
|
selectedVariation === null || selectedVariation === void 0 ? void 0 : selectedVariation.tariffId,
|
|
86
99
|
selectedVariation === null || selectedVariation === void 0 ? void 0 : selectedVariation.duration,
|
|
87
100
|
selectedVariation,
|
|
88
|
-
onVariationResolved,
|
|
89
101
|
]);
|
|
90
102
|
const [_players, setPlayers] = (0, react_1.useState)(players);
|
|
91
103
|
const [_children, setChildren] = (0, react_1.useState)(child);
|
|
@@ -111,9 +123,18 @@ const PlayersAndVariationPicker = ({ slot, currentTariffId, currentDuration, loa
|
|
|
111
123
|
})), [tariff]);
|
|
112
124
|
const playersArray = (0, get_prices_1.getPricesPlayersArray)(tariff);
|
|
113
125
|
const maxFromTariff = playersArray.length ? +playersArray[playersArray.length - 1] : 0;
|
|
126
|
+
const minFromTariff = playersArray.length ? +playersArray[0] : 0;
|
|
127
|
+
// Верхняя граница = пересечение тарифа и questroom-капа (с учётом
|
|
128
|
+
// numSeatsAvailable). За пределы тарифа всё равно нельзя — нет цены.
|
|
114
129
|
const effectiveMax = typeof maxPlayersLimit === 'number' && Number.isFinite(maxPlayersLimit)
|
|
115
130
|
? Math.min(maxFromTariff, maxPlayersLimit)
|
|
116
131
|
: maxFromTariff;
|
|
132
|
+
// Нижняя граница — приоритет questroom.playersMin (canonical), но не
|
|
133
|
+
// ниже минимального ключа тарифа (иначе не на что кликать). Если
|
|
134
|
+
// questroom.playersMin шире тарифа — берём тарифный минимум.
|
|
135
|
+
const effectiveMin = typeof minPlayers === 'number' && Number.isFinite(minPlayers)
|
|
136
|
+
? Math.max(minFromTariff, minPlayers)
|
|
137
|
+
: minFromTariff;
|
|
117
138
|
const childrenOptions = (0, react_1.useMemo)(() => {
|
|
118
139
|
if (!tariff.child || !maxFromTariff)
|
|
119
140
|
return [];
|
|
@@ -131,7 +152,7 @@ const PlayersAndVariationPicker = ({ slot, currentTariffId, currentDuration, loa
|
|
|
131
152
|
const totalHeads = _players + (_children || 0);
|
|
132
153
|
const personPrice = totalHeads > 0 ? Math.floor(teamPrice / totalHeads) : 0;
|
|
133
154
|
const showVariations = pickerOptions.length > 1;
|
|
134
|
-
const variationDescription = (
|
|
155
|
+
const variationDescription = (_a = selectedVariation === null || selectedVariation === void 0 ? void 0 : selectedVariation.description) !== null && _a !== void 0 ? _a : null;
|
|
135
156
|
const handleVariationClick = (optionId, isFree) => {
|
|
136
157
|
if (!isFree)
|
|
137
158
|
return;
|
|
@@ -170,7 +191,10 @@ const PlayersAndVariationPicker = ({ slot, currentTariffId, currentDuration, loa
|
|
|
170
191
|
tariff[_players] != null &&
|
|
171
192
|
`(${(0, format_amount_1.formatAmount)(tariff[_players], currency)})`),
|
|
172
193
|
react_1.default.createElement(flex_1.Flex, { gap: 'xs', wrap: true, justify: 'start' }, playersOptions
|
|
173
|
-
.filter((p) =>
|
|
194
|
+
.filter((p) => {
|
|
195
|
+
const total = p.key + (_children || 0);
|
|
196
|
+
return total >= effectiveMin && total <= effectiveMax;
|
|
197
|
+
})
|
|
174
198
|
.map((p) => (react_1.default.createElement(button_1.Button, { key: `adult-${p.key}`, size: 'xs', style: { width: 40, minWidth: 40 }, onClick: () => handleChangePlayers(p.key), view: _players === p.key ? 'primary' : 'outlined' }, p.key))))),
|
|
175
199
|
!!childrenOptions.length && (react_1.default.createElement(flex_columns_1.FlexColumns, { columns: 1, gr: 8 },
|
|
176
200
|
react_1.default.createElement(typography_1.Typography.Text, { view: 'title', color: 'secondary' },
|
|
@@ -179,7 +203,7 @@ const PlayersAndVariationPicker = ({ slot, currentTariffId, currentDuration, loa
|
|
|
179
203
|
!!_children &&
|
|
180
204
|
tariff.child != null &&
|
|
181
205
|
`(${(0, format_amount_1.formatAmount)(_children * tariff.child, currency)})`),
|
|
182
|
-
!!((
|
|
206
|
+
!!((_b = selectedVariation === null || selectedVariation === void 0 ? void 0 : selectedVariation.childPriceDescription) === null || _b === void 0 ? void 0 : _b.trim()) && (react_1.default.createElement("div", { style: { whiteSpace: 'pre-line' } },
|
|
183
207
|
react_1.default.createElement(typography_1.Typography.Text, { view: 'caps', color: 'secondary' }, selectedVariation.childPriceDescription))),
|
|
184
208
|
react_1.default.createElement(flex_1.Flex, { gap: 'xs', wrap: true, justify: 'start' }, childrenOptions
|
|
185
209
|
.filter((count) => _players + count <= effectiveMax)
|
|
@@ -38,7 +38,7 @@ const usePlayersAndVariationPicker = ({ slot, currentTariffId, currentDuration,
|
|
|
38
38
|
const loading = !!api[`${loadSlotDetails.displayName}Loading`];
|
|
39
39
|
const fetch = api[`${loadSlotDetails.displayName}Fetch`];
|
|
40
40
|
(0, react_1.useEffect)(() => {
|
|
41
|
-
if (!slot)
|
|
41
|
+
if (!(slot === null || slot === void 0 ? void 0 : slot.id) || !slot.questroomId || !slot.date || !slot.start)
|
|
42
42
|
return;
|
|
43
43
|
fetch({
|
|
44
44
|
slotId: slot.id,
|
|
@@ -47,8 +47,10 @@ const usePlayersAndVariationPicker = ({ slot, currentTariffId, currentDuration,
|
|
|
47
47
|
start: slot.start,
|
|
48
48
|
orderId,
|
|
49
49
|
});
|
|
50
|
-
//
|
|
51
|
-
|
|
50
|
+
// Only primitive slot fields — callers often pass inline `{ id, date, ... }`
|
|
51
|
+
// objects that get a new reference every render; including `slot` here
|
|
52
|
+
// re-triggers `/slots/details` on every parent render (ERR_INSUFFICIENT_RESOURCES).
|
|
53
|
+
}, [slot === null || slot === void 0 ? void 0 : slot.id, slot === null || slot === void 0 ? void 0 : slot.questroomId, slot === null || slot === void 0 ? void 0 : slot.date, slot === null || slot === void 0 ? void 0 : slot.start, orderId, fetch]);
|
|
52
54
|
const variations = (0, react_1.useMemo)(() => (data === null || data === void 0 ? void 0 : data.variations) || [], [data === null || data === void 0 ? void 0 : data.variations]);
|
|
53
55
|
const isFlex = !!(data === null || data === void 0 ? void 0 : data.isFlex);
|
|
54
56
|
const findCurrentVariation = (rows) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@escapenavigator/hooks",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.126",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"test": "jest"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@escapenavigator/services": "^1.10.
|
|
18
|
-
"@escapenavigator/types": "^1.10.
|
|
19
|
-
"@escapenavigator/utils": "^1.10.
|
|
17
|
+
"@escapenavigator/services": "^1.10.134",
|
|
18
|
+
"@escapenavigator/types": "^1.10.125",
|
|
19
|
+
"@escapenavigator/utils": "^1.10.129",
|
|
20
20
|
"react": "19.2.6"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"ts-jest": "^29.1.1",
|
|
31
31
|
"typescript": "^5.6"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "03bcfd8cda2090c1f3e3ad8aeb5ca019a46160d5"
|
|
34
34
|
}
|