arky-sdk 0.7.128 → 0.7.129
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/{admin-0rOB-o2E.d.ts → admin-CKVQJu8y.d.ts} +1 -1
- package/dist/{admin-DXfc0gEH.d.cts → admin-Cgqo1TcB.d.cts} +1 -1
- package/dist/admin.cjs +2 -4
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.d.cts +1 -1
- package/dist/admin.d.ts +1 -1
- package/dist/admin.js +2 -4
- package/dist/admin.js.map +1 -1
- package/dist/index.cjs +3 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/storefront-store.cjs +190 -189
- package/dist/storefront-store.cjs.map +1 -1
- package/dist/storefront-store.d.cts +2 -2
- package/dist/storefront-store.d.ts +2 -2
- package/dist/storefront-store.js +190 -189
- package/dist/storefront-store.js.map +1 -1
- package/dist/storefront.cjs +190 -189
- package/dist/storefront.cjs.map +1 -1
- package/dist/storefront.d.cts +94 -94
- package/dist/storefront.d.ts +94 -94
- package/dist/storefront.js +190 -189
- package/dist/storefront.js.map +1 -1
- package/package.json +1 -1
|
@@ -134,8 +134,7 @@ var getImageUrl = (imageBlock, isBlock = true) => {
|
|
|
134
134
|
function normalizeOrderCheckoutItems(items) {
|
|
135
135
|
return items.map((item) => {
|
|
136
136
|
if ("type" in item) {
|
|
137
|
-
|
|
138
|
-
return type === "booking" ? { ...item, type: "service" } : item;
|
|
137
|
+
return item;
|
|
139
138
|
}
|
|
140
139
|
if ("product_id" in item) {
|
|
141
140
|
return { type: "product", ...item };
|
|
@@ -1607,15 +1606,15 @@ function formSchemaToBlock(field) {
|
|
|
1607
1606
|
value: getFormBlockValue(field)
|
|
1608
1607
|
};
|
|
1609
1608
|
}
|
|
1610
|
-
function
|
|
1609
|
+
function formatServiceOrderTime(ts, tz) {
|
|
1611
1610
|
return new Date(ts * 1e3).toLocaleTimeString([], {
|
|
1612
1611
|
hour: "2-digit",
|
|
1613
1612
|
minute: "2-digit",
|
|
1614
1613
|
timeZone: tz
|
|
1615
1614
|
});
|
|
1616
1615
|
}
|
|
1617
|
-
function
|
|
1618
|
-
return `${
|
|
1616
|
+
function formatServiceOrderSlotTime(from, to, tz) {
|
|
1617
|
+
return `${formatServiceOrderTime(from, tz)} - ${formatServiceOrderTime(to, tz)}`;
|
|
1619
1618
|
}
|
|
1620
1619
|
function getSlotsForDate(availability, dateStr, providerId) {
|
|
1621
1620
|
if (!availability) return [];
|
|
@@ -1638,8 +1637,8 @@ function hasAvailableSlotsForDate(availability, dateStr, providerId) {
|
|
|
1638
1637
|
return !!day?.slots.some((slot) => slot.spots > 0);
|
|
1639
1638
|
});
|
|
1640
1639
|
}
|
|
1641
|
-
var
|
|
1642
|
-
function
|
|
1640
|
+
var SERVICE_ORDER_WEEKDAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
1641
|
+
function createServiceOrderInitialState() {
|
|
1643
1642
|
return {
|
|
1644
1643
|
service: null,
|
|
1645
1644
|
availability: null,
|
|
@@ -1656,7 +1655,7 @@ function createBookingInitialState() {
|
|
|
1656
1655
|
timezone: typeof window !== "undefined" ? Intl.DateTimeFormat().resolvedOptions().timeZone : "UTC",
|
|
1657
1656
|
tzGroups: {},
|
|
1658
1657
|
loading: false,
|
|
1659
|
-
weekdays:
|
|
1658
|
+
weekdays: SERVICE_ORDER_WEEKDAYS,
|
|
1660
1659
|
quote: null,
|
|
1661
1660
|
fetchingQuote: false,
|
|
1662
1661
|
quoteError: null,
|
|
@@ -1741,16 +1740,16 @@ function createArkyStore(config) {
|
|
|
1741
1740
|
loading_availability: false,
|
|
1742
1741
|
error: null
|
|
1743
1742
|
});
|
|
1744
|
-
const
|
|
1745
|
-
const
|
|
1746
|
-
const
|
|
1743
|
+
const service_order_state = nanostores.map(createServiceOrderInitialState());
|
|
1744
|
+
const service_order_form_node = nanostores.atom(null);
|
|
1745
|
+
const service_order_form_blocks = nanostores.computed(service_order_form_node, (node) => node?.blocks || []);
|
|
1747
1746
|
client.onAuthStateChanged((value) => session.set(value));
|
|
1748
1747
|
snapshot.subscribe((value) => config.onCartChange?.(value));
|
|
1749
|
-
currency.subscribe((value) =>
|
|
1748
|
+
currency.subscribe((value) => service_order_state.setKey("currency", value));
|
|
1750
1749
|
session.subscribe((value) => {
|
|
1751
1750
|
const methods = value?.market?.payment_methods || [];
|
|
1752
|
-
if (methods.length &&
|
|
1753
|
-
|
|
1751
|
+
if (methods.length && service_order_state.get().availablePaymentMethods.length === 0) {
|
|
1752
|
+
service_order_state.setKey("availablePaymentMethods", methods);
|
|
1754
1753
|
}
|
|
1755
1754
|
});
|
|
1756
1755
|
function currentMarketKey() {
|
|
@@ -2014,8 +2013,8 @@ function createArkyStore(config) {
|
|
|
2014
2013
|
cart_status.setKey("processing_checkout", false);
|
|
2015
2014
|
}
|
|
2016
2015
|
}
|
|
2017
|
-
function
|
|
2018
|
-
const state =
|
|
2016
|
+
function serviceOrderCalendar() {
|
|
2017
|
+
const state = service_order_state.get();
|
|
2019
2018
|
const { currentMonth, selectedDate, startDate, endDate, availability, selectedProviderId } = state;
|
|
2020
2019
|
const year = currentMonth.getFullYear();
|
|
2021
2020
|
const monthIndex = currentMonth.getMonth();
|
|
@@ -2069,8 +2068,8 @@ function createArkyStore(config) {
|
|
|
2069
2068
|
}
|
|
2070
2069
|
return cells;
|
|
2071
2070
|
}
|
|
2072
|
-
function
|
|
2073
|
-
const state =
|
|
2071
|
+
function computeServiceOrderSlots(dateStr) {
|
|
2072
|
+
const state = service_order_state.get();
|
|
2074
2073
|
const { availability, selectedProviderId, timezone, service } = state;
|
|
2075
2074
|
return getSlotsForDate(availability, dateStr, selectedProviderId).map((slot, index) => ({
|
|
2076
2075
|
id: `${service?.id || "service"}-${slot.from}-${index}`,
|
|
@@ -2078,7 +2077,7 @@ function createArkyStore(config) {
|
|
|
2078
2077
|
providerId: slot.providerId,
|
|
2079
2078
|
from: slot.from,
|
|
2080
2079
|
to: slot.to,
|
|
2081
|
-
timeText:
|
|
2080
|
+
timeText: formatServiceOrderSlotTime(slot.from, slot.to, timezone),
|
|
2082
2081
|
dateText: new Date(slot.from * 1e3).toLocaleDateString([], {
|
|
2083
2082
|
weekday: "short",
|
|
2084
2083
|
month: "short",
|
|
@@ -2111,63 +2110,63 @@ function createArkyStore(config) {
|
|
|
2111
2110
|
serviceName: item.service_name || "",
|
|
2112
2111
|
date: item.date_text || "",
|
|
2113
2112
|
dateText: item.date_text || "",
|
|
2114
|
-
timeText: item.time_text ||
|
|
2113
|
+
timeText: item.time_text || formatServiceOrderSlotTime(item.from, item.to, service_order_state.get().timezone),
|
|
2115
2114
|
isMultiDay: item.is_multi_day
|
|
2116
2115
|
};
|
|
2117
2116
|
}
|
|
2118
|
-
function
|
|
2117
|
+
function setServiceOrderCartFromServiceItems(items) {
|
|
2119
2118
|
const next = items.map(fromServiceCartItem);
|
|
2120
|
-
const current =
|
|
2119
|
+
const current = service_order_state.get().cart;
|
|
2121
2120
|
if (JSON.stringify(current) !== JSON.stringify(next)) {
|
|
2122
|
-
|
|
2121
|
+
service_order_state.setKey("cart", next);
|
|
2123
2122
|
}
|
|
2124
2123
|
}
|
|
2125
|
-
async function
|
|
2124
|
+
async function syncServiceOrderCart(slots) {
|
|
2126
2125
|
try {
|
|
2127
2126
|
return await syncCart({
|
|
2128
2127
|
product_items: product_items.get(),
|
|
2129
2128
|
service_items: slots.map(toServiceCartItem)
|
|
2130
2129
|
});
|
|
2131
2130
|
} catch (error) {
|
|
2132
|
-
|
|
2131
|
+
service_order_state.setKey("quoteError", readErrorMessage(error, "Failed to sync service order cart."));
|
|
2133
2132
|
throw error;
|
|
2134
2133
|
}
|
|
2135
2134
|
}
|
|
2136
|
-
function
|
|
2137
|
-
const state =
|
|
2135
|
+
function serviceOrderCurrentStepName() {
|
|
2136
|
+
const state = service_order_state.get();
|
|
2138
2137
|
if (!state.service) return "";
|
|
2139
2138
|
if (!state.selectedSlot || !state.dateTimeConfirmed) return "datetime";
|
|
2140
2139
|
return "review";
|
|
2141
2140
|
}
|
|
2142
|
-
const
|
|
2143
|
-
const
|
|
2144
|
-
const step =
|
|
2141
|
+
const service_order_current_step_name = nanostores.computed(service_order_state, serviceOrderCurrentStepName);
|
|
2142
|
+
const service_order_can_proceed = nanostores.computed(service_order_state, (state) => {
|
|
2143
|
+
const step = serviceOrderCurrentStepName();
|
|
2145
2144
|
if (step === "datetime") {
|
|
2146
2145
|
return state.isMultiDay ? !!(state.startDate && state.endDate && state.selectedSlot) : !!(state.selectedDate && state.selectedSlot);
|
|
2147
2146
|
}
|
|
2148
2147
|
if (step === "review") return true;
|
|
2149
2148
|
return false;
|
|
2150
2149
|
});
|
|
2151
|
-
const
|
|
2152
|
-
|
|
2150
|
+
const service_order_month_year = nanostores.computed(
|
|
2151
|
+
service_order_state,
|
|
2153
2152
|
(state) => state.currentMonth.toLocaleString(void 0, { month: "long", year: "numeric" })
|
|
2154
2153
|
);
|
|
2155
|
-
const
|
|
2154
|
+
const service_order_chain_start = nanostores.computed(service_order_state, (state) => {
|
|
2156
2155
|
if (!state.cart.length) return null;
|
|
2157
2156
|
return Math.max(...state.cart.map((slot) => slot.to));
|
|
2158
2157
|
});
|
|
2159
|
-
const
|
|
2160
|
-
const
|
|
2158
|
+
const service_order_total_steps = nanostores.computed(service_order_state, (state) => state.service ? 2 : 0);
|
|
2159
|
+
const service_order_steps = nanostores.computed(service_order_state, () => ({
|
|
2161
2160
|
1: { name: "datetime" },
|
|
2162
2161
|
2: { name: "review" }
|
|
2163
2162
|
}));
|
|
2164
|
-
const
|
|
2163
|
+
const service_order_current_step = nanostores.computed([service_order_current_step_name, service_order_steps], (name, steps) => {
|
|
2165
2164
|
for (const [idx, step] of Object.entries(steps)) {
|
|
2166
2165
|
if (step.name === name) return Number(idx);
|
|
2167
2166
|
}
|
|
2168
2167
|
return 1;
|
|
2169
2168
|
});
|
|
2170
|
-
function
|
|
2169
|
+
function formatServiceOrderDateDisplay(value) {
|
|
2171
2170
|
if (!value) return "";
|
|
2172
2171
|
return new Date(value).toLocaleDateString(void 0, { month: "short", day: "numeric" });
|
|
2173
2172
|
}
|
|
@@ -2184,37 +2183,37 @@ function createArkyStore(config) {
|
|
|
2184
2183
|
}
|
|
2185
2184
|
return providers[0];
|
|
2186
2185
|
}
|
|
2187
|
-
async function
|
|
2186
|
+
async function loadServiceOrderForm() {
|
|
2188
2187
|
try {
|
|
2189
2188
|
const form = await loadForm({ key: "order-form" });
|
|
2190
2189
|
const blocks = (form.schema || []).map(formSchemaToBlock);
|
|
2191
|
-
|
|
2190
|
+
service_order_form_node.set({ blocks });
|
|
2192
2191
|
return blocks;
|
|
2193
2192
|
} catch {
|
|
2194
|
-
|
|
2193
|
+
service_order_form_node.set({ blocks: [] });
|
|
2195
2194
|
return [];
|
|
2196
2195
|
}
|
|
2197
2196
|
}
|
|
2198
|
-
const
|
|
2197
|
+
const service_order_actions = {
|
|
2199
2198
|
async initialize() {
|
|
2200
|
-
|
|
2199
|
+
service_order_state.setKey("tzGroups", normalizeTimezoneGroups(client.utils.tzGroups));
|
|
2201
2200
|
await ensureCart();
|
|
2202
|
-
|
|
2201
|
+
setServiceOrderCartFromServiceItems(service_items.get());
|
|
2203
2202
|
const methods = session.get()?.market?.payment_methods || [];
|
|
2204
|
-
if (methods.length)
|
|
2205
|
-
await
|
|
2203
|
+
if (methods.length) service_order_state.setKey("availablePaymentMethods", methods);
|
|
2204
|
+
await loadServiceOrderForm();
|
|
2206
2205
|
},
|
|
2207
2206
|
setTimezone(tz) {
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
const state =
|
|
2207
|
+
service_order_state.setKey("timezone", tz);
|
|
2208
|
+
service_order_state.setKey("calendar", serviceOrderCalendar());
|
|
2209
|
+
const state = service_order_state.get();
|
|
2211
2210
|
if (state.selectedDate) {
|
|
2212
|
-
|
|
2213
|
-
|
|
2211
|
+
service_order_state.setKey("slots", computeServiceOrderSlots(state.selectedDate));
|
|
2212
|
+
service_order_state.setKey("selectedSlot", null);
|
|
2214
2213
|
}
|
|
2215
2214
|
},
|
|
2216
2215
|
async setService(service) {
|
|
2217
|
-
|
|
2216
|
+
service_order_state.setKey("loading", true);
|
|
2218
2217
|
try {
|
|
2219
2218
|
const isMultiDayBlock = service.blocks?.find((block) => block.key === "isMultiDay");
|
|
2220
2219
|
const blockValue = isMultiDayBlock?.value;
|
|
@@ -2227,8 +2226,8 @@ function createArkyStore(config) {
|
|
|
2227
2226
|
const providerResults = await Promise.all(
|
|
2228
2227
|
providerIds.map((id) => client.eshop.provider.get({ id }).catch(() => null))
|
|
2229
2228
|
);
|
|
2230
|
-
|
|
2231
|
-
...
|
|
2229
|
+
service_order_state.set({
|
|
2230
|
+
...service_order_state.get(),
|
|
2232
2231
|
service: fullService,
|
|
2233
2232
|
providers: providerResults.filter((provider) => provider !== null),
|
|
2234
2233
|
selectedProviderId: null,
|
|
@@ -2242,18 +2241,18 @@ function createArkyStore(config) {
|
|
|
2242
2241
|
loading: false,
|
|
2243
2242
|
isMultiDay
|
|
2244
2243
|
});
|
|
2245
|
-
await
|
|
2244
|
+
await service_order_actions.loadMonth();
|
|
2246
2245
|
} catch (error) {
|
|
2247
|
-
|
|
2246
|
+
service_order_state.setKey("loading", false);
|
|
2248
2247
|
throw error;
|
|
2249
2248
|
}
|
|
2250
2249
|
},
|
|
2251
2250
|
async loadMonth() {
|
|
2252
|
-
const state =
|
|
2251
|
+
const state = service_order_state.get();
|
|
2253
2252
|
if (!state.service) return;
|
|
2254
|
-
|
|
2253
|
+
service_order_state.setKey("loading", true);
|
|
2255
2254
|
try {
|
|
2256
|
-
const chainedStart =
|
|
2255
|
+
const chainedStart = service_order_chain_start.get();
|
|
2257
2256
|
let from;
|
|
2258
2257
|
let to;
|
|
2259
2258
|
if (chainedStart) {
|
|
@@ -2269,25 +2268,25 @@ function createArkyStore(config) {
|
|
|
2269
2268
|
from,
|
|
2270
2269
|
to
|
|
2271
2270
|
});
|
|
2272
|
-
|
|
2273
|
-
|
|
2271
|
+
service_order_state.setKey("availability", availability);
|
|
2272
|
+
service_order_state.setKey("calendar", serviceOrderCalendar());
|
|
2274
2273
|
} finally {
|
|
2275
|
-
|
|
2274
|
+
service_order_state.setKey("loading", false);
|
|
2276
2275
|
}
|
|
2277
2276
|
},
|
|
2278
2277
|
prevMonth() {
|
|
2279
|
-
const { currentMonth } =
|
|
2280
|
-
|
|
2281
|
-
void
|
|
2278
|
+
const { currentMonth } = service_order_state.get();
|
|
2279
|
+
service_order_state.setKey("currentMonth", new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1));
|
|
2280
|
+
void service_order_actions.loadMonth();
|
|
2282
2281
|
},
|
|
2283
2282
|
nextMonth() {
|
|
2284
|
-
const { currentMonth } =
|
|
2285
|
-
|
|
2286
|
-
void
|
|
2283
|
+
const { currentMonth } = service_order_state.get();
|
|
2284
|
+
service_order_state.setKey("currentMonth", new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1));
|
|
2285
|
+
void service_order_actions.loadMonth();
|
|
2287
2286
|
},
|
|
2288
2287
|
selectProvider(providerId) {
|
|
2289
|
-
|
|
2290
|
-
...
|
|
2288
|
+
service_order_state.set({
|
|
2289
|
+
...service_order_state.get(),
|
|
2291
2290
|
selectedProviderId: providerId,
|
|
2292
2291
|
selectedDate: null,
|
|
2293
2292
|
startDate: null,
|
|
@@ -2295,45 +2294,45 @@ function createArkyStore(config) {
|
|
|
2295
2294
|
slots: [],
|
|
2296
2295
|
selectedSlot: null
|
|
2297
2296
|
});
|
|
2298
|
-
void
|
|
2297
|
+
void service_order_actions.loadMonth();
|
|
2299
2298
|
},
|
|
2300
2299
|
selectDate(cell) {
|
|
2301
2300
|
if (cell.blank || !cell.available) return;
|
|
2302
|
-
|
|
2303
|
-
const state =
|
|
2301
|
+
service_order_state.setKey("dateTimeConfirmed", false);
|
|
2302
|
+
const state = service_order_state.get();
|
|
2304
2303
|
if (state.isMultiDay) {
|
|
2305
2304
|
if (!state.startDate) {
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2305
|
+
service_order_state.setKey("startDate", cell.iso);
|
|
2306
|
+
service_order_state.setKey("selectedDate", cell.iso);
|
|
2307
|
+
service_order_state.setKey("endDate", null);
|
|
2308
|
+
service_order_state.setKey("selectedSlot", null);
|
|
2310
2309
|
} else if (!state.endDate) {
|
|
2311
2310
|
if (cell.date.getTime() < new Date(state.startDate).getTime()) {
|
|
2312
|
-
|
|
2313
|
-
|
|
2311
|
+
service_order_state.setKey("startDate", cell.iso);
|
|
2312
|
+
service_order_state.setKey("endDate", state.startDate);
|
|
2314
2313
|
} else {
|
|
2315
|
-
|
|
2314
|
+
service_order_state.setKey("endDate", cell.iso);
|
|
2316
2315
|
}
|
|
2317
|
-
|
|
2316
|
+
service_order_actions.createMultiDaySlots();
|
|
2318
2317
|
} else {
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2318
|
+
service_order_state.setKey("startDate", cell.iso);
|
|
2319
|
+
service_order_state.setKey("selectedDate", cell.iso);
|
|
2320
|
+
service_order_state.setKey("endDate", null);
|
|
2321
|
+
service_order_state.setKey("selectedSlot", null);
|
|
2323
2322
|
}
|
|
2324
|
-
|
|
2323
|
+
service_order_actions.updateCalendar();
|
|
2325
2324
|
} else {
|
|
2326
|
-
|
|
2325
|
+
service_order_state.set({
|
|
2327
2326
|
...state,
|
|
2328
2327
|
selectedDate: cell.iso,
|
|
2329
|
-
slots:
|
|
2328
|
+
slots: computeServiceOrderSlots(cell.iso),
|
|
2330
2329
|
selectedSlot: null
|
|
2331
2330
|
});
|
|
2332
|
-
|
|
2331
|
+
service_order_state.setKey("calendar", serviceOrderCalendar());
|
|
2333
2332
|
}
|
|
2334
2333
|
},
|
|
2335
2334
|
createMultiDaySlots() {
|
|
2336
|
-
const state =
|
|
2335
|
+
const state = service_order_state.get();
|
|
2337
2336
|
if (!state.startDate || !state.endDate || !state.availability) return;
|
|
2338
2337
|
const slots = [];
|
|
2339
2338
|
for (let day = new Date(state.startDate); day <= new Date(state.endDate); day.setDate(day.getDate() + 1)) {
|
|
@@ -2345,7 +2344,7 @@ function createArkyStore(config) {
|
|
|
2345
2344
|
providerId: slot.providerId,
|
|
2346
2345
|
from: slot.from,
|
|
2347
2346
|
to: slot.to,
|
|
2348
|
-
timeText:
|
|
2347
|
+
timeText: formatServiceOrderSlotTime(slot.from, slot.to, state.timezone),
|
|
2349
2348
|
dateText: new Date(slot.from * 1e3).toLocaleDateString([], {
|
|
2350
2349
|
weekday: "short",
|
|
2351
2350
|
month: "short",
|
|
@@ -2356,34 +2355,34 @@ function createArkyStore(config) {
|
|
|
2356
2355
|
});
|
|
2357
2356
|
}
|
|
2358
2357
|
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2358
|
+
service_order_state.setKey("slots", slots);
|
|
2359
|
+
service_order_state.setKey("selectedSlot", slots.length === 1 ? slots[0] : null);
|
|
2361
2360
|
},
|
|
2362
2361
|
selectTimeSlot(slot) {
|
|
2363
|
-
|
|
2364
|
-
|
|
2362
|
+
service_order_state.setKey("dateTimeConfirmed", false);
|
|
2363
|
+
service_order_state.setKey("selectedSlot", slot);
|
|
2365
2364
|
},
|
|
2366
2365
|
resetDateSelection() {
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2366
|
+
service_order_state.setKey("selectedDate", null);
|
|
2367
|
+
service_order_state.setKey("startDate", null);
|
|
2368
|
+
service_order_state.setKey("endDate", null);
|
|
2369
|
+
service_order_state.setKey("slots", []);
|
|
2370
|
+
service_order_state.setKey("selectedSlot", null);
|
|
2371
|
+
service_order_state.setKey("dateTimeConfirmed", false);
|
|
2373
2372
|
},
|
|
2374
2373
|
updateCalendar() {
|
|
2375
|
-
|
|
2374
|
+
service_order_state.setKey("calendar", serviceOrderCalendar());
|
|
2376
2375
|
},
|
|
2377
2376
|
findFirstAvailable() {
|
|
2378
|
-
for (const day of
|
|
2377
|
+
for (const day of service_order_state.get().calendar) {
|
|
2379
2378
|
if (!day.blank && day.available) {
|
|
2380
|
-
|
|
2379
|
+
service_order_actions.selectDate(day);
|
|
2381
2380
|
return;
|
|
2382
2381
|
}
|
|
2383
2382
|
}
|
|
2384
2383
|
},
|
|
2385
2384
|
async addToCart() {
|
|
2386
|
-
const state =
|
|
2385
|
+
const state = service_order_state.get();
|
|
2387
2386
|
const serviceBlocks = state.service?.forms || [];
|
|
2388
2387
|
const enrich = (slot) => ({
|
|
2389
2388
|
...slot,
|
|
@@ -2394,7 +2393,7 @@ function createArkyStore(config) {
|
|
|
2394
2393
|
const selected = state.isMultiDay && state.slots.length > 0 ? state.slots.map(enrich) : state.selectedSlot ? [enrich(state.selectedSlot)] : [];
|
|
2395
2394
|
if (!selected.length) return;
|
|
2396
2395
|
const nextCart = [...state.cart, ...selected];
|
|
2397
|
-
|
|
2396
|
+
service_order_state.set({
|
|
2398
2397
|
...state,
|
|
2399
2398
|
cart: nextCart,
|
|
2400
2399
|
selectedDate: null,
|
|
@@ -2403,22 +2402,22 @@ function createArkyStore(config) {
|
|
|
2403
2402
|
slots: [],
|
|
2404
2403
|
selectedSlot: null
|
|
2405
2404
|
});
|
|
2406
|
-
await
|
|
2407
|
-
|
|
2405
|
+
await syncServiceOrderCart(nextCart);
|
|
2406
|
+
service_order_state.setKey("calendar", serviceOrderCalendar());
|
|
2408
2407
|
},
|
|
2409
2408
|
async removeFromCart(slotId) {
|
|
2410
|
-
const nextCart =
|
|
2411
|
-
|
|
2412
|
-
await
|
|
2409
|
+
const nextCart = service_order_state.get().cart.filter((slot) => slot.id !== slotId);
|
|
2410
|
+
service_order_state.setKey("cart", nextCart);
|
|
2411
|
+
await syncServiceOrderCart(nextCart);
|
|
2413
2412
|
},
|
|
2414
2413
|
async clearCart() {
|
|
2415
|
-
|
|
2416
|
-
await
|
|
2414
|
+
service_order_state.setKey("cart", []);
|
|
2415
|
+
await syncServiceOrderCart([]);
|
|
2417
2416
|
},
|
|
2418
2417
|
async checkout(paymentMethodId, forms = []) {
|
|
2419
|
-
const state =
|
|
2418
|
+
const state = service_order_state.get();
|
|
2420
2419
|
if (!state.cart.length) return { success: false, error: "Cart is empty" };
|
|
2421
|
-
|
|
2420
|
+
service_order_state.setKey("loading", true);
|
|
2422
2421
|
try {
|
|
2423
2422
|
const result = await checkout({
|
|
2424
2423
|
service_items: state.cart.map((slot) => ({
|
|
@@ -2429,70 +2428,70 @@ function createArkyStore(config) {
|
|
|
2429
2428
|
promo_code: state.promoCode || void 0,
|
|
2430
2429
|
forms
|
|
2431
2430
|
});
|
|
2432
|
-
|
|
2431
|
+
service_order_state.setKey("cartId", cart.get()?.id || null);
|
|
2433
2432
|
return { success: true, data: result };
|
|
2434
2433
|
} catch (error) {
|
|
2435
2434
|
return { success: false, error: readErrorMessage(error, "Checkout failed.") };
|
|
2436
2435
|
} finally {
|
|
2437
|
-
|
|
2436
|
+
service_order_state.setKey("loading", false);
|
|
2438
2437
|
}
|
|
2439
2438
|
},
|
|
2440
2439
|
async fetchQuote(paymentMethodId, promoCode) {
|
|
2441
|
-
const state =
|
|
2440
|
+
const state = service_order_state.get();
|
|
2442
2441
|
if (!state.cart.length) return null;
|
|
2443
|
-
|
|
2444
|
-
|
|
2442
|
+
service_order_state.setKey("fetchingQuote", true);
|
|
2443
|
+
service_order_state.setKey("quoteError", null);
|
|
2445
2444
|
try {
|
|
2446
|
-
|
|
2445
|
+
service_order_state.setKey("promoCode", promoCode || null);
|
|
2447
2446
|
const response = await fetchQuote({
|
|
2448
2447
|
service_items: state.cart.map(toServiceCartItem),
|
|
2449
2448
|
payment_method_id: paymentMethodId,
|
|
2450
2449
|
promo_code: promoCode || void 0
|
|
2451
2450
|
});
|
|
2452
|
-
|
|
2453
|
-
|
|
2451
|
+
service_order_state.setKey("cartId", cart.get()?.id || null);
|
|
2452
|
+
service_order_state.setKey("quote", response);
|
|
2454
2453
|
const methods = response?.payment_methods || session.get()?.market?.payment_methods || [];
|
|
2455
|
-
if (methods.length)
|
|
2454
|
+
if (methods.length) service_order_state.setKey("availablePaymentMethods", methods);
|
|
2456
2455
|
return response;
|
|
2457
2456
|
} catch (error) {
|
|
2458
|
-
|
|
2457
|
+
service_order_state.setKey("quoteError", readErrorMessage(error, "Failed to fetch quote."));
|
|
2459
2458
|
return null;
|
|
2460
2459
|
} finally {
|
|
2461
|
-
|
|
2460
|
+
service_order_state.setKey("fetchingQuote", false);
|
|
2462
2461
|
}
|
|
2463
2462
|
},
|
|
2464
2463
|
getProvidersList() {
|
|
2465
|
-
return
|
|
2464
|
+
return service_order_state.get().providers;
|
|
2466
2465
|
},
|
|
2467
2466
|
prevStep() {
|
|
2468
|
-
const current =
|
|
2467
|
+
const current = serviceOrderCurrentStepName();
|
|
2469
2468
|
if (current === "review") {
|
|
2470
|
-
|
|
2469
|
+
service_order_state.setKey("dateTimeConfirmed", false);
|
|
2471
2470
|
return;
|
|
2472
2471
|
}
|
|
2473
2472
|
if (current === "datetime") {
|
|
2474
|
-
|
|
2475
|
-
|
|
2473
|
+
service_order_state.setKey("selectedSlot", null);
|
|
2474
|
+
service_order_state.setKey("dateTimeConfirmed", false);
|
|
2476
2475
|
}
|
|
2477
2476
|
},
|
|
2478
2477
|
nextStep() {
|
|
2479
|
-
if (
|
|
2480
|
-
|
|
2478
|
+
if (serviceOrderCurrentStepName() === "datetime" && service_order_can_proceed.get()) {
|
|
2479
|
+
service_order_state.setKey("dateTimeConfirmed", true);
|
|
2481
2480
|
}
|
|
2482
2481
|
},
|
|
2483
2482
|
getServicePrice() {
|
|
2484
|
-
const state =
|
|
2483
|
+
const state = service_order_state.get();
|
|
2485
2484
|
if (state.quote?.total !== void 0) return String(state.quote.total);
|
|
2486
2485
|
const provider = getFirstServiceProviderEntry(state);
|
|
2487
2486
|
if (!provider?.prices) return "";
|
|
2488
2487
|
return client.utils.formatPrice(provider.prices) || "0";
|
|
2489
2488
|
},
|
|
2490
|
-
formatDateDisplay:
|
|
2489
|
+
formatDateDisplay: formatServiceOrderDateDisplay,
|
|
2491
2490
|
serviceItemsFromSlots(slots) {
|
|
2492
2491
|
return slots.map(toServiceCartItem);
|
|
2493
2492
|
}
|
|
2494
2493
|
};
|
|
2495
|
-
service_items.subscribe((items) =>
|
|
2494
|
+
service_items.subscribe((items) => setServiceOrderCartFromServiceItems(items));
|
|
2496
2495
|
async function loadNode(params, options) {
|
|
2497
2496
|
cms_state.setKey("loading", true);
|
|
2498
2497
|
cms_state.setKey("error", null);
|
|
@@ -2605,6 +2604,59 @@ function createArkyStore(config) {
|
|
|
2605
2604
|
if (options.load_website) results.website_node = await loadWebsiteNode();
|
|
2606
2605
|
return results;
|
|
2607
2606
|
}
|
|
2607
|
+
const cart_store = {
|
|
2608
|
+
cart,
|
|
2609
|
+
product_items,
|
|
2610
|
+
service_items,
|
|
2611
|
+
quote,
|
|
2612
|
+
promo_code,
|
|
2613
|
+
last_order,
|
|
2614
|
+
status: cart_status,
|
|
2615
|
+
product_item_count,
|
|
2616
|
+
service_item_count,
|
|
2617
|
+
item_count,
|
|
2618
|
+
snapshot,
|
|
2619
|
+
actions: {
|
|
2620
|
+
ensure: ensureCart,
|
|
2621
|
+
hydrate: hydrateCart,
|
|
2622
|
+
sync: syncCart,
|
|
2623
|
+
addProduct,
|
|
2624
|
+
setProductQuantity,
|
|
2625
|
+
removeProduct,
|
|
2626
|
+
addServiceItem,
|
|
2627
|
+
removeServiceItem,
|
|
2628
|
+
clear: clearCart,
|
|
2629
|
+
quote: fetchQuote,
|
|
2630
|
+
checkout,
|
|
2631
|
+
applyPromoCode(code, input = {}) {
|
|
2632
|
+
promo_code.set(code);
|
|
2633
|
+
return fetchQuote({ ...input, promo_code: code });
|
|
2634
|
+
},
|
|
2635
|
+
removePromoCode(input = {}) {
|
|
2636
|
+
promo_code.set(null);
|
|
2637
|
+
return fetchQuote({ ...input, promo_code: null });
|
|
2638
|
+
},
|
|
2639
|
+
selectShippingMethod(id) {
|
|
2640
|
+
cart_status.setKey("selected_shipping_method_id", id);
|
|
2641
|
+
},
|
|
2642
|
+
locationToAddress,
|
|
2643
|
+
buildItems: checkoutItems,
|
|
2644
|
+
buildProductItems: toProductCheckoutItems,
|
|
2645
|
+
buildServiceItems: toServiceCheckoutItems
|
|
2646
|
+
}
|
|
2647
|
+
};
|
|
2648
|
+
const service_order_store = {
|
|
2649
|
+
state: service_order_state,
|
|
2650
|
+
form_blocks: service_order_form_blocks,
|
|
2651
|
+
current_step_name: service_order_current_step_name,
|
|
2652
|
+
can_proceed: service_order_can_proceed,
|
|
2653
|
+
month_year: service_order_month_year,
|
|
2654
|
+
chain_start: service_order_chain_start,
|
|
2655
|
+
total_steps: service_order_total_steps,
|
|
2656
|
+
steps: service_order_steps,
|
|
2657
|
+
current_step: service_order_current_step,
|
|
2658
|
+
actions: service_order_actions
|
|
2659
|
+
};
|
|
2608
2660
|
return {
|
|
2609
2661
|
client,
|
|
2610
2662
|
session,
|
|
@@ -2653,60 +2705,9 @@ function createArkyStore(config) {
|
|
|
2653
2705
|
get: (params, options) => client.eshop.provider.get(params, options),
|
|
2654
2706
|
find: loadProviders
|
|
2655
2707
|
},
|
|
2656
|
-
order: client.eshop.order
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
cart,
|
|
2660
|
-
product_items,
|
|
2661
|
-
service_items,
|
|
2662
|
-
quote,
|
|
2663
|
-
promo_code,
|
|
2664
|
-
last_order,
|
|
2665
|
-
status: cart_status,
|
|
2666
|
-
product_item_count,
|
|
2667
|
-
service_item_count,
|
|
2668
|
-
item_count,
|
|
2669
|
-
snapshot,
|
|
2670
|
-
actions: {
|
|
2671
|
-
ensure: ensureCart,
|
|
2672
|
-
hydrate: hydrateCart,
|
|
2673
|
-
sync: syncCart,
|
|
2674
|
-
addProduct,
|
|
2675
|
-
setProductQuantity,
|
|
2676
|
-
removeProduct,
|
|
2677
|
-
addServiceItem,
|
|
2678
|
-
removeServiceItem,
|
|
2679
|
-
clear: clearCart,
|
|
2680
|
-
quote: fetchQuote,
|
|
2681
|
-
checkout,
|
|
2682
|
-
applyPromoCode(code, input = {}) {
|
|
2683
|
-
promo_code.set(code);
|
|
2684
|
-
return fetchQuote({ ...input, promo_code: code });
|
|
2685
|
-
},
|
|
2686
|
-
removePromoCode(input = {}) {
|
|
2687
|
-
promo_code.set(null);
|
|
2688
|
-
return fetchQuote({ ...input, promo_code: null });
|
|
2689
|
-
},
|
|
2690
|
-
selectShippingMethod(id) {
|
|
2691
|
-
cart_status.setKey("selected_shipping_method_id", id);
|
|
2692
|
-
},
|
|
2693
|
-
locationToAddress,
|
|
2694
|
-
buildItems: checkoutItems,
|
|
2695
|
-
buildProductItems: toProductCheckoutItems,
|
|
2696
|
-
buildServiceItems: toServiceCheckoutItems
|
|
2697
|
-
}
|
|
2698
|
-
},
|
|
2699
|
-
booking: {
|
|
2700
|
-
state: booking_state,
|
|
2701
|
-
form_blocks: booking_form_blocks,
|
|
2702
|
-
current_step_name: booking_current_step_name,
|
|
2703
|
-
can_proceed: booking_can_proceed,
|
|
2704
|
-
month_year: booking_month_year,
|
|
2705
|
-
chain_start: booking_chain_start,
|
|
2706
|
-
total_steps: booking_total_steps,
|
|
2707
|
-
steps: booking_steps,
|
|
2708
|
-
current_step: booking_current_step,
|
|
2709
|
-
actions: booking_actions
|
|
2708
|
+
order: client.eshop.order,
|
|
2709
|
+
cart: cart_store,
|
|
2710
|
+
serviceOrder: service_order_store
|
|
2710
2711
|
},
|
|
2711
2712
|
crm: client.crm,
|
|
2712
2713
|
activity: {
|