mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-12 01:37:40 +02:00
Fix issue with assigning correct group for customer orders
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
This commit is contained in:
1 parent
8c35e8e32f
commit
b7adbd9ee8
3 files changed
+71
-2
No files matched your search
@@ -0,0 +1,59 @@
|
||||
# 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.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 131 KiB |
@@ -135,8 +135,18 @@ export function CustomerOrderForm({
|
||||
fullUserObject: user
|
||||
});
|
||||
|
||||
// GroupId should already be correct from defaultValues - no override needed
|
||||
console.log("✅ Customer Order: Using groupId from form (defaultValues already correct):", groupId);
|
||||
// Override groupId if needed (defaultValues might be calculated before userGroups is loaded)
|
||||
if (!groupId || groupId === 1) {
|
||||
if (user?.userGroups?.[0]?.groupId) {
|
||||
groupId = user.userGroups[0].groupId;
|
||||
console.log("🔧 Customer Order Override: Using user's assigned group:", groupId);
|
||||
} else if (user?.role === 'admin' && selectedStoreId) {
|
||||
groupId = selectedStoreId;
|
||||
console.log("🔧 Customer Order Override: Using admin selected store:", groupId);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("✅ Customer Order: Final groupId after override check:", groupId);
|
||||
|
||||
console.log("✅ CUSTOMER ORDER - Final groupId selected:", groupId, typeof groupId);
|
||||
|
||||
|
||||
Reference in new issue
Block a user