mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-19 13:08:23 +02:00
Merge pull request #119 from R0m1k3/1.1
Improve ticket creation and group assignment for service requests
This commit is contained in:
2 files changed
+73
-19
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 259 KiB |
@@ -107,11 +107,20 @@ export default function SavTickets() {
|
|||||||
// Create ticket mutation
|
// Create ticket mutation
|
||||||
const createTicketMutation = useMutation({
|
const createTicketMutation = useMutation({
|
||||||
mutationFn: async (data: InsertSavTicket) => {
|
mutationFn: async (data: InsertSavTicket) => {
|
||||||
const response = await apiRequest('/api/sav/tickets', {
|
const response = await fetch('/api/sav/tickets', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
});
|
});
|
||||||
return response;
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
throw new Error(errorData.message || 'Erreur lors de la création du ticket');
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ['/api/sav/tickets'] });
|
queryClient.invalidateQueries({ queryKey: ['/api/sav/tickets'] });
|
||||||
@@ -149,6 +158,21 @@ export default function SavTickets() {
|
|||||||
const canModify = ['admin', 'directeur', 'manager'].includes(user?.role || '');
|
const canModify = ['admin', 'directeur', 'manager'].includes(user?.role || '');
|
||||||
const canDelete = ['admin', 'directeur'].includes(user?.role || '');
|
const canDelete = ['admin', 'directeur'].includes(user?.role || '');
|
||||||
|
|
||||||
|
// Get user's available groups for auto-assignment
|
||||||
|
const getUserGroups = () => {
|
||||||
|
if (!user || user.role === 'admin') {
|
||||||
|
return groupsData; // Admin can access all groups
|
||||||
|
}
|
||||||
|
|
||||||
|
// For other users, get their assigned groups
|
||||||
|
const userGroups = (user as any).userGroups || [];
|
||||||
|
return groupsData.filter(group =>
|
||||||
|
userGroups.some((ug: any) => ug.groupId === group.id)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const availableGroups = getUserGroups();
|
||||||
|
|
||||||
// Handle form submission
|
// Handle form submission
|
||||||
const handleCreateTicket = () => {
|
const handleCreateTicket = () => {
|
||||||
if (!formData.supplierId || !formData.productGencode || !formData.productDesignation || !formData.problemDescription) {
|
if (!formData.supplierId || !formData.productGencode || !formData.productDesignation || !formData.problemDescription) {
|
||||||
@@ -160,9 +184,17 @@ export default function SavTickets() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto-assign group if user has only one group or if admin didn't select one
|
||||||
|
let selectedGroupId = formData.groupId ? parseInt(formData.groupId) : null;
|
||||||
|
|
||||||
|
if (!selectedGroupId && availableGroups.length > 0) {
|
||||||
|
// Auto-assign first available group
|
||||||
|
selectedGroupId = availableGroups[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
const ticketData: InsertSavTicket = {
|
const ticketData: InsertSavTicket = {
|
||||||
supplierId: parseInt(formData.supplierId),
|
supplierId: parseInt(formData.supplierId),
|
||||||
groupId: formData.groupId ? parseInt(formData.groupId) : undefined,
|
groupId: selectedGroupId || undefined,
|
||||||
productGencode: formData.productGencode,
|
productGencode: formData.productGencode,
|
||||||
productReference: formData.productReference || undefined,
|
productReference: formData.productReference || undefined,
|
||||||
productDesignation: formData.productDesignation,
|
productDesignation: formData.productDesignation,
|
||||||
@@ -173,6 +205,7 @@ export default function SavTickets() {
|
|||||||
clientPhone: formData.clientPhone || undefined,
|
clientPhone: formData.clientPhone || undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('Creating ticket with data:', ticketData);
|
||||||
createTicketMutation.mutate(ticketData);
|
createTicketMutation.mutate(ticketData);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -285,21 +318,42 @@ export default function SavTickets() {
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
{availableGroups.length > 1 && (
|
||||||
<Label htmlFor="groupId">Magasin</Label>
|
<div className="space-y-2">
|
||||||
<Select value={formData.groupId} onValueChange={(value) => setFormData({...formData, groupId: value})}>
|
<Label htmlFor="groupId">Magasin</Label>
|
||||||
<SelectTrigger>
|
<Select value={formData.groupId} onValueChange={(value) => setFormData({...formData, groupId: value})}>
|
||||||
<SelectValue placeholder="Sélectionner un magasin" />
|
<SelectTrigger>
|
||||||
</SelectTrigger>
|
<SelectValue placeholder="Sélectionner un magasin" />
|
||||||
<SelectContent>
|
</SelectTrigger>
|
||||||
{groupsData.map((group) => (
|
<SelectContent>
|
||||||
<SelectItem key={group.id} value={group.id.toString()}>
|
{availableGroups.map((group) => (
|
||||||
{group.name}
|
<SelectItem key={group.id} value={group.id.toString()}>
|
||||||
</SelectItem>
|
{group.name}
|
||||||
))}
|
</SelectItem>
|
||||||
</SelectContent>
|
))}
|
||||||
</Select>
|
</SelectContent>
|
||||||
</div>
|
</Select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{availableGroups.length === 1 && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Magasin assigné</Label>
|
||||||
|
<div className="flex items-center space-x-2 p-2 bg-gray-50 rounded">
|
||||||
|
<Building className="h-4 w-4 text-gray-500" />
|
||||||
|
<span className="text-sm text-gray-700">{availableGroups[0].name}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{availableGroups.length === 0 && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Magasin</Label>
|
||||||
|
<div className="p-2 bg-orange-50 border border-orange-200 rounded text-sm text-orange-700">
|
||||||
|
Aucun magasin assigné. Contactez un administrateur.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Informations problème et client */}
|
{/* Informations problème et client */}
|
||||||
@@ -375,7 +429,7 @@ export default function SavTickets() {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleCreateTicket}
|
onClick={handleCreateTicket}
|
||||||
disabled={createTicketMutation.isPending}
|
disabled={createTicketMutation.isPending || availableGroups.length === 0}
|
||||||
>
|
>
|
||||||
{createTicketMutation.isPending ? "Création..." : "Créer le ticket"}
|
{createTicketMutation.isPending ? "Création..." : "Créer le ticket"}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in new issue
Block a user