chore: build
This commit is contained in:
@@ -690,9 +690,22 @@ export default function CheckoutScreen() {
|
||||
<View style={styles.summaryTotal}>
|
||||
<Text style={styles.summaryTotalLabel}>Total</Text>
|
||||
<Text style={styles.summaryTotalValue}>
|
||||
{cartTotal.toFixed(2)} €
|
||||
{(useReferral && referralBalance > 0
|
||||
? Math.max(0, cartTotal - referralBalance)
|
||||
: cartTotal
|
||||
).toFixed(2)} €
|
||||
</Text>
|
||||
</View>
|
||||
{useReferral && referralBalance > 0 && (
|
||||
<View style={{ flexDirection: "row", justifyContent: "space-between", marginTop: 4 }}>
|
||||
<Text style={{ color: colors.textMuted, fontSize: fontSize.sm }}>
|
||||
Dont crédit parrainage
|
||||
</Text>
|
||||
<Text style={{ color: colors.success, fontSize: fontSize.sm }}>
|
||||
-{Math.min(referralBalance, cartTotal).toFixed(2)} €
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -1169,7 +1182,10 @@ export default function CheckoutScreen() {
|
||||
<View style={styles.recapTotalRow}>
|
||||
<Text style={styles.recapTotalLabel}>Total</Text>
|
||||
<Text style={styles.recapTotalValue}>
|
||||
{cartTotal.toFixed(2)} €
|
||||
{(useReferral && referralBalance > 0
|
||||
? Math.max(0, cartTotal - referralBalance)
|
||||
: cartTotal
|
||||
).toFixed(2)} €
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
|
||||
@@ -15,10 +15,12 @@ import {
|
||||
getMyPenalties,
|
||||
getPublicSettings,
|
||||
getReferralBalance,
|
||||
getMyPointsRewards,
|
||||
claimMyReward,
|
||||
formatOrderDate,
|
||||
formatPrice,
|
||||
} from "../../api/api";
|
||||
import type { PublicSettings } from "../../api/api";
|
||||
import type { PublicSettings, PointsPoolInfo, PointsRewardConfig } from "../../api/api";
|
||||
import type {
|
||||
CompletedOrder,
|
||||
ClientStats,
|
||||
@@ -47,16 +49,24 @@ export default function OrderHistoryScreen() {
|
||||
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, referral_enabled: false, pool_names: ['Pool 1', 'Pool 2'], crypto_payment_enabled: false, nowpayments_currencies: [], crypto_only: false, telegram_notifications_enabled: false, two_fa_enabled: false });
|
||||
const [referralBalance, setReferralBalance] = useState(0);
|
||||
const [pointsRewards, setPointsRewards] = useState<{
|
||||
enabled: boolean;
|
||||
pools: PointsPoolInfo[];
|
||||
reward: PointsRewardConfig | null;
|
||||
} | null>(null);
|
||||
const [claimingPool, setClaimingPool] = useState<string | null>(null);
|
||||
const [claimFeedback, setClaimFeedback] = useState<{ pool: string; type: "success" | "error"; text: string } | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const fetchData = useCallback(async () => {
|
||||
try {
|
||||
const [histRes, penRes, settings, refRes] = await Promise.all([
|
||||
const [histRes, penRes, settings, refRes, rewardsRes] = await Promise.all([
|
||||
getMyCompletedOrders(),
|
||||
getMyPenalties(),
|
||||
getPublicSettings(),
|
||||
getReferralBalance(),
|
||||
getMyPointsRewards(),
|
||||
]);
|
||||
if (histRes.success) {
|
||||
setOrders(histRes.commands || []);
|
||||
@@ -69,6 +79,9 @@ export default function OrderHistoryScreen() {
|
||||
setReferralBalance(refRes.balance);
|
||||
}
|
||||
setAppSettings(settings);
|
||||
if (rewardsRes.success && rewardsRes.enabled) {
|
||||
setPointsRewards(rewardsRes);
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
} finally {
|
||||
@@ -77,6 +90,19 @@ export default function OrderHistoryScreen() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleClaim = async (poolKey: string) => {
|
||||
setClaimingPool(poolKey);
|
||||
setClaimFeedback(null);
|
||||
const res = await claimMyReward(poolKey);
|
||||
setClaimingPool(null);
|
||||
if (res.success) {
|
||||
setClaimFeedback({ pool: poolKey, type: "success", text: res.description || "Récompense réclamée !" });
|
||||
getMyPointsRewards().then((r) => { if (r.success) setPointsRewards(r); });
|
||||
} else {
|
||||
setClaimFeedback({ pool: poolKey, type: "error", text: res.error || "Erreur" });
|
||||
}
|
||||
};
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
setLoading(true);
|
||||
@@ -132,6 +158,107 @@ export default function OrderHistoryScreen() {
|
||||
letterSpacing: 1,
|
||||
marginBottom: spacing.m,
|
||||
},
|
||||
rewardsSection: {
|
||||
backgroundColor: colors.bgCard,
|
||||
borderRadius: borderRadius.md,
|
||||
borderWidth: 1,
|
||||
borderColor: "#f59e0b44",
|
||||
padding: spacing.m,
|
||||
marginBottom: spacing.l,
|
||||
},
|
||||
rewardsSectionTitle: {
|
||||
color: "#f59e0b",
|
||||
fontSize: fontSize.xs,
|
||||
fontWeight: fontWeight.bold,
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: 0.8,
|
||||
},
|
||||
rewardsSectionDesc: {
|
||||
color: colors.textMuted,
|
||||
fontSize: fontSize.xs,
|
||||
fontStyle: "italic",
|
||||
marginBottom: spacing.m,
|
||||
},
|
||||
rewardPoolCard: {
|
||||
backgroundColor: "rgba(245,158,11,0.07)",
|
||||
borderRadius: borderRadius.sm,
|
||||
borderWidth: 1,
|
||||
borderColor: "rgba(245,158,11,0.2)",
|
||||
padding: spacing.m,
|
||||
marginTop: spacing.s,
|
||||
},
|
||||
rewardPoolName: {
|
||||
color: colors.textPrimary,
|
||||
fontSize: fontSize.sm,
|
||||
fontWeight: fontWeight.semibold,
|
||||
},
|
||||
rewardPoolPts: {
|
||||
color: "#f59e0b",
|
||||
fontSize: fontSize.sm,
|
||||
fontWeight: fontWeight.bold,
|
||||
},
|
||||
rewardAmountBadge: {
|
||||
backgroundColor: "rgba(16,185,129,0.15)",
|
||||
borderRadius: borderRadius.sm,
|
||||
paddingHorizontal: spacing.s,
|
||||
paddingVertical: 2,
|
||||
flexDirection: "row" as const,
|
||||
},
|
||||
rewardAmountText: {
|
||||
color: "#10b981",
|
||||
fontSize: fontSize.xs,
|
||||
fontWeight: fontWeight.bold,
|
||||
},
|
||||
progressBarBg: {
|
||||
height: 5,
|
||||
backgroundColor: "rgba(245,158,11,0.15)",
|
||||
borderRadius: 3,
|
||||
overflow: "hidden",
|
||||
marginVertical: spacing.xs,
|
||||
},
|
||||
progressBarFill: {
|
||||
height: "100%",
|
||||
backgroundColor: "#f59e0b",
|
||||
borderRadius: 3,
|
||||
},
|
||||
rewardAvailable: {
|
||||
color: "#10b981",
|
||||
fontSize: fontSize.xs,
|
||||
fontWeight: fontWeight.semibold,
|
||||
marginBottom: spacing.s,
|
||||
},
|
||||
rewardRemaining: {
|
||||
color: colors.textMuted,
|
||||
fontSize: fontSize.xs,
|
||||
marginBottom: spacing.s,
|
||||
},
|
||||
feedbackSuccess: {
|
||||
color: "#10b981",
|
||||
fontSize: fontSize.xs,
|
||||
fontStyle: "italic",
|
||||
marginBottom: spacing.xs,
|
||||
},
|
||||
feedbackError: {
|
||||
color: "#ef4444",
|
||||
fontSize: fontSize.xs,
|
||||
fontStyle: "italic",
|
||||
marginBottom: spacing.xs,
|
||||
},
|
||||
claimBtn: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
gap: spacing.xs,
|
||||
backgroundColor: "#f59e0b",
|
||||
borderRadius: borderRadius.sm,
|
||||
paddingVertical: spacing.s,
|
||||
paddingHorizontal: spacing.m,
|
||||
},
|
||||
claimBtnText: {
|
||||
color: "#fff",
|
||||
fontSize: fontSize.sm,
|
||||
fontWeight: fontWeight.bold,
|
||||
},
|
||||
referralBtn: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
@@ -342,6 +469,70 @@ export default function OrderHistoryScreen() {
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Section récompenses */}
|
||||
{pointsRewards?.enabled && pointsRewards.reward && pointsRewards.pools.length > 0 && (
|
||||
<View style={styles.rewardsSection}>
|
||||
<View style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs, marginBottom: spacing.xs }}>
|
||||
<Ionicons name="trophy-outline" size={14} color="#f59e0b" />
|
||||
<Text style={styles.rewardsSectionTitle}>Récompenses</Text>
|
||||
</View>
|
||||
{pointsRewards.reward.description !== "" && (
|
||||
<Text style={styles.rewardsSectionDesc}>{pointsRewards.reward.description}</Text>
|
||||
)}
|
||||
{pointsRewards.pools.map((pool) => {
|
||||
const threshold = pointsRewards.reward!.threshold;
|
||||
const progress = Math.min(1, (pool.points % threshold) / threshold);
|
||||
const remaining = threshold - (pool.points % threshold);
|
||||
const isClaiming = claimingPool === pool.key;
|
||||
const feedback = claimFeedback?.pool === pool.key ? claimFeedback : null;
|
||||
return (
|
||||
<View key={pool.key} style={styles.rewardPoolCard}>
|
||||
<View style={{ flexDirection: "row", justifyContent: "space-between", marginBottom: spacing.xs }}>
|
||||
<Text style={styles.rewardPoolName}>{pool.name}</Text>
|
||||
<Text style={styles.rewardPoolPts}>{pool.points} pts</Text>
|
||||
</View>
|
||||
{pool.eligible_configs.length > 0 && (
|
||||
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 4, marginBottom: spacing.xs }}>
|
||||
{pool.eligible_configs.map((cfg) => (
|
||||
<View key={cfg.category} style={styles.rewardAmountBadge}>
|
||||
<Text style={styles.rewardAmountText}>
|
||||
{cfg.category}{cfg.amount > 0 ? ` — ${cfg.amount}€` : ""}
|
||||
</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
<View style={styles.progressBarBg}>
|
||||
<View style={[styles.progressBarFill, { width: `${Math.round(progress * 100)}%` as any }]} />
|
||||
</View>
|
||||
<Text style={pool.rewards_available > 0 ? styles.rewardAvailable : styles.rewardRemaining}>
|
||||
{pool.rewards_available > 0
|
||||
? `${pool.rewards_available} récompense${pool.rewards_available > 1 ? "s" : ""} disponible${pool.rewards_available > 1 ? "s" : ""}`
|
||||
: `Encore ${remaining} pts pour une récompense`}
|
||||
</Text>
|
||||
{feedback && (
|
||||
<Text style={feedback.type === "success" ? styles.feedbackSuccess : styles.feedbackError}>
|
||||
{feedback.text}
|
||||
</Text>
|
||||
)}
|
||||
{pool.rewards_available > 0 && (
|
||||
<TouchableOpacity
|
||||
style={[styles.claimBtn, isClaiming && { opacity: 0.5 }]}
|
||||
onPress={() => handleClaim(pool.key)}
|
||||
disabled={isClaiming}
|
||||
>
|
||||
<Ionicons name="gift-outline" size={14} color="#fff" />
|
||||
<Text style={styles.claimBtnText}>
|
||||
{isClaiming ? "..." : "Réclamer ma récompense"}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* Bouton parrainage — visible seulement si activé dans les settings */}
|
||||
{appSettings.referral_enabled && <TouchableOpacity
|
||||
style={styles.referralBtn}
|
||||
|
||||
Reference in New Issue
Block a user