import { OPEN_WIZARD_STATUSES, workOrderDrilldownUrl, } from "@/domain/dashboard/utils/work-order-drilldown-links"; import type { NotificationItem } from "@/domain/notifications/types/notification-feed"; import { ASSIGNEE_FILTER_UNASSIGNED } from "@/domain/work-orders/types/work-order-list"; import { UNASSIGNED_QUEUE_DATE_FROM, UNASSIGNED_QUEUE_DATE_TO, } from "@/domain/work-orders/utils/board-query-params"; import { workOrderDeepLinkUrl } from "@/domain/work-orders/utils/work-order-deep-link"; const COMMENT_REASONS = new Set(["mentions", "activity"]); /** Every open work order held by `dispatcher`, in any week, through the Work Orders filter params. */ function openQueueUrl(dispatcher: string): string { const search = new URLSearchParams(); search.set("dateFrom", UNASSIGNED_QUEUE_DATE_FROM); search.set("dateTo", UNASSIGNED_QUEUE_DATE_TO); search.set("dispatchers", dispatcher); search.set("statuses", OPEN_WIZARD_STATUSES.join(",")); return workOrderDrilldownUrl(search, "notification"); } export function unassignedQueueUrl(): string { return openQueueUrl(ASSIGNEE_FILTER_UNASSIGNED); } /** The work order form with vendor assignment open — where the vendor reminders always sent "Choose vendor". */ export function chooseVendorUrl(workOrderId: number): string { return `/workorders/edit/${workOrderId}?assignVendor=1`; } export function workOrderViewUrl(workOrderId: number): string { return `/workorders/${workOrderId}`; } /** * Where a feed item leads. Queues open the Work Orders board filtered; work-order items open the * slide-over on their tab, and comment or mention items also carry which comments to highlight. */ export function notificationTargetUrl( item: Pick, currentUserId?: string | number | null, ): string | null { const { target } = item; if (target.kind === "queue") { if (target.queue === "unassigned") return unassignedQueueUrl(); if (target.queue === "assigned-to-me" && currentUserId != null && currentUserId !== "") { return openQueueUrl(String(currentUserId)); } return null; } if (target.workOrderId == null) { return null; } if (item.reason === "no-vendor") { return chooseVendorUrl(target.workOrderId); } const highlight = target.tab === "comments" && COMMENT_REASONS.has(item.reason) ? { since: item.triggeredAt, mentions: item.reason === "mentions" } : null; return workOrderDeepLinkUrl(target.workOrderId, target.tab, highlight); }