@shoppexio/storefront-react 0.2.0 → 0.2.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.
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useState, type ComponentType, type ReactElement, type ReactNode } from 'react';
2
+ import { notifyFavoritesChanged } from '@shoppexio/storefront-react';
2
3
  import { Link, Navigate, useLocation } from 'react-router-dom';
3
4
  import {
4
5
  isAccountTabOffered,
@@ -119,6 +120,26 @@ export interface AccountPageProps {
119
120
  notFound: ReactNode;
120
121
  }
121
122
 
123
+ /**
124
+ * The customer session changed inside this page (signed in or out) without a
125
+ * reload. Everything else on the storefront that reads the session must hear
126
+ * it: the favorites hearts reload, so a buyer who just signed in can save
127
+ * products and a signed-out page shows no one's saved set.
128
+ */
129
+ export function announceCustomerSessionChange(): void {
130
+ notifyFavoritesChanged();
131
+ }
132
+
133
+ /**
134
+ * Whether a sign-out request ended the session. The worker clears the session
135
+ * cookie on every response it produces, even a 500 from the backend, so an
136
+ * ANSWERED request means the buyer really is signed out. Only a result with no
137
+ * status at all means nothing reached the edge and the session is still live.
138
+ */
139
+ export function signOutEndedSession(result: { success: boolean; status?: number }): boolean {
140
+ return result.success || result.status !== undefined;
141
+ }
142
+
122
143
  export function AccountPage({ frame: Frame, notFound }: AccountPageProps) {
123
144
  const location = useLocation();
124
145
  const search = new URLSearchParams(location.search);
@@ -184,16 +205,14 @@ export function AccountPage({ frame: Frame, notFound }: AccountPageProps) {
184
205
  const result = await callCustomerApi((sdk) => sdk.logout());
185
206
  setSigningOut(false);
186
207
 
187
- // The worker clears the session cookie on every response it produces, even
188
- // a 500 from the backend — so an ANSWERED request means the buyer really is
189
- // signed out, whatever the status says. Only a result with no status at all
190
- // means nothing reached the edge: the cookie is still there, the session is
191
- // still live, and a signed-out page would be a lie the next reload exposes.
192
- if (!result.success && result.status === undefined) {
208
+ // A signed-out page for a session that is still live would be a lie the
209
+ // next reload exposes (see signOutEndedSession).
210
+ if (!signOutEndedSession(result)) {
193
211
  setSignOutError(result.message?.trim() || t('account.signOutFailed'));
194
212
  return;
195
213
  }
196
214
  setSession({ status: 'signed-out' });
215
+ announceCustomerSessionChange();
197
216
  };
198
217
 
199
218
  /*
@@ -255,6 +274,7 @@ export function AccountPage({ frame: Frame, notFound }: AccountPageProps) {
255
274
  // and their already-used code.
256
275
  setPrefill(spendSignInPrefill());
257
276
  setSession({ status: 'signed-in' });
277
+ announceCustomerSessionChange();
258
278
  }}
259
279
  />
260
280
  ) : null}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoppexio/storefront-react",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "React hooks, models and a customer account for Shoppex code storefronts",
5
5
  "type": "module",
6
6
  "homepage": "https://docs.shoppex.io/storefront/code-storefront-development",