mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-20 21:49:07 +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
59 lines
1.9 KiB
Markdown
59 lines
1.9 KiB
Markdown
# 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 :**
|
|
1. Formulaire se render → `user.userGroups` = `undefined`
|
|
2. `getDefaultGroupId()` → retourne `1` (fallback)
|
|
3. `/api/user` charge → `user.userGroups` = `[{groupId: 2}]`
|
|
4. Mais `defaultValues` déjà fixés à `1` ❌
|
|
|
|
## Solution Appliquée
|
|
|
|
### 1. Double Sécurité (DefaultValues + Override)
|
|
```javascript
|
|
// É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) :**
|
|
1. 🎯 **Groupe assigné utilisateur** - PRIORITÉ ABSOLUE
|
|
2. 🏪 **Admin store selection** - Si pas de groupe assigné
|
|
3. 🚨 **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 :**
|
|
```javascript
|
|
🎯 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. |