feat: Record Salesforce ownership assignment (#17775)
This commit is contained in:
1 parent
04b49acbb0
commit
1490642260
20 files changed
+279
-63
No files matched your search
@@ -33,6 +33,8 @@ type StoreInitializeType = {
|
||||
org?: string | null;
|
||||
isInstantMeeting?: boolean;
|
||||
teamMemberEmail?: string | null;
|
||||
crmOwnerRecordType?: string | null;
|
||||
crmAppSlug?: string | null;
|
||||
};
|
||||
|
||||
type SeatedEventData = {
|
||||
@@ -151,6 +153,8 @@ export type BookerStore = {
|
||||
setOrg: (org: string | null | undefined) => void;
|
||||
|
||||
teamMemberEmail?: string | null;
|
||||
crmOwnerRecordType?: string | null;
|
||||
crmAppSlug?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -257,6 +261,8 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
|
||||
org,
|
||||
isInstantMeeting,
|
||||
teamMemberEmail,
|
||||
crmOwnerRecordType,
|
||||
crmAppSlug,
|
||||
}: StoreInitializeType) => {
|
||||
const selectedDateInStore = get().selectedDate;
|
||||
|
||||
@@ -270,7 +276,9 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
|
||||
get().bookingData?.responses.email === bookingData?.responses.email &&
|
||||
get().layout === layout &&
|
||||
get().rescheduledBy === rescheduledBy &&
|
||||
get().teamMemberEmail
|
||||
get().teamMemberEmail === teamMemberEmail &&
|
||||
get().crmOwnerRecordType === crmOwnerRecordType &&
|
||||
get().crmAppSlug
|
||||
)
|
||||
return;
|
||||
set({
|
||||
@@ -290,6 +298,8 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
|
||||
selectedDateInStore ||
|
||||
(["week_view", "column_view"].includes(layout) ? dayjs().format("YYYY-MM-DD") : null),
|
||||
teamMemberEmail,
|
||||
crmOwnerRecordType,
|
||||
crmAppSlug,
|
||||
});
|
||||
|
||||
if (durationConfig?.includes(Number(getQueryParam("duration")))) {
|
||||
@@ -379,6 +389,8 @@ export const useInitializeBookerStore = ({
|
||||
org,
|
||||
isInstantMeeting,
|
||||
teamMemberEmail,
|
||||
crmOwnerRecordType,
|
||||
crmAppSlug,
|
||||
}: StoreInitializeType) => {
|
||||
const initializeStore = useBookerStore((state) => state.initialize);
|
||||
useEffect(() => {
|
||||
@@ -397,6 +409,8 @@ export const useInitializeBookerStore = ({
|
||||
durationConfig,
|
||||
isInstantMeeting,
|
||||
teamMemberEmail,
|
||||
crmOwnerRecordType,
|
||||
crmAppSlug,
|
||||
});
|
||||
}, [
|
||||
initializeStore,
|
||||
@@ -414,5 +428,7 @@ export const useInitializeBookerStore = ({
|
||||
durationConfig,
|
||||
isInstantMeeting,
|
||||
teamMemberEmail,
|
||||
crmOwnerRecordType,
|
||||
crmAppSlug,
|
||||
]);
|
||||
};
|
||||
@@ -88,6 +88,8 @@ export interface BookerProps {
|
||||
hashedLink?: string | null;
|
||||
isInstantMeeting?: boolean;
|
||||
teamMemberEmail?: string | null;
|
||||
crmOwnerRecordType?: string | null;
|
||||
crmAppSlug?: string | null;
|
||||
}
|
||||
|
||||
export type WrappedBookerPropsMain = {
|
||||
|
||||
@@ -22,6 +22,8 @@ export type BookingOptions = {
|
||||
seatReferenceUid?: string;
|
||||
hashedLink?: string | null;
|
||||
teamMemberEmail?: string | null;
|
||||
crmOwnerRecordType?: string | null;
|
||||
crmAppSlug?: string | null;
|
||||
orgSlug?: string;
|
||||
};
|
||||
|
||||
@@ -40,6 +42,8 @@ export const mapBookingToMutationInput = ({
|
||||
seatReferenceUid,
|
||||
hashedLink,
|
||||
teamMemberEmail,
|
||||
crmOwnerRecordType,
|
||||
crmAppSlug,
|
||||
orgSlug,
|
||||
}: BookingOptions): BookingCreateBody => {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
@@ -70,6 +74,8 @@ export const mapBookingToMutationInput = ({
|
||||
seatReferenceUid,
|
||||
hashedLink,
|
||||
teamMemberEmail,
|
||||
crmOwnerRecordType,
|
||||
crmAppSlug,
|
||||
orgSlug,
|
||||
routedTeamMemberIds,
|
||||
routingFormResponseId,
|
||||
|
||||
@@ -1166,13 +1166,24 @@ async function handler(
|
||||
await usersRepository.updateLastActiveAt(booking.userId);
|
||||
}
|
||||
|
||||
if (routingFormResponseId && teamId) {
|
||||
await AssignmentReasonRecorder.routingFormRoute({
|
||||
bookingId: booking.id,
|
||||
routingFormResponseId,
|
||||
organizerId: organizerUser.id,
|
||||
teamId,
|
||||
});
|
||||
// If it's a round robin event, record the reason for the host assignment
|
||||
if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) {
|
||||
if (reqBody.crmOwnerRecordType && reqBody.crmAppSlug && contactOwnerEmail && routingFormResponseId) {
|
||||
await AssignmentReasonRecorder.CRMOwnership({
|
||||
bookingId: booking.id,
|
||||
crmAppSlug: reqBody.crmAppSlug,
|
||||
teamMemberEmail: contactOwnerEmail,
|
||||
recordType: reqBody.crmOwnerRecordType,
|
||||
routingFormResponseId,
|
||||
});
|
||||
} else if (routingFormResponseId && teamId) {
|
||||
await AssignmentReasonRecorder.routingFormRoute({
|
||||
bookingId: booking.id,
|
||||
routingFormResponseId,
|
||||
organizerId: organizerUser.id,
|
||||
teamId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -109,7 +109,35 @@ export default class AssignmentReasonRecorder {
|
||||
|
||||
// Separate method to handle rerouting
|
||||
|
||||
// Routing via CRM ownership, need to keep each specific CRM logic in it's own package
|
||||
static async CRMOwnership({
|
||||
bookingId,
|
||||
crmAppSlug,
|
||||
teamMemberEmail,
|
||||
recordType,
|
||||
routingFormResponseId,
|
||||
}: {
|
||||
bookingId: number;
|
||||
crmAppSlug: string;
|
||||
teamMemberEmail: string;
|
||||
recordType: string;
|
||||
routingFormResponseId: number;
|
||||
}) {
|
||||
const appAssignmentReasonHandler = (await import("./appAssignmentReasonHandler")).default;
|
||||
const appHandler = appAssignmentReasonHandler[crmAppSlug];
|
||||
if (!appHandler) return;
|
||||
|
||||
const crmRoutingReason = await appHandler({ recordType, teamMemberEmail, routingFormResponseId });
|
||||
|
||||
if (!crmRoutingReason || !crmRoutingReason.assignmentReason) return;
|
||||
|
||||
await prisma.assignmentReason.create({
|
||||
data: {
|
||||
bookingId,
|
||||
reasonEnum: crmRoutingReason.reasonEnum,
|
||||
reasonString: crmRoutingReason.assignmentReason,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
static async roundRobinReassignment({
|
||||
bookingId,
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { assignmentReasonHandler as salesforceAssignmentReasonHandler } from "@calcom/app-store/salesforce/lib/assignmentReasonHandler";
|
||||
import type { AssignmentReasonEnum } from "@calcom/prisma/enums";
|
||||
|
||||
type AppAssignmentReasonHandler = ({
|
||||
recordType,
|
||||
teamMemberEmail,
|
||||
routingFormResponseId,
|
||||
}: {
|
||||
recordType: string;
|
||||
teamMemberEmail: string;
|
||||
routingFormResponseId: number;
|
||||
}) => Promise<{ assignmentReason: string | undefined; reasonEnum: AssignmentReasonEnum } | undefined>;
|
||||
|
||||
const appBookingFormHandler: Record<string, AppAssignmentReasonHandler> = {
|
||||
salesforce: salesforceAssignmentReasonHandler,
|
||||
};
|
||||
|
||||
export default appBookingFormHandler;
|
||||
Reference in new issue
Block a user