shoc-frontend-new/src/domain/notifications/utils/notification-target-url.ts
Codex Review Integration 75c2c1c1fa Merge remote-tracking branch 'origin/feat/ab/sh-292-notification-center' into HEAD
# Conflicts:
#	src/app/(protected)/workorders/_components/detail/use-slide-over-edit-state.ts
#	src/app/(protected)/workorders/_components/detail/use-work-order-slide-over.ts
#	src/app/(protected)/workorders/_components/detail/work-order-slide-over.tsx
#	src/app/(protected)/workorders/_components/list/work-orders-list-page-panels.tsx
#	src/app/(protected)/workorders/_hooks/use-work-orders-list-page.ts
2026-09-18 14:35:17 -03:00

65 lines
2.5 KiB
TypeScript

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<NotificationItem, "reason" | "triggeredAt" | "target">,
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);
}