|
1 | | -import { camelCaseObject } from '@edx/frontend-platform'; |
2 | | -import notificationsList from './notifications.json'; |
| 1 | +import { getConfig, snakeCaseObject } from '@edx/frontend-platform'; |
| 2 | +import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; |
| 3 | + |
| 4 | +export const getNotificationsCountApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/count/`; |
| 5 | +export const getNotificationsApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/`; |
| 6 | +export const markNotificationsSeenApiUrl = (appName) => `${getConfig().LMS_BASE_URL}/api/notifications/mark-notifications-unseen/${appName}/`; |
| 7 | +export const markNotificationAsReadApiUrl = () => `${getConfig().LMS_BASE_URL}/api/notifications/read/`; |
3 | 8 |
|
4 | 9 | export async function getNotifications(appName, page, pageSize) { |
5 | | - const { data } = notificationsList; |
| 10 | + const params = snakeCaseObject({ page, pageSize }); |
| 11 | + const { data } = await getAuthenticatedHttpClient().get(getNotificationsApiUrl(), { params }); |
| 12 | + |
6 | 13 | const startIndex = (page - 1) * pageSize; |
7 | 14 | const endIndex = startIndex + pageSize; |
8 | 15 |
|
9 | 16 | const notifications = data.slice(startIndex, endIndex); |
10 | | - return { notifications: camelCaseObject(notifications), numPages: 2, currentPage: page }; |
| 17 | + return { notifications, numPages: 2, currentPage: page }; |
11 | 18 | } |
12 | 19 |
|
13 | 20 | export async function getNotificationCounts() { |
14 | | - const data = { |
15 | | - count: 45, |
16 | | - count_by_app_name: { |
17 | | - reminders: 10, |
18 | | - discussions: 20, |
19 | | - grades: 10, |
20 | | - authoring: 5, |
21 | | - }, |
22 | | - show_notification_tray: false, |
23 | | - }; |
24 | | - return camelCaseObject(data); |
| 21 | + const { data } = await getAuthenticatedHttpClient().get(getNotificationsCountApiUrl()); |
| 22 | + |
| 23 | + return data; |
25 | 24 | } |
26 | 25 |
|
27 | | -export async function markNotificationSeen() { |
28 | | - const data = []; |
29 | | - return camelCaseObject(data); |
| 26 | +export async function markNotificationSeen(appName) { |
| 27 | + const { data } = await getAuthenticatedHttpClient().put(`${markNotificationsSeenApiUrl(appName)}`); |
| 28 | + |
| 29 | + return data; |
30 | 30 | } |
31 | 31 |
|
32 | | -export async function markAllNotificationRead() { |
33 | | - const { data } = camelCaseObject(notificationsList); |
| 32 | +export async function markAllNotificationRead(appName) { |
| 33 | + const params = snakeCaseObject({ appName }); |
| 34 | + const { data } = await getAuthenticatedHttpClient().put(markNotificationAsReadApiUrl(), { params }); |
| 35 | + |
34 | 36 | return data; |
35 | 37 | } |
36 | 38 |
|
37 | 39 | export async function markNotificationRead(notificationId) { |
38 | | - const { data } = camelCaseObject(notificationsList); |
| 40 | + const params = snakeCaseObject({ notificationId }); |
| 41 | + const { data } = await getAuthenticatedHttpClient().put(markNotificationAsReadApiUrl(), { params }); |
| 42 | + |
39 | 43 | return { data, id: notificationId }; |
40 | 44 | } |
0 commit comments