import { ISystemNotification, NotificationType } from "@core/Models/SystemNotifications.model"; import API from "@services/Api.Service"; type ResolveNotificationRouteParams = { notification: ISystemNotification; sessionUser: string; organizationSubscriptions?: Record; }; export const NOTIFICATIONS_ROUTE = "/user/profile/notifications"; export const resolveNotificationRoute = async ({ notification, sessionUser, organizationSubscriptions, }: ResolveNotificationRouteParams): Promise => { if (!notification.type || !notification.code) { return NOTIFICATIONS_ROUTE; } let companyId = notification.companyId; switch (notification.type) { case NotificationType.APPOINTMENT: { const aptRes = await API.post("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("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; };