@usequeek/theme-kit 0.1.43 → 0.1.44
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 +8 -0
- package/apps/follow-card.tsx +17 -5
- package/apps/subscribe-form.tsx +13 -2
- package/hooks/use-address-autocomplete.ts +12 -3
- package/hooks/use-auth-flow.tsx +14 -1
- package/hooks/use-resolve-coordinates.ts +7 -2
- package/locales/en.default.json +5 -0
- package/package.json +1 -1
- package/provider.tsx +5 -0
- package/shared-blocks/product-qa.tsx +7 -1
package/apps/apps.css
CHANGED
|
@@ -148,6 +148,14 @@
|
|
|
148
148
|
line-height: 1.4;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
/* Shown in a theme preview instead of sending the follow (nothing to follow). */
|
|
152
|
+
.core-follow-card__notice {
|
|
153
|
+
font-size: 0.75rem;
|
|
154
|
+
color: var(--brand-text-muted, #666);
|
|
155
|
+
margin: 0 0 0.5rem;
|
|
156
|
+
line-height: 1.4;
|
|
157
|
+
}
|
|
158
|
+
|
|
151
159
|
.core-follow-card__count {
|
|
152
160
|
font-size: 0.7rem;
|
|
153
161
|
color: var(--brand-text-muted, #999);
|
package/apps/follow-card.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { JSX } from 'react';
|
|
4
4
|
import { useState, useCallback, useEffect, useSyncExternalStore } from 'react';
|
|
5
|
-
import { useStorefront, useStorefrontLocale, useThemeStrings } from '../provider';
|
|
5
|
+
import { useIsThemePreview, 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';
|
|
@@ -84,6 +84,8 @@ function registerInlineMount(): () => void {
|
|
|
84
84
|
export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}): JSX.Element | null {
|
|
85
85
|
const { config, vendor } = useStorefront();
|
|
86
86
|
const t = useThemeStrings();
|
|
87
|
+
const isThemePreview = useIsThemePreview();
|
|
88
|
+
const [previewMessage, setPreviewMessage] = useState(false);
|
|
87
89
|
const locale = useStorefrontLocale();
|
|
88
90
|
const followConfig = config.apps?.follow_card;
|
|
89
91
|
const mount = display === 'inline' ? 'inline' : 'floating';
|
|
@@ -107,7 +109,7 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
107
109
|
// Check follow status when user is logged in
|
|
108
110
|
useEffect(() => {
|
|
109
111
|
if (!shows) return;
|
|
110
|
-
if (!user || !vendor.slug) {
|
|
112
|
+
if (isThemePreview || !user || !vendor.slug) {
|
|
111
113
|
setChecked(true);
|
|
112
114
|
return;
|
|
113
115
|
}
|
|
@@ -119,7 +121,7 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
119
121
|
})
|
|
120
122
|
.catch(() => {})
|
|
121
123
|
.finally(() => setChecked(true));
|
|
122
|
-
}, [user, vendor.slug, shows]);
|
|
124
|
+
}, [user, vendor.slug, shows, isThemePreview]);
|
|
123
125
|
|
|
124
126
|
// Check persistent dismiss
|
|
125
127
|
useEffect(() => {
|
|
@@ -129,6 +131,10 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
129
131
|
}, [vendor.id]);
|
|
130
132
|
|
|
131
133
|
const handleFollow = useCallback(async () => {
|
|
134
|
+
if (isThemePreview) {
|
|
135
|
+
setPreviewMessage(true);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
132
138
|
if (!user) {
|
|
133
139
|
openAuth('login');
|
|
134
140
|
return;
|
|
@@ -148,9 +154,13 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
148
154
|
} finally {
|
|
149
155
|
setLoading(false);
|
|
150
156
|
}
|
|
151
|
-
}, [user, vendor.slug, openAuth, shareContact]);
|
|
157
|
+
}, [user, vendor.slug, openAuth, shareContact, isThemePreview]);
|
|
152
158
|
|
|
153
159
|
const handleUnfollow = useCallback(async () => {
|
|
160
|
+
if (isThemePreview) {
|
|
161
|
+
setPreviewMessage(true);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
154
164
|
if (!user) return;
|
|
155
165
|
|
|
156
166
|
setLoading(true);
|
|
@@ -164,7 +174,7 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
164
174
|
} finally {
|
|
165
175
|
setLoading(false);
|
|
166
176
|
}
|
|
167
|
-
}, [user, vendor.slug]);
|
|
177
|
+
}, [user, vendor.slug, isThemePreview]);
|
|
168
178
|
|
|
169
179
|
const handleDismiss = useCallback(() => {
|
|
170
180
|
setDismissed(true);
|
|
@@ -184,6 +194,7 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
184
194
|
if (isFollowing) {
|
|
185
195
|
return (
|
|
186
196
|
<div className={`core-follow-card core-follow-card--compact ${placement}`} role="complementary" aria-label={t('follow.following')}>
|
|
197
|
+
{previewMessage && <p className="core-follow-card__notice" role="status">{t('preview.action')}</p>}
|
|
187
198
|
<span className="core-follow-card__state">{t('follow.following')}</span>
|
|
188
199
|
<button type="button" className="core-follow-card__unfollow" onClick={handleUnfollow} disabled={loading}>
|
|
189
200
|
{loading ? t('follow.leaving') : t('follow.unfollow')}
|
|
@@ -214,6 +225,7 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
214
225
|
</button>
|
|
215
226
|
)}
|
|
216
227
|
|
|
228
|
+
{previewMessage && <p className="core-follow-card__notice" role="status">{t('preview.action')}</p>}
|
|
217
229
|
<div className="core-follow-card__body">
|
|
218
230
|
{vendor.logo && (
|
|
219
231
|
<img
|
package/apps/subscribe-form.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { JSX } from 'react';
|
|
4
4
|
import { useCallback, useId, useState } from 'react';
|
|
5
|
-
import { useStorefront } from '../provider';
|
|
5
|
+
import { useIsThemePreview, useStorefront, useThemeStrings } from '../provider';
|
|
6
6
|
import { getQueekClient } from '../sdk/queek-client';
|
|
7
7
|
import type { SubscribeFormProps } from '../types/theme';
|
|
8
8
|
|
|
@@ -33,6 +33,8 @@ export function SubscribeForm({
|
|
|
33
33
|
onSuccess,
|
|
34
34
|
}: SubscribeFormProps & { layout?: 'stacked' | 'inline'; onSuccess?: () => void } = {}): JSX.Element {
|
|
35
35
|
const { vendor } = useStorefront();
|
|
36
|
+
const isThemePreview = useIsThemePreview();
|
|
37
|
+
const t = useThemeStrings();
|
|
36
38
|
const emailId = useId();
|
|
37
39
|
const nameId = useId();
|
|
38
40
|
|
|
@@ -46,6 +48,15 @@ export function SubscribeForm({
|
|
|
46
48
|
event.preventDefault();
|
|
47
49
|
if (status === 'saving' || email.trim() === '') return;
|
|
48
50
|
|
|
51
|
+
if (isThemePreview) {
|
|
52
|
+
setStatus('done');
|
|
53
|
+
setMessage(t('preview.action'));
|
|
54
|
+
setName('');
|
|
55
|
+
setEmail('');
|
|
56
|
+
onSuccess?.();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
49
60
|
setStatus('saving');
|
|
50
61
|
try {
|
|
51
62
|
const res = await getQueekClient(vendor.slug ?? undefined).post<{ message?: string }>(
|
|
@@ -62,7 +73,7 @@ export function SubscribeForm({
|
|
|
62
73
|
setMessage('That didn’t go through. Please check the address and try again.');
|
|
63
74
|
}
|
|
64
75
|
},
|
|
65
|
-
[name, email, status, vendor.slug, onSuccess],
|
|
76
|
+
[name, email, status, vendor.slug, onSuccess, isThemePreview, t],
|
|
66
77
|
);
|
|
67
78
|
|
|
68
79
|
if (status === 'done') {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
|
-
import { useStorefront } from '../provider';
|
|
4
|
+
import { useIsThemePreview, useStorefront, useThemeStrings } from '../provider';
|
|
5
5
|
import { getQueekClient } from '../sdk/queek-client';
|
|
6
6
|
|
|
7
7
|
/** One address suggestion. Pass `place_id` to `useResolveCoordinates` to get its position. */
|
|
@@ -23,12 +23,21 @@ const DEBOUNCE_MS = 300;
|
|
|
23
23
|
export function useAddressAutocomplete(query: string): {
|
|
24
24
|
suggestions: AddressSuggestion[];
|
|
25
25
|
loading: boolean;
|
|
26
|
+
/** Preview notice for the address field to display. */
|
|
27
|
+
error: string | null;
|
|
26
28
|
} {
|
|
27
29
|
const { vendor } = useStorefront();
|
|
30
|
+
const isThemePreview = useIsThemePreview();
|
|
31
|
+
const t = useThemeStrings();
|
|
28
32
|
const [suggestions, setSuggestions] = useState<AddressSuggestion[]>([]);
|
|
29
33
|
const [loading, setLoading] = useState(false);
|
|
30
34
|
|
|
31
35
|
useEffect(() => {
|
|
36
|
+
if (isThemePreview) {
|
|
37
|
+
setSuggestions([]);
|
|
38
|
+
setLoading(false);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
32
41
|
if (!query || query.trim().length < 2) {
|
|
33
42
|
setSuggestions([]);
|
|
34
43
|
return;
|
|
@@ -65,7 +74,7 @@ export function useAddressAutocomplete(query: string): {
|
|
|
65
74
|
cancelled = true;
|
|
66
75
|
clearTimeout(timer);
|
|
67
76
|
};
|
|
68
|
-
}, [query, vendor.slug]);
|
|
77
|
+
}, [query, vendor.slug, isThemePreview]);
|
|
69
78
|
|
|
70
|
-
return { suggestions, loading };
|
|
79
|
+
return { suggestions, loading, error: isThemePreview ? t('preview.address') : null };
|
|
71
80
|
}
|
package/hooks/use-auth-flow.tsx
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { JSX } from 'react';
|
|
4
4
|
import { createContext, useContext, useState, type ReactNode } from 'react';
|
|
5
5
|
import { QueekSdkError, type EmailVerifyOtpResponse } from '@usequeek/client-sdk';
|
|
6
|
-
import { useStorefront, useThemeStrings } from '../provider';
|
|
6
|
+
import { useIsThemePreview, useStorefront, useThemeStrings } from '../provider';
|
|
7
7
|
import { getQueekClient, setAuthTokens, QUEEK_AUTH_URL } from '../sdk/queek-client';
|
|
8
8
|
import { useAuthModalStore } from '../stores/auth-modal-store';
|
|
9
9
|
import { useUserStore } from '../stores/user-store';
|
|
@@ -90,6 +90,7 @@ const AuthFlowContext = createContext<AuthFlowValue | null>(null);
|
|
|
90
90
|
export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Element {
|
|
91
91
|
const { vendor } = useStorefront();
|
|
92
92
|
const t = useThemeStrings();
|
|
93
|
+
const isThemePreview = useIsThemePreview();
|
|
93
94
|
const closeModal = useAuthModalStore((s) => s.close);
|
|
94
95
|
const setUser = useUserStore((s) => s.setUser);
|
|
95
96
|
|
|
@@ -103,6 +104,12 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
|
|
|
103
104
|
const [loading, setLoading] = useState(false);
|
|
104
105
|
const [error, setError] = useState<string | null>(null);
|
|
105
106
|
|
|
107
|
+
function blockPreview(): boolean {
|
|
108
|
+
if (!isThemePreview) return false;
|
|
109
|
+
setError(t('auth.error.preview'));
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
106
113
|
function applyUser(u: { id: string; name: string; first_name?: string | null; last_name?: string | null; email: string | null; phone?: string | null; avatar: string | null; profile_complete?: boolean }): void {
|
|
107
114
|
setUser({
|
|
108
115
|
id: u.id,
|
|
@@ -122,6 +129,7 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
|
|
|
122
129
|
// ── Email OTP flow (primary) ──────────────────────────────────────────────
|
|
123
130
|
|
|
124
131
|
const submitEmailRequestOtp = async (): Promise<void> => {
|
|
132
|
+
if (blockPreview()) return;
|
|
125
133
|
const trimmedEmail = email.trim();
|
|
126
134
|
if (!trimmedEmail) return;
|
|
127
135
|
setError(null);
|
|
@@ -139,6 +147,7 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
|
|
|
139
147
|
};
|
|
140
148
|
|
|
141
149
|
const submitEmailVerifyOtp = async (): Promise<void> => {
|
|
150
|
+
if (blockPreview()) return;
|
|
142
151
|
if (otp.length < EMAIL_OTP_LENGTH) return;
|
|
143
152
|
setError(null);
|
|
144
153
|
setLoading(true);
|
|
@@ -167,6 +176,7 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
|
|
|
167
176
|
// ── Signup (email OTP flow) ───────────────────────────────────────────────
|
|
168
177
|
|
|
169
178
|
const submitRegister = async (): Promise<void> => {
|
|
179
|
+
if (blockPreview()) return;
|
|
170
180
|
if (!firstName.trim()) {
|
|
171
181
|
setError(t('auth.error.firstname'));
|
|
172
182
|
return;
|
|
@@ -193,6 +203,7 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
|
|
|
193
203
|
// ── Email password flow ───────────────────────────────────────────────────
|
|
194
204
|
|
|
195
205
|
const submitEmailLogin = async (): Promise<void> => {
|
|
206
|
+
if (blockPreview()) return;
|
|
196
207
|
if (!email.trim() || !password) return;
|
|
197
208
|
setError(null);
|
|
198
209
|
setLoading(true);
|
|
@@ -214,6 +225,7 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
|
|
|
214
225
|
};
|
|
215
226
|
|
|
216
227
|
const submitEmailRegister = async (): Promise<void> => {
|
|
228
|
+
if (blockPreview()) return;
|
|
217
229
|
if (!firstName.trim() || !email.trim() || password.length < 8) return;
|
|
218
230
|
setError(null);
|
|
219
231
|
setLoading(true);
|
|
@@ -240,6 +252,7 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
|
|
|
240
252
|
// ── Google OAuth ──────────────────────────────────────────────────────────
|
|
241
253
|
|
|
242
254
|
const initiateGoogleAuth = async (): Promise<void> => {
|
|
255
|
+
if (blockPreview()) return;
|
|
243
256
|
setError(null);
|
|
244
257
|
setLoading(true);
|
|
245
258
|
try {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useState } from 'react';
|
|
4
|
-
import { useStorefront } from '../provider';
|
|
4
|
+
import { useIsThemePreview, useStorefront, useThemeStrings } from '../provider';
|
|
5
5
|
import { getQueekClient } from '../sdk/queek-client';
|
|
6
6
|
import { useLocationStore } from '../stores/location-store';
|
|
7
7
|
|
|
@@ -26,12 +26,17 @@ interface CoordinatesResponse {
|
|
|
26
26
|
export function useResolveCoordinates(): {
|
|
27
27
|
resolve: (placeId: string, description: string) => Promise<boolean>;
|
|
28
28
|
resolving: boolean;
|
|
29
|
+
/** Preview notice for the address field to display. */
|
|
30
|
+
error: string | null;
|
|
29
31
|
} {
|
|
30
32
|
const { vendor } = useStorefront();
|
|
33
|
+
const isThemePreview = useIsThemePreview();
|
|
34
|
+
const t = useThemeStrings();
|
|
31
35
|
const setLocation = useLocationStore((s) => s.setLocation);
|
|
32
36
|
const [resolving, setResolving] = useState(false);
|
|
33
37
|
|
|
34
38
|
const resolve = async (placeId: string, description: string): Promise<boolean> => {
|
|
39
|
+
if (isThemePreview) return false;
|
|
35
40
|
setResolving(true);
|
|
36
41
|
try {
|
|
37
42
|
const client = getQueekClient(vendor.slug ?? undefined);
|
|
@@ -53,5 +58,5 @@ export function useResolveCoordinates(): {
|
|
|
53
58
|
}
|
|
54
59
|
};
|
|
55
60
|
|
|
56
|
-
return { resolve, resolving };
|
|
61
|
+
return { resolve, resolving, error: isThemePreview ? t('preview.address') : null };
|
|
57
62
|
}
|
package/locales/en.default.json
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"preview": {
|
|
3
|
+
"action": "This is a theme preview, so nothing was sent.",
|
|
4
|
+
"address": "Address lookup isn't available in a theme preview."
|
|
5
|
+
},
|
|
2
6
|
"cart": {
|
|
3
7
|
"title": "Your cart",
|
|
4
8
|
"empty": {
|
|
@@ -132,6 +136,7 @@
|
|
|
132
136
|
"different": "← Use a different email"
|
|
133
137
|
},
|
|
134
138
|
"error": {
|
|
139
|
+
"preview": "Signing in isn't available in a theme preview.",
|
|
135
140
|
"credentials": "Wrong email or password. Please try again.",
|
|
136
141
|
"method": "This account uses a different sign-in method (Google or phone).",
|
|
137
142
|
"exists": "Email already registered. Please sign in instead.",
|
package/package.json
CHANGED
package/provider.tsx
CHANGED
|
@@ -218,6 +218,11 @@ export function useStorefront(): StorefrontContextValue {
|
|
|
218
218
|
return context;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
/** Whether this storefront is a theme demo with no backing store. */
|
|
222
|
+
export function useIsThemePreview(): boolean {
|
|
223
|
+
return useStorefront().previewData !== undefined;
|
|
224
|
+
}
|
|
225
|
+
|
|
221
226
|
/**
|
|
222
227
|
* Validated request locale for translated reads (`null` = primary).
|
|
223
228
|
* Browser hooks send `?locale=` when this is set and key their client
|
|
@@ -6,7 +6,7 @@ import type { ProductQaBlockData, ProductQuestionItem } from '../types/block';
|
|
|
6
6
|
import { Image } from '../components/image';
|
|
7
7
|
import { useProductQuestions } from '../hooks/use-product-questions';
|
|
8
8
|
import { useAuth } from '../hooks/use-auth';
|
|
9
|
-
import { useStorefront } from '../provider';
|
|
9
|
+
import { useIsThemePreview, useStorefront, useThemeStrings } from '../provider';
|
|
10
10
|
import { getQueekClient } from '../sdk/queek-client';
|
|
11
11
|
import { formatDisplayDate } from '../utils/format';
|
|
12
12
|
|
|
@@ -47,6 +47,8 @@ export function CoreProductQaBlock(props: ProductQaBlockData): JSX.Element {
|
|
|
47
47
|
|
|
48
48
|
function AskQuestionPanel({ productSlug }: { productSlug: string }): JSX.Element {
|
|
49
49
|
const { vendor } = useStorefront();
|
|
50
|
+
const isThemePreview = useIsThemePreview();
|
|
51
|
+
const t = useThemeStrings();
|
|
50
52
|
const { user, openAuthModal } = useAuth();
|
|
51
53
|
const [open, setOpen] = useState(false);
|
|
52
54
|
const [question, setQuestion] = useState('');
|
|
@@ -70,6 +72,10 @@ function AskQuestionPanel({ productSlug }: { productSlug: string }): JSX.Element
|
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
const handleSubmit = async (): Promise<void> => {
|
|
75
|
+
if (isThemePreview) {
|
|
76
|
+
setError(t('preview.action'));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
73
79
|
const trimmed = question.trim();
|
|
74
80
|
if (!trimmed) {
|
|
75
81
|
setError('Please write a question.');
|