mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Adjusts the customer order form to correctly assign the user's group ID by overriding default values if they are not properly loaded, ensuring accurate order processing. Replit-Commit-Author: Agent Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/6jcZipu
1.9 KiB
1.9 KiB
Fix Final - Problème GroupId Commandes Client Production
Problème Identifié
DLC ✅ → groupId: 2 (fonctionne)
Commandes Client ❌ → groupId: 1 (ne fonctionne pas)
Cause Racine
Les defaultValues du formulaire sont calculés avant que user.userGroups soit complètement chargé depuis /api/user.
Séquence problématique :
- Formulaire se render →
user.userGroups=undefined getDefaultGroupId()→ retourne1(fallback)/api/usercharge →user.userGroups=[{groupId: 2}]- Mais
defaultValuesdéjà fixés à1❌
Solution Appliquée
1. Double Sécurité (DefaultValues + Override)
// ÉTAPE 1: defaultValues avec priorité groupe assigné
const getDefaultGroupId = () => {
if (user?.userGroups?.[0]?.groupId) {
return user.userGroups[0].groupId; // Priorité absolue
}
return 1; // Fallback temporaire
};
// ÉTAPE 2: Override dans handleSubmit si besoin
if (!groupId || groupId === 1) {
if (user?.userGroups?.[0]?.groupId) {
groupId = user.userGroups[0].groupId; // ✅ Force groupId correct
}
}
2. Logique de Priorité Unifiée
PARTOUT (DLC + Commandes Client) :
- 🎯 Groupe assigné utilisateur - PRIORITÉ ABSOLUE
- 🏪 Admin store selection - Si pas de groupe assigné
- 🚨 Fallback
1- Urgence seulement
Résultat Attendu
Employé magasin #2 (Houdemont) :
- ✅ DLC →
groupId: 2(déjà fixé) - ✅ Commandes Client →
groupId: 2(maintenant fixé avec override)
Test de Validation :
🎯 CustomerOrderForm defaultValue: Using user's assigned group: 2
🔧 Customer Order Override: Using user's assigned group: 2 // ✅ Double sécurité
✅ Final groupId after override check: 2
Déploiement
PRÊT POUR PRODUCTION - Fix double sécurité garantit le bon groupId même si defaultValues ne sont pas corrects au moment du render initial.