@usequeek/theme-kit 0.1.35 → 0.1.37

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/apps/apps.css CHANGED
@@ -61,10 +61,42 @@
61
61
  max-width: 400px;
62
62
  }
63
63
 
64
+ /* Following: a one-line state with the way out. */
65
+ .core-follow-card--compact {
66
+ display: flex;
67
+ align-items: center;
68
+ gap: 0.75rem;
69
+ }
70
+ .core-follow-card--compact.core-follow-card--floating {
71
+ width: auto;
72
+ padding: 0.5rem 0.75rem;
73
+ }
74
+ .core-follow-card--compact.core-follow-card--inline {
75
+ padding: 0.75rem 1.25rem;
76
+ }
77
+ .core-follow-card__state {
78
+ font-size: 0.8rem;
79
+ font-weight: 600;
80
+ }
81
+ .core-follow-card__unfollow {
82
+ background: none;
83
+ border: 0;
84
+ padding: 0;
85
+ font: inherit;
86
+ font-size: 0.8rem;
87
+ color: var(--brand-text-muted, #666);
88
+ text-decoration: underline;
89
+ cursor: pointer;
90
+ }
91
+ .core-follow-card__unfollow:disabled {
92
+ opacity: 0.6;
93
+ cursor: not-allowed;
94
+ }
95
+
64
96
  .core-follow-card__dismiss {
65
97
  position: absolute;
66
98
  top: 0.5rem;
67
- right: 0.5rem;
99
+ inset-inline-end: 0.5rem;
68
100
  width: 24px;
69
101
  height: 24px;
70
102
  border: 0;
@@ -173,6 +205,12 @@
173
205
  width: auto;
174
206
  bottom: 5rem;
175
207
  }
208
+ /* The compact following state stays a small chip at the right edge. */
209
+ .core-follow-card--compact.core-follow-card--floating {
210
+ inset-inline-start: auto;
211
+ inset-inline-end: 1rem;
212
+ width: auto;
213
+ }
176
214
  /* Reset position overrides on mobile — always full-width bottom */
177
215
  .core-follow-card--bottom-left,
178
216
  .core-follow-card--center-right,
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
 
3
3
  import type { JSX } from 'react';
4
- import { useState, useCallback, useEffect } from 'react';
5
- import { useStorefront } from '../provider';
4
+ import { useState, useCallback, useEffect, useSyncExternalStore } from 'react';
5
+ import { useStorefront, useStorefrontLocale, useThemeStrings } from '../provider';
6
6
  import { useUserStore } from '../stores/user-store';
7
7
  import { useAuthModalStore } from '../stores/auth-modal-store';
8
8
  import { getQueekClient } from '../sdk/queek-client';
@@ -42,26 +42,71 @@ const POSITION_CLASS: Record<string, string> = {
42
42
  };
43
43
 
44
44
  /**
45
- * The store's follow card, shown when the merchant has turned it on. It is
46
- * floating by default; `display="inline"` places it in the page flow. Renders
47
- * nothing when the app is off.
45
+ * Where the merchant put the card: `footer` is the inline mount a theme places in its footer, anything else
46
+ * (`floating`, and the retired `block`) is the floating mount the shell places.
47
+ */
48
+ function settingFor(display: string | undefined): 'floating' | 'footer' {
49
+ return display === 'footer' ? 'footer' : 'floating';
50
+ }
51
+
52
+ /**
53
+ * The inline mounts currently rendered by a theme, so the floating mount can tell that a theme has no footer mount
54
+ * and take the card itself: a card the merchant switched on is always reachable, and never shown twice.
55
+ */
56
+ let inlineMounts = 0;
57
+ const mountListeners = new Set<() => void>();
58
+
59
+ function subscribeToMounts(listener: () => void): () => void {
60
+ mountListeners.add(listener);
61
+ return () => {
62
+ mountListeners.delete(listener);
63
+ };
64
+ }
65
+
66
+ function registerInlineMount(): () => void {
67
+ inlineMounts += 1;
68
+ mountListeners.forEach((notify) => notify());
69
+ return () => {
70
+ inlineMounts -= 1;
71
+ mountListeners.forEach((notify) => notify());
72
+ };
73
+ }
74
+
75
+ /**
76
+ * The store's follow card, shown when the merchant has turned it on, in the one place they chose: the shell mounts
77
+ * `display="floating"` and a theme's footer mounts `display="inline"`; each renders only when the merchant's setting
78
+ * matches its mount, and a theme with no footer mount shows the floating card instead. Renders nothing when the app
79
+ * is off.
80
+ *
81
+ * Sharing contact details is the shopper's own choice: the box starts unticked and nothing is sent unless it is ticked.
82
+ * A shopper who follows sees a compact "Following · Unfollow" state instead of the prompt.
48
83
  */
49
84
  export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}): JSX.Element | null {
50
85
  const { config, vendor } = useStorefront();
86
+ const t = useThemeStrings();
87
+ const locale = useStorefrontLocale();
51
88
  const followConfig = config.apps?.follow_card;
52
- const resolvedDisplay = display ?? followConfig?.display ?? 'floating';
89
+ const mount = display === 'inline' ? 'inline' : 'floating';
90
+ const setting = settingFor(followConfig?.display);
91
+ const registersInline = mount === 'inline' && setting === 'footer' && !!followConfig?.enabled;
92
+ // The server answer is "a footer mount exists" so a footer-placed card is never painted floating before hydration.
93
+ const footerMountExists = useSyncExternalStore(subscribeToMounts, () => inlineMounts > 0, () => true);
94
+ const shows = mount === 'inline' ? setting === 'footer' : setting === 'floating' || !footerMountExists;
53
95
  const user = useUserStore((s) => s.user);
54
96
  const openAuth = useAuthModalStore((s) => s.open);
55
97
 
56
98
  const [isFollowing, setIsFollowing] = useState(false);
57
99
  const [followersCount, setFollowersCount] = useState(config.followers_count ?? 0);
58
- const [shareContact, setShareContact] = useState(true);
100
+ const [shareContact, setShareContact] = useState(false);
59
101
  const [loading, setLoading] = useState(false);
60
102
  const [dismissed, setDismissed] = useState(false);
61
103
  const [checked, setChecked] = useState(false);
62
104
 
105
+ useEffect(() => (registersInline ? registerInlineMount() : undefined), [registersInline]);
106
+
63
107
  // Check follow status when user is logged in
64
108
  useEffect(() => {
109
+ if (!shows) return;
65
110
  if (!user || !vendor.slug) {
66
111
  setChecked(true);
67
112
  return;
@@ -74,7 +119,7 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
74
119
  })
75
120
  .catch(() => {})
76
121
  .finally(() => setChecked(true));
77
- }, [user, vendor.slug]);
122
+ }, [user, vendor.slug, shows]);
78
123
 
