chore: add parrainage
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
getMyCompletedOrders,
|
||||
getMyPenalties,
|
||||
getPublicSettings,
|
||||
getReferralBalance,
|
||||
formatOrderDate,
|
||||
formatPrice,
|
||||
} from "../../api/api";
|
||||
@@ -44,16 +45,18 @@ export default function OrderHistoryScreen() {
|
||||
const [orders, setOrders] = useState<CompletedOrder[]>([]);
|
||||
const [stats, setStats] = useState<ClientStats | null>(null);
|
||||
const [penalties, setPenalties] = useState<PenaltyInfo | null>(null);
|
||||
const [appSettings, setAppSettings] = useState<PublicSettings>({ penalties_enabled: true, show_amende_score: true, points_enabled: true, points_separated: true });
|
||||
const [appSettings, setAppSettings] = useState<PublicSettings>({ penalties_enabled: true, show_amende_score: true, points_enabled: true, points_separated: true, referral_enabled: true });
|
||||
const [referralBalance, setReferralBalance] = useState(0);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const fetchData = useCallback(async () => {
|
||||
try {
|
||||
const [histRes, penRes, settings] = await Promise.all([
|
||||
const [histRes, penRes, settings, refRes] = await Promise.all([
|
||||
getMyCompletedOrders(),
|
||||
getMyPenalties(),
|
||||
getPublicSettings(),
|
||||
getReferralBalance(),
|
||||
]);
|
||||
if (histRes.success) {
|
||||
setOrders(histRes.commands || []);
|
||||
@@ -62,6 +65,9 @@ export default function OrderHistoryScreen() {
|
||||
if (penRes.success) {
|
||||
setPenalties(penRes.data || null);
|
||||
}
|
||||
if (refRes.success) {
|
||||
setReferralBalance(refRes.balance);
|
||||
}
|
||||
setAppSettings(settings);
|
||||
} catch {
|
||||
/* ignore */
|
||||
@@ -118,28 +124,6 @@ export default function OrderHistoryScreen() {
|
||||
fontSize: fontSize.xs,
|
||||
marginTop: spacing.xs,
|
||||
},
|
||||
penaltyBanner: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.s,
|
||||
padding: spacing.m,
|
||||
borderRadius: borderRadius.sm,
|
||||
marginBottom: spacing.xl,
|
||||
},
|
||||
penaltyWarning: {
|
||||
backgroundColor: colors.warning + "22",
|
||||
borderWidth: 1,
|
||||
borderColor: colors.warning + "44",
|
||||
},
|
||||
penaltyCritical: {
|
||||
backgroundColor: colors.danger + "22",
|
||||
borderWidth: 1,
|
||||
borderColor: colors.danger + "44",
|
||||
},
|
||||
penaltyText: {
|
||||
fontSize: fontSize.sm,
|
||||
fontWeight: fontWeight.semibold,
|
||||
},
|
||||
sectionTitle: {
|
||||
color: colors.textSecondary,
|
||||
fontSize: fontSize.sm,
|
||||
@@ -148,6 +132,24 @@ export default function OrderHistoryScreen() {
|
||||
letterSpacing: 1,
|
||||
marginBottom: spacing.m,
|
||||
},
|
||||
referralBtn: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: spacing.s,
|
||||
backgroundColor: colors.bgCard,
|
||||
borderRadius: borderRadius.sm,
|
||||
borderWidth: 1,
|
||||
borderColor: colors.accent + "44",
|
||||
paddingVertical: spacing.m,
|
||||
paddingHorizontal: spacing.l,
|
||||
marginBottom: spacing.l,
|
||||
},
|
||||
referralBtnText: {
|
||||
color: colors.accent,
|
||||
fontSize: fontSize.sm,
|
||||
fontWeight: fontWeight.semibold,
|
||||
flex: 1,
|
||||
},
|
||||
emptyContainer: {
|
||||
alignItems: "center",
|
||||
paddingTop: spacing.xxxl,
|
||||
@@ -303,42 +305,63 @@ export default function OrderHistoryScreen() {
|
||||
</View>
|
||||
)
|
||||
)}
|
||||
</View>
|
||||
|
||||
{appSettings.show_amende_score && penaltyCount > 0 && (
|
||||
<View
|
||||
style={[
|
||||
styles.penaltyBanner,
|
||||
penaltyCount >= 3
|
||||
? styles.penaltyCritical
|
||||
: styles.penaltyWarning,
|
||||
]}
|
||||
>
|
||||
<Ionicons
|
||||
name="warning"
|
||||
size={20}
|
||||
color={
|
||||
penaltyCount >= 3
|
||||
? colors.danger
|
||||
: colors.warning
|
||||
}
|
||||
/>
|
||||
<Text
|
||||
{appSettings.show_amende_score && (
|
||||
<View
|
||||
style={[
|
||||
styles.penaltyText,
|
||||
{
|
||||
color:
|
||||
styles.statCard,
|
||||
shadows.sm,
|
||||
penaltyCount > 0 && {
|
||||
borderWidth: 1,
|
||||
borderColor:
|
||||
penaltyCount >= 3
|
||||
? colors.danger
|
||||
: colors.warning,
|
||||
? colors.danger + "88"
|
||||
: colors.warning + "88",
|
||||
backgroundColor:
|
||||
penaltyCount >= 3
|
||||
? colors.danger + "18"
|
||||
: colors.warning + "18",
|
||||
},
|
||||
]}
|
||||
>
|
||||
{penaltyCount} penalite
|
||||
{penaltyCount > 1 ? "s" : ""}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
<Ionicons
|
||||
name={penaltyCount > 0 ? "warning" : "shield-checkmark-outline"}
|
||||
size={24}
|
||||
color={
|
||||
penaltyCount >= 3
|
||||
? colors.danger
|
||||
: penaltyCount > 0
|
||||
? colors.warning
|
||||
: colors.textMuted
|
||||
}
|
||||
/>
|
||||
<Text
|
||||
style={[
|
||||
styles.statValue,
|
||||
penaltyCount >= 3 && { color: colors.danger },
|
||||
penaltyCount > 0 && penaltyCount < 3 && { color: colors.warning },
|
||||
]}
|
||||
>
|
||||
{penaltyCount}
|
||||
</Text>
|
||||
<Text style={styles.statLabel}>
|
||||
Score amendes
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Bouton parrainage — visible seulement si activé dans les settings */}
|
||||
{appSettings.referral_enabled && <TouchableOpacity
|
||||
style={styles.referralBtn}
|
||||
onPress={() => navigation.navigate("Parrainage")}
|
||||
>
|
||||
<Ionicons name="gift-outline" size={18} color={colors.accent} />
|
||||
<Text style={styles.referralBtnText}>
|
||||
Parrainage
|
||||
{referralBalance > 0 ? ` — ${referralBalance.toFixed(2)} €` : ""}
|
||||
</Text>
|
||||
<Ionicons name="chevron-forward" size={16} color={colors.textMuted} />
|
||||
</TouchableOpacity>}
|
||||
|
||||
{orders.length > 0 && (
|
||||
<Text style={styles.sectionTitle}>
|
||||
|
||||
Reference in New Issue
Block a user