Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add rerouting to AssignmentReasonRecorder #19252

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions apps/web/components/dialog/RerouteDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation } from "@tanstack/react-query";
import { useSession } from "next-auth/react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
Expand Down Expand Up @@ -277,6 +278,7 @@ const NewRoutingManager = ({
const { t } = useLocale();
const router = useRouter();
const bookerUrl = useBookerUrl();
const session = useSession();
const teamMemberIdsMatchingAttributeLogic =
teamMembersMatchingAttributeLogic?.data
?.map((member) => member.id)
Expand Down Expand Up @@ -467,6 +469,7 @@ const NewRoutingManager = ({
// TODO: Long term, we should refactor handleNewBooking and use a different route specific for this purpose,
createBookingMutation.mutate({
rescheduleUid: booking.uid,
rescheduledBy: session?.data?.user?.email,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to track who is calling the reroute

// rescheduleReason,
reroutingFormResponses: reroutingFormResponses,
...getTimeslotFields(),
Expand Down
2 changes: 2 additions & 0 deletions packages/features/bookings/lib/handleNewBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,8 @@ async function handler(
routingFormResponseId,
organizerId: organizerUser.id,
teamId,
isRerouting: isReroutingCase,
reroutedByEmail: reqBody.rescheduledBy,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ export default class AssignmentReasonRecorder {
routingFormResponseId,
organizerId,
teamId,
isRerouting,
reroutedByEmail,
Comment on lines +16 to +17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can reuse the logic that we use when recording the initial routing. That way we can see what attributes changed.

}: {
bookingId: number;
routingFormResponseId: number;
organizerId: number;
teamId: number;
isRerouting: boolean;
reroutedByEmail?: string | null;
}) {
// Get the routing form data
const routingFormResponse = await prisma.app_RoutingForms_FormResponse.findFirst({
Expand Down Expand Up @@ -98,11 +102,29 @@ export default class AssignmentReasonRecorder {
}
}

let reroutedByUserId: number | null = null;
if (isRerouting && reroutedByEmail) {
const userQuery = await prisma.user.findFirst({
where: {
email: reroutedByEmail,
},
select: {
id: true,
},
});

if (userQuery) {
reroutedByUserId = userQuery.id;
}
}

await prisma.assignmentReason.create({
data: {
bookingId: bookingId,
reasonEnum: AssignmentReasonEnum.ROUTING_FORM_ROUTING,
reasonString: attributeValues.join(", "),
reasonEnum: isRerouting ? AssignmentReasonEnum.REROUTED : AssignmentReasonEnum.ROUTING_FORM_ROUTING,
reasonString: `${
reroutedByUserId ? `Rerouted by user: ${reroutedByUserId}` : ""
} ${attributeValues.join(", ")}`,
},
});
}
Expand Down
Loading