1
0
Fork 0
polaris-task-force/src/collections/users/UserNotifications.ts
Z8MB1E 9c15117b9b feat(notifications): add in-app player notification center
- user-notifications collection (per-user inbox, owner-scoped read)
- notifyUser() fire-and-forget helper + notification label mapping
- NotificationsBell in the site header with 30s polling, unread badge,
  mark-read on click, and "Mark all read"
- markNotificationsRead / markAllNotificationsRead server actions
2026-08-10 16:02:55 -04:00

70 lines
1.7 KiB
TypeScript

import { CollectionConfig } from "payload";
import type { User } from "@/payload-types";
import hasRoles from "@/utils/access-control/hasRoles";
import { isDeveloper } from "@/utils/access-control/isRole";
export const UserNotifications: CollectionConfig = {
slug: "user-notifications",
admin: {
group: "Users",
useAsTitle: "title",
defaultColumns: ["title", "user", "read", "createdAt"],
listSearchableFields: ["title", "message"],
pagination: { defaultLimit: 25 },
},
access: {
read: ({ req }) => {
const user = req.user as User | null;
if (!user) return false;
if (hasRoles(["admin", "developer"], user)) return true;
return { user: { equals: user.id } };
},
create: isDeveloper,
update: ({ req }) => {
const user = req.user as User | null;
if (!user) return false;
if (hasRoles(["admin", "developer"], user)) return true;
return { user: { equals: user.id } };
},
delete: isDeveloper,
},
fields: [
{
name: "user",
type: "relationship",
relationTo: "users",
required: true,
index: true,
},
{
name: "type",
type: "text",
admin: {
description: "Machine-readable notification type, e.g. `market:offer`.",
},
},
{
name: "title",
type: "text",
required: true,
},
{
name: "message",
type: "textarea",
},
{
name: "link",
type: "text",
admin: {
description: "Optional internal path to navigate to when clicked.",
},
},
{
name: "read",
type: "checkbox",
defaultValue: false,
index: true,
},
],
timestamps: true,
};