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, }); } }}