From ac5ec11f5437789ab034415746a67fa841e607a0 Mon Sep 17 00:00:00 2001 From: Xor290 Date: Wed, 25 Mar 2026 09:41:53 +0100 Subject: [PATCH] chore: fix ui bug --- frontend-admin/src/api/api_delivery.ts | 14 +++++ .../src/screens/admin/UsersScreen.tsx | 57 ++++++++++++++----- .../src/screens/delivery/DashboardScreen.tsx | 16 +++--- mobile/src/api/api_types.ts | 3 +- 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/frontend-admin/src/api/api_delivery.ts b/frontend-admin/src/api/api_delivery.ts index 3fa8e2cd..31242526 100644 --- a/frontend-admin/src/api/api_delivery.ts +++ b/frontend-admin/src/api/api_delivery.ts @@ -180,6 +180,20 @@ export const updateMyLocation = async ( } }; +export const getDeliveryNavLink = async ( + deliveryId: number, +): Promise<{ success: boolean; waze_app?: string; error?: string }> => { + try { + const { data } = await apiClient.get(`${API}/deliveries/${deliveryId}/nav-link`); + return { success: true, waze_app: data.waze_app }; + } catch (error: any) { + return { + success: false, + error: error.response?.data?.error || "Erreur réseau", + }; + } +}; + export const getMyLocation = async (): Promise<{ success: boolean; latitude?: number; diff --git a/frontend-admin/src/screens/admin/UsersScreen.tsx b/frontend-admin/src/screens/admin/UsersScreen.tsx index 9a11d15e..0ec3bacf 100644 --- a/frontend-admin/src/screens/admin/UsersScreen.tsx +++ b/frontend-admin/src/screens/admin/UsersScreen.tsx @@ -131,6 +131,7 @@ export default function UsersScreen() { const [poolKeys, setPoolKeys] = useState([]); const [pointsEnabled, setPointsEnabled] = useState(true); const [amendeEnabled, setAmendeEnabled] = useState(true); + const [referralEnabled, setReferralEnabled] = useState(true); const [filter, setFilter] = useState("all"); const [search, setSearch] = useState(""); @@ -142,6 +143,8 @@ export default function UsersScreen() { const [editNom, setEditNom] = useState(""); const [editPrenom, setEditPrenom] = useState(""); const [editTel, setEditTel] = useState(""); + const [editClientUsername, setEditClientUsername] = useState(""); + const [editClientPassword, setEditClientPassword] = useState(""); // Edit user modal (livreur/cabine) const [editUserModal, setEditUserModal] = useState<{ @@ -192,6 +195,7 @@ export default function UsersScreen() { setPoolKeys(pools.map((p) => p.key)); setPointsEnabled(settingsRes.settings.points_enabled ?? true); setAmendeEnabled(settingsRes.settings.show_amende_score ?? true); + setReferralEnabled(settingsRes.settings.referral_enabled ?? true); } } catch { /* ignore */ @@ -283,21 +287,32 @@ export default function UsersScreen() { setEditNom(client.nom); setEditPrenom(client.prenom); setEditTel(client.telephone); + setEditClientUsername(client.username); + setEditClientPassword(""); setEditClientModal({ visible: true, client }); }; const handleSaveClient = async () => { if (!editClientModal.client) return; + if (editClientPassword.trim() && editClientPassword.trim().length < 8) { + showError("Erreur", "Le mot de passe doit contenir au moins 8 caractères"); + return; + } try { - await updateClientByAdmin(editClientModal.client.id, { + const updates: Record = { nom: editNom, prenom: editPrenom, telephone: editTel, - }); + username: editClientUsername, + }; + if (editClientPassword.trim()) { + updates.password = editClientPassword.trim(); + } + await updateClientByAdmin(editClientModal.client.id, updates); setEditClientModal({ visible: false, client: null }); await loadData(); } catch (e: any) { - showError("Erreur", e.message); + showError("Erreur", e.response?.data?.error || e.message); } }; @@ -723,16 +738,18 @@ export default function UsersScreen() { {isClient && ( <> - openReferralModal(item.clientData!)} - > - - + {referralEnabled && ( + openReferralModal(item.clientData!)} + > + + + )} openEditClient(item.clientData!)} @@ -826,7 +843,7 @@ export default function UsersScreen() { Annul. - {(item.clientData.referral_balance ?? 0) > 0 && ( + {referralEnabled && (item.clientData.referral_balance ?? 0) > 0 && ( + + { - const encoded = encodeURIComponent(address); - const wazeApp = `waze://?q=${encoded}&navigate=yes`; - const wazeWeb = `https://waze.com/ul?q=${encoded}&navigate=yes`; - Linking.openURL(wazeApp).catch(() => { - Linking.openURL(wazeWeb); - }); + const openNavigation = async (deliveryId: number, address: string) => { + const res = await getDeliveryNavLink(deliveryId); + const link = res.success && res.waze_app + ? res.waze_app + : `waze://?q=${encodeURIComponent(address)}&navigate=yes`; + Linking.openURL(link); }; // -------------------------------------------------- @@ -577,7 +577,7 @@ export default function DashboardScreen() { openNavigation(item.adresse)} + onPress={() => openNavigation(item.id, item.adresse)} activeOpacity={0.7} >