Skip to content

feat: implement notification inbox system #16901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,22 @@ class ApiMethods {
);
return res.data;
};

// Notification inbox API methods
getUserNotifications = async () => {
const response = await this.axios.get<TypesGen.UserNotificationsResponse>(
"/api/v2/users/me/notifications"
);
return response.data;
};

markAllNotificationsAsRead = async (): Promise<void> => {
await this.axios.post("/api/v2/users/me/notifications/read");
};

markNotificationAsRead = async (notificationId: string): Promise<void> => {
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,
Expand Down
18 changes: 18 additions & 0 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions site/src/modules/dashboard/Navbar/NavbarView.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -57,6 +59,14 @@ export const NavbarView: FC<NavbarViewProps> = ({
{proxyContextValue && (
<ProxyMenu proxyContextValue={proxyContextValue} />
)}

{user && (
<NotificationsInbox
fetchNotifications={API.getUserNotifications}
markAllAsRead={API.markAllNotificationsAsRead}
markNotificationAsRead={API.markNotificationAsRead}
/>
)}

<DeploymentDropdown
canViewAuditLog={canViewAuditLog}
Expand Down
15 changes: 4 additions & 11 deletions site/src/modules/notifications/NotificationsInbox/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
// TODO: Remove this file when the types from API are available
// This file uses the official API types
import type { InboxNotification } from "api/typesGenerated";

export type Notification = {
id: string;
read_status: "read" | "unread";
content: string;
created_at: string;
actions: {
label: string;
url: string;
}[];
};
// Reexport the InboxNotification type for backward compatibility
export type Notification = InboxNotification;
Loading