chore: build
Backend - Build & Lint / build (push) Successful in 32m22s
Frontend Admin - EAS Build / build (push) Successful in 1h39m14s

This commit is contained in:
Cameron Foussard
2026-11-03 09:12:36 +01:00
parent 0a18460f13
commit ae89d995d2
5 changed files with 98 additions and 15 deletions
+11 -1
View File
@@ -233,10 +233,19 @@ export const getAllClients = async (
};
};
// Totaux globaux (toute la base, pas seulement la page chargée).
export interface UserCounts {
all: number;
client: number;
livreur: number;
cabine: number;
admin: number;
}
export const getAllUsers = async (
offset = 0,
limit = 100,
): Promise<PagedResult<AdminUserItem>> => {
): Promise<PagedResult<AdminUserItem> & { counts?: UserCounts }> => {
const { data } = await apiClient.get(`${V2}/admin/protected/all/users`, {
params: { limit, offset },
});
@@ -244,6 +253,7 @@ export const getAllUsers = async (
items: data.users || [],
total: data.count ?? 0,
hasMore: !!data.has_more,
counts: data.counts ?? undefined,
};
};
@@ -18,6 +18,7 @@ import { useAuth } from "../../auth/AuthContext";
import {
getAllCommands,
getAllClients,
getAllUsers,
getAvailableDeliveryPersons,
getCommandCountByStatus,
getAdminTelegramStatus,
@@ -46,15 +47,22 @@ export default function DashboardScreen() {
const loadStats = useCallback(async () => {
try {
const [allCmd, pending, enRoute, completed, clients, livreurs] =
const [allCmd, pending, enRoute, completed, userCounts, livreurs] =
await Promise.all([
getAllCommands().then((r) => r.count),
getCommandCountByStatus("pending"),
getCommandCountByStatus("en_route"),
getCommandCountByStatus("approved"),
getAllClients(0, 1)
.then((r) => r.total)
.catch(() => 0),
// Totaux globaux (toute la base) : on ne charge qu'1 user,
// seuls les compteurs nous intéressent.
getAllUsers(0, 1)
.then(async (r) => ({
all: r.counts?.all ?? r.total,
client:
r.counts?.client ??
(await getAllClients(0, 1)).total,
}))
.catch(() => ({ all: 0, client: 0 })),
getAvailableDeliveryPersons()
.then((r) => r.count)
.catch(() => 0),
@@ -85,9 +93,15 @@ export default function DashboardScreen() {
icon: "checkmark-circle-outline",
color: colors.success,
},
{
label: "Utilisateurs",
value: userCounts.all,
icon: "person-outline",
color: colors.accent,
},
{
label: "Clients",
value: clients,
value: userCounts.client,
icon: "people-outline",
color: colors.accentLight,
},
@@ -36,7 +36,11 @@ import {
subtractClientPoints,
getLivreurLoginHistory,
} from "../../api/api_admin";
import type { CancelledOrder, LoginHistoryWeek } from "../../api/api_admin";
import type {
CancelledOrder,
LoginHistoryWeek,
UserCounts,
} from "../../api/api_admin";
import type { ClientResponse } from "../../api/types";
import LoadingSpinner from "../../components/ui/LoadingSpinner";
import Card from "../../components/ui/Card";
@@ -144,6 +148,9 @@ export default function UsersScreen() {
const [usersHasMore, setUsersHasMore] = useState(true);
const [clientsHasMore, setClientsHasMore] = useState(true);
const [loadingMore, setLoadingMore] = useState(false);
// Totaux globaux renvoyés par le backend (toute la base, pas seulement
// les pages déjà chargées).
const [counts, setCounts] = useState<UserCounts | null>(null);
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [poolNames, setPoolNames] = useState<string[]>([]);
@@ -264,6 +271,7 @@ export default function UsersScreen() {
]);
setUsers(usersRes.items);
setClients(clientsRes.items);
if (usersRes.counts) setCounts(usersRes.counts);
setUsersHasMore(usersRes.hasMore);
setClientsHasMore(clientsRes.hasMore);
if (settingsRes.success && settingsRes.settings) {
@@ -402,15 +410,21 @@ export default function UsersScreen() {
return merged;
}, [allMergedUsers, filter, search]);
// Stats
// Stats : totaux globaux du backend. Repli sur les données chargées
// uniquement si le backend n'a pas renvoyé les totaux.
const totalAll = counts?.all ?? allMergedUsers.length;
const totalClients =
users.filter((u) => u.role === "client").length || clients.length;
const totalLivreurs = users.filter((u) => u.role === "livreur").length;
const totalCabines = users.filter((u) => u.role === "cabine").length;
const totalAdmins = users.filter((u) => u.role === "admin").length;
counts?.client ??
(users.filter((u) => u.role === "client").length || clients.length);
const totalLivreurs =
counts?.livreur ?? users.filter((u) => u.role === "livreur").length;
const totalCabines =
counts?.cabine ?? users.filter((u) => u.role === "cabine").length;
const totalAdmins =
counts?.admin ?? users.filter((u) => u.role === "admin").length;
const getCountForFilter = (f: RoleFilter) => {
if (f === "all") return mergedUsers.length;
if (f === "all") return totalAll;
if (f === "client") return totalClients;
if (f === "livreur") return totalLivreurs;
if (f === "cabine") return totalCabines;
@@ -933,6 +947,7 @@ export default function UsersScreen() {
const freshUsers = await getAllUsers(0, PAGE_SIZE);
setUsers(freshUsers.items);
setUsersHasMore(freshUsers.hasMore);
if (freshUsers.counts) setCounts(freshUsers.counts);
if (
freshUsers.items.find(
(u) => u.username === usernameToCreate,