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

View File

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