MonEspacePro/pro/src/ui.tsx
Tony AVERTY 6725358a7c App Pro (Expo) et API du comptoir avec anti-triche
- API /staff : profil, scan d'une carte, crédit (montant ou tampon),
  récompenses, historique (gérant : tout le magasin, employé : le sien),
  résumé du jour
- Anti-triche côté serveur : carte du bon magasin, plafond de montant,
  délai minimum entre deux crédits (atomique, scans simultanés compris),
  tentatives refusées journalisées avec l'employé
- App Expo SDK 54 / Expo Router : connexion, accueil, scanner QR avec
  lampe, fiche client, pavé numérique, récompenses, confirmation, erreurs,
  historique ; icônes générées depuis le logo

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 12:50:59 +02:00

115 lines
4.3 KiB
TypeScript

import { ReactNode } from 'react';
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, TextProps, View, ViewStyle } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import Svg, { Circle, Path } from 'react-native-svg';
import { font, useColors } from './theme';
export function Screen({ children, scroll = false, style }: { children: ReactNode; scroll?: boolean; style?: ViewStyle }) {
const c = useColors();
const inner = <View style={[{ padding: 20, gap: 20, flexGrow: 1 }, style]}>{children}</View>;
return (
<SafeAreaView style={{ flex: 1, backgroundColor: c.bg }} edges={['bottom', 'left', 'right']}>
{scroll ? <ScrollView contentContainerStyle={{ flexGrow: 1 }}>{inner}</ScrollView> : inner}
</SafeAreaView>
);
}
type Variant = 'h1' | 'h2' | 'body' | 'label' | 'muted' | 'big';
export function T({ v = 'body', style, ...props }: TextProps & { v?: Variant }) {
const c = useColors();
const s = {
h1: { fontFamily: font.bold, fontSize: 28, lineHeight: 34, color: c.text },
h2: { fontFamily: font.bold, fontSize: 20, lineHeight: 26, color: c.text },
body: { fontFamily: font.regular, fontSize: 17, lineHeight: 24, color: c.text },
label: { fontFamily: font.semibold, fontSize: 15, lineHeight: 20, color: c.text },
muted: { fontFamily: font.regular, fontSize: 15, lineHeight: 21, color: c.text3 },
big: { fontFamily: font.extrabold, fontSize: 56, lineHeight: 62, color: c.text },
}[v];
return <Text {...props} style={[s, style]} />;
}
export function Button({
label,
onPress,
variant = 'primary',
disabled,
loading,
icon,
large,
}: {
label: string;
onPress: () => void;
variant?: 'primary' | 'secondary' | 'danger';
disabled?: boolean;
loading?: boolean;
icon?: ReactNode;
large?: boolean;
}) {
const c = useColors();
const bg = { primary: c.primary, secondary: c.surface, danger: c.err }[variant];
const fg = variant === 'secondary' ? c.text : c.onPrimary;
return (
<Pressable
accessibilityRole="button"
accessibilityState={{ disabled: !!disabled || !!loading }}
disabled={disabled || loading}
onPress={onPress}
style={({ pressed }) => [
styles.btn,
{
backgroundColor: variant === 'primary' && pressed ? c.primaryPressed : bg,
borderColor: variant === 'secondary' ? c.border : bg,
minHeight: large ? 72 : 56,
opacity: disabled ? 0.5 : pressed && variant !== 'primary' ? 0.8 : 1,
},
]}
>
{loading ? (
<ActivityIndicator color={fg} />
) : (
<>
{icon}
<Text style={{ fontFamily: font.bold, fontSize: large ? 20 : 17, color: fg }}>{label}</Text>
</>
)}
</Pressable>
);
}
export function Card({ children, style }: { children: ReactNode; style?: ViewStyle }) {
const c = useColors();
return <View style={[{ backgroundColor: c.surface, borderColor: c.border, borderWidth: 1, borderRadius: 16, padding: 18, gap: 8 }, style]}>{children}</View>;
}
export function Banner({ tone, children }: { tone: 'error' | 'warn' | 'ok'; children: ReactNode }) {
const c = useColors();
const [bg, fg] = { error: [c.errBg, c.err], warn: [c.warnBg, c.warn], ok: [c.okBg, c.ok] }[tone];
return (
<View accessibilityRole="alert" style={{ backgroundColor: bg, borderRadius: 12, padding: 14 }}>
<Text style={{ color: fg, fontFamily: font.semibold, fontSize: 15, lineHeight: 21 }}>{children}</Text>
</View>
);
}
/** Symbole officiel MonEspacePro. */
export function BrandSymbol({ size = 32, arch }: { size?: number; arch?: string }) {
const c = useColors();
return (
<Svg width={size} height={size} viewBox="0.5 -2 64 64">
<Path d="M12 54V32a9 9 0 0 1 18 0v22M30 32a9 9 0 0 1 18 0v22" fill="none" stroke={arch ?? c.primary} strokeWidth={8} />
<Circle cx={51} cy={12} r={6} fill="#F2B544" />
</Svg>
);
}
export const euros = (cents: number) => (cents / 100).toLocaleString('fr-FR', { style: 'currency', currency: 'EUR' });
export function unit(mode: 'AMOUNT' | 'STAMP', n = 2) {
if (mode === 'STAMP') return n > 1 ? 'tampons' : 'tampon';
return n > 1 ? 'points' : 'point';
}
const styles = StyleSheet.create({
btn: { borderRadius: 14, borderWidth: 1, paddingHorizontal: 20, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 10 },
});