feat(notifications): add notification history page and API
This commit introduces the notification history feature, allowing users to view a log of their past notifications. Key changes include: - Added a "Notifications" link to the sidebar with a new icon. - Defined API endpoints for fetching notification history and details. - Added a "sent" status variant for displaying notification status. Additionally, this commit includes related UI improvements: - The user's full name is now dynamically displayed in the header, replacing the hardcoded placeholder. - Table headers are now styled in uppercase for improved readability and consistency.
This commit is contained in:
@@ -50,4 +50,8 @@ export const API_ENDPOINTS = {
|
||||
DETAILS: (id: string) => `feedback/${id}`,
|
||||
DELETE: (id: string) => `feedback/${id}`,
|
||||
},
|
||||
NOTIFICATIONS: {
|
||||
HISTORY: "notifications",
|
||||
DETAILS: (id: string) => `notifications/view/${id}`,
|
||||
},
|
||||
} as const;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import api from "../axios";
|
||||
import { API_ENDPOINTS } from "../endpoints";
|
||||
import {
|
||||
TNotificationDetailsResponse,
|
||||
TNotificationHistoryResponse,
|
||||
} from "../types/NotificationHistory";
|
||||
import { ApiResponse } from "../types/shared";
|
||||
|
||||
export const notificationService = {
|
||||
getNotifications: async (
|
||||
params?: Record<string, any>,
|
||||
): Promise<TNotificationHistoryResponse> => {
|
||||
try {
|
||||
return (await api.get(API_ENDPOINTS.NOTIFICATIONS.HISTORY, { params }))
|
||||
.data;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"ERROR Caught in notification service => getNotifications",
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
getNotificationDetails: async (
|
||||
id: string,
|
||||
): Promise<ApiResponse<TNotificationDetailsResponse>> => {
|
||||
try {
|
||||
return (await api.get(API_ENDPOINTS.NOTIFICATIONS.DETAILS(id))).data;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"ERROR Caught in notification service => getNotificationDetails",
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -31,9 +31,6 @@ const customersSchema = z.object({
|
||||
username: z.string(),
|
||||
});
|
||||
|
||||
export const customersListResponse = z.object({
|
||||
customers: z.array(customersSchema),
|
||||
});
|
||||
const createCustomerCredentials = z.object({
|
||||
address: z
|
||||
.object({
|
||||
@@ -99,6 +96,9 @@ const createCustomerCredentials = z.object({
|
||||
"Username must contain only alphanumeric characters",
|
||||
),
|
||||
});
|
||||
export const customersListResponse = z.object({
|
||||
customers: z.array(customersSchema),
|
||||
});
|
||||
const assignCustomerToCompanySchema = z.object({
|
||||
company_ids: z.array(z.string()),
|
||||
});
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { z } from "zod";
|
||||
import { createApiResponseSchema } from "./Factory";
|
||||
|
||||
export const notificationSchema = z.object({
|
||||
created_at: z.string(),
|
||||
event_type: z.string(),
|
||||
id: z.string(),
|
||||
image: z.string(),
|
||||
is_scheduled: z.boolean(),
|
||||
link: z.string(),
|
||||
message: z.string(),
|
||||
metadata: z.object({
|
||||
additionalProp1: z.string(),
|
||||
additionalProp2: z.string(),
|
||||
additionalProp3: z.string(),
|
||||
}),
|
||||
method: z.object({
|
||||
additionalProp1: z.string(),
|
||||
additionalProp2: z.string(),
|
||||
additionalProp3: z.string(),
|
||||
}),
|
||||
priority: z.string(),
|
||||
schedule_at: z.number(),
|
||||
scheduled_at: z.number(),
|
||||
seen: z.boolean(),
|
||||
seen_at: z.number(),
|
||||
status: z.string(),
|
||||
title: z.string(),
|
||||
type: z.string(),
|
||||
updated_at: z.string(),
|
||||
user_id: z.string(),
|
||||
});
|
||||
|
||||
const notificationHistoryResponseSchema = createApiResponseSchema(
|
||||
z.object({
|
||||
notifications: z.array(notificationSchema),
|
||||
}),
|
||||
);
|
||||
export type TNotificationHistory = z.infer<typeof notificationSchema>;
|
||||
export type TNotificationDetailsResponse = z.infer<typeof notificationSchema>;
|
||||
export type TNotificationHistoryResponse = z.infer<
|
||||
typeof notificationHistoryResponseSchema
|
||||
>;
|
||||
Reference in New Issue
Block a user