From 8cf21643eafa6fe131685ca792ad94a2161afb0c Mon Sep 17 00:00:00 2001 From: vinix Date: Thu, 18 Dec 2025 17:57:25 +0700 Subject: [PATCH] refactor: update notification handling to prioritize active solutions and improve data extraction --- .../component/DetailNotification.jsx | 7 +- .../component/ListNotification.jsx | 21 ++--- .../IndexNotificationDetail.jsx | 78 +++++++++++-------- 3 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/pages/notification/component/DetailNotification.jsx b/src/pages/notification/component/DetailNotification.jsx index d86ff09..19a1e81 100644 --- a/src/pages/notification/component/DetailNotification.jsx +++ b/src/pages/notification/component/DetailNotification.jsx @@ -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
- {solutionData?.solution_name || 'N/A'} + {activeSolution?.solution_name || 'N/A'}
diff --git a/src/pages/notification/component/ListNotification.jsx b/src/pages/notification/component/ListNotification.jsx index 94a844d..4fe046e 100644 --- a/src/pages/notification/component/ListNotification.jsx +++ b/src/pages/notification/component/ListNotification.jsx @@ -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, })); }; diff --git a/src/pages/notificationDetail/IndexNotificationDetail.jsx b/src/pages/notificationDetail/IndexNotificationDetail.jsx index f820eb1..1e94992 100644 --- a/src/pages/notificationDetail/IndexNotificationDetail.jsx +++ b/src/pages/notificationDetail/IndexNotificationDetail.jsx @@ -37,12 +37,13 @@ const { Text, Paragraph, Link } = Typography; const transformNotificationData = (apiData) => { // Extract nested data const errorCodeData = apiData.error_code; - const solutionData = errorCodeData?.solution?.[0] || {}; + // Get active solution (is_active: true) + const activeSolution = errorCodeData?.solution?.find(sol => sol.is_active) || errorCodeData?.solution?.[0] || {}; return { id: `notification-${apiData.notification_error_id}-0`, type: apiData.is_read ? 'resolved' : apiData.is_delivered ? 'warning' : 'critical', - title: errorCodeData?.error_code_name || 'Unknown Device', + title: errorCodeData?.error_code_name || 'Unknown Error', issue: errorCodeData?.error_code || 'Unknown Error', description: apiData.message_error_issue || 'No details available', timestamp: apiData.created_at ? new Date(apiData.created_at).toLocaleString('id-ID', { @@ -52,7 +53,7 @@ const transformNotificationData = (apiData) => { hour: '2-digit', minute: '2-digit', }) + ' WIB' : 'N/A', - location: solutionData?.solution_name || 'Location not specified', + location: apiData.plant_sub_section_name || 'Location not specified', details: apiData.message_error_issue || 'No details available', isRead: apiData.is_read || false, isDelivered: apiData.is_delivered || false, @@ -62,9 +63,19 @@ const transformNotificationData = (apiData) => { plc: 'N/A', // PLC not available in API response notification_error_id: apiData.notification_error_id, error_code_id: apiData.error_code_id, + error_chanel: apiData.error_chanel, spareparts: errorCodeData?.spareparts || [], - solution: solutionData, // Include the solution data + solution: { + ...activeSolution, + path_document: activeSolution.path_document ? activeSolution.path_document.replace('/detail-notification/pdf/', '/notification-detail/pdf/') : activeSolution.path_document + }, // Include the active solution data with fixed URL error_code: errorCodeData, + device_info: { + device_code: apiData.device_code, + device_name: apiData.device_name, + device_location: apiData.device_location, + brand_name: apiData.brand_name + } }; }; @@ -222,12 +233,6 @@ const NotificationDetailTab = () => { Time
{notification.timestamp.split(' ')[1]} WIB
-
- - Value
N/A
- Treshold
N/A
-
-
@@ -236,9 +241,11 @@ const NotificationDetailTab = () => { -
PLC
{notification.plc || 'N/A'}
-
Status
{notification.status}
-
Tag
{notification.tag}
+
Error Channel
{notification.error_chanel || 'N/A'}
+
Device Code
{notification.device_info?.device_code || 'N/A'}
+
Device Name
{notification.device_info?.device_name || 'N/A'}
+
Device Location
{notification.device_info?.device_location || 'N/A'}
+
Brand
{notification.device_info?.brand_name || 'N/A'}
@@ -259,28 +266,35 @@ const NotificationDetailTab = () => { - {notification.solution && ( + {notification.error_code?.solution && notification.error_code.solution.length > 0 ? ( <> - {notification.solution.path_document ? ( - PDF}> -
-
- {notification.solution.file_upload_name || 'Solution Document.pdf'} - lihat disini -
+ {notification.error_code.solution + .filter(sol => sol.is_active) // Hanya tampilkan solusi yang aktif + .map((sol, index) => ( +
+ {sol.path_document ? ( + PDF}> +
+
+ {sol.file_upload_name || 'Solution Document.pdf'} + lihat disini +
+
+
+ ) : null} + {sol.type_solution === 'text' && sol.text_solution ? ( + {sol.type_solution.toUpperCase()}}> +
+ {sol.solution_name}: +
{sol.text_solution}
+
+
+ ) : null}
- - ) : null} - {notification.solution.type_solution === 'text' && notification.solution.text_solution ? ( - {notification.solution.type_solution.toUpperCase()}}> - - {notification.issue}: {notification.solution.text_solution} - - - ) : null} + )) + } - )} - {!notification.solution && ( + ) : (
Tidak ada dokumen solusi tersedia