mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-22 06:28:19 +02:00
Merge pull request #125 from R0m1k3/1.1
Simplify customer order form by using assigned store group
This commit is contained in:
3 files changed
+39
-99
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 251 KiB |
@@ -66,24 +66,23 @@ export function CustomerOrderForm({
|
|||||||
queryKey: ['/api/suppliers'],
|
queryKey: ['/api/suppliers'],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calculate correct groupId with PRIORITY for user's assigned group
|
// Get user's assigned group automatically - no selection needed
|
||||||
const getDefaultGroupId = () => {
|
const getUserAssignedGroupId = () => {
|
||||||
if (order?.groupId) return order.groupId;
|
// Priority 1: User's first assigned group (employees have exactly one group)
|
||||||
|
|
||||||
// PRIORITY 1: User's assigned group (works for employees assigned to specific stores)
|
|
||||||
if (user?.userGroups?.[0]?.groupId) {
|
if (user?.userGroups?.[0]?.groupId) {
|
||||||
console.log("🎯 CustomerOrderForm defaultValue: Using user's assigned group:", user.userGroups[0].groupId);
|
|
||||||
return user.userGroups[0].groupId;
|
return user.userGroups[0].groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRIORITY 2: Admin selected store (only if no assigned group)
|
// Priority 2: Admin can use selected store
|
||||||
if (user?.role === 'admin' && selectedStoreId) {
|
if (user?.role === 'admin' && selectedStoreId) {
|
||||||
console.log("🎯 CustomerOrderForm defaultValue: Using admin selected store:", selectedStoreId);
|
|
||||||
return selectedStoreId;
|
return selectedStoreId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FALLBACK: Return null to force proper assignment later
|
// Priority 3: Admin gets first available group if no store selected
|
||||||
console.log("🚨 CustomerOrderForm defaultValue: No group found, will be set dynamically");
|
if (user?.role === 'admin' && groups.length > 0) {
|
||||||
|
return groups[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,7 +101,7 @@ export function CustomerOrderForm({
|
|||||||
deposit: order?.deposit || 0,
|
deposit: order?.deposit || 0,
|
||||||
isPromotionalPrice: order?.isPromotionalPrice || false,
|
isPromotionalPrice: order?.isPromotionalPrice || false,
|
||||||
customerNotified: order?.customerNotified || false,
|
customerNotified: order?.customerNotified || false,
|
||||||
groupId: getDefaultGroupId(), // ✅ PRIORITÉ CORRECTE APPLIQUÉE
|
groupId: order?.groupId || getUserAssignedGroupId(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -117,46 +116,23 @@ export function CustomerOrderForm({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure groupId is set - force assignment for ALL users
|
// Always use user's assigned group - no override needed
|
||||||
let groupId = data.groupId;
|
const groupId = getUserAssignedGroupId();
|
||||||
|
|
||||||
console.log("🔍 CUSTOMER ORDER FRONTEND DEBUG - Complete user data:", {
|
if (!groupId) {
|
||||||
userRole: user?.role,
|
console.error("❌ No group available for user:", user?.role, user?.userGroups);
|
||||||
selectedStoreId,
|
return;
|
||||||
userHasGroups: !!user?.userGroups,
|
|
||||||
userGroupsLength: user?.userGroups?.length,
|
|
||||||
userGroups: user?.userGroups?.map(ug => ({
|
|
||||||
groupId: ug.groupId || ug.group?.id,
|
|
||||||
groupName: ug.group?.name,
|
|
||||||
fullGroupData: ug
|
|
||||||
})),
|
|
||||||
initialGroupId: groupId,
|
|
||||||
availableGroups: groups.map(g => ({id: g.id, name: g.name})),
|
|
||||||
fullUserObject: user
|
|
||||||
});
|
|
||||||
|
|
||||||
// Ensure correct groupId assignment for non-admin users
|
|
||||||
if (!groupId || (user?.role !== 'admin' && !user?.userGroups?.some(ug => ug.groupId === groupId))) {
|
|
||||||
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: Using assigned group:", groupId, "for user:", user?.role);
|
||||||
|
|
||||||
console.log("✅ CUSTOMER ORDER - Final groupId selected:", groupId, typeof groupId);
|
// Prepare final data with user's assigned group
|
||||||
|
|
||||||
// Prepare data with proper types for frontend schema
|
|
||||||
const submitData = {
|
const submitData = {
|
||||||
customerName: data.customerName.trim(),
|
customerName: data.customerName.trim(),
|
||||||
contactNumber: data.contactNumber || '',
|
contactNumber: data.contactNumber || '',
|
||||||
productName: data.productName || '',
|
productName: data.productName || '',
|
||||||
quantity: data.quantity,
|
quantity: data.quantity,
|
||||||
groupId: typeof groupId === 'number' ? groupId : parseInt(groupId.toString()),
|
groupId: groupId, // Always use the assigned group
|
||||||
isPickup: false,
|
isPickup: false,
|
||||||
notes: data.notes,
|
notes: data.notes,
|
||||||
deposit: data.deposit || 0,
|
deposit: data.deposit || 0,
|
||||||
@@ -165,30 +141,23 @@ export function CustomerOrderForm({
|
|||||||
gencode: data.gencode || '',
|
gencode: data.gencode || '',
|
||||||
supplierId: data.supplierId || 1,
|
supplierId: data.supplierId || 1,
|
||||||
};
|
};
|
||||||
console.log("🔍 CUSTOMER ORDER - Frontend submit data final:", submitData);
|
|
||||||
console.log("🔍 CUSTOMER ORDER - Submit data groupId:", submitData.groupId, typeof submitData.groupId);
|
console.log("✅ Customer Order Submit:", {
|
||||||
|
userRole: user?.role,
|
||||||
|
assignedGroupId: groupId,
|
||||||
|
submitData: submitData
|
||||||
|
});
|
||||||
|
|
||||||
onSubmit(submitData);
|
onSubmit(submitData);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get available groups for the user
|
// Auto-ensure groupId is always set to user's assigned group
|
||||||
const availableGroups = user?.role === 'admin'
|
|
||||||
? groups
|
|
||||||
: user?.userGroups?.map(ug => ug.group) || [];
|
|
||||||
|
|
||||||
// Auto-select group for users respecting admin store selection
|
|
||||||
const currentGroupId = form.getValues('groupId');
|
const currentGroupId = form.getValues('groupId');
|
||||||
if (!currentGroupId) {
|
const userGroupId = getUserAssignedGroupId();
|
||||||
if (user?.role === 'admin' && selectedStoreId) {
|
|
||||||
// Admin has selected a specific store - use it
|
if (!currentGroupId && userGroupId) {
|
||||||
form.setValue('groupId', selectedStoreId);
|
form.setValue('groupId', userGroupId);
|
||||||
console.log("🏪 Auto-selecting admin store:", selectedStoreId);
|
console.log("🏪 Auto-setting user's assigned group:", userGroupId);
|
||||||
} else if (user?.userGroups?.[0]?.groupId) {
|
|
||||||
// User has assigned groups - use first one
|
|
||||||
form.setValue('groupId', user.userGroups[0].groupId);
|
|
||||||
} else if (user?.role === 'admin' && groups.length > 0) {
|
|
||||||
// Admin with no specific groups - use first available group
|
|
||||||
form.setValue('groupId', groups[0].id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -265,38 +234,7 @@ export function CustomerOrderForm({
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Sélection du magasin/groupe avec restrictions de permissions */}
|
{/* Magasin automatiquement assigné selon l'utilisateur */}
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="groupId"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Magasin</FormLabel>
|
|
||||||
<Select
|
|
||||||
onValueChange={(value) => {
|
|
||||||
const numValue = parseInt(value);
|
|
||||||
field.onChange(numValue);
|
|
||||||
console.log("🏪 Group selected:", numValue);
|
|
||||||
}}
|
|
||||||
value={field.value?.toString()}
|
|
||||||
>
|
|
||||||
<FormControl>
|
|
||||||
<SelectTrigger>
|
|
||||||
<SelectValue placeholder="Sélectionner un magasin" />
|
|
||||||
</SelectTrigger>
|
|
||||||
</FormControl>
|
|
||||||
<SelectContent>
|
|
||||||
{availableGroups.map((group) => (
|
|
||||||
<SelectItem key={group.id} value={group.id.toString()}>
|
|
||||||
{group.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<h3 className="text-lg font-medium">Informations produit</h3>
|
<h3 className="text-lg font-medium">Informations produit</h3>
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,14 @@ La plateforme fournit une gestion robuste des flux de travail de livraison avec
|
|||||||
|
|
||||||
## Recent Changes
|
## Recent Changes
|
||||||
|
|
||||||
### 2025-08-14 - Correction permissions employés commandes clients + modals SAV
|
### 2025-08-14 - Correction finale permissions employés commandes clients
|
||||||
✅ **Problème permissions employés résolu** :
|
✅ **Problème permissions employés entièrement résolu** :
|
||||||
- **Problème** : Employés ne pouvaient pas créer de commandes clients (erreur "Access denied to this group")
|
- **Problème** : Employés ne pouvaient pas créer de commandes clients (erreur "Access denied to this group")
|
||||||
- **Cause** : Vérification permissions trop restrictive dans `/api/customer-orders`
|
- **Cause racine** : Formulaire utilisait groupe 1 par défaut au lieu du groupe assigné à l'employé
|
||||||
- **Solution** : Autorisation pour rôles 'manager', 'directeur', 'employee' dans leurs groupes assignés
|
- **Solution complète** : Formulaire utilise automatiquement le groupe assigné à l'utilisateur
|
||||||
- **Logs ajoutés** : Debug complet des permissions pour diagnostic production
|
- **Simplification** : Suppression du sélecteur de magasin (inutile car utilisateurs ont un magasin assigné)
|
||||||
|
- **Code nettoyé** : Logique simplifiée pour utiliser uniquement `user.userGroups[0].groupId`
|
||||||
|
- **Production ready** : Code optimisé pour fonctionner sur serveur privé
|
||||||
|
|
||||||
✅ **Boutons SAV "Détail" et "Éditer" opérationnels** :
|
✅ **Boutons SAV "Détail" et "Éditer" opérationnels** :
|
||||||
- **Bouton Détail** : Modal complet avec toutes informations ticket
|
- **Bouton Détail** : Modal complet avec toutes informations ticket
|
||||||
|
|||||||
Reference in new issue
Block a user