mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-16 03:40:06 +02:00
Fix ticket assignment to ensure it's assigned to the user's store
Correctly assigns SAV tickets to the user's group, resolving an issue where tickets were not being assigned to the creating user's store. Includes backend and frontend logic adjustments for accurate group assignment based on user roles and available groups. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/i2gFnxm
This commit is contained in:
1 parent
32161ae797
commit
2ff22c4821
2 files changed
+42
-6
No files matched your search
@@ -265,14 +265,24 @@ export default function SavTickets() {
|
||||
// Get user's available groups for auto-assignment
|
||||
const getUserGroups = () => {
|
||||
if (!user || user.role === 'admin') {
|
||||
console.log('🎫 [CLIENT] Admin user - can access all groups:', groupsData?.length || 0);
|
||||
return groupsData; // Admin can access all groups
|
||||
}
|
||||
|
||||
// For other users, get their assigned groups
|
||||
const userGroups = (user as any).userGroups || [];
|
||||
return groupsData.filter(group =>
|
||||
const filteredGroups = groupsData.filter(group =>
|
||||
userGroups.some((ug: any) => ug.groupId === group.id)
|
||||
);
|
||||
|
||||
console.log('🎫 [CLIENT] Non-admin user groups:', {
|
||||
userRole: user.role,
|
||||
userUsername: user.username,
|
||||
allUserGroups: userGroups,
|
||||
filteredGroups: filteredGroups.map(g => ({ id: g.id, name: g.name }))
|
||||
});
|
||||
|
||||
return filteredGroups;
|
||||
};
|
||||
|
||||
const availableGroups = getUserGroups();
|
||||
@@ -288,12 +298,20 @@ export default function SavTickets() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-assign group if user has only one group or if admin didn't select one
|
||||
// Auto-assign group based on user role and available groups
|
||||
let selectedGroupId = formData.groupId ? parseInt(formData.groupId) : null;
|
||||
|
||||
console.log('🎫 [CLIENT] User groups analysis:', {
|
||||
userRole: user?.role,
|
||||
formDataGroupId: formData.groupId,
|
||||
availableGroups: availableGroups.map(g => ({ id: g.id, name: g.name })),
|
||||
selectedGroupId
|
||||
});
|
||||
|
||||
if (!selectedGroupId && availableGroups.length > 0) {
|
||||
// Auto-assign first available group
|
||||
selectedGroupId = availableGroups[0].id;
|
||||
console.log('🎫 [CLIENT] Auto-assigned group:', selectedGroupId, availableGroups[0].name);
|
||||
}
|
||||
|
||||
const ticketData: InsertSavTicket = {
|
||||
@@ -311,7 +329,14 @@ export default function SavTickets() {
|
||||
clientPhone: formData.clientPhone || undefined,
|
||||
};
|
||||
|
||||
console.log('Creating ticket with data:', ticketData);
|
||||
console.log('🎫 [CLIENT] Creating ticket with data:', {
|
||||
...ticketData,
|
||||
userInfo: {
|
||||
role: user?.role,
|
||||
username: user?.username,
|
||||
availableGroups: availableGroups.length
|
||||
}
|
||||
});
|
||||
createTicketMutation.mutate(ticketData);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user