refactor: update notification handling to prioritize active solutions and improve data extraction

This commit is contained in:
2025-12-18 17:57:25 +07:00
parent 6b75f6f4b9
commit 8cf21643ea
3 changed files with 61 additions and 45 deletions

View File

@@ -14,8 +14,9 @@ const DetailNotification = memo(function DetailNotification({ selectedData, onCl
// Get error code data from the nested structure
const errorCodeData = selectedData.error_code;
const solutionData = errorCodeData?.solution?.[0] || {};
const sparepartsData = errorCodeData?.spareparts || [];
// Get active solution (is_active: true) or first solution
const activeSolution = errorCodeData?.solution?.find(sol => sol.is_active) || errorCodeData?.solution?.[0] || {};
const sparepartsData = selectedData.spareparts || errorCodeData?.spareparts || [];
// Determine notification type based on is_read status
const getTypeFromStatus = () => {
@@ -137,7 +138,7 @@ const DetailNotification = memo(function DetailNotification({ selectedData, onCl
Solusi
</div>
<div style={{ fontSize: '13px', color: '#262626', fontWeight: 500 }}>
{solutionData?.solution_name || 'N/A'}
{activeSolution?.solution_name || 'N/A'}
</div>
</div>
</Col>

View File

@@ -47,28 +47,29 @@ const transformNotificationData = (apiData) => {
return apiData.map((item, index) => ({
id: `notification-${item.notification_error_id}-${index}`, // Unique key prefix with array index
type: item.is_read ? 'resolved' : item.is_delivered ? 'warning' : 'critical',
title: item.device_name || 'Unknown Device',
issue: item.error_code_name || 'Unknown Error',
description: `${item.error_code} - ${item.error_code_name}`,
title: item.error_code?.error_code_name || item.device_name || 'Unknown Error',
issue: item.error_code || item.error_code_name || 'Unknown Error',
description: `${item.error_code} - ${item.error_code_name || ''}`,
timestamp:
new Date(item.created_at).toLocaleString('id-ID', {
item.created_at ? new Date(item.created_at).toLocaleString('id-ID', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
}) + ' WIB',
location: item.device_location || 'Location not specified',
}) + ' WIB' : 'N/A',
location: item.plant_sub_section_name || item.device_location || 'Location not specified',
details: item.message_error_issue || 'No details available',
link: `/verification-sparepart/${item.notification_error_id}`, // Dummy URL untuk verifikasi spare part
subsection: item.solution_name || 'N/A',
subsection: item.plant_sub_section_name || 'N/A',
isRead: item.is_read,
status: item.is_read ? 'Resolved' : item.is_delivered ? 'Delivered' : 'Pending',
tag: item.error_code,
errorCode: item.error_code,
solutionName: item.solution_name,
typeSolution: item.type_solution,
pathSolution: item.path_solution,
solutionName: item.error_code?.solution?.[0]?.solution_name || 'N/A',
typeSolution: item.error_code?.solution?.[0]?.type_solution || 'N/A',
pathSolution: item.error_code?.solution?.[0]?.path_document || item.error_code?.solution?.[0]?.path_solution || 'N/A',
error_code: item.error_code,
}));
};