feat(api): add update is_read for detail

This commit is contained in:
zain94rif
2026-01-06 16:12:58 +07:00
parent 0935d7c9f5
commit 14e97fead2
2 changed files with 82 additions and 33 deletions

View File

@@ -46,6 +46,15 @@ const getNotificationLogByNotificationId = async (notificationId) => {
return response.data; 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 // Resend notification to specific user
const resendNotificationToUser = async (notificationId, userId) => { const resendNotificationToUser = async (notificationId, userId) => {
const response = await SendRequest({ const response = await SendRequest({
@@ -79,6 +88,7 @@ export {
getNotificationDetail, getNotificationDetail,
createNotificationLog, createNotificationLog,
getNotificationLogByNotificationId, getNotificationLogByNotificationId,
updateIsRead,
resendNotificationToUser, resendNotificationToUser,
resendChatByUser, resendChatByUser,
resendChatAllUser, resendChatAllUser,

View File

@@ -38,6 +38,7 @@ import {
getNotificationDetail, getNotificationDetail,
createNotificationLog, createNotificationLog,
getNotificationLogByNotificationId, getNotificationLogByNotificationId,
updateIsRead,
resendNotificationToUser, resendNotificationToUser,
} from '../../api/notification'; } from '../../api/notification';
@@ -234,6 +235,8 @@ const NotificationDetailTab = (props) => {
// Fetch using the actual API // Fetch using the actual API
const response = await getNotificationDetail(notificationId); const response = await getNotificationDetail(notificationId);
// Fetch using the actual API
const resUpdate = await updateIsRead(notificationId);
if (response && response.data) { if (response && response.data) {
const transformedData = transformNotificationData(response.data); const transformedData = transformNotificationData(response.data);
@@ -497,59 +500,95 @@ const NotificationDetailTab = (props) => {
loading={user.loading} loading={user.loading}
onClick={async (e) => { onClick={async (e) => {
e.stopPropagation(); e.stopPropagation();
const userId = parseInt(user.id); const userId = parseInt(
user.id
);
try { try {
// Update user status to show loading // Update user status to show loading
const updatedUsers = notification.users.map(u => const updatedUsers =
u.notification_error_user_id === userId notification.users.map(
? { ...u, loading: true } (u) =>
u.notification_error_user_id ===
userId
? {
...u,
loading: true,
}
: u : u
); );
setNotification({ setNotification({
...notification, ...notification,
users: updatedUsers users: updatedUsers,
}); });
// Call the resend API // Call the resend API
const response = await resendNotificationToUser( const response =
await resendNotificationToUser(
notification.notification_error_id, notification.notification_error_id,
userId userId
); );
if (response && response.statusCode === 200) { if (
message.success(`Notification resent to ${user.name}`); response &&
response.statusCode ===
200
) {
message.success(
`Notification resent to ${user.name}`
);
// Update user status // Update user status
const updatedUsersAfterSuccess = notification.users.map(u => const updatedUsersAfterSuccess =
u.notification_error_user_id === userId notification.users.map(
(u) =>
u.notification_error_user_id ===
userId
? { ? {
...u, ...u,
is_send: true, is_send: true,
status: 'sent', status: 'sent',
loading: false loading: false,
}
: {
...u,
loading: false,
} }
: { ...u, loading: false }
); );
setNotification({ setNotification({
...notification, ...notification,
users: updatedUsersAfterSuccess users: updatedUsersAfterSuccess,
}); });
} else { } else {
throw new Error(response?.message || 'Failed to resend notification'); throw new Error(
response?.message ||
'Failed to resend notification'
);
} }
} catch (error) { } catch (error) {
console.error('Error resending notification:', error); console.error(
message.error(error.message || 'Failed to resend notification'); 'Error resending notification:',
error
);
message.error(
error.message ||
'Failed to resend notification'
);
// Reset loading state // Reset loading state
const resetUsers = notification.users.map(u => const resetUsers =
u.notification_error_user_id === userId notification.users.map(
? { ...u, loading: false } (u) =>
u.notification_error_user_id ===
userId
? {
...u,
loading: false,
}
: u : u
); );
setNotification({ setNotification({
...notification, ...notification,
users: resetUsers users: resetUsers,
}); });
} }
}} }}