@zappie/foundations 0.5.0 → 0.7.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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # @zappie/foundations
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4f55e71: `Schedule` tells loading and failed hours apart from a closed branch. While the branch's menu hours load or after they fail, `days` and `slots` are empty and `canAsap` is false, which looked the same as a closed branch, so a site could say the branch wasn't taking orders while it was open.
8
+
9
+ `ScheduleState` adds `status` (`"loading"`, `"error"` or `"ready"`), `retry()`, which loads the hours again after an error, and `isClosed`, true only when the hours are known and nothing can be ordered. Show a loading or error state until `status` is `"ready"`, and say the branch is closed only when `isClosed` is true. The `Schedule` element adds `data-status`, sets `aria-busy` while loading and sets `data-invalid` only once the hours are known. `ScheduleStatus` is exported.
10
+
11
+ The kit's and the starter's schedule picker (registry item `schedule-picker` 1.1.0, which requires `@zappie/foundations` ^0.7.0) show "Checking opening hours…" while loading, "Couldn’t load opening hours." with a "Try again" button after an error, and "<branch> isn’t taking orders right now." when the branch is closed.
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [97d7e6a]
16
+ - @zappie/sdk@0.7.0
17
+
18
+ ## 0.6.0
19
+
20
+ ### Minor Changes
21
+
22
+ - 9893d0c: Breaking: the site account client is removed. It was deprecated in the previous release because the shopper's Zappie account lives on the accounts portal and the API no longer serves its routes. Both packages take a minor bump because they are below 1.0.
23
+
24
+ `@zappie/sdk/account` no longer exports `createAccount`, `AccountClient`, `ScopeRequiredError`, `NotFoundError` or the account types. `@zappie/sdk/testing` no longer exports `mockAccountFetch`, `accountFixtures`, `MockAccountFixtures` or `MockAccountOptions`. The `@zappie/foundations/account` entry is removed with every part in it.
25
+
26
+ To link to the shopper's account, add `ZappieAccountLink` from `@zappie/foundations`, or build the address with `useZappieAccountUrl()`, `zappieAccountUrl(page)` or `accountsUrl()` from `@zappie/sdk/account`. These stay as they are.
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [9893d0c]
31
+ - Updated dependencies [546e44c]
32
+ - Updated dependencies [490c672]
33
+ - @zappie/sdk@0.6.0
34
+
3
35
  ## 0.5.0
4
36
 
5
37
  ### Minor Changes
package/README.md CHANGED
@@ -31,12 +31,11 @@ Want ready-made, styled components instead? Copy them into your project from the
31
31
 
32
32
  ## Entry points
33
33
 
34
- | Import | For |
35
- | ------------------------------- | ------------------------------------------------------------------------------ |
36
- | `@zappie/foundations` | Every part |
37
- | `@zappie/foundations/account` | Deprecated, removed in the next minor release. Add `ZappieAccountLink` instead |
38
- | `@zappie/foundations/next` | Keeping overlays in step with Back and Forward in a Next.js app |
39
- | `@zappie/foundations/rich-text` | Sanitising and parsing merchant rich text before you render it |
34
+ | Import | For |
35
+ | ------------------------------- | --------------------------------------------------------------- |
36
+ | `@zappie/foundations` | Every part |
37
+ | `@zappie/foundations/next` | Keeping overlays in step with Back and Forward in a Next.js app |
38
+ | `@zappie/foundations/rich-text` | Sanitising and parsing merchant rich text before you render it |
40
39
 
41
40
  ## Docs
42
41
 
@@ -0,0 +1,61 @@
1
+ import * as react from 'react';
2
+ import { AllHTMLAttributes, ReactNode, Ref } from 'react';
3
+ import { Dialog } from '@base-ui/react/dialog';
4
+
5
+ type PartOwnedAttributes = "children" | "defaultValue" | "value";
6
+ /**
7
+ * HTML attributes shared by foundation parts, with optional render-function children.
8
+ * Set asChild to merge the part props and ref into a single child element.
9
+ */
10
+ type PartProps<S = Record<string, never>> = Omit<AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
11
+ asChild?: boolean;
12
+ children?: ReactNode | ((state: S) => ReactNode);
13
+ };
14
+
15
+ type Presentation = "dialog" | "drawer" | "sheet";
16
+ type SwipeDirection = "up" | "down" | "left" | "right";
17
+ type SurfaceProps = {
18
+ open: boolean;
19
+ presentation: Presentation;
20
+ swipeDirection: SwipeDirection;
21
+ /** Ids the trigger points at; caller-supplied ids win. */
22
+ contentId: string;
23
+ titleId?: string | undefined;
24
+ trigger: {
25
+ current: HTMLElement | null;
26
+ };
27
+ onOpen: () => void;
28
+ onClose: () => void;
29
+ onEscape?: ((event: KeyboardEvent) => void) | undefined;
30
+ onInteractOutside?: ((event: Event) => void) | undefined;
31
+ forceMount?: true | undefined;
32
+ container?: HTMLElement | null | undefined;
33
+ state: unknown;
34
+ contentProps: PartProps<never>;
35
+ contentRef: Ref<HTMLElement>;
36
+ };
37
+ type Parts = {
38
+ Title: typeof Dialog.Title;
39
+ Close: typeof Dialog.Close;
40
+ };
41
+ declare function useEngineParts(): Parts;
42
+ declare function Surface(props: SurfaceProps & {
43
+ children?: ReactNode;
44
+ }): react.JSX.Element;
45
+ declare const EngineTitle: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
46
+ asChild?: boolean;
47
+ children?: ReactNode | ((state: unknown) => ReactNode);
48
+ } & {
49
+ id?: string | undefined;
50
+ state: unknown;
51
+ } & react.RefAttributes<HTMLElement>>;
52
+ declare const EngineClose: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
53
+ asChild?: boolean;
54
+ children?: ReactNode | ((state: unknown) => ReactNode);
55
+ } & {
56
+ id?: string | undefined;
57
+ state: unknown;
58
+ } & react.RefAttributes<HTMLElement>>;
59
+
60
+ export { EngineClose as E, EngineTitle as c, Surface as d, useEngineParts as u };
61
+ export type { PartOwnedAttributes as P, SwipeDirection as S, PartProps as a, Presentation as b, SurfaceProps as e };
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/fulfilment/schedule.tsx
4
- import { useMenu, useStore } from "@zappie/sdk/react";
4
+ import { useMenu, useStore, useZappie } from "@zappie/sdk/react";
5
5
  import { forwardRef, useEffect, useMemo, useState } from "react";
