mirror of
https://github.com/coder/coder.git
synced 2025-03-14 10:09:57 +00:00
feat: implement notification inbox system
- Add API methods for getting notifications and marking them as read - Add TypeScript types for the notification inbox API - Update notification components to use the official API types - Integrate NotificationsInbox component into the navbar Closes #16804 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -2388,6 +2388,22 @@ class ApiMethods {
|
|||||||
);
|
);
|
||||||
return res.data;
|
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,
|
// This is a hard coded CSRF token/cookie pair for local development. In prod,
|
||||||
|
18
site/src/api/typesGenerated.ts
generated
18
site/src/api/typesGenerated.ts
generated
@ -1237,6 +1237,24 @@ export interface NotificationMethodsResponse {
|
|||||||
readonly default: string;
|
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
|
// From codersdk/notifications.go
|
||||||
export interface NotificationPreference {
|
export interface NotificationPreference {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
import { API } from "api/api";
|
||||||
import type * as TypesGen from "api/typesGenerated";
|
import type * as TypesGen from "api/typesGenerated";
|
||||||
import { ExternalImage } from "components/ExternalImage/ExternalImage";
|
import { ExternalImage } from "components/ExternalImage/ExternalImage";
|
||||||
import { CoderIcon } from "components/Icons/CoderIcon";
|
import { CoderIcon } from "components/Icons/CoderIcon";
|
||||||
import type { ProxyContextValue } from "contexts/ProxyContext";
|
import type { ProxyContextValue } from "contexts/ProxyContext";
|
||||||
|
import { NotificationsInbox } from "modules/notifications/NotificationsInbox/NotificationsInbox";
|
||||||
import type { FC } from "react";
|
import type { FC } from "react";
|
||||||
import { NavLink, useLocation } from "react-router-dom";
|
import { NavLink, useLocation } from "react-router-dom";
|
||||||
import { cn } from "utils/cn";
|
import { cn } from "utils/cn";
|
||||||
@ -57,6 +59,14 @@ export const NavbarView: FC<NavbarViewProps> = ({
|
|||||||
{proxyContextValue && (
|
{proxyContextValue && (
|
||||||
<ProxyMenu proxyContextValue={proxyContextValue} />
|
<ProxyMenu proxyContextValue={proxyContextValue} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{user && (
|
||||||
|
<NotificationsInbox
|
||||||
|
fetchNotifications={API.getUserNotifications}
|
||||||
|
markAllAsRead={API.markAllNotificationsAsRead}
|
||||||
|
markNotificationAsRead={API.markNotificationAsRead}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<DeploymentDropdown
|
<DeploymentDropdown
|
||||||
canViewAuditLog={canViewAuditLog}
|
canViewAuditLog={canViewAuditLog}
|
||||||
|
@ -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 = {
|
// Reexport the InboxNotification type for backward compatibility
|
||||||
id: string;
|
export type Notification = InboxNotification;
|
||||||
read_status: "read" | "unread";
|
|
||||||
content: string;
|
|
||||||
created_at: string;
|
|
||||||
actions: {
|
|
||||||
label: string;
|
|
||||||
url: string;
|
|
||||||
}[];
|
|
||||||
};
|
|
||||||
|
Reference in New Issue
Block a user