Prioritize assigned user group for creating customer orders and DLCs

Update frontend logic in CustomerOrderForm and DlcPage to correctly assign the user's group as the primary identifier, fixing an issue where group ID 1 was used incorrectly.

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/JC3ViEJ
This commit is contained in:
michaelschal committed 2025-08-12 15:14:34 +00:00
1 parent 39bae75d82
commit c419733954
5 files changed
+298 -20

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
# Fix Final Frontend - GroupId Production
## Problème Identifié en Production
Les logs production montrent clairement :
- ✅ **Utilisateur assigné groupe #2** : `group_id: 2, group_name: 'Houdemont'`
- ✅ **API DLC lit correctement** : `userGroups: [ { groupId: 2, groupName: 'Houdemont' } ]`
- ❌ **Création utilise groupId: 1** au lieu du groupe assigné
## Cause Exacte
Le frontend ne priorise pas correctement le groupe assigné lors de la création. La logique donnait priorité à `selectedStoreId` (admin) avant le groupe assigné de l'utilisateur.
## Fix Appliqué
### 1. DLC Page - Nouvelle Priorité
```javascript
// AVANT (Problématique)
if (user?.role === 'admin' && selectedStoreId) {
groupId = selectedStoreId; // Admin prioritaire
} else if (user?.userGroups?.[0]?.groupId) {
groupId = user.userGroups[0].groupId; // Groupe utilisateur second
}
// APRÈS (Corrigé)
if (user?.userGroups?.[0]?.groupId) {
// PRIORITÉ ABSOLUE: groupe assigné utilisateur
groupId = user.userGroups[0].groupId;
} else if (user?.role === 'admin' && selectedStoreId) {
// Admin seulement si pas de groupe assigné
groupId = selectedStoreId;
}
```
### 2. Customer Order Form - Même Logique
```javascript
// Même priorité dans les deux endroits:
// 1. user.userGroups[0].groupId (PRIORITÉ)
// 2. admin selectedStoreId
// 3. fallbacks...
```
### 3. Formulaire Default Value Fix
```javascript
// AVANT
groupId: order?.groupId || (user?.role === 'admin' && selectedStoreId ? selectedStoreId : user?.userGroups?.[0]?.groupId) || 1
// APRÈS
groupId: order?.groupId || (user?.userGroups?.[0]?.groupId || (user?.role === 'admin' && selectedStoreId ? selectedStoreId : 1))
```
## Logique de Priorité Unifiée
**PARTOUT DANS L'APPLICATION :**
1. 🎯 **Groupe assigné utilisateur** (`user.userGroups[0].groupId`) - **PRIORITÉ ABSOLUE**
2. 🏪 **Admin store selection** (`selectedStoreId`) - Si pas de groupe assigné
3. 📋 **Premier groupe disponible** - Fallback admin
4. 🚨 **groupId = 1** - Urgence
## Résultat Attendu Production
Employé assigné magasin #2 (Houdemont) :
- ✅ **DLC création** → `groupId: 2` (groupe assigné prioritaire)
- ✅ **Commande client** → `groupId: 2` (groupe assigné prioritaire)
- ✅ **Cohérence** avec les autres modules qui fonctionnent déjà
**DÉPLOIEMENT PRODUCTION IMMÉDIAT REQUIS**
@@ -0,0 +1,204 @@
nocodb_table_name: 'CommandeH',
invoice_column_name: 'RefFacture',
group_created_at: '2025-07-22 11:09:08.977622',
group_updated_at: '2025-08-12 09:39:32.989'
}
]
✅ Processed 1 groups for user _1753266816257
🔍 getUserWithGroups called for user: _1753266816257
🔍 Querying user_groups for user: _1753266816257
🔍 Found 1 group assignments for user _1753266816257
🔍 Raw query result: [
{
user_id: '_1753266816257',
group_id: 2,
group_id_ref: 2,
group_name: 'Houdemont',
group_color: '#455A64',
nocodb_config_id: 1,
nocodb_table_id: 'my7zunxprumahmm',
nocodb_table_name: 'CommandeH',
invoice_column_name: 'RefFacture',
group_created_at: '2025-07-22 11:09:08.977622',
group_updated_at: '2025-08-12 09:39:32.989'
}
]
✅ Processed 1 groups for user _1753266816257
🔍 DLC Products API called with: {
userId: '_1753266816257',
userRole: 'employee',
userGroups: [ { groupId: 2, groupName: 'Houdemont' } ],
groupIds: [ 2 ],
filters: {},
queryStoreId: undefined
}
📋 DLC Products returned: 133 items
📋 Sample DLC products groupIds: [
{ id: 178, name: 'Nesta grenier strawberry aloe vera', groupId: 2 },
{ id: 48, name: 'Gressins sésame', groupId: 2 },
{ id: 154, name: 'M&m’s crispy 240g', groupId: 2 }
]
🔍 getUserWithGroups called for user: _1753266816257
GET /api/dlc-products 304 in 34ms
🔍 Querying user_groups for user: _1753266816257
🔍 Found 1 group assignments for user _1753266816257
🔍 Raw query result: [
{
user_id: '_1753266816257',
group_id: 2,
group_id_ref: 2,
group_name: 'Houdemont',
group_color: '#455A64',
nocodb_config_id: 1,
nocodb_table_id: 'my7zunxprumahmm',
nocodb_table_name: 'CommandeH',
invoice_column_name: 'RefFacture',
group_created_at: '2025-07-22 11:09:08.977622',
group_updated_at: '2025-08-12 09:39:32.989'
}
]
✅ Processed 1 groups for user _1753266816257
🔍 getUserWithGroups called for user: _1753266816257
🔍 Querying user_groups for user: _1753266816257
🔍 Found 1 group assignments for user _1753266816257
🔍 Raw query result: [
{
user_id: '_1753266816257',
group_id: 2,
group_id_ref: 2,
group_name: 'Houdemont',
group_color: '#455A64',
nocodb_config_id: 1,
nocodb_table_id: 'my7zunxprumahmm',
nocodb_table_name: 'CommandeH',
invoice_column_name: 'RefFacture',
group_created_at: '2025-07-22 11:09:08.977622',
group_updated_at: '2025-08-12 09:39:32.989'
}
]
✅ Processed 1 groups for user _1753266816257
🔍 getUserWithGroups called for user: _1753266816257
🔍 Querying user_groups for user: _1753266816257
🔍 Found 1 group assignments for user _1753266816257
🔍 Raw query result: [
{
user_id: '_1753266816257',
group_id: 2,
group_id_ref: 2,
group_name: 'Houdemont',
group_color: '#455A64',
nocodb_config_id: 1,
nocodb_table_id: 'my7zunxprumahmm',
nocodb_table_name: 'CommandeH',
invoice_column_name: 'RefFacture',
group_created_at: '2025-07-22 11:09:08.977622',
group_updated_at: '2025-08-12 09:39:32.989'
}
]
✅ Processed 1 groups for user _1753266816257
GET /api/dlc-products/stats 304 in 45ms
HEAD /api/health 200 in 1ms
Binary file not shown.

