chore: fix
This commit is contained in:
@@ -704,6 +704,27 @@ export const markNotificationsRead = async (): Promise<{
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================
|
||||
// PUBLIC SETTINGS
|
||||
// ============================================
|
||||
|
||||
export interface PublicSettings {
|
||||
penalties_enabled: boolean;
|
||||
points_enabled: boolean;
|
||||
}
|
||||
|
||||
export const getPublicSettings = async (): Promise<PublicSettings> => {
|
||||
try {
|
||||
const { data } = await apiClient.get(`${V1}/app-settings`);
|
||||
return {
|
||||
penalties_enabled: data.penalties_enabled ?? true,
|
||||
points_enabled: data.points_enabled ?? true,
|
||||
};
|
||||
} catch {
|
||||
return { penalties_enabled: true, points_enabled: true };
|
||||
}
|
||||
};
|
||||
|
||||
export const calculateOrderTotal = (order: any): number => {
|
||||
if (typeof order.total === "number" && order.total > 0) return order.total;
|
||||
if (typeof order.total_prix === "number" && order.total_prix > 0)
|
||||
|
||||
@@ -13,9 +13,11 @@ import { Ionicons } from "@expo/vector-icons";
|
||||
import {
|
||||
getMyCompletedOrders,
|
||||
getMyPenalties,
|
||||
getPublicSettings,
|
||||
formatOrderDate,
|
||||
formatPrice,
|
||||
} from "../../api/api";
|
||||
import type { PublicSettings } from "../../api/api";
|
||||
import type {
|
||||
CompletedOrder,
|
||||
ClientStats,
|
||||
@@ -42,14 +44,16 @@ 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, points_enabled: true });
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const fetchData = useCallback(async () => {
|
||||
try {
|
||||
const [histRes, penRes] = await Promise.all([
|
||||
const [histRes, penRes, settings] = await Promise.all([
|
||||
getMyCompletedOrders(),
|
||||
getMyPenalties(),
|
||||
getPublicSettings(),
|
||||
]);
|
||||
if (histRes.success) {
|
||||
setOrders(histRes.commands || []);
|
||||
@@ -58,6 +62,7 @@ export default function OrderHistoryScreen() {
|
||||
if (penRes.success) {
|
||||
setPenalties(penRes.data || null);
|
||||
}
|
||||
setAppSettings(settings);
|
||||
} catch {
|
||||
/* ignore */
|
||||
} finally {
|
||||
@@ -239,48 +244,52 @@ export default function OrderHistoryScreen() {
|
||||
</Text>
|
||||
<Text style={styles.statLabel}>Commandes</Text>
|
||||
</View>
|
||||
<View style={[styles.statCard, shadows.sm]}>
|
||||
<Ionicons
|
||||
name="leaf-outline"
|
||||
size={24}
|
||||
color={colors.categoryWeedHash}
|
||||
/>
|
||||
<Text style={styles.statValue}>
|
||||
{stats?.points || 0}
|
||||
</Text>
|
||||
<Text style={styles.statLabel}>
|
||||
Pts Weed/Hash
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[styles.statCard, shadows.sm]}>
|
||||
<Ionicons
|
||||
name="flash-outline"
|
||||
size={24}
|
||||
color={colors.info}
|
||||
/>
|
||||
<Text style={styles.statValue}>
|
||||
{stats?.points_zipette || 0}
|
||||
</Text>
|
||||
<Text style={styles.statLabel}>
|
||||
Pts Zipette
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[styles.statCard, shadows.sm]}>
|
||||
<Ionicons
|
||||
name="trophy-outline"
|
||||
size={24}
|
||||
color={colors.warning}
|
||||
/>
|
||||
<Text style={styles.statValue}>
|
||||
{totalPoints}
|
||||
</Text>
|
||||
<Text style={styles.statLabel}>
|
||||
Total Points
|
||||
</Text>
|
||||
</View>
|
||||
{appSettings.points_enabled && (
|
||||
<>
|
||||
<View style={[styles.statCard, shadows.sm]}>
|
||||
<Ionicons
|
||||
name="leaf-outline"
|
||||
size={24}
|
||||
color={colors.categoryWeedHash}
|
||||
/>
|
||||
<Text style={styles.statValue}>
|
||||
{stats?.points || 0}
|
||||
</Text>
|
||||
<Text style={styles.statLabel}>
|
||||
Pts Weed/Hash
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[styles.statCard, shadows.sm]}>
|
||||
<Ionicons
|
||||
name="flash-outline"
|
||||
size={24}
|
||||
color={colors.info}
|
||||
/>
|
||||
<Text style={styles.statValue}>
|
||||
{stats?.points_zipette || 0}
|
||||
</Text>
|
||||
<Text style={styles.statLabel}>
|
||||
Pts Zipette
|
||||
</Text>
|
||||
</View>
|
||||
<View style={[styles.statCard, shadows.sm]}>
|
||||
<Ionicons
|
||||
name="trophy-outline"
|
||||
size={24}
|
||||
color={colors.warning}
|
||||
/>
|
||||
<Text style={styles.statValue}>
|
||||
{totalPoints}
|
||||
</Text>
|
||||
<Text style={styles.statLabel}>
|
||||
Total Points
|
||||
</Text>
|
||||
</View>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{penaltyCount > 0 && (
|
||||
{appSettings.penalties_enabled && penaltyCount > 0 && (
|
||||
<View
|
||||
style={[
|
||||
styles.penaltyBanner,
|
||||
|
||||
Reference in New Issue
Block a user