lavoce #33

Merged
bragaz_rexita merged 5 commits from lavoce into main 2026-01-06 11:30:27 +00:00
2 changed files with 82 additions and 33 deletions
Showing only changes of commit 14e97fead2 - Show all commits

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 u.notification_error_user_id ===
); userId
? {
...u,
loading: true,
}
: u
);
setNotification({ setNotification({
...notification, ...notification,
users: updatedUsers users: updatedUsers,
}); });
// Call the resend API // Call the resend API
const response = await resendNotificationToUser( const response =
notification.notification_error_id, await resendNotificationToUser(
userId notification.notification_error_id,
); 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, u.notification_error_user_id ===
is_send: true, userId
status: 'sent', ? {
loading: false ...u,
} is_send: true,
: { ...u, loading: false } status: 'sent',
); 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 u.notification_error_user_id ===
); userId
? {
...u,
loading: false,
}
: u
);
setNotification({ setNotification({
...notification, ...notification,
users: resetUsers users: resetUsers,
}); });
} }
}} }}