Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/components/store/StoreItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ErrorPopup, { useErrorPopup } from '../ErrorPopup';
import ReactNavbar from '../generic/ReactNavbar';
import { LoadingSpinner } from '../generic/LargeLoadingSpinner';
import AuthActionButton, { type ShowErrorFunction } from '../AuthActionButton';
import { Turnstile } from '@marsidev/react-turnstile';
import { Turnstile, type TurnstileInstance } from '@marsidev/react-turnstile';
import type {
IPublicClientApplication,
AccountInfo,
Expand Down Expand Up @@ -91,6 +91,7 @@ const StoreItem = ({
const activeMembershipKeyRef = useRef<string | null>(null);
const membershipCache = useRef<Map<string, boolean>>(new Map());

const turnstileRef = useRef<TurnstileInstance>(null);
const { error, showError, clearError } = useErrorPopup();

const turnstileSiteKey = import.meta.env.PUBLIC_TURNSTILE_SITE_KEY!;
Expand All @@ -107,6 +108,13 @@ const StoreItem = ({
.catch(console.error);
}, []);

// If there is only one variant, select it by default.
useEffect(() => {
if (!selectedVariantId && productInfo?.variants.length === 1) {
setSelectedVariantId(productInfo.variants[0].variantId ?? '');
}
}, [productInfo]);

// Check membership status with specific lists (with caching)
const checkMembershipStatus = useCallback(
async (lists: string[] | null) => {
Expand Down Expand Up @@ -935,11 +943,18 @@ const StoreItem = ({

<div className="w-full">
<Turnstile
ref={turnstileRef}
id={id}
siteKey={turnstileSiteKey}
onSuccess={setTurnstileToken}
onExpire={() => setTurnstileToken(undefined)}
onError={() => setTurnstileToken(undefined)}
onExpire={() => {
setTurnstileToken(undefined);
turnstileRef.current?.reset();
}}
onError={() => {
setTurnstileToken(undefined);
turnstileRef.current?.reset();
}}
options={{
size: 'flexible',
theme: 'light',
Expand Down