Merge pull request 'lavoce' (#33) from lavoce into main

Reviewed-on: #33
This commit is contained in:
2026-01-06 11:30:27 +00:00
3 changed files with 112 additions and 39 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({
@@ -55,11 +64,32 @@ const resendNotificationToUser = async (notificationId, userId) => {
return response.data; return response.data;
}; };
// Resend Chat by User
const resendChatByUser = async (notificationId, userPhone) => {
const response = await SendRequest({
method: 'post',
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/resend/${notificationId}`,
});
return response.data;
};
export { export {
getAllNotification, getAllNotification,
getNotificationById, getNotificationById,
getNotificationDetail, getNotificationDetail,
createNotificationLog, createNotificationLog,
getNotificationLogByNotificationId, getNotificationLogByNotificationId,
updateIsRead,
resendNotificationToUser, resendNotificationToUser,
resendChatByUser,
resendChatAllUser,
}; };

View File

@@ -42,6 +42,8 @@ import {
getAllNotification, getAllNotification,
getNotificationLogByNotificationId, getNotificationLogByNotificationId,
getNotificationDetail, getNotificationDetail,
resendChatByUser,
resendChatAllUser,
} from '../../../api/notification'; } from '../../../api/notification';
const { Text, Paragraph, Link: AntdLink } = Typography; const { Text, Paragraph, Link: AntdLink } = Typography;
@@ -65,6 +67,7 @@ const transformNotificationData = (apiData) => {
: 'N/A', : 'N/A',
location: item.plant_sub_section_name || item.device_location || 'Location not specified', location: item.plant_sub_section_name || item.device_location || 'Location not specified',
details: item.device_name || '-', details: item.device_name || '-',
errId: item.notification_error_id || 0,
link: `/verification-sparepart/${item.notification_error_id}`, // Dummy URL untuk verifikasi spare part link: `/verification-sparepart/${item.notification_error_id}`, // Dummy URL untuk verifikasi spare part
subsection: item.plant_sub_section_name || 'N/A', subsection: item.plant_sub_section_name || 'N/A',
isRead: item.is_read, 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}"?`, content: `Are you sure you want to resend the notification for "${notification.title}"?`,
okText: 'Resend', okText: 'Resend',
cancelText: 'Cancel', cancelText: 'Cancel',
onOk() { async onOk() {
console.log('Resending notification:', notification.id); console.log('Resending notification:', notification.id);
await resendChatAllUser(notification.errId);
message.success( message.success(
`Notification for "${notification.title}" has been resent successfully.` `Notification for "${notification.title}" has been resent successfully.`
); );
@@ -605,10 +608,11 @@ const ListNotification = memo(function ListNotification(props) {
type="primary" type="primary"
ghost ghost
icon={<SendOutlined />} icon={<SendOutlined />}
onClick={() => { onClick={async () => {
message.info( await resendChatByUser(user.id, user.phone);
'Resend feature is not available yet. This feature is still under development.' // message.info(
); // 'Resend feature is not available yet. This feature is still under development.'
// );
}} }}
> >
Resend Resend

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