fix(incidents): update detail dialog and PDF generation to prefer assigned_users over assigned_to for assignee
This commit is contained in:
@@ -22,7 +22,7 @@ export const updateIncidentStatus = async (id: string, status: string): Promise<
|
||||
|
||||
console.log(`Incident ${id} status updated successfully to ${status}`);
|
||||
} catch (error) {
|
||||
console.error('Error updating incident status:', error);ok gib mir die
|
||||
console.error('Error updating incident status:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
import jsPDF from 'jspdf';
|
||||
import { IncidentItem } from '../types';
|
||||
import { userService } from '@/services/userService';
|
||||
import {
|
||||
addBasicInfoSection,
|
||||
addDescriptionSection,
|
||||
@@ -22,6 +23,18 @@ export const generatePdf = async (incident: IncidentItem): Promise<string> => {
|
||||
throw new Error('Invalid incident data');
|
||||
}
|
||||
|
||||
// Fetch assigned user data if available
|
||||
let assignedUser = null;
|
||||
const assigneeId = incident?.assigned_users || incident?.assigned_to;
|
||||
if (assigneeId) {
|
||||
try {
|
||||
assignedUser = await userService.getUser(assigneeId);
|
||||
} catch (error) {
|
||||
console.warn('Failed to fetch assigned user for PDF:', error);
|
||||
// Continue without user data
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Create new PDF document with portrait orientation
|
||||
const doc = new jsPDF({
|
||||
@@ -85,7 +98,7 @@ export const generatePdf = async (incident: IncidentItem): Promise<string> => {
|
||||
}
|
||||
|
||||
// Add assignment section
|
||||
yPos = addAssignmentSection(doc, incident, yPos);
|
||||
yPos = addAssignmentSection(doc, incident, yPos, assignedUser);
|
||||
|
||||
// Check if we need to add a new page
|
||||
if (yPos > 250) {
|
||||
|
||||
@@ -146,7 +146,7 @@ export const addResolutionSection = (doc: jsPDF, incident: IncidentItem, yPos: n
|
||||
/**
|
||||
* Add the assignment information section to the PDF
|
||||
*/
|
||||
export const addAssignmentSection = (doc: jsPDF, incident: IncidentItem, yPos: number): number => {
|
||||
export const addAssignmentSection = (doc: jsPDF, incident: IncidentItem, yPos: number, assignedUser?: any): number => {
|
||||
doc.setFontSize(14);
|
||||
doc.setTextColor(30, 64, 175); // Blue-800
|
||||
doc.text('Assignment Information', 15, yPos);
|
||||
@@ -158,8 +158,16 @@ export const addAssignmentSection = (doc: jsPDF, incident: IncidentItem, yPos: n
|
||||
yPos += 10;
|
||||
doc.setFontSize(10);
|
||||
doc.setTextColor(0, 0, 0);
|
||||
const assignedTo = incident.assigned_users || incident.assigned_to || 'Not assigned';
|
||||
doc.text(`Assigned to: ${assignedTo}`, 15, yPos);
|
||||
|
||||
if (assignedUser) {
|
||||
// Show user name if available
|
||||
const userName = assignedUser.full_name || assignedUser.username || 'Unknown User';
|
||||
doc.text(`Assigned to: ${userName}`, 15, yPos);
|
||||
} else {
|
||||
// Fallback to ID if no user data available
|
||||
const assignedTo = incident.assigned_users || incident.assigned_to || 'Not assigned';
|
||||
doc.text(`Assigned to: ${assignedTo}`, 15, yPos);
|
||||
}
|
||||
|
||||
return yPos + 10;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user