Expo Router app for summit attendees: email OTP login, booth and investee QR scanning (camera + manual entry, /q/<token> universal links), mystery investee celebration, points/rank/progress home, leaderboard, raffles, merch ordering with pickup QR, and ticket QRs. Built against the attendee, auth and public endpoints in GRV-Backend/API.md. Theme, fonts, icon and splash follow the GRVSummit site. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
194 lines
6.8 KiB
TypeScript
194 lines
6.8 KiB
TypeScript
import { router } from 'expo-router';
|
||
import { useState } from 'react';
|
||
import { Image, Pressable, Text, View } from 'react-native';
|
||
import { OrderCard } from '../components/OrderCard';
|
||
import { BackBar, Button, Card, ErrorBox, H1, Loading, P, Screen, s } from '../components/ui';
|
||
import { api, formatMoney, invalidateAll, useMerch, type Order } from '../lib/api';
|
||
import { colors, fonts, radius } from '../lib/theme';
|
||
|
||
type Pick = { size: string | null; qty: number };
|
||
|
||
export default function Merch() {
|
||
const q = useMerch();
|
||
const [picks, setPicks] = useState<Record<string, Pick>>({});
|
||
const [busy, setBusy] = useState(false);
|
||
const [error, setError] = useState<string | null>(null);
|
||
const [order, setOrder] = useState<Order | null>(null);
|
||
|
||
const items = q.data ?? [];
|
||
const chosen = items.filter((i) => (picks[i.id]?.qty ?? 0) > 0);
|
||
const total = chosen.reduce((sum, i) => sum + i.priceMinor * picks[i.id]!.qty, 0);
|
||
const missingSize = chosen.some((i) => i.sizes.length > 0 && !picks[i.id]!.size);
|
||
const set = (id: string, patch: Partial<Pick>) =>
|
||
setPicks((p) => ({ ...p, [id]: { size: null, qty: 0, ...p[id], ...patch } }));
|
||
|
||
async function place() {
|
||
setBusy(true);
|
||
setError(null);
|
||
try {
|
||
const o = await api<Order>('/merch-orders', {
|
||
body: {
|
||
items: chosen.map((i) => ({
|
||
merchItemId: i.id,
|
||
qty: picks[i.id]!.qty,
|
||
...(picks[i.id]!.size ? { size: picks[i.id]!.size } : {}),
|
||
})),
|
||
},
|
||
});
|
||
setOrder(o);
|
||
setPicks({});
|
||
void invalidateAll();
|
||
} catch (e) {
|
||
setError((e as Error).message);
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}
|
||
|
||
if (order) {
|
||
return (
|
||
<Screen bar={<BackBar title="Order placed" onBack={() => router.back()} />}>
|
||
<H1 style={{ fontSize: 24 }}>Pay and collect at the GRV booth</H1>
|
||
<P muted>Show this QR at the GRV booth. You'll pay there and pick up your merch.</P>
|
||
<OrderCard order={order} />
|
||
<Button title="Done" onPress={() => router.back()} />
|
||
</Screen>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<Screen
|
||
bar={<BackBar title="GRV merch" onBack={() => router.back()} />}
|
||
onRefresh={() => void q.refetch()}
|
||
refreshing={q.isRefetching}
|
||
>
|
||
<P muted>Order here, then pay and collect at the GRV booth.</P>
|
||
{q.isPending ? (
|
||
<Loading />
|
||
) : q.error ? (
|
||
<ErrorBox error={q.error} onRetry={() => void q.refetch()} />
|
||
) : items.length === 0 ? (
|
||
<P muted>Merch is coming soon.</P>
|
||
) : (
|
||
items.map((i) => {
|
||
const pick = picks[i.id] ?? { size: null, qty: 0 };
|
||
const soldOut = i.stock <= 0;
|
||
return (
|
||
<Card key={i.id} style={{ gap: 10 }}>
|
||
{i.imageUrl && (
|
||
<Image
|
||
source={{ uri: i.imageUrl }}
|
||
style={{
|
||
width: '100%',
|
||
aspectRatio: 4 / 3,
|
||
borderRadius: radius,
|
||
backgroundColor: colors.surfaceMuted,
|
||
}}
|
||
/>
|
||
)}
|
||
<View style={{ flexDirection: 'row', justifyContent: 'space-between', gap: 8 }}>
|
||
<Text style={{ flex: 1, fontFamily: fonts.bold, fontSize: 17, color: colors.ink }}>
|
||
{i.name}
|
||
</Text>
|
||
<Text style={[s.num, { fontSize: 17 }]}>
|
||
{formatMoney(i.priceMinor, i.currency)}
|
||
</Text>
|
||
</View>
|
||
{i.description && (
|
||
<P muted style={{ fontSize: 14 }}>
|
||
{i.description}
|
||
</P>
|
||
)}
|
||
{soldOut ? (
|
||
<Text style={{ fontFamily: fonts.semibold, color: colors.destructive }}>
|
||
Sold out
|
||
</Text>
|
||
) : (
|
||
<>
|
||
{i.sizes.length > 0 && (
|
||
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 8 }}>
|
||
{i.sizes.map((sz) => (
|
||
<Pressable
|
||
key={sz}
|
||
onPress={() => set(i.id, { size: sz, qty: pick.qty || 1 })}
|
||
style={[s.chip, pick.size === sz && s.chipOn]}
|
||
>
|
||
<Text style={{ fontFamily: fonts.semibold, color: colors.ink }}>
|
||
{sz}
|
||
</Text>
|
||
</Pressable>
|
||
))}
|
||
</View>
|
||
)}
|
||
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 16 }}>
|
||
<Stepper
|
||
label="−"
|
||
onPress={() => set(i.id, { qty: Math.max(0, pick.qty - 1) })}
|
||
disabled={pick.qty === 0}
|
||
/>
|
||
<Text style={[s.num, { fontSize: 18, minWidth: 24, textAlign: 'center' }]}>
|
||
{pick.qty}
|
||
</Text>
|
||
<Stepper
|
||
label="+"
|
||
onPress={() => set(i.id, { qty: Math.min(i.stock, pick.qty + 1) })}
|
||
disabled={pick.qty >= i.stock}
|
||
/>
|
||
</View>
|
||
</>
|
||
)}
|
||
</Card>
|
||
);
|
||
})
|
||
)}
|
||
{chosen.length > 0 && (
|
||
<Card tone="muted" style={{ gap: 10 }}>
|
||
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
|
||
<Text style={{ fontFamily: fonts.semibold, color: colors.ink }}>Total</Text>
|
||
<Text style={[s.num, { fontSize: 18 }]}>{formatMoney(total, chosen[0]!.currency)}</Text>
|
||
</View>
|
||
{missingSize && (
|
||
<P style={{ fontSize: 14, color: colors.destructive }}>Pick a size for each item.</P>
|
||
)}
|
||
<Button title="Place order" onPress={place} loading={busy} disabled={missingSize} />
|
||
<P muted style={{ fontSize: 13, textAlign: 'center' }}>
|
||
Pay & collect at the GRV booth.
|
||
</P>
|
||
</Card>
|
||
)}
|
||
{error && <P style={{ color: colors.destructive }}>{error}</P>}
|
||
</Screen>
|
||
);
|
||
}
|
||
|
||
function Stepper({
|
||
label,
|
||
onPress,
|
||
disabled,
|
||
}: {
|
||
label: string;
|
||
onPress: () => void;
|
||
disabled?: boolean;
|
||
}) {
|
||
return (
|
||
<Pressable
|
||
onPress={onPress}
|
||
disabled={disabled}
|
||
accessibilityRole="button"
|
||
accessibilityLabel={label === '+' ? 'Increase quantity' : 'Decrease quantity'}
|
||
style={{
|
||
width: 40,
|
||
height: 40,
|
||
borderRadius: 20,
|
||
borderWidth: 1.5,
|
||
borderColor: colors.primary,
|
||
alignItems: 'center',
|
||
justifyContent: 'center',
|
||
opacity: disabled ? 0.35 : 1,
|
||
}}
|
||
>
|
||
<Text style={{ fontFamily: fonts.bold, fontSize: 20, color: colors.primary }}>{label}</Text>
|
||
</Pressable>
|
||
);
|
||
}
|