commit task-ep.1.6.2-r1
This commit is contained in:
@@ -1,4 +1,26 @@
|
||||
import type { BigCalendarEvent, CalendarProjectionItem } from '../api/types';
|
||||
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
|
||||
@@ -24,7 +46,9 @@ export function mapCalendarProjectionToBigCalendarEvent(
|
||||
leadId: item.leadId,
|
||||
opportunityId: item.opportunityId,
|
||||
quotationId: item.quotationId,
|
||||
approvalId: item.approvalId
|
||||
approvalId: item.approvalId,
|
||||
ownerId: item.ownerId,
|
||||
assigneeId: item.assigneeId
|
||||
},
|
||||
display: {
|
||||
summary: item.summary,
|
||||
@@ -35,3 +59,80 @@ export function mapCalendarProjectionToBigCalendarEvent(
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user