bitsnap-react 1.6.0 → 1.6.1
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 +321 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -210,6 +210,326 @@ conflicting Tailwind utilities from the library are resolved in your favor.
|
|
|
210
210
|
focus ring and stacking) as soon as you pass an `appearance`; without one it
|
|
211
211
|
renders exactly as before.
|
|
212
212
|
|
|
213
|
+
## Returns
|
|
214
|
+
|
|
215
|
+
`BitsnapReturns` is the customer return flow: email, verification code, orders,
|
|
216
|
+
line and quantity selection, confirmation, result, plus a list of earlier returns
|
|
217
|
+
with their status. The views are themeable from the start, with the same
|
|
218
|
+
`appearance` shape as the checkout. It needs the same stylesheet
|
|
219
|
+
(`bitsnap-react/dist/index.css`).
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
import { BitsnapReturns } from "bitsnap-react";
|
|
223
|
+
import "bitsnap-react/dist/index.css";
|
|
224
|
+
|
|
225
|
+
function ReturnsPage() {
|
|
226
|
+
return <BitsnapReturns projectID="your-project-id" />;
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
It is an inline page section, not an overlay, and it is safe to render on the
|
|
231
|
+
server.
|
|
232
|
+
|
|
233
|
+
**Upgrading from 1.6.0.** 1.6.0 code keeps working without changes, imported
|
|
234
|
+
from `bitsnap-react` or `bitsnap-react/returns`. Both paths now export this
|
|
235
|
+
implementation.
|
|
236
|
+
- **`BitsnapReturns` props:** it still accepts the `Environment` enum, `theme.brandColor` (prefer `appearance.tokens`) and the old text keys (`title`, `email`, `sendCode`, `code`, `verify`, `orders`, `submit`, `note`, `loading`, `history`).
|
|
237
|
+
- **Provider:** `BitsnapReturnsProvider` is an alias of `ReturnsProvider`.
|
|
238
|
+
- **Hooks:** they accept both the 1.6.0 calls (`useReturnOrders(pageSize, pageToken)`, `useMyReturns(pageSize, pageToken)`) and the new object form. Their results include the 1.6.0 fields (`data`, `mutateAsync`, `startSession`, `verifySession`, `starting`, `verifying`) next to the new ones.
|
|
239
|
+
- **Visual change:** the widget now uses the new themed views.
|
|
240
|
+
- **Wording:** without `texts`, the wording follows the library locale (`setLocale`). 1.6.0 was always English.
|
|
241
|
+
|
|
242
|
+
| Prop | Meaning |
|
|
243
|
+
| ------------------- | -------------------------------------------------------------------------- |
|
|
244
|
+
| `projectID` | Bitsnap project ID |
|
|
245
|
+
| `host` | API host. Falls back to `setCustomHost`, then `https://bitsnap.pl` |
|
|
246
|
+
| `environment` | `"production"` (default) or `"test"` |
|
|
247
|
+
| `appearance` | `{ theme, tokens, elements }`, see below |
|
|
248
|
+
| `texts` | Partial text overrides, see [Texts](#texts) |
|
|
249
|
+
| `locale` | Locale of texts, dates and money. Defaults to `getLocale()` |
|
|
250
|
+
| `panelAccessToken` | Customer panel token; skips email and code, see [Panel](#returns-in-the-customer-panel) |
|
|
251
|
+
| `className` | Class of the themed root element |
|
|
252
|
+
|
|
253
|
+
The session token lives in React state and `sessionStorage` (one key per project),
|
|
254
|
+
never in `localStorage`, and is never logged. An expired session returns the flow
|
|
255
|
+
to the email step.
|
|
256
|
+
|
|
257
|
+
### Shared brand
|
|
258
|
+
|
|
259
|
+
One object can style the checkout and the returns views:
|
|
260
|
+
|
|
261
|
+
```tsx
|
|
262
|
+
import { BitsnapCheckout, BitsnapReturns } from "bitsnap-react";
|
|
263
|
+
|
|
264
|
+
const brand = {
|
|
265
|
+
theme: "light",
|
|
266
|
+
tokens: {
|
|
267
|
+
fontFamily: '"Inter", sans-serif',
|
|
268
|
+
buttonBackground: "#635bff",
|
|
269
|
+
buttonForeground: "#ffffff",
|
|
270
|
+
radius: "12px",
|
|
271
|
+
},
|
|
272
|
+
} as const;
|
|
273
|
+
|
|
274
|
+
<BitsnapCheckout projectID="your-project-id" appearance={brand} />
|
|
275
|
+
<BitsnapReturns
|
|
276
|
+
projectID="your-project-id"
|
|
277
|
+
appearance={{
|
|
278
|
+
...brand,
|
|
279
|
+
elements: {
|
|
280
|
+
title: { style: { fontFamily: '"Georgia", serif' } },
|
|
281
|
+
submitButton: { className: "store-primary-button" },
|
|
282
|
+
},
|
|
283
|
+
}}
|
|
284
|
+
/>
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
`theme` is `"light"` or `"dark"`. The default for returns is `"light"`; the
|
|
288
|
+
checkout keeps its `"dark"` default. `elements` take `{ className, style }`,
|
|
289
|
+
merged after the built-in classes and styles, exactly like the checkout slots.
|
|
290
|
+
|
|
291
|
+
### Return tokens
|
|
292
|
+
|
|
293
|
+
The returns views use the checkout tokens, plus five more. `overlay` is
|
|
294
|
+
checkout-only and ignored by returns.
|
|
295
|
+
|
|
296
|
+
| Token | Applies to | Returns only |
|
|
297
|
+
| ------------------------- | ---------------------------------------------------------- | ------------ |
|
|
298
|
+
| `fontFamily`, `fontSize` | All returns views | |
|
|
299
|
+
| `background` | Page background | |
|
|
300
|
+
| `surface` | Cards, summaries, loading skeletons | |
|
|
301
|
+
| `foreground` | Titles, names, amounts | |
|
|
302
|
+
| `mutedForeground` | Descriptions, dates, hints | |
|
|
303
|
+
| `border` | Cards, inputs, separators | |
|
|
304
|
+
| `buttonBackground` | Primary buttons | |
|
|
305
|
+
| `buttonForeground` | Primary buttons | |
|
|
306
|
+
| `buttonHoverBackground` | Primary buttons on hover | |
|
|
307
|
+
| `hoverSurface` | Secondary buttons, selectable cards | |
|
|
308
|
+
| `focusRing` | Focus rings | |
|
|
309
|
+
| `error` | Error messages | |
|
|
310
|
+
| `radius` | Rounded elements | |
|
|
311
|
+
| `success` | Result screen, completed and refunded statuses | yes |
|
|
312
|
+
| `warning` | Statuses that need attention | yes |
|
|
313
|
+
| `badgeBackground` | Status badges | yes |
|
|
314
|
+
| `badgeForeground` | Status badges | yes |
|
|
315
|
+
| `inputBackground` | Text inputs and the note field | yes |
|
|
316
|
+
|
|
317
|
+
### Return slots
|
|
318
|
+
|
|
319
|
+
Slots are exported as `RETURNS_SLOT_NAMES` and rendered as
|
|
320
|
+
`data-bitsnap-returns-slot` attributes.
|
|
321
|
+
|
|
322
|
+
| Group | Slots |
|
|
323
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
324
|
+
| Frame | `root`, `header`, `title`, `description`, `backButton`, `stepIndicator`, `error`, `emptyState`, `skeleton` |
|
|
325
|
+
| Auth | `emailForm`, `emailInput`, `codeForm`, `codeInput`, `resendButton`, `logoutButton` |
|
|
326
|
+
| Orders | `orderList`, `orderCard`, `orderReference`, `orderDate`, `orderTotal`, `pagination` |
|
|
327
|
+
| Selection | `lineList`, `line`, `lineName`, `linePrice`, `lineQuantityControl`, `quantityButton`, `quantityInput`, `lineIneligibleReason`, `noteInput` |
|
|
328
|
+
| Confirmation and result | `summary`, `submitButton`, `secondaryButton`, `successState`, `returnReference`, `returnInstructions` |
|
|
329
|
+
| My returns | `returnList`, `returnCard`, `statusBadge`, `history`, `historyEntry` |
|
|
330
|
+
|
|
331
|
+
### Texts
|
|
332
|
+
|
|
333
|
+
Both `BitsnapCheckout` and `BitsnapReturns` accept a `texts` prop: a partial
|
|
334
|
+
object that overrides the default strings whatever the locale. Without it the
|
|
335
|
+
strings are unchanged, and `setLocale`/`getLocale` keep working. For different
|
|
336
|
+
copy per language, pass a different object.
|
|
337
|
+
|
|
338
|
+
```tsx
|
|
339
|
+
<BitsnapCheckout
|
|
340
|
+
projectID="your-project-id"
|
|
341
|
+
texts={{ cart: "Your basket", nextStep: "Pay now" }}
|
|
342
|
+
/>
|
|
343
|
+
|
|
344
|
+
<BitsnapReturns
|
|
345
|
+
projectID="your-project-id"
|
|
346
|
+
locale="en"
|
|
347
|
+
texts={{
|
|
348
|
+
emailStepTitle: "Return a product",
|
|
349
|
+
successDescription: "We'll email you once it arrives.",
|
|
350
|
+
statusAwaitingReceipt: "On its way to us",
|
|
351
|
+
}}
|
|
352
|
+
/>
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Checkout keys (`CheckoutTexts`): `cart`, `emptyCart`, `total`, `delivery`,
|
|
356
|
+
`chooseCountry`, `nextStep`, `unavailableProducts`.
|
|
357
|
+
|
|
358
|
+
Returns keys (`ReturnsTexts`) cover each step (`emailStepTitle`,
|
|
359
|
+
`codeStepDescription`, `ordersEmpty`, `confirmationSubmit`, `successTitle`,
|
|
360
|
+
`myReturnsTitle`, ...), the request statuses (`statusSubmitted`,
|
|
361
|
+
`statusApproved`, `statusAwaitingReceipt`, `statusReceived`, `statusRefunded`,
|
|
362
|
+
`statusFallback`, ...) and the error messages (`errorGeneric`,
|
|
363
|
+
`errorInvalidCode`, `errorSessionExpired`, ...). Strings with placeholders such
|
|
364
|
+
as `{reference}` or `{count}` keep them in overrides. See `ReturnsTexts` and
|
|
365
|
+
`CheckoutTexts` in the type declarations for the full list and the placeholders.
|
|
366
|
+
|
|
367
|
+
### Custom layout
|
|
368
|
+
|
|
369
|
+
Compose your own page from the step components under `ReturnsProvider`. The
|
|
370
|
+
provider holds the session, appearance, texts and the transport, and renders the
|
|
371
|
+
themed root. Each step takes small navigation callbacks and the IDs it needs, and
|
|
372
|
+
throws a clear error when rendered outside the provider.
|
|
373
|
+
|
|
374
|
+
```tsx
|
|
375
|
+
import {
|
|
376
|
+
ReturnsConfirmation,
|
|
377
|
+
ReturnsEmailStep,
|
|
378
|
+
ReturnsCodeStep,
|
|
379
|
+
ReturnsOrderDetail,
|
|
380
|
+
ReturnsOrderList,
|
|
381
|
+
ReturnsProvider,
|
|
382
|
+
ReturnsResult,
|
|
383
|
+
useReturnSession,
|
|
384
|
+
type SelectedReturnLine,
|
|
385
|
+
} from "bitsnap-react";
|
|
386
|
+
|
|
387
|
+
function Flow() {
|
|
388
|
+
const { isAuthenticated } = useReturnSession();
|
|
389
|
+
const [step, setStep] = useState<"email" | "code" | "orders" | "order" | "confirm" | "done">("email");
|
|
390
|
+
const [orderId, setOrderId] = useState("");
|
|
391
|
+
const [items, setItems] = useState<SelectedReturnLine[]>([]);
|
|
392
|
+
const [note, setNote] = useState("");
|
|
393
|
+
const [returnId, setReturnId] = useState("");
|
|
394
|
+
|
|
395
|
+
if (!isAuthenticated) {
|
|
396
|
+
return step === "code" ? (
|
|
397
|
+
<ReturnsCodeStep onBack={() => setStep("email")} />
|
|
398
|
+
) : (
|
|
399
|
+
<ReturnsEmailStep onSubmitted={() => setStep("code")} />
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
if (step === "order") {
|
|
403
|
+
return (
|
|
404
|
+
<ReturnsOrderDetail
|
|
405
|
+
orderId={orderId}
|
|
406
|
+
initialItems={items}
|
|
407
|
+
initialNote={note}
|
|
408
|
+
onBack={() => setStep("orders")}
|
|
409
|
+
onContinue={(selection) => {
|
|
410
|
+
setItems(selection.items);
|
|
411
|
+
setNote(selection.note);
|
|
412
|
+
setStep("confirm");
|
|
413
|
+
}}
|
|
414
|
+
/>
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
if (step === "confirm") {
|
|
418
|
+
return (
|
|
419
|
+
<ReturnsConfirmation
|
|
420
|
+
orderId={orderId}
|
|
421
|
+
items={items}
|
|
422
|
+
note={note}
|
|
423
|
+
onBack={() => setStep("order")}
|
|
424
|
+
onSubmitted={(id) => {
|
|
425
|
+
setReturnId(id);
|
|
426
|
+
setStep("done");
|
|
427
|
+
}}
|
|
428
|
+
/>
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
if (step === "done") {
|
|
432
|
+
return <ReturnsResult returnId={returnId} onContinue={() => setStep("orders")} />;
|
|
433
|
+
}
|
|
434
|
+
return (
|
|
435
|
+
<ReturnsOrderList
|
|
436
|
+
onSelectOrder={(id) => {
|
|
437
|
+
setOrderId(id);
|
|
438
|
+
setStep("order");
|
|
439
|
+
}}
|
|
440
|
+
/>
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
<ReturnsProvider projectID="your-project-id" appearance={brand}>
|
|
445
|
+
<Flow />
|
|
446
|
+
</ReturnsProvider>;
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
Available steps: `ReturnsEmailStep`, `ReturnsCodeStep`, `ReturnsOrderList`
|
|
450
|
+
(`onSelectOrder`, `onOpenMyReturns`, `showLogout`), `ReturnsOrderDetail`,
|
|
451
|
+
`ReturnsConfirmation`, `ReturnsResult`, `ReturnsMyReturnsList` and
|
|
452
|
+
`ReturnsMyReturnDetail`. Each accepts its own `className`. A session left in
|
|
453
|
+
`sessionStorage` is picked up on the next visit, so `useReturnSession().status`
|
|
454
|
+
is `"hydrating"` until the provider has read it on the client.
|
|
455
|
+
|
|
456
|
+
### Headless hooks
|
|
457
|
+
|
|
458
|
+
To build the markup yourself, use the hooks under `ReturnsProvider`: they return
|
|
459
|
+
data, loading and error state, and actions, and no markup.
|
|
460
|
+
|
|
461
|
+
| Hook | Returns |
|
|
462
|
+
| ---------------------------- | ----------------------------------------------------------------------- |
|
|
463
|
+
| `useReturnSession()` | `status`, `isAuthenticated`, `start(email)`, `verify(code)`, `resend()`, `logout()`, `error` |
|
|
464
|
+
| `useReturnOrders(options?)` | Paged returnable `orders`, `total`, `next()`, `previous()`, `refetch()` |
|
|
465
|
+
| `useReturnableOrder(id)` | `order` with per-line eligibility, `returnHistory` |
|
|
466
|
+
| `useCreateReturn()` | `submit({ orderId, items, note })`; retries reuse one idempotency key |
|
|
467
|
+
| `useMyReturns(options?)` | Paged earlier returns |
|
|
468
|
+
| `useMyReturn(id)` | One return with its status and history |
|
|
469
|
+
|
|
470
|
+
```tsx
|
|
471
|
+
function Orders() {
|
|
472
|
+
const { orders, isLoading, errorKey } = useReturnOrders();
|
|
473
|
+
if (isLoading) return null;
|
|
474
|
+
return <ul>{orders.map((order) => <li key={order.canonicalOrderId}>{order.displayReference}</li>)}</ul>;
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
A request that fails with `SESSION_EXPIRED` drops the session, so
|
|
479
|
+
`useReturnSession().status` becomes `"anonymous"`.
|
|
480
|
+
|
|
481
|
+
### CSS only
|
|
482
|
+
|
|
483
|
+
Everything is also addressable without props. The root carries
|
|
484
|
+
`data-bitsnap-returns` and the theme class (`light` or `dark`), and every slot
|
|
485
|
+
carries `data-bitsnap-returns-slot`. The library rules sit in `@layer components`,
|
|
486
|
+
so ordinary stylesheets win:
|
|
487
|
+
|
|
488
|
+
```css
|
|
489
|
+
/* the theme is applied as inline custom properties, so overrides need !important */
|
|
490
|
+
[data-bitsnap-returns] {
|
|
491
|
+
--bitsnap-returns-button-background: #635bff !important;
|
|
492
|
+
--bitsnap-returns-radius: 12px !important;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
[data-bitsnap-returns-slot="orderCard"]:hover {
|
|
496
|
+
border-color: #635bff;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
[data-bitsnap-returns-slot="line"][data-ineligible] {
|
|
500
|
+
opacity: 0.5;
|
|
501
|
+
}
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
Token variables are named `--bitsnap-returns-<token in kebab case>`, for example
|
|
505
|
+
`--bitsnap-returns-muted-foreground`.
|
|
506
|
+
|
|
507
|
+
### Returns in the customer panel
|
|
508
|
+
|
|
509
|
+
The `Panel` has a Returns screen (`/panel?state=returns`, with `orderId` and
|
|
510
|
+
`returnId` in the URL for the selected order and return). It is built from the
|
|
511
|
+
step components above and reuses the panel login: the panel access token is
|
|
512
|
+
exchanged for a returns session, so the customer sees their orders with no
|
|
513
|
+
second code, and there is no email, code or logout step. When the panel session
|
|
514
|
+
has expired, the customer is sent to the panel login.
|
|
515
|
+
|
|
516
|
+
```tsx
|
|
517
|
+
<Panel
|
|
518
|
+
returnsAppearance={{ theme: "light", tokens: { buttonBackground: "#635bff" } }}
|
|
519
|
+
returnsTexts={{ ordersTitle: "Choose an order to return" }}
|
|
520
|
+
/>
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
| Prop | Meaning |
|
|
524
|
+
| ------------------- | ------------------------------------------------------------------------------- |
|
|
525
|
+
| `returnsAppearance` | `ReturnsAppearance` of the screen |
|
|
526
|
+
| `returnsTexts` | `Partial<ReturnsTexts>` of the screen |
|
|
527
|
+
|
|
528
|
+
Without `returnsAppearance`, `buttonBackground` and `focusRing` come from the
|
|
529
|
+
panel's `theme.colors.brand` (set with `setTheme`) and `buttonForeground` is
|
|
530
|
+
chosen for contrast. Other panel screens and `setTheme` are unchanged. The
|
|
531
|
+
navigation label follows `setLocale` ("Zwroty" / "Returns").
|
|
532
|
+
|
|
213
533
|
# Examples
|
|
214
534
|
|
|
215
535
|
1. `BitsnapCheckout` Component:
|
|
@@ -603,6 +923,7 @@ The panel provides the following screens:
|
|
|
603
923
|
| Profile | `/panel?state=profile` | User profile and settings |
|
|
604
924
|
| Notifications | `/panel?state=notifications` | Notification preferences |
|
|
605
925
|
| Plans | `/panel?state=plans` | Subscription management |
|
|
926
|
+
| Returns | `/panel?state=returns` | Return products, track returns |
|
|
606
927
|
|
|
607
928
|
## Features Detail
|
|
608
929
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bitsnap-react",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "This is Bitsnap React library for easy integration with any website which is using React framework",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"clean": "rimraf ./dist",
|
|
13
13
|
"dev": "tsup --watch",
|
|
14
14
|
"dev:publish": "pnpm dev --env.publish",
|
|
15
|
-
"test": "tsup src/components/checkout/appearance.test.ts --format esm --out-dir .test-dist --no-config --silent && node --test \".test-dist/**/*.test.mjs\"",
|
|
15
|
+
"test": "tsup src/components/checkout/appearance.test.ts src/components/checkout/texts.test.ts src/lib/appearance-core.test.ts src/lib/texts.test.ts src/components/returns/appearance.test.ts src/components/returns/texts.test.ts src/components/returns/errors.test.ts src/components/returns/money.test.ts src/components/returns/session-storage.test.ts src/components/returns/state-machine.test.ts src/components/returns/selection.test.ts src/components/returns/legacy.test.ts src/panel/returns-appearance.test.ts --format esm --out-dir .test-dist --no-config --silent && node --test \".test-dist/**/*.test.mjs\"",
|
|
16
16
|
"test:types": "tsc -p test/consumer/tsconfig.json",
|
|
17
17
|
"test:package": "node test/consumer/verify-package.mjs"
|
|
18
18
|
},
|