mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Improve store selection and user group assignment logic for orders
Update CustomerOrderForm to dynamically set the groupId based on user roles and permissions, falling back to null for proper assignment. Introduce a Select component for manual store/group selection with permission-based filtering. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 31f9bd88-0285-4787-81b3-31ceeea5a08b Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/31f9bd88-0285-4787-81b3-31ceeea5a08b/VwtKkP4
This commit is contained in:
1 parent
2da7a21908
commit
e89f9b1041
1 file changed
+37
-6
@@ -82,9 +82,9 @@ export function CustomerOrderForm({
|
||||
return selectedStoreId;
|
||||
}
|
||||
|
||||
// FALLBACK: Default to 1
|
||||
console.log("🚨 CustomerOrderForm defaultValue: Using fallback groupId 1");
|
||||
return 1;
|
||||
// FALLBACK: Return null to force proper assignment later
|
||||
console.log("🚨 CustomerOrderForm defaultValue: No group found, will be set dynamically");
|
||||
return null;
|
||||
};
|
||||
|
||||
const form = useForm<CustomerOrderFormData>({
|
||||
@@ -135,8 +135,8 @@ export function CustomerOrderForm({
|
||||
fullUserObject: user
|
||||
});
|
||||
|
||||
// Override groupId if needed (defaultValues might be calculated before userGroups is loaded)
|
||||
if (!groupId || groupId === 1) {
|
||||
// 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);
|
||||
@@ -265,7 +265,38 @@ export function CustomerOrderForm({
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Magasin automatiquement sélectionné - pas de champ visible */}
|
||||
{/* Sélection du magasin/groupe avec restrictions de permissions */}
|
||||
<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>
|
||||
|
||||
|
||||
Reference in new issue
Block a user