80 lines
2.8 KiB
TypeScript
80 lines
2.8 KiB
TypeScript
import { ISystemNotification, NotificationType } from "@core/Models/SystemNotifications.model";
|
|
import API from "@services/Api.Service";
|
|
|
|
type ResolveNotificationRouteParams = {
|
|
notification: ISystemNotification;
|
|
sessionUser: string;
|
|
organizationSubscriptions?: Record<string, unknown>;
|
|
};
|
|
|
|
export const NOTIFICATIONS_ROUTE = "/user/profile/notifications";
|
|
|
|
export const resolveNotificationRoute = async ({
|
|
notification,
|
|
sessionUser,
|
|
organizationSubscriptions,
|
|
}: ResolveNotificationRouteParams): Promise<string> => {
|
|
if (!notification.type || !notification.code) {
|
|
return NOTIFICATIONS_ROUTE;
|
|
}
|
|
|
|
let companyId = notification.companyId;
|
|
|
|
switch (notification.type) {
|
|
case NotificationType.APPOINTMENT: {
|
|
const aptRes = await API.post<any>("appointments/get-event", {
|
|
appointmentId: notification.code,
|
|
sessionUser,
|
|
});
|
|
|
|
companyId = companyId || aptRes?.companyId;
|
|
if (aptRes?.clientId && companyId) {
|
|
return `/admin/org/${companyId}/client/${aptRes.clientId}/appointments/${notification.code}`;
|
|
}
|
|
break;
|
|
}
|
|
case NotificationType.COMPANY:
|
|
return `/admin/org/profile/${notification.code}`;
|
|
case NotificationType.EMPLOYEE:
|
|
case NotificationType.SCHEDULE:
|
|
case NotificationType.SCHEDULE_EXCEPTION:
|
|
case NotificationType.SCHEDULE_RESTRICTION:
|
|
if (!companyId) {
|
|
const empRes = await API.post<any>("employees/get-by-id", {
|
|
id: notification.code,
|
|
sessionUser,
|
|
});
|
|
companyId = empRes?.companyId;
|
|
}
|
|
|
|
if (companyId) {
|
|
if (
|
|
notification.type === NotificationType.EMPLOYEE ||
|
|
notification.type === NotificationType.SCHEDULE
|
|
) {
|
|
return `/admin/org/profile/${companyId}/collaborators/${notification.code}`;
|
|
}
|
|
|
|
if (notification.type === NotificationType.SCHEDULE_EXCEPTION) {
|
|
return `/admin/org/profile/${companyId}/collaborators/${notification.code}/exceptions`;
|
|
}
|
|
|
|
return `/admin/org/profile/${companyId}/collaborators/${notification.code}/restrictions`;
|
|
}
|
|
break;
|
|
case NotificationType.BILLING:
|
|
companyId = companyId || Object.keys(organizationSubscriptions || {})[0];
|
|
if (companyId) {
|
|
return `/admin/org/profile/${companyId}/dashboard`;
|
|
}
|
|
break;
|
|
case NotificationType.MESSAGE:
|
|
if (notification.conversationId) {
|
|
return `/messages?conversation=${notification.conversationId}`;
|
|
}
|
|
break;
|
|
}
|
|
|
|
return NOTIFICATIONS_ROUTE;
|
|
};
|