79
124
  // Check persistent dismiss
80
125
  useEffect(() => {
@@ -92,8 +137,9 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
92
137
  setLoading(true);
93
138
  try {
94
139
  const client = getQueekClient(vendor.slug ?? undefined);
140
+ // `contact_opt_in` is the only consent the API reads; the older `share_contact` is ignored as not consent.
95
141
  const res = await client.post<FollowData>('/client/store/follow', {
96
- share_contact: shareContact,
142
+ contact_opt_in: shareContact,
97
143
  });
98
144
  setIsFollowing(res.data?.following ?? true);
99
145
  setFollowersCount(res.data?.followers_count ?? followersCount + 1);
@@ -125,28 +171,42 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
125
171
  if (vendor.id) persistDismiss(vendor.id);
126
172
  }, [vendor.id]);
127
173
 
128
- if (!followConfig?.enabled || dismissed || !checked) return null;
129
- // Don't show to users already following
130
- if (isFollowing) return null;
174
+ if (!followConfig?.enabled || !shows || !checked) return null;
131
175
 
132
- const isFloating = resolvedDisplay === 'floating';
176
+ const storeName = vendor.name ?? t('follow.thisstore');
177
+ const isFloating = mount === 'floating';
133
178
  const posClass = isFloating
134
179
  ? POSITION_CLASS[followConfig.position ?? 'bottom-right'] ?? POSITION_CLASS['bottom-right']
135
180
  : '';
181
+ const placement = isFloating ? `core-follow-card--floating ${posClass}` : 'core-follow-card--inline';
182
+
183
+ // A shopper who follows still sees the card, compact, with the way out: Unfollow. Dismissing the prompt never hides it.
184
+ if (isFollowing) {
185
+ return (
186
+ <div className={`core-follow-card core-follow-card--compact ${placement}`} role="complementary" aria-label={t('follow.following')}>
187
+ <span className="core-follow-card__state">{t('follow.following')}</span>
188
+ <button type="button" className="core-follow-card__unfollow" onClick={handleUnfollow} disabled={loading}>
189
+ {loading ? t('follow.leaving') : t('follow.unfollow')}
190
+ </button>
191
+ </div>
192
+ );
193
+ }
194
+
195
+ if (dismissed) return null;
136
196
 
137
197
  return (
138
198
  <div
139
- className={`core-follow-card ${isFloating ? `core-follow-card--floating ${posClass}` : 'core-follow-card--inline'}`}
199
+ className={`core-follow-card ${placement}`}
140
200
  role="complementary"
141
- aria-label="Follow this store"
201
+ aria-label={t('follow.aria')}
142
202
  >
143
203
  {isFloating && (
144
204
  <button
145
205
  type="button"
146
206
  className="core-follow-card__dismiss"
147
207
  onClick={handleDismiss}
148
- aria-label="Don't show again"
149
- title="Don't show again"
208
+ aria-label={t('follow.dismiss')}
209
+ title={t('follow.dismiss')}
150
210
  >
151
211
  <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.5" width="12" height="12">
152
212
  <path d="M3 3l10 10M13 3L3 13" />
@@ -164,14 +224,14 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
164
224
  )}
165
225
  <div className="core-follow-card__text">
166
226
  <p className="core-follow-card__title">
167
- Follow {vendor.name ?? 'this store'}
227
+ {t('follow.title', { name: storeName })}
168
228
  </p>
169
229
  <p className="core-follow-card__sub">
170
- Get notified about new arrivals and exclusive offers.
230
+ {t('follow.tagline')}
171
231
  </p>
172
232
  {followersCount > 0 && (
173
233
  <p className="core-follow-card__count">
174
- {formatCount(followersCount)} {followersCount === 1 ? 'follower' : 'followers'}
234
+ {t('follow.count', { count: followersCount, n: formatCount(followersCount, locale) })}
175
235
  </p>
176
236
  )}
177
237
  </div>
@@ -184,7 +244,7 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
184
244
  onChange={(e) => setShareContact(e.target.checked)}
185
245
  className="core-follow-card__checkbox"
186
246
  />
187
- <span>Share my contact info with this store</span>
247
+ <span>{t('follow.share', { name: storeName })}</span>
188
248
  </label>
189
249
  <button
190
250
  type="button"
@@ -192,7 +252,7 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
192
252
  onClick={handleFollow}
193
253
  disabled={loading}
194
254
  >
195
- {loading ? 'Following...' : 'Follow'}
255
+ {loading ? t('follow.busy') : t('follow.action')}
196
256
  </button>
197
257
  </div>
198
258
  );
@@ -185,5 +185,22 @@
185
185
  "market": {
186
186
  "label": "Currency",
187
187
  "named": "Currency: {name}"
188
+ },
189
+ "follow": {
190
+ "aria": "Follow this store",
191
+ "dismiss": "Don't show again",
192
+ "title": "Follow {name}",
193
+ "thisstore": "this store",
194
+ "tagline": "Get notified about new arrivals and exclusive offers.",
195
+ "count": {
196
+ "one": "{n} follower",
197
+ "other": "{n} followers"
198
+ },
199
+ "share": "Optional: share my name, email and phone number with {name}, so they can contact me.",
200
+ "action": "Follow",
201
+ "busy": "Following…",
202
+ "following": "Following",
203
+ "unfollow": "Unfollow",
204
+ "leaving": "Unfollowing…"
188
205
  }
189
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The runtime a Queek storefront theme is built on: hooks, stores, page renderer, navigation, shared blocks and locale strings.",
package/utils/market.ts CHANGED
@@ -150,6 +150,8 @@ export const MARKET_ERROR_CODES = [
150
150
  'market_rate_expired',
151
151
  // 422 at the quote and the order (and cart `market.unavailable`): the market total is zero or below the provider minimum.
152
152
  'market_total_unusable',
153
+ // 422 at the cart code, the quote and the order: a discount code is refused in a fixed-price market (codes are shop-currency money). Remove the code.
154
+ 'market_coupon_unavailable',
153
155
  ] as const;
154
156
 
155
157
  export type MarketErrorCode = (typeof MARKET_ERROR_CODES)[number];