diff --git a/site/src/api/api.ts b/site/src/api/api.ts index 627ede80976c6..b8a0c91fac2ea 100644 --- a/site/src/api/api.ts +++ b/site/src/api/api.ts @@ -2388,6 +2388,22 @@ class ApiMethods { ); return res.data; }; + + // Notification inbox API methods + getUserNotifications = async () => { + const response = await this.axios.get( + "/api/v2/users/me/notifications" + ); + return response.data; + }; + + markAllNotificationsAsRead = async (): Promise => { + await this.axios.post("/api/v2/users/me/notifications/read"); + }; + + markNotificationAsRead = async (notificationId: string): Promise => { + await this.axios.post(`/api/v2/users/me/notifications/${notificationId}/read`); + }; } // This is a hard coded CSRF token/cookie pair for local development. In prod, diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 6fdfb5ea9d9a1..9a3e6287d6421 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -1237,6 +1237,24 @@ export interface NotificationMethodsResponse { readonly default: string; } +// From codersdk/notifications.go +export interface InboxNotification { + readonly id: string; + readonly read_status: "read" | "unread"; + readonly content: string; + readonly created_at: string; + readonly actions: { + readonly label: string; + readonly url: string; + }[]; +} + +// From codersdk/notifications.go +export interface UserNotificationsResponse { + readonly notifications: InboxNotification[]; + readonly unread_count: number; +} + // From codersdk/notifications.go export interface NotificationPreference { readonly id: string; diff --git a/site/src/modules/dashboard/Navbar/NavbarView.tsx b/site/src/modules/dashboard/Navbar/NavbarView.tsx index d5ee661025f47..1a5ffc0bfa683 100644 --- a/site/src/modules/dashboard/Navbar/NavbarView.tsx +++ b/site/src/modules/dashboard/Navbar/NavbarView.tsx @@ -1,7 +1,9 @@ +import { API } from "api/api"; import type * as TypesGen from "api/typesGenerated"; import { ExternalImage } from "components/ExternalImage/ExternalImage"; import { CoderIcon } from "components/Icons/CoderIcon"; import type { ProxyContextValue } from "contexts/ProxyContext"; +import { NotificationsInbox } from "modules/notifications/NotificationsInbox/NotificationsInbox"; import type { FC } from "react"; import { NavLink, useLocation } from "react-router-dom"; import { cn } from "utils/cn"; @@ -57,6 +59,14 @@ export const NavbarView: FC = ({ {proxyContextValue && ( )} + + {user && ( + + )}