@zappie/foundations 0.12.13 → 0.14.0
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/CHANGELOG.md +30 -0
- package/README.md +58 -0
- package/dist/checkout/attempt.js +1 -0
- package/dist/checkout/attempt.js.map +1 -1
- package/dist/checkout/use-checkout-flow.js +2 -0
- package/dist/checkout/use-checkout-flow.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/loyalty/index.d.ts +171 -0
- package/dist/loyalty/index.js +279 -0
- package/dist/loyalty/index.js.map +6 -0
- package/dist/order/index.d.ts +200 -0
- package/dist/order/index.js +576 -0
- package/dist/order/index.js.map +6 -0
- package/dist/order/model.js +84 -0
- package/dist/order/model.js.map +6 -0
- package/dist/order/use-customer-order.js +56 -0
- package/dist/order/use-customer-order.js.map +6 -0
- package/dist/overlay/engine.d.ts +57 -3
- package/dist/slot-CHfqzPTd.d.ts +13 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +11 -3
- package/dist/engine-TxMNPD2g.d.ts +0 -65
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/loyalty/index.tsx
|
|
4
|
+
import {
|
|
5
|
+
format,
|
|
6
|
+
money
|
|
7
|
+
} from "@zappie/sdk";
|
|
8
|
+
import {
|
|
9
|
+
signInAgain,
|
|
10
|
+
useCartPerks,
|
|
11
|
+
useClaimPoints,
|
|
12
|
+
useLoyalty,
|
|
13
|
+
usePerks,
|
|
14
|
+
useStoreCredit
|
|
15
|
+
} from "@zappie/sdk/loyalty/react";
|
|
16
|
+
import { useCart } from "@zappie/sdk/react";
|
|
17
|
+
import { createContext, forwardRef, useContext, useEffect } from "react";
|
|
18
|
+
import { part } from "../internal/slot.js";
|
|
19
|
+
import { jsx } from "react/jsx-runtime";
|
|
20
|
+
var wire = (value) => money(value.amount_minor, value.currency);
|
|
21
|
+
function rewardLabel(reward) {
|
|
22
|
+
if (reward.type === "free_item") {
|
|
23
|
+
return "Free item";
|
|
24
|
+
}
|
|
25
|
+
if (reward.amount_off) {
|
|
26
|
+
return `${format.money(wire(reward.amount_off))} off`;
|
|
27
|
+
}
|
|
28
|
+
return `${reward.percent_off ?? 0}% off`;
|
|
29
|
+
}
|
|
30
|
+
function useRewardsRow(options = {}) {
|
|
31
|
+
const cart = useCart();
|
|
32
|
+
const loyalty = useLoyalty(
|
|
33
|
+
options.signedIn === false ? { enabled: false } : {}
|
|
34
|
+
);
|
|
35
|
+
return {
|
|
36
|
+
visible: options.signedIn !== false && loyalty.enabled && cart.fulfilment?.type !== "dine_in",
|
|
37
|
+
points: loyalty.points,
|
|
38
|
+
status: loyalty.status
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function usePerkLines() {
|
|
42
|
+
const cart = useCart();
|
|
43
|
+
const perks = useCartPerks();
|
|
44
|
+
const quote = "quote" in cart.state ? cart.state.quote : void 0;
|
|
45
|
+
const lines = [];
|
|
46
|
+
for (const perk of cart.perks) {
|
|
47
|
+
const discount = quote?.discounts.find(
|
|
48
|
+
(line) => line.redemptionId === perk.redemptionId
|
|
49
|
+
);
|
|
50
|
+
if (discount) {
|
|
51
|
+
lines.push({
|
|
52
|
+
redemptionId: perk.redemptionId,
|
|
53
|
+
name: discount.label,
|
|
54
|
+
amount: discount.amount,
|
|
55
|
+
kind: "discount"
|
|
56
|
+
});
|
|
57
|
+
} else if (perk.reward === "free_item" && quote) {
|
|
58
|
+
lines.push({
|
|
59
|
+
redemptionId: perk.redemptionId,
|
|
60
|
+
name: perk.name,
|
|
61
|
+
amount: money(0, quote.total.currency),
|
|
62
|
+
kind: "free_item"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
lines,
|
|
68
|
+
remove: perks.remove,
|
|
69
|
+
busy: perks.busy,
|
|
70
|
+
error: perks.error
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
var Context = /* @__PURE__ */ createContext(null);
|
|
74
|
+
function useRewards() {
|
|
75
|
+
const value = useContext(Context);
|
|
76
|
+
if (!value) {
|
|
77
|
+
throw new Error("Rewards parts require Rewards.Root");
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function rewardsErrorMessage(error) {
|
|
82
|
+
return error instanceof Error ? error.message : void 0;
|
|
83
|
+
}
|
|
84
|
+
function Root({
|
|
85
|
+
branchId,
|
|
86
|
+
open = true,
|
|
87
|
+
...props
|
|
88
|
+
}) {
|
|
89
|
+
const cart = useCart();
|
|
90
|
+
const branch = branchId ?? cart.branchId;
|
|
91
|
+
const loyalty = useLoyalty();
|
|
92
|
+
const perks = usePerks(open ? branch : void 0);
|
|
93
|
+
const credit = useStoreCredit(open ? branch : void 0);
|
|
94
|
+
const actions = useCartPerks();
|
|
95
|
+
const value = {
|
|
96
|
+
status: loyalty.status,
|
|
97
|
+
points: loyalty.points,
|
|
98
|
+
perks: perks.perks,
|
|
99
|
+
perksStatus: perks.status,
|
|
100
|
+
applied: cart.perks,
|
|
101
|
+
storeCredit: credit.enabled && credit.balance && credit.balance.amount_minor > 0 ? wire(credit.balance) : void 0,
|
|
102
|
+
busy: actions.busy,
|
|
103
|
+
error: actions.error,
|
|
104
|
+
clearError: actions.clearError,
|
|
105
|
+
apply: actions.apply,
|
|
106
|
+
remove: actions.remove
|
|
107
|
+
};
|
|
108
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value, children: part("div", props, value, {
|
|
109
|
+
"data-state": loyalty.status,
|
|
110
|
+
"aria-busy": loyalty.status === "loading" || void 0
|
|
111
|
+
}) });
|
|
112
|
+
}
|
|
113
|
+
var Points = /* @__PURE__ */ forwardRef(function Points2(props, ref) {
|
|
114
|
+
const { points } = useRewards();
|
|
115
|
+
return part(
|
|
116
|
+
"data",
|
|
117
|
+
{
|
|
118
|
+
...props,
|
|
119
|
+
children: props.children ?? (points === void 0 ? "" : `${points.toLocaleString("en")} pts`)
|
|
120
|
+
},
|
|
121
|
+
{ points },
|
|
122
|
+
{ value: points === void 0 ? void 0 : String(points) },
|
|
123
|
+
ref
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
var StoreCredit = /* @__PURE__ */ forwardRef(function StoreCredit2(props, ref) {
|
|
127
|
+
const { storeCredit } = useRewards();
|
|
128
|
+
return storeCredit ? part(
|
|
129
|
+
"div",
|
|
130
|
+
{
|
|
131
|
+
...props,
|
|
132
|
+
children: props.children ?? format.money(storeCredit)
|
|
133
|
+
},
|
|
134
|
+
{ balance: storeCredit },
|
|
135
|
+
{},
|
|
136
|
+
ref
|
|
137
|
+
) : null;
|
|
138
|
+
});
|
|
139
|
+
var List = /* @__PURE__ */ forwardRef(function List2(props, ref) {
|
|
140
|
+
const { perks, perksStatus } = useRewards();
|
|
141
|
+
return perks.length ? part(
|
|
142
|
+
"ul",
|
|
143
|
+
props,
|
|
144
|
+
{ perks },
|
|
145
|
+
{ "aria-busy": perksStatus === "loading" || void 0 },
|
|
146
|
+
ref
|
|
147
|
+
) : null;
|
|
148
|
+
});
|
|
149
|
+
var PerkContext = /* @__PURE__ */ createContext(null);
|
|
150
|
+
var PerkPart = /* @__PURE__ */ forwardRef(function PerkPart2({ perk, ...props }, ref) {
|
|
151
|
+
const rewards = useRewards();
|
|
152
|
+
const applied = rewards.applied.find((p) => p.perkId === perk.id);
|
|
153
|
+
const state = {
|
|
154
|
+
perk,
|
|
155
|
+
reward: rewardLabel(perk.reward),
|
|
156
|
+
applied,
|
|
157
|
+
affordable: (rewards.points ?? 0) >= perk.points_cost,
|
|
158
|
+
busy: rewards.busy === perk.id || applied !== void 0 && rewards.busy === applied.redemptionId,
|
|
159
|
+
locked: rewards.busy !== void 0
|
|
160
|
+
};
|
|
161
|
+
return /* @__PURE__ */ jsx(PerkContext.Provider, { value: state, children: part(
|
|
162
|
+
"li",
|
|
163
|
+
props,
|
|
164
|
+
state,
|
|
165
|
+
{
|
|
166
|
+
"data-state": applied ? "applied" : state.affordable ? "available" : "unaffordable"
|
|
167
|
+
},
|
|
168
|
+
ref
|
|
169
|
+
) });
|
|
170
|
+
});
|
|
171
|
+
var Action = /* @__PURE__ */ forwardRef(function Action2(props, ref) {
|
|
172
|
+
const rewards = useRewards();
|
|
173
|
+
const state = useContext(PerkContext);
|
|
174
|
+
if (!state) {
|
|
175
|
+
throw new Error("Rewards.Action requires Rewards.Perk");
|
|
176
|
+
}
|
|
177
|
+
const { perk, applied, affordable, busy, locked } = state;
|
|
178
|
+
const label = applied ? "Remove" : affordable ? "Redeem" : "Not enough points";
|
|
179
|
+
return part(
|
|
180
|
+
"button",
|
|
181
|
+
{ ...props, children: props.children ?? label },
|
|
182
|
+
{ ...state, label },
|
|
183
|
+
{
|
|
184
|
+
type: "button",
|
|
185
|
+
"aria-label": applied ? `Remove ${perk.name} and get ${applied.pointsSpent || perk.points_cost} points back` : affordable ? `Redeem ${perk.name} for ${perk.points_cost} points` : `${perk.name} costs ${perk.points_cost} points. Not enough points`,
|
|
186
|
+
"aria-busy": busy || void 0,
|
|
187
|
+
disabled: !applied && !affordable || locked,
|
|
188
|
+
"data-state": busy ? "busy" : applied ? "applied" : "idle",
|
|
189
|
+
onClick: () => void (applied ? rewards.remove(applied.redemptionId) : rewards.apply(perk))
|
|
190
|
+
},
|
|
191
|
+
ref
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
var Empty = /* @__PURE__ */ forwardRef(
|
|
195
|
+
function Empty2(props, ref) {
|
|
196
|
+
const { perks, perksStatus } = useRewards();
|
|
197
|
+
return perksStatus === "ready" && !perks.length ? part(
|
|
198
|
+
"p",
|
|
199
|
+
{ ...props, children: props.children ?? "No rewards available yet" },
|
|
200
|
+
{},
|
|
201
|
+
{},
|
|
202
|
+
ref
|
|
203
|
+
) : null;
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
var ErrorPart = /* @__PURE__ */ forwardRef(function ErrorPart2(props, ref) {
|
|
207
|
+
const { error, clearError } = useRewards();
|
|
208
|
+
const message = rewardsErrorMessage(error);
|
|
209
|
+
return message ? part(
|
|
210
|
+
"p",
|
|
211
|
+
{ ...props, children: props.children ?? message },
|
|
212
|
+
{ message, dismiss: clearError },
|
|
213
|
+
{ role: "alert" },
|
|
214
|
+
ref
|
|
215
|
+
) : null;
|
|
216
|
+
});
|
|
217
|
+
var SignInAgain = /* @__PURE__ */ forwardRef(
|
|
218
|
+
function SignInAgain2(props, ref) {
|
|
219
|
+
const { status } = useRewards();
|
|
220
|
+
return status === "scope_required" ? part(
|
|
221
|
+
"button",
|
|
222
|
+
{
|
|
223
|
+
...props,
|
|
224
|
+
children: props.children ?? "Sign in again to use your rewards"
|
|
225
|
+
},
|
|
226
|
+
{},
|
|
227
|
+
{ type: "button", onClick: () => signInAgain() },
|
|
228
|
+
ref
|
|
229
|
+
) : null;
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
var Rewards = {
|
|
233
|
+
Root,
|
|
234
|
+
Points,
|
|
235
|
+
StoreCredit,
|
|
236
|
+
List,
|
|
237
|
+
Perk: PerkPart,
|
|
238
|
+
Action,
|
|
239
|
+
Empty,
|
|
240
|
+
Error: ErrorPart,
|
|
241
|
+
SignInAgain
|
|
242
|
+
};
|
|
243
|
+
function useClaimToast(orderId, options) {
|
|
244
|
+
const claim = useClaimPoints(orderId, options);
|
|
245
|
+
const points = claim.pointsEarned;
|
|
246
|
+
return {
|
|
247
|
+
points,
|
|
248
|
+
message: points === void 0 ? void 0 : `You earned ${points.toLocaleString("en")} ${points === 1 ? "point" : "points"}`,
|
|
249
|
+
dismiss: claim.dismiss
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
var ClaimToast = /* @__PURE__ */ forwardRef(function ClaimToast2({ orderId, paid, durationMs = 6e3, ...props }, ref) {
|
|
253
|
+
const toast = useClaimToast(orderId, { paid });
|
|
254
|
+
const { message, dismiss } = toast;
|
|
255
|
+
useEffect(() => {
|
|
256
|
+
if (message === void 0) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const timer = setTimeout(dismiss, durationMs);
|
|
260
|
+
return () => clearTimeout(timer);
|
|
261
|
+
}, [message, durationMs]);
|
|
262
|
+
return message === void 0 ? null : part(
|
|
263
|
+
"div",
|
|
264
|
+
{ ...props, children: props.children ?? message },
|
|
265
|
+
{ message, points: toast.points, dismiss },
|
|
266
|
+
{ role: "status", "aria-live": "polite" },
|
|
267
|
+
ref
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
export {
|
|
271
|
+
ClaimToast,
|
|
272
|
+
Rewards,
|
|
273
|
+
rewardLabel,
|
|
274
|
+
rewardsErrorMessage,
|
|
275
|
+
useClaimToast,
|
|
276
|
+
usePerkLines,
|
|
277
|
+
useRewardsRow
|
|
278
|
+
};
|
|
279
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/loyalty/index.tsx"],
|
|
4
|
+
"mappings": ";;;AACA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,eAAe;AACxB,SAAS,eAAe,YAAY,YAAY,iBAAiB;AACjE,SAAS,YAA4B;AAwJjC;AAtJJ,IAAM,OAAO,CAAC,UACZ,MAAM,MAAM,cAAc,MAAM,QAAQ;AAOnC,SAAS,YAAY,QAA4B;AACtD,MAAI,OAAO,SAAS,aAAa;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY;AACrB,WAAO,GAAG,OAAO,MAAM,KAAK,OAAO,UAAU,CAAC,CAAC;AAAA,EACjD;AACA,SAAO,GAAG,OAAO,eAAe,CAAC;AACnC;AASO,SAAS,cAAc,UAAkC,CAAC,GAAG;AAClE,QAAM,OAAO,QAAQ;AACrB,QAAM,UAAU;AAAA,IACd,QAAQ,a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ACN,CAAC;",
|
|
5
|
+
"names": ["Points", "StoreCredit", "List", "PerkPart", "Action", "Empty", "ErrorPart", "SignInAgain", "ClaimToast"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { P as PartOwnedAttributes } from '../slot-CHfqzPTd.js';
|
|
2
|
+
import { PartProps } from '../index.js';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import { Money, Branch } from '@zappie/sdk';
|
|
6
|
+
import { CustomerOrder, Money as Money$1, CustomerClient, OrderTimelineStep, OrderLine, OrderPayment } from '@zappie/sdk/customer';
|
|
7
|
+
import { ReorderResult } from '@zappie/sdk/customer/reorder';
|
|
8
|
+
|
|
9
|
+
/** An order amount as SDK money, ready for `format.money` or `Money`. */
|
|
10
|
+
declare const orderMoney: (value: Money$1) => Money;
|
|
11
|
+
/** One row of an order's totals. */
|
|
12
|
+
type OrderTotalRow = {
|
|
13
|
+
kind: "subtotal" | "charge" | "delivery" | "discount" | "total" | "paid" | "due";
|
|
14
|
+
label: string;
|
|
15
|
+
/** Negative for a discount. Zero for a waived charge. */
|
|
16
|
+
amount: Money;
|
|
17
|
+
/** `included` when the prices already hold the charge, `waived` when the business waived it. */
|
|
18
|
+
note?: "included" | "waived";
|
|
19
|
+
/** The promo code the customer entered, on a discount that came with one. */
|
|
20
|
+
promoCode?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* An order's totals as rows: the subtotal, each charge, delivery, each discount, the total, then
|
|
24
|
+
* what was paid and what is still due. Included and waived charges add nothing, so the rows above
|
|
25
|
+
* the total add up to it. Voided lines are in no row.
|
|
26
|
+
*
|
|
27
|
+
* @param order - The order.
|
|
28
|
+
* @returns The rows, in the order to show them.
|
|
29
|
+
*/
|
|
30
|
+
declare function orderTotals(order: CustomerOrder): OrderTotalRow[];
|
|
31
|
+
/** Whether the order has ended: completed, cancelled or rejected. */
|
|
32
|
+
declare const orderEnded: (order: CustomerOrder) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The order's current step, as a title and a description to show. The last timeline step, or the
|
|
35
|
+
* status in words when the timeline is empty.
|
|
36
|
+
*/
|
|
37
|
+
declare function currentStep(order: CustomerOrder): {
|
|
38
|
+
title: string;
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A time on the order in words, such as "25 Nov, 14:05", in the branch's time zone so the server
|
|
43
|
+
* and the browser render the same text.
|
|
44
|
+
*/
|
|
45
|
+
declare function orderTime(iso: string, timeZone?: string): string;
|
|
46
|
+
|
|
47
|
+
/** Where reading an order stands. */
|
|
48
|
+
type CustomerOrderStatus = "loading" | "ready" | "not_found" | "error";
|
|
49
|
+
/** An order as `useCustomerOrder` reads and follows it. */
|
|
50
|
+
type CustomerOrderState = {
|
|
51
|
+
order: CustomerOrder | undefined;
|
|
52
|
+
status: CustomerOrderStatus;
|
|
53
|
+
/** The last read's failure, while `status` is `not_found` or `error`. */
|
|
54
|
+
error: unknown;
|
|
55
|
+
/** Read the order again after a failure. */
|
|
56
|
+
retry(): void;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Read a customer's order and follow it live until it ends. Each change replaces `order`, so the
|
|
60
|
+
* page updates in place. A 404 is `not_found`: the order is someone else's or doesn't exist.
|
|
61
|
+
*
|
|
62
|
+
* @param customer - The customer client.
|
|
63
|
+
* @param orderId - The order's id.
|
|
64
|
+
* @param options - An order the server already read, shown until the first read lands.
|
|
65
|
+
* @returns The order, where reading it stands, and `retry`.
|
|
66
|
+
*/
|
|
67
|
+
declare function useCustomerOrder(customer: CustomerClient, orderId: string, options?: {
|
|
68
|
+
initialOrder?: CustomerOrder;
|
|
69
|
+
}): CustomerOrderState;
|
|
70
|
+
|
|
71
|
+
/** What every order part reads from `Order.Root`. */
|
|
72
|
+
type OrderContext = CustomerOrderState & {
|
|
73
|
+
customer: CustomerClient;
|
|
74
|
+
/** The order's branch from the store, for its name, phone and time zone. */
|
|
75
|
+
branch: Branch | undefined;
|
|
76
|
+
/** The time zone the order's times show in: the branch's, else the store's. */
|
|
77
|
+
timeZone: string | undefined;
|
|
78
|
+
};
|
|
79
|
+
/** The order `Order.Root` shows, while it has one. Throws outside `Order.Root`. */
|
|
80
|
+
declare function useOrder(): CustomerOrder | undefined;
|
|
81
|
+
declare function Root({ customer, orderId, initialOrder, ...props }: PartProps<OrderContext> & {
|
|
82
|
+
customer: CustomerClient;
|
|
83
|
+
orderId: string;
|
|
84
|
+
/** An order the server already read, shown until the first read lands. */
|
|
85
|
+
initialOrder?: CustomerOrder;
|
|
86
|
+
}): react.JSX.Element;
|
|
87
|
+
/** The state `Order.Status` passes to a render function. */
|
|
88
|
+
type OrderStatusState = {
|
|
89
|
+
status: CustomerOrder["status"] | "loading" | "not_found" | "error";
|
|
90
|
+
title: string;
|
|
91
|
+
description: string;
|
|
92
|
+
};
|
|
93
|
+
/** The state `Order.Timeline` passes to a render function. */
|
|
94
|
+
type OrderTimelineState = {
|
|
95
|
+
steps: OrderTimelineStep[];
|
|
96
|
+
next: CustomerOrder["next_step"];
|
|
97
|
+
};
|
|
98
|
+
/** One fact about how the order reaches the customer. */
|
|
99
|
+
type OrderFulfilmentRow = {
|
|
100
|
+
kind: "type" | "address" | "note" | "scheduled" | "ready" | "eta" | "contact" | "branch";
|
|
101
|
+
label: string;
|
|
102
|
+
value: string;
|
|
103
|
+
};
|
|
104
|
+
/** What an order action's render function gets. */
|
|
105
|
+
type OrderActionState = {
|
|
106
|
+
busy: boolean;
|
|
107
|
+
/** The last failure, in the API's words. */
|
|
108
|
+
error: string | undefined;
|
|
109
|
+
};
|
|
110
|
+
/** What an Order again result says: what went in, and which items didn't. */
|
|
111
|
+
declare function reorderNotice(result: ReorderResult): string;
|
|
112
|
+
/**
|
|
113
|
+
* A customer's order, without styles. `Order.Root` reads it and follows it live, and the parts show
|
|
114
|
+
* it: the number, the status, the timeline, how it reaches the customer, the items, the totals, the
|
|
115
|
+
* payments and the actions. Style each part with your own tokens through its `data-*` attributes.
|
|
116
|
+
* Each part renders nothing until the order is read, except `Status`, which says it is loading.
|
|
117
|
+
*/
|
|
118
|
+
declare const Order: {
|
|
119
|
+
Root: typeof Root;
|
|
120
|
+
Reference: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
121
|
+
asChild?: boolean;
|
|
122
|
+
children?: ReactNode | ((state: {
|
|
123
|
+
reference: string;
|
|
124
|
+
}) => ReactNode);
|
|
125
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
126
|
+
Status: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
127
|
+
asChild?: boolean;
|
|
128
|
+
children?: ReactNode | ((state: OrderStatusState) => ReactNode);
|
|
129
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
130
|
+
Timeline: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
131
|
+
asChild?: boolean;
|
|
132
|
+
children?: ReactNode | ((state: OrderTimelineState) => ReactNode);
|
|
133
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
134
|
+
Fulfilment: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
135
|
+
asChild?: boolean;
|
|
136
|
+
children?: ReactNode | ((state: {
|
|
137
|
+
rows: OrderFulfilmentRow[];
|
|
138
|
+
branch: Branch | undefined;
|
|
139
|
+
}) => ReactNode);
|
|
140
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
141
|
+
Lines: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
142
|
+
asChild?: boolean;
|
|
143
|
+
children?: ReactNode | ((state: {
|
|
144
|
+
lines: OrderLine[];
|
|
145
|
+
voided: OrderLine[];
|
|
146
|
+
}) => ReactNode);
|
|
147
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
148
|
+
Totals: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
149
|
+
asChild?: boolean;
|
|
150
|
+
children?: ReactNode | ((state: {
|
|
151
|
+
rows: OrderTotalRow[];
|
|
152
|
+
}) => ReactNode);
|
|
153
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
154
|
+
Payments: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
155
|
+
asChild?: boolean;
|
|
156
|
+
children?: ReactNode | ((state: {
|
|
157
|
+
payments: OrderPayment[];
|
|
158
|
+
}) => ReactNode);
|
|
159
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
160
|
+
Actions: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
161
|
+
asChild?: boolean;
|
|
162
|
+
children?: ReactNode | ((state: Record<string, never>) => ReactNode);
|
|
163
|
+
} & {
|
|
164
|
+
/** Claim the order's loyalty points once it is paid. Pass it where the site has loyalty. */
|
|
165
|
+
loyalty?: boolean;
|
|
166
|
+
onReorder?: (result: ReorderResult) => void;
|
|
167
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
168
|
+
Receipt: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
169
|
+
asChild?: boolean;
|
|
170
|
+
children?: ReactNode | ((state: {
|
|
171
|
+
shared: boolean;
|
|
172
|
+
}) => ReactNode);
|
|
173
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
174
|
+
PayBalance: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
175
|
+
asChild?: boolean;
|
|
176
|
+
children?: ReactNode | ((state: OrderActionState) => ReactNode);
|
|
177
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
178
|
+
OrderAgain: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
|
|
179
|
+
asChild?: boolean;
|
|
180
|
+
children?: ReactNode | ((state: OrderActionState & {
|
|
181
|
+
result: ReorderResult | undefined;
|
|
182
|
+
}) => ReactNode);
|
|
183
|
+
} & {
|
|
184
|
+
onReorder?: (result: ReorderResult) => void;
|
|
185
|
+
} & react.RefAttributes<HTMLElement>>;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Every order part in one default layout: the number and status, the timeline, the fulfilment, the
|
|
189
|
+
* items, the totals, the payments and the actions. Pass `loyalty` where the site has it.
|
|
190
|
+
*/
|
|
191
|
+
declare function OrderDetails({ customer, orderId, initialOrder, loyalty, onReorder, ...props }: PartProps<OrderContext> & {
|
|
192
|
+
customer: CustomerClient;
|
|
193
|
+
orderId: string;
|
|
194
|
+
initialOrder?: CustomerOrder;
|
|
195
|
+
loyalty?: boolean;
|
|
196
|
+
onReorder?: (result: ReorderResult) => void;
|
|
197
|
+
}): react.JSX.Element;
|
|
198
|
+
|
|
199
|
+
export { Order, OrderDetails, currentStep, orderEnded, orderMoney, orderTime, orderTotals, reorderNotice, useCustomerOrder, useOrder };
|
|
200
|
+
export type { CustomerOrderState, CustomerOrderStatus, OrderActionState, OrderContext, OrderFulfilmentRow, OrderStatusState, OrderTimelineState, OrderTotalRow };
|