After

Width:  |  Height:  |  Size: 472 KiB

+13 -12
View File
@@ -81,7 +81,7 @@ export function CustomerOrderForm({
deposit: order?.deposit || 0,
isPromotionalPrice: order?.isPromotionalPrice || false,
customerNotified: order?.customerNotified || false,
groupId: order?.groupId || (user?.role === 'admin' && selectedStoreId ? selectedStoreId : user?.userGroups?.[0]?.groupId) || 1, // Force assignment with fallback
groupId: order?.groupId || (user?.userGroups?.[0]?.groupId || (user?.role === 'admin' && selectedStoreId ? selectedStoreId : 1)), // PRIORITÉ: groupe utilisateur assigné
},
});
@@ -107,27 +107,28 @@ export function CustomerOrderForm({
availableGroups: groups.map(g => ({id: g.id, name: g.name}))
});
// FORCE L'UTILISATION DU GROUPE ASSIGNÉ EN PREMIER - MÊME LOGIQUE QUE DLC
if (!groupId) {
if (user?.role === 'admin' && selectedStoreId) {
// Admin has selected a specific store - use it
groupId = selectedStoreId;
console.log("🏪 Using admin selected store:", selectedStoreId);
} else if (user?.userGroups?.[0]?.groupId) {
// User has assigned groups - use first one
if (user?.userGroups?.[0]?.groupId) {
// Utilisateur avec groupe assigné : TOUJOURS utiliser ce groupe (PRIORITÉ)
groupId = user.userGroups[0].groupId;
console.log("👤 Using user group:", groupId);
console.log("🎯 Customer Order Frontend: Using user's assigned group (PRIORITY):", groupId);
} else if (user?.role === 'admin' && selectedStoreId) {
// Admin avec magasin sélectionné ET pas de groupe assigné
groupId = selectedStoreId;
console.log("🎯 Customer Order Frontend: Using admin selected store:", groupId);
} else if (user?.role === 'admin' && groups.length > 0) {
// Admin in "tous magasins" mode - use first group
// Admin sans sélection : premier groupe disponible
groupId = groups[0].id;
console.log("🏢 Admin fallback to first group:", groupId);
console.log("🎯 Customer Order Frontend: Using first group for admin:", groupId);
} else if (groups.length > 0) {
// EMERGENCY FALLBACK: Force assignment to first available group
groupId = groups[0].id;
console.log("⚠️ EMERGENCY: Force assigning to first group:", groupId);
console.log("⚠️ Customer Order Frontend: Emergency fallback to first group:", groupId);
} else {
// LAST RESORT: Hard-coded fallback
groupId = 1;
console.log("🚨 LAST RESORT: Using hard-coded groupId 1");
console.log("🚨 Customer Order Frontend: Using hard-coded groupId 1");
}
}
+14 -8
View File
@@ -200,18 +200,24 @@ export default function DlcPage() {
// Déterminer le groupId correctement selon le rôle utilisateur
let groupId;
if (user?.role === 'admin' && selectedStoreId) {
// Admin avec magasin sélectionné
groupId = selectedStoreId;
} else if (user?.userGroups?.[0]?.groupId) {
// Utilisateur non-admin : utiliser son groupe assigné
// FORCE L'UTILISATION DU GROUPE ASSIGNÉ EN PREMIER
if (user?.userGroups?.[0]?.groupId) {
// Utilisateur avec groupe assigné : TOUJOURS utiliser ce groupe
groupId = user.userGroups[0].groupId;
} else if (user?.role === 'admin') {
console.log("🎯 DLC Frontend: Using user's assigned group (PRIORITY):", groupId);
} else if (user?.role === 'admin' && selectedStoreId) {
// Admin avec magasin sélectionné ET pas de groupe assigné
groupId = selectedStoreId;
console.log("🎯 DLC Frontend: Using admin selected store:", groupId);
} else if (user?.role === 'admin' && stores?.[0]?.id) {
// Admin sans sélection : premier magasin disponible
groupId = stores[0]?.id || 1;
groupId = stores[0].id;
console.log("🎯 DLC Frontend: Using first available store for admin:", groupId);
} else {
// Fallback par défaut
// Fallback d'urgence
groupId = 1;
console.log("🚨 DLC Frontend: Using emergency fallback groupId:", groupId);
}
console.log("🏪 DLC GroupId Selection DEBUG:", {