6
6
  import { part } from "../internal/slot.js";
7
7
  import { useControllableState } from "../internal/use-controllable-state.js";
@@ -82,8 +82,12 @@ var Schedule = forwardRef(function Schedule2({
82
82
  noticeMinutes,
83
83
  ...props
84
84
  }, ref) {
85
+ const client = useZappie();
85
86
  const store = useStore();
86
87
  const menu = useMenu(branch.id, { metadataOnly: true });
88
+ const [retrying, setRetrying] = useState(false);
89
+ const status = menu.isLoading || retrying ? "loading" : menu.error ? "error" : "ready";
90
+ const ready = status === "ready";
87
91
  const timezone = suppliedTimezone ?? branch.timezone ?? store.data?.timezone ?? "UTC";
88
92
  const [now, setNow] = useState(() => /* @__PURE__ */ new Date());
89
93
  useEffect(() => {
@@ -99,7 +103,7 @@ var Schedule = forwardRef(function Schedule2({
99
103
  onChange: onValueChange
100
104
  });
101
105
  const slots = useMemo(
102
- () => menu.isLoading || menu.error ? [] : scheduleSlots(branch, timezone, now, {
106
+ () => !ready ? [] : scheduleSlots(branch, timezone, now, {
103
107
  intervalMinutes,
104
108
  maxDays,
105
109
  noticeMinutes,
@@ -113,15 +117,22 @@ var Schedule = forwardRef(function Schedule2({
113
117
  maxDays,
114
118
  noticeMinutes,
115
119
  menu.data?.schedule,
116
- menu.isLoading,
117
- menu.error
120
+ ready
118
121
  ]
119
122
  );
120
123
  const days = Array.from(new Set(slots.map((slot) => slot.date))).map(
121
124
  (date) => ({ date, slots: slots.filter((slot) => slot.date === date) })
122
125
  );
123
- const canAsap = !menu.isLoading && !menu.error && !menu.data?.schedule?.preorder && getOpenStatus(branch, timezone, now).isOpen;
126
+ const canAsap = ready && !menu.data?.schedule?.preorder && getOpenStatus(branch, timezone, now).isOpen;
124
127
  const isValid = selection === null ? canAsap : slots.some((slot) => slot.value === selection);
128
+ const retry = () => {
129
+ if (retrying || !menu.error) {
130
+ return;
131
+ }
132
+ setRetrying(true);
133
+ void client.menu.get({ branch: branch.id, metadataOnly: true }).catch(() => {
134
+ }).finally(() => setRetrying(false));
135
+ };
125
136
  const setValue = (next) => {
126
137
  if (next === null ? canAsap : slots.some((slot) => slot.value === next)) {
127
138
  setSelection(next);
@@ -131,6 +142,9 @@ var Schedule = forwardRef(function Schedule2({
131
142
  "div",
132
143
  props,
133
144
  {
145
+ status,
146
+ retry,
147
+ isClosed: ready && !canAsap && slots.length === 0,
134
148
  days,
135
149
  slots,
136
150
  value: selection,
@@ -141,8 +155,10 @@ var Schedule = forwardRef(function Schedule2({
141
155
  },
142
156
  {
143
157
  role: "group",
158
+ "aria-busy": status === "loading" ? true : void 0,
159
+ "data-status": status,
144
160
  "data-state": isValid ? "valid" : "invalid",
145
- "data-invalid": isValid ? void 0 : ""
161
+ "data-invalid": isValid || !ready ? void 0 : ""
146
162
  },
147
163
  ref
148
164
  );
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/fulfilment/schedule.tsx"],
4
- "mappings": ";;;AAEA,SAAS,SAAS,gBAAgB;AAClC,SAAS,YAAY,WAAW,SAAS,gBAAgB;AACzD,SAAS,YAA4B;AACrC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA4BA,SAAS,cACd,QACA,UACA,KACA;AAAA,EACE,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB;AACF,IAKI,CAAC,GACL;AACA,MACE,CAAC,OAAO,UAAU,eAAe,KACjC,kBAAkB,KAClB,CAAC,OAAO,UAAU,OAAO,KACzB,UAAU,KACV,UAAU,MACV,CAAC,OAAO,SAAS,aAAa,KAC9B,gBAAgB,GAChB;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAGA,QAAM,WAAW,cAAc,WAAW,eAAe;AACzD,MAAI,CAAC,OAAO,WAAW,cAAe,CAAC,YAAY,CAAC,cAAc,MAAM,GAAI;AAC1E,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,OAAO,KAAK;AAAA,IAChB;AAAA,IACA,UAAU,mBAAmB,SAAS,kBAAkB,IACpD,SAAS,kBACR,OAAO,kBAAkB;AAAA,EAChC;AACA,QA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KAAK,UAAU,SAAS;AACnD,QAAM,QAAQ,MAAM;AAClB,QAAI,YAAY,CAAC,KAAK,OAAO;AAC3B;AAAA,IACF;AACA,gBAAY,IAAI;AAChB,SAAK,OAAO,KACT,IAAI,EAAE,QAAQ,OAAO,IAAI,cAAc,KAAK,CAAC,EAC7C,MAAM,MAAM;AAAA,IAAC,CAAC,EACd,QAAQ,MAAM,YAAY,KAAK,CAAC;AAAA,EACrC;AACA,QAAM,WAAW,CAAC,SAAwB;AACxC,QAAI,SAAS,OAAO,UAAU,MAAM,KAAK,CAAC,SAAS,KAAK,UAAU,IAAI,GAAG;AACvE,mBAAa,IAAI;AAAA,IACnB;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA,UAAU,SAAS,CAAC,WAAW,MAAM,WAAW;AAAA,MAChD;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA,QAAQ,cAAc;AAAA,MACtB;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,aAAa,WAAW,YAAY,OAAO;AAAA,MAC3C,eAAe;AAAA,MACf,cAAc,UAAU,UAAU;AAAA,MAClC,gBAAgB,WAAW,CAAC,QAAQ,SAAY;AAAA,IAClD;AAAA,IACA;AAAA,EACF;AACF,CAAC;",
5
5
  "names": ["Schedule"]
6
6
  }
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { P as PartOwnedAttributes, a as PartProps } from './slot-CHfqzPTd.js';
1
+ import { P as PartOwnedAttributes, a as PartProps } from './engine-D2iRshfW.js';
2
+ import { Presentation, SwipeDirection } from './overlay/engine.js';
2
3
  import * as react from 'react';
3
4
  import { HTMLAttributes, ReactNode, ComponentType, ReactElement, KeyboardEvent as KeyboardEvent$1, ImgHTMLAttributes, ChangeEvent, ClipboardEvent } from 'react';
4
5
  import { ZappieEnvironment } from '@zappie/sdk/services';
5
6
  import * as _zappie_sdk from '@zappie/sdk';
6
7
  import { Branch as Branch$1, CartLine, CartLineInput, CartIssue, CartFix, Quote, DeliveryAddress, MenuSchedule, CartFulfilment, OptionGroup as OptionGroup$1, Item, Money as Money$1, Choice as Choice$1, MoneyFormatOptions, PaymentMethodKind, Category, Menu, Store, OpeningTime } from '@zappie/sdk';
7
8
  import { useCart } from '@zappie/sdk/react';
8
- import { Presentation, SwipeDirection } from './overlay/engine.js';
9
9
  import { C as CloseOptions, O as OverlayQuery } from './history-BlytQinP.js';
10
10
  import '@base-ui/react/dialog';
11
11
 
@@ -517,10 +517,25 @@ type ScheduleSlot = {
517
517
  label: string;
518
518
  date: string;
519
519
  };
520
+ /**
521
+ * Whether the branch's menu hours have loaded. `loading` and `error` say nothing about whether the
522
+ * branch is open.
523
+ */
524
+ type ScheduleStatus = "loading" | "error" | "ready";
520
525
  /**
521
526
  * Available days and slots, the selected time and controls for choosing ASAP or a scheduled time.
527
+ *
528
+ * Read `status` first. Until it is `ready`, `days` and `slots` are empty and `canAsap` is false
529
+ * because the hours haven't loaded yet. Show a loading or error state then. Telling the shopper
530
+ * the branch is closed is only right when `isClosed` is true.
522
531
  */
523
532
  type ScheduleState = {
533
+ /** `loading` while the menu hours load, `error` when they failed, and `ready` once they're known. */
534
+ status: ScheduleStatus;
535
+ /** Load the menu hours again after an error. */
536
+ retry: () => void;
537
+ /** True when the hours are known and the branch takes neither ASAP nor scheduled orders. */
538
+ isClosed: boolean;
524
539
  days: {
525
540
  date: string;
526
541
  slots: ScheduleSlot[];
@@ -529,6 +544,7 @@ type ScheduleState = {
529
544
  value: string | null;
530
545
  setValue: (value: string | null) => void;
531
546
  isAsap: boolean;
547
+ /** True when the hours are known and the branch takes an order now. */
532
548
  canAsap: boolean;
533
549
  isValid: boolean;
534
550
  };
@@ -552,6 +568,7 @@ declare function scheduleSlots(branch: Branch$1, timezone: string, now: Date, {
552
568
  /**
553
569
  * Expose valid fulfilment slots and ASAP eligibility using branch hours and loaded menu metadata.
554
570
  * Use null for ASAP. Requires a ZappieProvider and refreshes the available times each minute.
571
+ * While the menu hours load or after they fail, `status` says so. Don't show those states as closed.
555
572
  */
556
573
  declare const Schedule: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
557
574
  asChild?: boolean;
@@ -1104,4 +1121,4 @@ declare const OpenStatus: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttr
1104
1121
  declare const FOUNDATIONS_VERSION: string;
1105
1122
 
1106
1123
  export { Account, AccountNotConfiguredError, Address, Branch, BranchMap, Cart, Choice, DeliveryMap, FOUNDATIONS_VERSION, Fulfilment, Image, ItemForm, Money, OpenStatus, OptionGroup, Otp, Overlay, PartProps, PaymentMethods, Quantity, Schedule, Search, Totals, ZappieAccountLink, canOrderAhead, contactLinks, createSearchIndex, deferred, formatOpeningHours, formatWallClock, getOpenStatus, parseWallClock, scheduleSlots, useControllableState, useIntentPreload, useOverlay, useZappieAccountUrl, zappieAccountUrl, zappieEnvironment, zappieSupportUrl };
1107
- export type { ActiveGroup, AddressState, AddressSuggestion, BranchMapLoadErrorState, BranchMapProps, ContactLink, Customer, Deferred, DeferredIdleOptions, DeferredProps, DeliveryMapProps, ImageProps, IntentPreloadHandlers, ItemFormContext, ItemFormInvalidGroup, ItemFormProps, MapLoadErrorState, PaymentMethod, QuantityProps, QuantityState, ScheduleSlot, ScheduleState, SearchResult, SearchSource, SearchState, SignInOptions, TotalsState, ZappieSupportContext };
1124
+ export type { ActiveGroup, AddressState, AddressSuggestion, BranchMapLoadErrorState, BranchMapProps, ContactLink, Customer, Deferred, DeferredIdleOptions, DeferredProps, DeliveryMapProps, ImageProps, IntentPreloadHandlers, ItemFormContext, ItemFormInvalidGroup, ItemFormProps, MapLoadErrorState, PaymentMethod, QuantityProps, QuantityState, ScheduleSlot, ScheduleState, ScheduleStatus, SearchResult, SearchSource, SearchState, SignInOptions, TotalsState, ZappieSupportContext };
package/dist/index.js.map CHANGED
@@ -1,6 +1,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sBAA8B;",
5
5
  "names": []
6
6
  }
@@ -1,53 +1,3 @@
1
- import { P as PartOwnedAttributes } from '../slot-CHfqzPTd.js';
2
- import { PartProps } from '../index.js';
3
- import * as react from 'react';
4
- import { ReactNode, Ref } from 'react';
5
- import { Dialog } from '@base-ui/react/dialog';
6
-
7
- type Presentation = "dialog" | "drawer" | "sheet";
8
- type SwipeDirection = "up" | "down" | "left" | "right";
9
- type SurfaceProps = {
10
- open: boolean;
11
- presentation: Presentation;
12
- swipeDirection: SwipeDirection;
13
- /** Ids the trigger points at; caller-supplied ids win. */
14
- contentId: string;
15
- titleId?: string | undefined;
16
- trigger: {
17
- current: HTMLElement | null;
18
- };
19
- onOpen: () => void;
20
- onClose: () => void;
21
- onEscape?: ((event: KeyboardEvent) => void) | undefined;
22
- onInteractOutside?: ((event: Event) => void) | undefined;
23
- forceMount?: true | undefined;
24
- container?: HTMLElement | null | undefined;
25
- state: unknown;
26
- contentProps: PartProps<never>;
27
- contentRef: Ref<HTMLElement>;
28
- };
29
- type Parts = {
30
- Title: typeof Dialog.Title;
31
- Close: typeof Dialog.Close;
32
- };
33
- declare function useEngineParts(): Parts;
34
- declare function Surface(props: SurfaceProps & {
35
- children?: ReactNode;
36
- }): react.JSX.Element;
37
- declare const EngineTitle: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
38
- asChild?: boolean;
39
- children?: ReactNode | ((state: unknown) => ReactNode);
40
- } & {
41
- id?: string | undefined;
42
- state: unknown;
43
- } & react.RefAttributes<HTMLElement>>;
44
- declare const EngineClose: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
45
- asChild?: boolean;
46
- children?: ReactNode | ((state: unknown) => ReactNode);
47
- } & {
48
- id?: string | undefined;
49
- state: unknown;
50
- } & react.RefAttributes<HTMLElement>>;
51
-
52
- export { EngineClose, EngineTitle, Surface, useEngineParts };
53
- export type { Presentation, SurfaceProps, SwipeDirection };
1
+ export { E as EngineClose, c as EngineTitle, b as Presentation, d as Surface, e as SurfaceProps, S as SwipeDirection, u as useEngineParts } from '../engine-D2iRshfW.js';
2
+ import 'react';
3
+ import '@base-ui/react/dialog';
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var PACKAGE_VERSION = true ? "0.5.0" : "0.0.0-development";
2
+ var PACKAGE_VERSION = true ? "0.7.0" : "0.0.0-development";
3
3
  export {
4
4
  PACKAGE_VERSION
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappie/foundations",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "UI-less React primitives for Zappie storefronts: behaviour, state and accessibility without styles.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -9,10 +9,6 @@
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.js"
11
11
  },
12
- "./account": {
13
- "types": "./dist/account/parts.d.ts",
14
- "import": "./dist/account/parts.js"
15
- },
16
12
  "./next": {
17
13
  "types": "./dist/next.d.ts",
18
14
  "import": "./dist/next.js"
@@ -37,7 +33,7 @@
37
33
  "dependencies": {
38
34
  "@base-ui/react": "^1.9.0",
39
35
  "@googlemaps/markerclusterer": "^2.6.2",
40
- "@zappie/sdk": "^0.5.2"
36
+ "@zappie/sdk": "^0.7.0"
41
37
  },
42
38
  "peerDependencies": {
43
39
  "react": "^18.2.0 || ^19.0.0",
@@ -1,163 +0,0 @@
1
- import { P as PartOwnedAttributes } from '../slot-CHfqzPTd.js';
2
- import { PartProps } from '../index.js';
3
- import * as react from 'react';
4
- import { SavedCard, AccountClient, CustomerPayment, PaymentReceipt, AccountScope, Wallet } from '@zappie/sdk/account';
5
-
6
- /**
7
- * Where an account read stands. `scope_required` means the shopper's sign-in doesn't cover it yet,
8
- * and `not_found` that the card or payment isn't theirs.
9
- *
10
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
11
- */
12
- type AccountReadStatus = "loading" | "ready" | "error" | "scope_required" | "not_found";
13
- /**
14
- * An account read's status, its data once it has loaded, the error behind a failed read and a retry.
15
- *
16
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
17
- */
18
- type AccountReadState<T> = {
19
- status: AccountReadStatus;
20
- data: T | undefined;
21
- error: unknown;
22
- retry: () => void;
23
- };
24
- /**
25
- * The scope a ScopeRequiredError names, or undefined for any other value.
26
- *
27
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
28
- */
29
- declare function missingScope(error: unknown): AccountScope | undefined;
30
- /**
31
- * Load the shopper's Zappie wallet and expose its balances, one per currency with naira first,
32
- * to your render function. The element's `data-state` is the read's status.
33
- *
34
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
35
- */
36
- declare const Wallets: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
37
- asChild?: boolean;
38
- children?: react.ReactNode | ((state: AccountReadState<Wallet[]>) => react.ReactNode);
39
- } & {
40
- account: Pick<AccountClient, "wallets">;
41
- } & react.RefAttributes<HTMLElement>>;
42
- /**
43
- * The saved cards read, and a remove that drops a card from the list once the API removes it.
44
- *
45
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
46
- */
47
- type CardsState = AccountReadState<SavedCard[]> & {
48
- remove: (id: string) => Promise<void>;
49
- };
50
- /**
51
- * Load the shopper's saved cards and expose them to your render function with `remove`.
52
- * Pair `remove` with RemoveCard so the shopper confirms first.
53
- *
54
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
55
- */
56
- declare const Cards: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
57
- asChild?: boolean;
58
- children?: react.ReactNode | ((state: CardsState) => react.ReactNode);
59
- } & {
60
- account: Pick<AccountClient, "cards" | "removeCard">;
61
- } & react.RefAttributes<HTMLElement>>;
62
- /**
63
- * Whether the confirmation is open, the removal is running, and the error from a failed removal.
64
- *
65
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
66
- */
67
- type RemoveCardState = {
68
- open: boolean;
69
- pending: boolean;
70
- error: unknown;
71
- };
72
- declare function RemoveRoot({ onRemove, onRemoved, ...props }: PartProps<RemoveCardState> & {
73
- /** Removes the card, such as `() => cards.remove(card.id)`. */
74
- onRemove: () => Promise<void>;
75
- onRemoved?: () => void;
76
- }): react.JSX.Element;
77
- /**
78
- * A two-step card removal. Trigger opens the confirmation and Confirm takes focus. Confirm and
79
- * Cancel render only while it is open, and Confirm runs `onRemove` once. A failed removal keeps it
80
- * open with the error. Cancel returns focus to Trigger.
81
- *
82
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
83
- */
84
- declare const RemoveCard: {
85
- Root: typeof RemoveRoot;
86
- Trigger: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
87
- asChild?: boolean;
88
- children?: react.ReactNode | ((state: RemoveCardState) => react.ReactNode);
89
- } & react.RefAttributes<HTMLElement>>;
90
- Confirm: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
91
- asChild?: boolean;
92
- children?: react.ReactNode | ((state: RemoveCardState) => react.ReactNode);
93
- } & react.RefAttributes<HTMLElement>>;
94
- Cancel: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
95
- asChild?: boolean;
96
- children?: react.ReactNode | ((state: RemoveCardState) => react.ReactNode);
97
- } & react.RefAttributes<HTMLElement>>;
98
- };
99
- /**
100
- * The payments read so far, newest first, and the next page.
101
- *
102
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
103
- */
104
- type PaymentsState = AccountReadState<CustomerPayment[]> & {
105
- hasMore: boolean;
106
- loadingMore: boolean;
107
- loadMore: () => void;
108
- };
109
- /**
110
- * Load the shopper's payments at this business, newest first, and expose them to your render
111
- * function. `loadMore` appends the next page while `hasMore` is true.
112
- *
113
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
114
- */
115
- declare const Payments: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
116
- asChild?: boolean;
117
- children?: react.ReactNode | ((state: PaymentsState) => react.ReactNode);
118
- } & {
119
- account: Pick<AccountClient, "payments">;
120
- /** Payments a page, from 1 to 50. Defaults to the API's 20. */
121
- limit?: number;
122
- } & react.RefAttributes<HTMLElement>>;
123
- /**
124
- * The receipt read, and print, which opens the browser's print dialog.
125
- *
126
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
127
- */
128
- type ReceiptState = AccountReadState<PaymentReceipt> & {
129
- print: () => void;
130
- };
131
- /**
132
- * Load one payment's receipt and expose it to your render function with `print`. A payment that
133
- * isn't the shopper's, or isn't at this business, reads as `not_found`.
134
- *
135
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
136
- */
137
- declare const Receipt: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
138
- asChild?: boolean;
139
- children?: react.ReactNode | ((state: ReceiptState) => react.ReactNode);
140
- } & {
141
- account: Pick<AccountClient, "payment">;
142
- paymentId: string;
143
- } & react.RefAttributes<HTMLElement>>;
144
- /**
145
- * Offer to sign in again when an account read failed for a scope the shopper's sign-in doesn't
146
- * cover. It renders nothing for any other error. Its default label is "Sign in again to see this".
147
- *
148
- * @deprecated The shopper's Zappie account lives on the accounts portal, so this is removed in the next minor release. Link to the portal with accountsUrl, or add ZappieAccountLink from @zappie/foundations.
149
- */
150
- declare const ScopeMissing: react.ForwardRefExoticComponent<Omit<react.AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
151
- asChild?: boolean;
152
- children?: react.ReactNode | ((state: {
153
- scope: AccountScope;
154
- }) => react.ReactNode);
155
- } & {
156
- /** The read's error, such as a part's `error` state. */
157
- error: unknown;
158
- /** Starts sign-in, such as `() => customer.signIn()`. */
159
- signIn: () => void;
160
- } & react.RefAttributes<HTMLElement>>;
161
-
162
- export { Cards, Payments, Receipt, RemoveCard, ScopeMissing, Wallets, missingScope };
163
- export type { AccountReadState, AccountReadStatus, CardsState, PaymentsState, ReceiptState, RemoveCardState };
@@ -1,271 +0,0 @@
1
- "use client";
2
-
3
- // src/account/parts.tsx
4
- import {
5
- createContext,
6
- forwardRef,
7
- useCallback,
8
- useContext,
9
- useEffect,
10
- useRef,
11
- useState
12
- } from "react";
13
- import { composeRefs, part } from "../internal/slot.js";
14
- import { jsx } from "react/jsx-runtime";
15
- function missingScope(error) {
16
- const value = error;
17
- return value?.apiCode === "scope_required" ? value.scope : void 0;
18
- }
19
- var statusOf = (error) => missingScope(error) ? "scope_required" : error?.status === 404 ? "not_found" : "error";
20
- function useRead(load, key) {
21
- const [state, setState] = useState({ status: "loading", data: void 0 });
22
- const [attempt, setAttempt] = useState(0);
23
- const latest = useRef(load);
24
- latest.current = load;
25
- useEffect(() => {
26
- let live = true;
27
- setState((current) => ({ status: "loading", data: current.data }));
28
- latest.current().then(
29
- (data) => {
30
- if (live) {
31
- setState({ status: "ready", data });
32
- }
33
- },
34
- (error) => {
35
- if (live) {
36
- setState({ status: statusOf(error), data: void 0, error });
37
- }
38
- }
39
- );
40
- return () => {
41
- live = false;
42
- };
43
- }, [key, attempt]);
44
- return {
45
- status: state.status,
46
- data: state.data,
47
- error: state.error,
48
- retry: useCallback(() => setAttempt((value) => value + 1), []),
49
- set: useCallback((data) => setState({ status: "ready", data }), [])
50
- };
51
- }
52
- var readAttributes = (status) => ({
53
- "data-state": status,
54
- "aria-busy": status === "loading" || void 0
55
- });
56
- var Wallets = forwardRef(function Wallets2({ account, ...props }, ref) {
57
- const { set: _set, ...state } = useRead(() => account.wallets(), account);
58
- return part("div", props, state, readAttributes(state.status), ref);
59
- });
60
- var Cards = forwardRef(function Cards2({ account, ...props }, ref) {
61
- const { set, ...read } = useRead(() => account.cards(), account);
62
- const cards = useRef(read.data);
63
- cards.current = read.data;
64
- const remove = useCallback(
65
- async (id) => {
66
- await account.removeCard(id);
67
- set((cards.current ?? []).filter((card) => card.id !== id));
68
- },
69
- [account, set]
70
- );
71
- const state = { ...read, remove };
72
- return part("div", props, state, readAttributes(state.status), ref);
73
- });
74
- var RemoveContext = createContext(null);
75
- var useRemove = (name) => {
76
- const context = useContext(RemoveContext);
77
- if (!context) {
78
- throw new Error(`RemoveCard.${name} requires RemoveCard.Root`);
79
- }
80
- return context;
81
- };
82
- function RemoveRoot({
83
- onRemove,
84
- onRemoved,
85
- ...props
86
- }) {
87
- const [state, setState] = useState({
88
- open: false,
89
- pending: false,
90
- error: void 0
91
- });
92
- const live = useRef(true);
93
- useEffect(() => {
94
- live.current = true;
95
- return () => {
96
- live.current = false;
97
- };
98
- }, []);
99
- const trigger = useRef(null);
100
- const wasOpen = useRef(false);
101
- useEffect(() => {
102
- if (wasOpen.current && !state.open) {
103
- trigger.current?.focus();
104
- }
105
- wasOpen.current = state.open;
106
- }, [state.open]);
107
- const value = {
108
- state,
109
- trigger,
110
- setOpen: (open) => setState(
111
- (current) => current.pending ? current : { open, pending: false, error: void 0 }
112
- ),
113
- confirm: () => {
114
- if (state.pending) {
115
- return;
116
- }
117
- setState({ open: true, pending: true, error: void 0 });
118
- onRemove().then(
119
- () => {
120
- if (live.current) {
121
- setState({ open: false, pending: false, error: void 0 });
122
- }
123
- onRemoved?.();
124
- },
125
- (error) => {
126
- if (live.current) {
127
- setState({ open: true, pending: false, error });
128
- }
129
- }
130
- );
131
- }
132
- };
133
- return /* @__PURE__ */ jsx(RemoveContext.Provider, { value, children: part("div", props, state, {
134
- role: "group",
135
- "data-state": state.open ? "open" : "closed"
136
- }) });
137
- }
138
- var RemoveTrigger = forwardRef(
139
- function RemoveTrigger2(props, ref) {
140
- const { state, setOpen, trigger } = useRemove("Trigger");
141
- return part(
142
- "button",
143
- props,
144
- state,
145
- {
146
- type: "button",
147
- "aria-expanded": state.open,
148
- onClick: () => setOpen(true)
149
- },
150
- composeRefs(ref, trigger)
151
- );
152
- }
153
- );
154
- var RemoveConfirm = forwardRef(
155
- function RemoveConfirm2(props, ref) {
156
- const { state, confirm } = useRemove("Confirm");
157
- const own = useRef(null);
158
- useEffect(() => {
159
- if (state.open) {
160
- own.current?.focus();
161
- }
162
- }, [state.open]);
163
- if (!state.open) {
164
- return null;
165
- }
166
- return part(
167
- "button",
168
- props,
169
- state,
170
- {
171
- type: "button",
172
- "aria-disabled": state.pending || void 0,
173
- "aria-busy": state.pending || void 0,
174
- onClick: confirm
175
- },
176
- composeRefs(ref, own)
177
- );
178
- }
179
- );
180
- var RemoveCancel = forwardRef(
181
- function RemoveCancel2(props, ref) {
182
- const { state, setOpen } = useRemove("Cancel");
183
- if (!state.open) {
184
- return null;
185
- }
186
- return part(
187
- "button",
188
- props,
189
- state,
190
- {
191
- type: "button",
192
- "aria-disabled": state.pending || void 0,
193
- onClick: () => setOpen(false)
194
- },
195
- ref
196
- );
197
- }
198
- );
199
- var RemoveCard = {
200
- Root: RemoveRoot,
201
- Trigger: RemoveTrigger,
202
- Confirm: RemoveConfirm,
203
- Cancel: RemoveCancel
204
- };
205
- var Payments = forwardRef(function Payments2({ account, limit, ...props }, ref) {
206
- const page = (cursor) => account.payments({
207
- ...limit !== void 0 ? { limit } : {},
208
- ...cursor !== void 0 ? { cursor } : {}
209
- });
210
- const [more, setMore] = useState({ payments: [], cursor: null, loading: false });
211
- const { set: _set, ...read } = useRead(async () => {
212
- const first = await page();
213
- setMore({ payments: [], cursor: first.next_cursor, loading: false });
214
- return first.payments;
215
- }, account);
216
- const loadMore = () => {
217
- const cursor = more.cursor;
218
- if (cursor === null || more.loading) {
219
- return;
220
- }
221
- setMore((current) => ({ ...current, loading: true }));
222
- page(cursor).then(
223
- (next) => setMore((current) => ({
224
- payments: [...current.payments, ...next.payments],
225
- cursor: next.next_cursor,
226
- loading: false
227
- })),
228
- (error) => setMore((current) => ({ ...current, loading: false, error }))
229
- );
230
- };
231
- const state = {
232
- ...read,
233
- data: read.data && [...read.data, ...more.payments],
234
- error: read.error ?? more.error,
235
- hasMore: more.cursor !== null,
236
- loadingMore: more.loading,
237
- loadMore
238
- };
239
- return part("div", props, state, readAttributes(state.status), ref);
240
- });
241
- var Receipt = forwardRef(function Receipt2({ account, paymentId, ...props }, ref) {
242
- const { set: _set, ...read } = useRead(
243
- () => account.payment(paymentId),
244
- `${paymentId}`
245
- );
246
- const state = { ...read, print: () => window.print() };
247
- return part("div", props, state, readAttributes(state.status), ref);
248
- });
249
- var ScopeMissing = forwardRef(function ScopeMissing2({ error, signIn, ...props }, ref) {
250
- const scope = missingScope(error);
251
- if (!scope) {
252
- return null;
253
- }
254
- return part(
255
- "button",
256
- { ...props, children: props.children ?? "Sign in again to see this" },
257
- { scope },
258
- { type: "button", "data-scope": scope, onClick: signIn },
259
- ref
260
- );
261
- });
262
- export {
263
- Cards,
264
- Payments,
265
- Receipt,
266
- RemoveCard,
267
- ScopeMissing,
268
- Wallets,
269
- missingScope
270
- };
271
- //# sourceMappingURL=parts.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/account/parts.tsx"],
4
- "mappings": ";;;AASA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,YAA4B;AA4N9C;AAhMG,SAAS,aAAa,OAA0C;AACrE,QAAM,QAAQ;AACd,SAAO,OAAO,YAAY,mBAAmB,MAAM,QAAQ;AAC7D;AAEA,IAAM,WAAW,CAAC,UAChB,aAAa,KAAK,IACd,mBACC,OAAuC,WAAW,MACjD,cACA;AAER,SAAS,QACP,MACA,KACkD;AAClD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAIvB,EAAE,QAAQ,WAAW,MAAM,OAAU,CAAC;AACzC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,CAAC;AACxC,QAAM,SAAS,OAAO,IAAI;AAC1B,SAAO,UAAU;AACjB,YAAU,MAAM;AACd,QAAI,OAAO;AACX,aAAS,CAAC,aAAa,EAAE,QAAQ,WAAW,MAAM,QAAQ,KAAK,EAAE;AACjE,WAAO,QAAQ,EAAE;AAAA,MACf,CAAC,SAAS;AACR,YAAI,MAAM;AACR,mBAAS,EAAE,QAAQ,SAAS,KAAK,CAAC;AAAA,QACpC;AAAA,MACF;AAAA,MACA,CAAC,UAAmB;AAClB,YAAI,MAAM;AACR,mBAAS,EAAE,QAAQ,SAAS,KAAK,GAAG,MAAM,QAAW,MAAM,CAAC;AAAA,QAC9D;AAAA,MACF;AAAA,IACF;AACA,WAAO,MAAM;AACX,aAAO;AAAA,IACT;AAAA,EACF,GAAG,CAAC,KAAK,OAAO,CAAC;AACjB,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,MAAM,MAAM;AAAA,IACZ,OAAO,MAAM;AAAA,IACb,OAAO,YAAY,MAAM,WAAW,CAAC,UAAU,QAAQ,CAAC,GAAG,CAA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B,SAAS,KAAK,WAAW;AAAA,IACzB,aAAa,KAAK;AAAA,IAClB;AAAA,EACF;AACA,SAAO,KAAK,OAAO,OAAO,OAAO,eAAe,MAAM,MAAM,GAAG,GAAG;AACpE,CAAC;AAiBM,IAAM,UAAU,WAMrB,SAASC,SAAQ,EAAE,SAAS,WAAW,GAAG,MAAM,GAAG,KAAK;AACxD,QAAM,EAAE,KAAK,MAAM,GAAG,KAAK,IAAI;AAAA,IAC7B,MAAM,QAAQ,QAAQ,SAAS;AAAA,IAC/B,GAAG,SAAS;AAAA,EACd;AACA,QAAM,QAAQ,EAAE,GAAG,MAAM,OAAO,MAAM,OAAO,MAAM,EAAE;AACrD,SAAO,KAAK,OAAO,OAAO,OAAO,eAAe,MAAM,MAAM,GAAG,GAAG;AACpE,CAAC;AAQM,IAAM,eAAe,WAQ1B,SAASC,cAAa,EAAE,OAAO,QAAQ,GAAG,MAAM,GAAG,KAAK;AACxD,QAAM,QAAQ,aAAa,KAAK;AAChC,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AACA,SAAO;AAAA,IACL;AAAA,IACA,EAAE,GAAG,OAAO,UAAU,MAAM,YAAY,4BAA4B;AAAA,IACpE,EAAE,MAAM;AAAA,IACR,EAAE,MAAM,UAAU,cAAc,OAAO,SAAS,OAAO;AAAA,IACvD;AAAA,EACF;AACF,CAAC;",
5
- "names": ["Wallets", "Cards", "RemoveTrigger", "RemoveConfirm", "RemoveCancel", "Payments", "Receipt", "ScopeMissing"]
6
- }
@@ -1,13 +0,0 @@
1
- import { AllHTMLAttributes, ReactNode } from 'react';
2
-
3
- type PartOwnedAttributes = "children" | "defaultValue" | "value";
4
- /**
5
- * HTML attributes shared by foundation parts, with optional render-function children.
6
- * Set asChild to merge the part props and ref into a single child element.
7
- */
8
- type PartProps<S = Record<string, never>> = Omit<AllHTMLAttributes<HTMLElement>, PartOwnedAttributes> & {
9
- asChild?: boolean;
10
- children?: ReactNode | ((state: S) => ReactNode);
11
- };
12
-
13
- export type { PartOwnedAttributes as P, PartProps as a };