Skip to content
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

[Feat]: Notification entry navigates to the relevant view #2786

Merged
Merged
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
34 changes: 34 additions & 0 deletions src/app/features/notification/model/notification-event.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
import { Entity } from "../../../core/entity/model/entity";
import { DatabaseField } from "../../../core/entity/database-field.decorator";
import { DatabaseEntity } from "../../../core/entity/database-entity.decorator";
import { NotificationType } from "./notification-config";

/**
* This represents one specific notification event for one specific user,
* displayed in the UI through the notification indicator in the toolbar.
*/
@DatabaseEntity("NotificationEvent")
export class NotificationEvent extends Entity {
/*
* The title of the notification.
*/
@DatabaseField() title: string;

/*
* The body of the notification.
*/
@DatabaseField() body: string;

/*
* The URL to redirect the user to when the notification is clicked.
*/
@DatabaseField() actionURL: string;

/*
* The user ID for whom the notification is intended
*/
@DatabaseField() notificationFor: string;

/*
* The notification token to be used for the notification.
*/
@DatabaseField() notificationToken: string;
tomwwinter marked this conversation as resolved.
Show resolved Hide resolved

/*
* The type of notification.
*/
@DatabaseField() notificationType: NotificationType;

/*
* The entity type of the notification.
*/
@DatabaseField() entityType: string;

/*
* The status of the notification.
*/
@DatabaseField() readStatus: boolean;
}
28 changes: 26 additions & 2 deletions src/app/features/notification/notification.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,39 @@ export class NotificationComponent implements OnInit {
await this.entityMapper.remove(notification);
}

private generateNotificationActionURL(
notification: NotificationEvent,
): string {
const routes = this.router.config;
let actionURL = "";

const entityRoute = routes.find(
(route) => route.data?.config?.entityType === notification.entityType,
);
sleidig marked this conversation as resolved.
Show resolved Hide resolved

switch (notification.notificationType) {
case "entity_change":
if (entityRoute) {
actionURL = `/${entityRoute.path}`;
}
break;
default:
break;
Comment on lines +154 to +155
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default: return notification.actionUrl?

}

return actionURL;
}

/**
* Updates the read status of a selected notification.
* Handles notification events by redirecting the user to the corresponding action URL.
* @param {NotificationEvent} notification - The notification event containing the action URL.
*/
async notificationClicked(notification: NotificationEvent) {
await this.updateReadStatus([notification], true);
if (!notification.actionURL) return;
await this.router.navigate([notification.actionURL]);
const actionURL = this.generateNotificationActionURL(notification);
if (!actionURL) return;
await this.router.navigate([actionURL]);
}

// TODO: remove test code before final merge
Expand Down
Loading