From 5b4485d20d6684680d5fec05c1d08d04decdf8ad Mon Sep 17 00:00:00 2001 From: zain94rif Date: Mon, 5 Jan 2026 14:08:02 +0700 Subject: [PATCH 1/5] feat(api): add API for resend chat user --- src/api/notification.jsx | 20 +++++++++++++++++++ .../component/ListNotification.jsx | 11 +++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/api/notification.jsx b/src/api/notification.jsx index 67daa9a..2738f88 100644 --- a/src/api/notification.jsx +++ b/src/api/notification.jsx @@ -55,6 +55,24 @@ const resendNotificationToUser = async (notificationId, userId) => { return response.data; }; +// Resend Chat by User +const resendChatByUser = async (notificationId, userPhone) => { + const response = await SendRequest({ + method: 'put', + prefix: `notification-user/resend/${notificationId}/${userPhone}`, + }); + return response.data; +}; + +// Resend Chat All User +const resendChatAllUser = async (notificationId) => { + const response = await SendRequest({ + method: 'post', + prefix: `notification-user/resend/${notificationId}`, + }); + return response.data; +}; + export { getAllNotification, getNotificationById, @@ -62,4 +80,6 @@ export { createNotificationLog, getNotificationLogByNotificationId, resendNotificationToUser, + resendChatByUser, + resendChatAllUser, }; diff --git a/src/pages/notification/component/ListNotification.jsx b/src/pages/notification/component/ListNotification.jsx index 91c0ecf..f35cdd2 100644 --- a/src/pages/notification/component/ListNotification.jsx +++ b/src/pages/notification/component/ListNotification.jsx @@ -42,6 +42,8 @@ import { getAllNotification, getNotificationLogByNotificationId, getNotificationDetail, + resendChatByUser, + resendChatAllUser, } from '../../../api/notification'; const { Text, Paragraph, Link: AntdLink } = Typography; @@ -65,6 +67,7 @@ const transformNotificationData = (apiData) => { : 'N/A', location: item.plant_sub_section_name || item.device_location || 'Location not specified', details: item.device_name || '-', + errId: item.users[0].notification_error_id || 0, link: `/verification-sparepart/${item.notification_error_id}`, // Dummy URL untuk verifikasi spare part subsection: item.plant_sub_section_name || 'N/A', isRead: item.is_read, @@ -195,9 +198,9 @@ const ListNotification = memo(function ListNotification(props) { content: `Are you sure you want to resend the notification for "${notification.title}"?`, okText: 'Resend', cancelText: 'Cancel', - onOk() { + async onOk() { console.log('Resending notification:', notification.id); - + await resendChatAllUser(notification.errId); message.success( `Notification for "${notification.title}" has been resent successfully.` ); @@ -284,6 +287,7 @@ const ListNotification = memo(function ListNotification(props) { id: user.notification_error_user_id.toString(), name: user.contact_name, phone: user.contact_phone, + userId: user.notification_error_user_id, status: user.is_send ? 'Delivered' : 'Pending', timestamp: user.created_at ? new Date(user.created_at).toLocaleString('id-ID', { @@ -605,7 +609,8 @@ const ListNotification = memo(function ListNotification(props) { type="primary" ghost icon={} - onClick={() => { + onClick={async () => { + await resendChatByUser(user.userId, user.phone); message.info( 'Resend feature is not available yet. This feature is still under development.' ); From 739c55c0bc4893a63c397e00fc855f1b93c11e60 Mon Sep 17 00:00:00 2001 From: zain94rif Date: Mon, 5 Jan 2026 14:26:12 +0700 Subject: [PATCH 2/5] fix(api): fixing endpoint notification --- src/api/notification.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/notification.jsx b/src/api/notification.jsx index 2738f88..12b832c 100644 --- a/src/api/notification.jsx +++ b/src/api/notification.jsx @@ -68,7 +68,7 @@ const resendChatByUser = async (notificationId, userPhone) => { const resendChatAllUser = async (notificationId) => { const response = await SendRequest({ method: 'post', - prefix: `notification-user/resend/${notificationId}`, + prefix: `notification/resend/${notificationId}`, }); return response.data; }; From 3266641f81ea2f60d1323f0af2feeb8f9192d368 Mon Sep 17 00:00:00 2001 From: zain94rif Date: Mon, 5 Jan 2026 14:48:46 +0700 Subject: [PATCH 3/5] fix(api): fixing put to post --- src/api/notification.jsx | 2 +- src/pages/notification/component/ListNotification.jsx | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/api/notification.jsx b/src/api/notification.jsx index 12b832c..fa35ddd 100644 --- a/src/api/notification.jsx +++ b/src/api/notification.jsx @@ -58,7 +58,7 @@ const resendNotificationToUser = async (notificationId, userId) => { // Resend Chat by User const resendChatByUser = async (notificationId, userPhone) => { const response = await SendRequest({ - method: 'put', + method: 'post', prefix: `notification-user/resend/${notificationId}/${userPhone}`, }); return response.data; diff --git a/src/pages/notification/component/ListNotification.jsx b/src/pages/notification/component/ListNotification.jsx index f35cdd2..cd0bdec 100644 --- a/src/pages/notification/component/ListNotification.jsx +++ b/src/pages/notification/component/ListNotification.jsx @@ -287,7 +287,6 @@ const ListNotification = memo(function ListNotification(props) { id: user.notification_error_user_id.toString(), name: user.contact_name, phone: user.contact_phone, - userId: user.notification_error_user_id, status: user.is_send ? 'Delivered' : 'Pending', timestamp: user.created_at ? new Date(user.created_at).toLocaleString('id-ID', { @@ -610,10 +609,10 @@ const ListNotification = memo(function ListNotification(props) { ghost icon={} onClick={async () => { - await resendChatByUser(user.userId, user.phone); - message.info( - 'Resend feature is not available yet. This feature is still under development.' - ); + await resendChatByUser(user.id, user.phone); + // message.info( + // 'Resend feature is not available yet. This feature is still under development.' + // ); }} > Resend From 0935d7c9f5e9f927ab67fbe18a3b64035b2f9a99 Mon Sep 17 00:00:00 2001 From: zain94rif Date: Tue, 6 Jan 2026 09:53:15 +0700 Subject: [PATCH 4/5] fix(var): use notification_error_id from item, not from users --- src/pages/notification/component/ListNotification.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/notification/component/ListNotification.jsx b/src/pages/notification/component/ListNotification.jsx index cd0bdec..5a590ed 100644 --- a/src/pages/notification/component/ListNotification.jsx +++ b/src/pages/notification/component/ListNotification.jsx @@ -67,7 +67,7 @@ const transformNotificationData = (apiData) => { : 'N/A', location: item.plant_sub_section_name || item.device_location || 'Location not specified', details: item.device_name || '-', - errId: item.users[0].notification_error_id || 0, + errId: item.notification_error_id || 0, link: `/verification-sparepart/${item.notification_error_id}`, // Dummy URL untuk verifikasi spare part subsection: item.plant_sub_section_name || 'N/A', isRead: item.is_read, From 14e97fead29109973961e99e6d061dfc9155c4cd Mon Sep 17 00:00:00 2001 From: zain94rif Date: Tue, 6 Jan 2026 16:12:58 +0700 Subject: [PATCH 5/5] feat(api): add update is_read for detail --- src/api/notification.jsx | 10 ++ .../IndexNotificationDetail.jsx | 105 ++++++++++++------ 2 files changed, 82 insertions(+), 33 deletions(-) diff --git a/src/api/notification.jsx b/src/api/notification.jsx index fa35ddd..3c526ed 100644 --- a/src/api/notification.jsx +++ b/src/api/notification.jsx @@ -46,6 +46,15 @@ const getNotificationLogByNotificationId = async (notificationId) => { return response.data; }; +// update is_read status +const updateIsRead = async (notificationId) => { + const response = await SendRequest({ + method: 'put', + prefix: `notification/${notificationId}`, + }); + return response.data; +}; + // Resend notification to specific user const resendNotificationToUser = async (notificationId, userId) => { const response = await SendRequest({ @@ -79,6 +88,7 @@ export { getNotificationDetail, createNotificationLog, getNotificationLogByNotificationId, + updateIsRead, resendNotificationToUser, resendChatByUser, resendChatAllUser, diff --git a/src/pages/notificationDetail/IndexNotificationDetail.jsx b/src/pages/notificationDetail/IndexNotificationDetail.jsx index a3eb466..0db8009 100644 --- a/src/pages/notificationDetail/IndexNotificationDetail.jsx +++ b/src/pages/notificationDetail/IndexNotificationDetail.jsx @@ -38,6 +38,7 @@ import { getNotificationDetail, createNotificationLog, getNotificationLogByNotificationId, + updateIsRead, resendNotificationToUser, } from '../../api/notification'; @@ -234,6 +235,8 @@ const NotificationDetailTab = (props) => { // Fetch using the actual API const response = await getNotificationDetail(notificationId); + // Fetch using the actual API + const resUpdate = await updateIsRead(notificationId); if (response && response.data) { const transformedData = transformNotificationData(response.data); @@ -497,59 +500,95 @@ const NotificationDetailTab = (props) => { loading={user.loading} onClick={async (e) => { e.stopPropagation(); - const userId = parseInt(user.id); + const userId = parseInt( + user.id + ); try { // Update user status to show loading - const updatedUsers = notification.users.map(u => - u.notification_error_user_id === userId - ? { ...u, loading: true } - : u - ); + const updatedUsers = + notification.users.map( + (u) => + u.notification_error_user_id === + userId + ? { + ...u, + loading: true, + } + : u + ); setNotification({ ...notification, - users: updatedUsers + users: updatedUsers, }); // Call the resend API - const response = await resendNotificationToUser( - notification.notification_error_id, - userId - ); + const response = + await resendNotificationToUser( + notification.notification_error_id, + userId + ); - if (response && response.statusCode === 200) { - message.success(`Notification resent to ${user.name}`); + if ( + response && + response.statusCode === + 200 + ) { + message.success( + `Notification resent to ${user.name}` + ); // Update user status - const updatedUsersAfterSuccess = notification.users.map(u => - u.notification_error_user_id === userId - ? { - ...u, - is_send: true, - status: 'sent', - loading: false - } - : { ...u, loading: false } - ); + const updatedUsersAfterSuccess = + notification.users.map( + (u) => + u.notification_error_user_id === + userId + ? { + ...u, + is_send: true, + status: 'sent', + loading: false, + } + : { + ...u, + loading: false, + } + ); setNotification({ ...notification, - users: updatedUsersAfterSuccess + users: updatedUsersAfterSuccess, }); } else { - throw new Error(response?.message || 'Failed to resend notification'); + throw new Error( + response?.message || + 'Failed to resend notification' + ); } } catch (error) { - console.error('Error resending notification:', error); - message.error(error.message || 'Failed to resend notification'); + console.error( + 'Error resending notification:', + error + ); + message.error( + error.message || + 'Failed to resend notification' + ); // Reset loading state - const resetUsers = notification.users.map(u => - u.notification_error_user_id === userId - ? { ...u, loading: false } - : u - ); + const resetUsers = + notification.users.map( + (u) => + u.notification_error_user_id === + userId + ? { + ...u, + loading: false, + } + : u + ); setNotification({ ...notification, - users: resetUsers + users: resetUsers, }); } }}