139 lines
3.9 KiB
TypeScript
139 lines
3.9 KiB
TypeScript
import type { BigCalendarEvent, CalendarProjectionItem } from "../api/types";
|
|
import type { IEvent, IUser } from "../upstream-big-calendar/interfaces";
|
|
|
|
interface LegacyBigCalendarAction {
|
|
type: "move" | "resize";
|
|
event: BigCalendarEvent;
|
|
start: string;
|
|
end: string;
|
|
}
|
|
|
|
interface LegacyBigCalendarActivityCommand {
|
|
type: "reschedule";
|
|
activityId: string;
|
|
scheduledStartAt: string;
|
|
scheduledEndAt: string;
|
|
}
|
|
|
|
export interface UpstreamCalendarActivityCommand {
|
|
type: "reschedule";
|
|
activityId: string;
|
|
scheduledStartAt: string;
|
|
scheduledEndAt: string;
|
|
}
|
|
|
|
export function mapCalendarProjectionToBigCalendarEvent(
|
|
item: CalendarProjectionItem
|
|
): BigCalendarEvent {
|
|
const activityEditable = item.editable && !item.milestone && item.activityId !== null;
|
|
|
|
return {
|
|
id: item.id,
|
|
title: item.title,
|
|
start: item.startAt,
|
|
end: item.endAt,
|
|
allDay: item.allDay,
|
|
editable: activityEditable,
|
|
draggable: activityEditable,
|
|
resizable: activityEditable,
|
|
category: item.category,
|
|
priority: item.priority,
|
|
source: {
|
|
entityType: item.entityType,
|
|
entityId: item.entityId,
|
|
activityId: item.activityId,
|
|
customerId: item.customerId,
|
|
leadId: item.leadId,
|
|
opportunityId: item.opportunityId,
|
|
quotationId: item.quotationId,
|
|
approvalId: item.approvalId,
|
|
ownerId: item.ownerId,
|
|
assigneeId: item.assigneeId
|
|
},
|
|
display: {
|
|
summary: item.summary,
|
|
location: item.location,
|
|
overdue: item.overdue,
|
|
hotProject: item.hotProject,
|
|
milestone: item.milestone
|
|
}
|
|
};
|
|
}
|
|
|
|
export function mapBigCalendarActionToActivityCommand(
|
|
action: LegacyBigCalendarAction
|
|
): LegacyBigCalendarActivityCommand | null {
|
|
if (!action.event.editable || !action.event.source.activityId) return null;
|
|
|
|
return {
|
|
type: "reschedule",
|
|
activityId: action.event.source.activityId,
|
|
scheduledStartAt: action.start,
|
|
scheduledEndAt: action.end
|
|
};
|
|
}
|
|
|
|
export function mapCalendarProjectionToUpstreamEvent(item: CalendarProjectionItem): IEvent {
|
|
const editable = item.editable && !item.milestone && item.activityId !== null;
|
|
|
|
return {
|
|
id: item.id,
|
|
title: item.title,
|
|
startDate: item.startAt,
|
|
endDate: item.endAt,
|
|
color: mapCalendarColor(item),
|
|
description: [item.summary, item.location].filter(Boolean).join(" - "),
|
|
user: mapCrmCalendarUserToUpstreamUser(item),
|
|
alla: {
|
|
activityId: item.activityId,
|
|
editable,
|
|
milestone: item.milestone,
|
|
sourceEntityType: item.entityType,
|
|
sourceEntityId: item.entityId,
|
|
customerId: item.customerId,
|
|
leadId: item.leadId,
|
|
opportunityId: item.opportunityId,
|
|
quotationId: item.quotationId,
|
|
approvalId: item.approvalId,
|
|
overdue: item.overdue,
|
|
hotProject: item.hotProject,
|
|
pricingSensitive: item.visibility.pricingSensitive,
|
|
internalOnly: item.visibility.internalOnly
|
|
}
|
|
};
|
|
}
|
|
|
|
export function mapCrmCalendarUserToUpstreamUser(item: CalendarProjectionItem): IUser {
|
|
const id = item.assigneeId ?? item.ownerId ?? "unassigned";
|
|
|
|
return {
|
|
id,
|
|
name: id === "unassigned" ? "Unassigned" : `User ${id.slice(0, 8)}`,
|
|
picturePath: null
|
|
};
|
|
}
|
|
|
|
export function mapUpstreamEventToActivityCommand(
|
|
event: IEvent
|
|
): UpstreamCalendarActivityCommand | null {
|
|
if (!event.alla?.editable || !event.alla.activityId) return null;
|
|
|
|
return {
|
|
type: "reschedule",
|
|
activityId: event.alla.activityId,
|
|
scheduledStartAt: event.startDate,
|
|
scheduledEndAt: event.endDate
|
|
};
|
|
}
|
|
|
|
function mapCalendarColor(item: CalendarProjectionItem): IEvent["color"] {
|
|
if (item.overdue) return "red";
|
|
if (item.hotProject) return "orange";
|
|
if (item.milestone) return "purple";
|
|
if (item.priority === "critical") return "red";
|
|
if (item.priority === "high") return "yellow";
|
|
if (item.category === "meeting") return "blue";
|
|
if (item.category === "visit" || item.category === "site_survey") return "green";
|
|
return "gray";
|
|
}
|