```
refactor notifications popover to include unread count, mark all as read button, and loading state ```
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
//
|
||||
// RULES:
|
||||
// api method for get notifications by user id
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
import type { Notification } from './type.d';
|
||||
|
||||
export async function getNotificationsByUserId(userId: string): Promise<Notification[]> {
|
||||
const records = await pb.collection(COL_NOTIFICATIONS).getFullList({
|
||||
filter: `author.id = "000000000000001"`,
|
||||
expand: 'author, to_user_id',
|
||||
filter: `to_user_id.id = "${userId}"`,
|
||||
sort: '-created',
|
||||
});
|
||||
|
||||
return records as unknown as Notification[];
|
||||
}
|
||||
|
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// RULES:
|
||||
// api method for get notifications by user id
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
import type { Notification } from './type.d';
|
||||
|
||||
export async function getUnreadNotificationsByUserId(userId: string): Promise<Notification[]> {
|
||||
const records = await pb.collection(COL_NOTIFICATIONS).getFullList({
|
||||
expand: 'author, to_user_id',
|
||||
filter: `to_user_id.id = "${userId}" && read = false`,
|
||||
sort: '-created',
|
||||
cache: 'no-cache',
|
||||
requestKey: null,
|
||||
});
|
||||
|
||||
return records as unknown as Notification[];
|
||||
}
|
11
002_source/cms/src/db/Notifications/mark-one-as-read.tsx
Normal file
11
002_source/cms/src/db/Notifications/mark-one-as-read.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
// api method for update notification record
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_NOTIFICATIONS } from '@/constants';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import type { NotificationFormProps } from '@/components/dashboard/notification/type.d';
|
||||
|
||||
export async function MarkOneAsRead(id: string): Promise<RecordModel> {
|
||||
return pb.collection(COL_NOTIFICATIONS).update(id, { read: true });
|
||||
}
|
16
002_source/cms/src/db/Notifications/type.d.ts
vendored
16
002_source/cms/src/db/Notifications/type.d.ts
vendored
@@ -1,17 +1,21 @@
|
||||
'use client';
|
||||
|
||||
import type { User } from '@/types/user';
|
||||
|
||||
export type SortDir = 'asc' | 'desc';
|
||||
|
||||
export interface Notification {
|
||||
id: string;
|
||||
created: string;
|
||||
createdAt: Date;
|
||||
read: boolean;
|
||||
type: string;
|
||||
author: Record<string, unknown>;
|
||||
job: Record<string, unknown>;
|
||||
description: string;
|
||||
NOTI_ID: string;
|
||||
created: string;
|
||||
updated: string;
|
||||
author?: User;
|
||||
job?: { title: string };
|
||||
description?: string;
|
||||
company?: { name: string };
|
||||
to_user_id?: User;
|
||||
link: string;
|
||||
}
|
||||
|
||||
export interface CreateFormProps {
|
||||
|
Reference in New Issue
Block a user