@swift-food-services/catering-widget 0.1.0-beta.3 → 0.1.0-beta.4
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/README.md +32 -8
- package/dist/index.cjs +337 -196
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +338 -197
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -16,7 +16,10 @@ export default function CateringPage() {
|
|
|
16
16
|
return (
|
|
17
17
|
<CateringWidget
|
|
18
18
|
publishableKey="pk_live_..."
|
|
19
|
+
googleMapsApiKey="AIzaSy..."
|
|
19
20
|
onOrderComplete={({ orderId }) => {
|
|
21
|
+
// Fires after the success-screen countdown (default 15s,
|
|
22
|
+
// configurable via `onOrderCompleteDelaySeconds`).
|
|
20
23
|
window.location.href = `/thanks?order=${orderId}`;
|
|
21
24
|
}}
|
|
22
25
|
/>
|
|
@@ -37,11 +40,13 @@ Defaults: Swift-hosted backend, `localStorage` persistence, neutral theme.
|
|
|
37
40
|
| Prop | Type | Required | Description |
|
|
38
41
|
|---|---|---|---|
|
|
39
42
|
| `publishableKey` | `string` | yes | Your `pk_live_...` or `pk_test_...` key from Swift. |
|
|
43
|
+
| `googleMapsApiKey` | `string` | yes | Google Maps JavaScript API key with the Places library enabled. Used by the address-autocomplete field. |
|
|
40
44
|
| `theme` | `Theme` | no | Primary color, border radius, and font overrides. |
|
|
41
45
|
| `initialData` | `InitialData` | no | Pre-populate event, address, and contact fields. Applied only on first mount. |
|
|
42
46
|
| `stickyTopOffset` | `number` | no | Pixels to offset the widget's internal sticky date/session nav from the top of the viewport. Set this to the height of any sticky/fixed navbar in your host layout so the widget's nav doesn't slide underneath it. Defaults to `0`. |
|
|
43
47
|
| `onReady` | `() => void` | no | Fires when the widget has initialized. |
|
|
44
|
-
| `onOrderComplete` | `(result: OrderCompleteResult) => void` | no | Fires after a successful order submission. |
|
|
48
|
+
| `onOrderComplete` | `(result: OrderCompleteResult) => void` | no | Fires after a successful order submission. See [`onOrderComplete` behaviour](#onordercompleteresult) for the timing. |
|
|
49
|
+
| `onOrderCompleteDelaySeconds` | `number` | no | Seconds to keep the success screen visible before firing `onOrderComplete`. Defaults to `15`. Ignored if `onOrderComplete` is not provided. |
|
|
45
50
|
| `onError` | `(error: WidgetError) => void` | no | Fires on unrecoverable errors (bad key, network, submit failure). |
|
|
46
51
|
|
|
47
52
|
## Examples
|
|
@@ -58,7 +63,8 @@ export default function Page() {
|
|
|
58
63
|
const router = useRouter();
|
|
59
64
|
return (
|
|
60
65
|
<CateringWidget
|
|
61
|
-
publishableKey={process.env.
|
|
66
|
+
publishableKey={process.env.NEXT_PUBLIC_SWIFT_PUBLISHABLE_KEY!}
|
|
67
|
+
googleMapsApiKey={process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY!}
|
|
62
68
|
onOrderComplete={({ orderId, accessToken }) => {
|
|
63
69
|
router.push(`/orders/${orderId}?token=${accessToken}`);
|
|
64
70
|
}}
|
|
@@ -94,6 +100,8 @@ export default function Page() {
|
|
|
94
100
|
line1: "1 Example Lane",
|
|
95
101
|
city: "London",
|
|
96
102
|
postcode: "E1 6AN",
|
|
103
|
+
lat: 51.5074,
|
|
104
|
+
lng: -0.1278,
|
|
97
105
|
},
|
|
98
106
|
contact: { name: "Alice", email: "alice@example.com" },
|
|
99
107
|
}}
|
|
@@ -103,6 +111,8 @@ export default function Page() {
|
|
|
103
111
|
|
|
104
112
|
Every field in `initialData` is optional. Fields remain editable after pre-fill. `initialData` is only applied on first mount — if the user has a half-finished order in progress (persisted in `localStorage`), the persisted state wins.
|
|
105
113
|
|
|
114
|
+
**Address requires `lat` and `lng`.** Delivery pricing depends on coordinates, so if you pass a `deliveryAddress` without both `lat` and `lng`, the widget ignores the entire address (no fields are pre-filled) and the guest is asked to pick one via the address-autocomplete field instead. The other `initialData` fields (event date/time, guest count, contact) still apply.
|
|
115
|
+
|
|
106
116
|
### Offsetting below a host navbar
|
|
107
117
|
|
|
108
118
|
If your page has its own sticky/fixed navbar, pass its height as `stickyTopOffset` so the widget's internal date/session nav pins just below it:
|
|
@@ -138,12 +148,29 @@ See the generated `dist/index.d.ts` for the full shapes — your IDE picks them
|
|
|
138
148
|
|
|
139
149
|
### `onOrderComplete(result)`
|
|
140
150
|
|
|
141
|
-
Fires
|
|
151
|
+
Fires after a successful order submission. `result` contains:
|
|
142
152
|
|
|
143
153
|
- `orderId: string` — Swift's order ID.
|
|
144
154
|
- `accessToken: string` — a token the customer can use to view the order on Swift's hosted view page.
|
|
145
155
|
- `summary: OrderSummary` — structured breakdown of the submitted order.
|
|
146
156
|
|
|
157
|
+
**Timing.** When `onOrderComplete` is wired, the widget shows its built-in success screen with a "Continuing in N seconds…" countdown for `onOrderCompleteDelaySeconds` seconds (default `15`), then fires the callback. This gives the guest a moment to read the confirmation before the host navigates away. A "Continue now" button under the countdown lets the guest skip the wait — clicking it cancels the timer and fires `onOrderComplete` immediately.
|
|
158
|
+
|
|
159
|
+
If `onOrderComplete` is **not** wired, the success screen stays up indefinitely. The success screen shows the event, customer, and pricing summary, and any navigation is the host's responsibility (do it from `onOrderComplete`).
|
|
160
|
+
|
|
161
|
+
**Heads up:** the widget does not navigate on its own. If your `onOrderComplete` runs without triggering a navigation (e.g. you only fire analytics or close a modal), the guest will stay on the widget's order-confirmation page even after the callback fires. To send them elsewhere, do it from inside `onOrderComplete` — `router.push(...)`, `window.location.href = ...`, hide the widget from your layout, etc.
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
<CateringWidget
|
|
165
|
+
publishableKey="pk_live_..."
|
|
166
|
+
googleMapsApiKey="AIzaSy..."
|
|
167
|
+
onOrderCompleteDelaySeconds={5}
|
|
168
|
+
onOrderComplete={({ orderId, accessToken }) => {
|
|
169
|
+
router.push(`/orders/${orderId}?token=${accessToken}`);
|
|
170
|
+
}}
|
|
171
|
+
/>
|
|
172
|
+
```
|
|
173
|
+
|
|
147
174
|
### `onError(error)`
|
|
148
175
|
|
|
149
176
|
Fires on errors the widget can't recover from. `error.code` is one of:
|
|
@@ -168,6 +195,7 @@ Fires on errors the widget can't recover from. `error.code` is one of:
|
|
|
168
195
|
|
|
169
196
|
- Getting a publishable key from Swift.
|
|
170
197
|
- Registering your site's origin(s) with Swift.
|
|
198
|
+
- Providing a Google Maps JavaScript API key (with the Places library enabled) via the `googleMapsApiKey` prop. Restrict the key to your own domain(s) in the Google Cloud Console.
|
|
171
199
|
- Rendering `<CateringWidget>` wherever you want the flow to live.
|
|
172
200
|
- Navigating after `onOrderComplete`.
|
|
173
201
|
- Page chrome around the widget.
|
|
@@ -175,14 +203,10 @@ Fires on errors the widget can't recover from. `error.code` is one of:
|
|
|
175
203
|
## What you're **not** responsible for
|
|
176
204
|
|
|
177
205
|
- Payment. Swift sends a payment link by email after reviewing the order.
|
|
178
|
-
- Loading Google Maps — the widget
|
|
206
|
+
- Loading the Google Maps script — the widget injects the script using the key you provide.
|
|
179
207
|
- Making API calls to Swift.
|
|
180
208
|
- Session or auth management.
|
|
181
209
|
|
|
182
|
-
## Build-time configuration
|
|
183
|
-
|
|
184
|
-
Set `SWIFT_WIDGET_GOOGLE_MAPS_KEY` before building the library so the Maps script loads with the correct key. CI publishes with the production key; local development can use a restricted dev key.
|
|
185
|
-
|
|
186
210
|
## Getting a publishable key
|
|
187
211
|
|
|
188
212
|
Contact Swift at [partners@swiftfood.uk](mailto:partners@swiftfood.uk) with:
|