fix: Improve wrong assignment report (#27162)

* Pass already fetched booking

* Fetch the assignment reason

* Update tests

* Label as first assignment reason

* Pass single booking object

* Remove unused repository method

* Only pass bookingUid to handler

* Rename booking `assignmentReason` to `assignmentReasonSortedByCreatedAt`

* fix: use renamed assignmentReasonSortedByCreatedAt property

Co-Authored-By: [email protected] <[email protected]>

* Remove take statement

* fix: address Udit's review comments

- Restore BookingAccessService for access control checks
- Rename repository method from findByUidForWrongAssignmentReport to findByUidIncludeUserAndEventTypeTeamAndAttendeesAndAssignmentReason

Co-Authored-By: [email protected] <[email protected]>

* test: update tests to use BookingAccessService mock

Co-Authored-By: [email protected] <[email protected]>

* fix: use latest assignment reason in BookingDetailsSheet for consistency

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-02-11 13:12:21 -05:00
1 parent b185cd231b
commit 06bb994145
11 files changed
+277 -232

No files matched your search

@@ -552,19 +552,14 @@ function BookingListItem(booking: BookingItemProps) {
userTimeZone={userTimeZone}
isRescheduled={isRescheduled}
onAssignmentReasonClick={
booking.assignmentReason.length > 0 ? () => setIsOpenRoutingTraceSheet(true) : undefined
booking.assignmentReasonSortedByCreatedAt.length > 0 ? () => setIsOpenRoutingTraceSheet(true) : undefined
}
/>
{isBookingFromRoutingForm && (
<WrongAssignmentDialog
isOpenDialog={isOpenWrongAssignmentDialog}
setIsOpenDialog={setIsOpenWrongAssignmentDialog}
bookingUid={booking.uid}
routingReason={booking.assignmentReason[0]?.reasonString ?? null}
guestEmail={booking.attendees[0]?.email ?? ""}
hostEmail={booking.user?.email ?? ""}
hostName={booking.user?.name ?? null}
teamId={booking.eventType?.team?.id ?? null}
booking={booking}
/>
)}
</div>
@@ -606,7 +601,7 @@ const BookingItemBadges = ({
</Badge>
</Tooltip>
)}
{isRejected && !isRescheduled && booking.assignmentReason.length === 0 && (
{isRejected && !isRescheduled && booking.assignmentReasonSortedByCreatedAt.length === 0 && (
<Badge variant="gray" className="ltr:mr-2 rtl:ml-2">
{t("rejected")}
</Badge>
@@ -616,9 +611,9 @@ const BookingItemBadges = ({
{booking.eventType.team.name}
</Badge>
)}
{booking?.assignmentReason.length > 0 && (
{booking?.assignmentReasonSortedByCreatedAt.length > 0 && (
<AssignmentReasonTooltip
assignmentReason={booking.assignmentReason[0]}
assignmentReason={booking.assignmentReasonSortedByCreatedAt[booking.assignmentReasonSortedByCreatedAt.length - 1]}
onClick={onAssignmentReasonClick}
/>
)}
@@ -458,15 +458,10 @@ export function BookingActionsDropdown({
<WrongAssignmentDialog
isOpenDialog={isOpenWrongAssignmentDialog}
setIsOpenDialog={setIsOpenWrongAssignmentDialog}
bookingUid={booking.uid}
routingReason={booking.assignmentReason[0]?.reasonString ?? null}
guestEmail={booking.attendees[0]?.email ?? ""}
hostEmail={booking.user?.email ?? ""}
hostName={booking.user?.name ?? null}
teamId={booking.eventType?.team?.id ?? null}
booking={booking}
/>
)}
{booking.assignmentReason.length > 0 && (
{booking.assignmentReasonSortedByCreatedAt.length > 0 && (
<RoutingTraceSheet
isOpen={isOpenRoutingTraceSheet}
setIsOpen={setIsOpenRoutingTraceSheet}
@@ -84,7 +84,7 @@ function createMockContext(overrides: Partial<BookingActionContext> = {}): Booki
location: "integrations:daily",
payment: [],
seatsReferences: [],
assignmentReason: [],
assignmentReasonSortedByCreatedAt: [],
metadata: null,
routedFromRoutingFormReponse: null,
listingStatus: "upcoming",
@@ -1,8 +1,10 @@
import { Dialog } from "@calcom/features/components/controlled-dialog";
import { useCopy } from "@calcom/lib/hooks/useCopy";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { AssignmentReasonEnum } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc/react";
import { Alert } from "@calcom/ui/components/alert";
import { Badge } from "@calcom/ui/components/badge";
import { Button } from "@calcom/ui/components/button";
import { DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/components/dialog";
import { Label, Select, TextArea } from "@calcom/ui/components/form";
@@ -12,15 +14,32 @@ import type { Dispatch, SetStateAction } from "react";
import type { Control, ControllerRenderProps } from "react-hook-form";
import { Controller, useForm } from "react-hook-form";
import assignmentReasonBadgeTitleMap from "@lib/booking/assignmentReasonBadgeTitleMap";
interface BookingData {
uid: string;
eventType?: {
team?: {
id: number;
} | null;
} | null;
user?: {
email: string;
name: string | null;
} | null;
assignmentReasonSortedByCreatedAt: Array<{
reasonString: string | null;
reasonEnum: AssignmentReasonEnum | null;
}>;
attendees: Array<{
email: string;
}>;
}
interface IWrongAssignmentDialog {
isOpenDialog: boolean;
setIsOpenDialog: Dispatch<SetStateAction<boolean>>;
bookingUid: string;
routingReason: string | null;
guestEmail: string;
hostEmail: string;
hostName: string | null;
teamId: number | null;
booking: BookingData;
}
interface FormValues {
@@ -36,6 +55,7 @@ interface TeamMemberOption {
interface RoutingInfoSectionProps {
routingReason: string | null;
routingReasonEnum: AssignmentReasonEnum | null;
noRoutingReasonText: string;
routingReasonLabel: string;
guestEmail: string;
@@ -48,8 +68,10 @@ interface RoutingInfoSectionProps {
}
function RoutingInfoSection(props: RoutingInfoSectionProps): JSX.Element {
const { t } = useLocale();
const {
routingReason,
routingReasonEnum,
noRoutingReasonText,
routingReasonLabel,
guestEmail,
@@ -79,9 +101,14 @@ function RoutingInfoSection(props: RoutingInfoSectionProps): JSX.Element {
<div className="-mt-2 mb-4 space-y-3">
<div>
<Label className="text-emphasis mb-1 block text-sm font-medium">{routingReasonLabel}</Label>
<p className="text-default bg-muted rounded-md px-3 py-2 text-sm">
{routingReason || noRoutingReasonText}
</p>
<div className="text-default bg-muted flex items-center gap-2 rounded-md px-3 py-2 text-sm">
{routingReasonEnum && (
<Badge variant="gray" className="shrink-0">
{t(assignmentReasonBadgeTitleMap(routingReasonEnum))}
</Badge>
)}
<span className="flex-1">{routingReason || noRoutingReasonText}</span>
</div>
</div>
<div>
@@ -212,16 +239,15 @@ export function WrongAssignmentDialog(props: IWrongAssignmentDialog): JSX.Elemen
const { t } = useLocale();
const utils = trpc.useUtils();
const { copyToClipboard, isCopied } = useCopy();
const {
isOpenDialog,
setIsOpenDialog,
bookingUid,
routingReason,
guestEmail,
hostEmail,
hostName,
teamId,
} = props;
const { isOpenDialog, setIsOpenDialog, booking } = props;
const bookingUid = booking.uid;
const teamId = booking.eventType?.team?.id ?? null;
const routingReason = booking.assignmentReasonSortedByCreatedAt[0]?.reasonString ?? null;
const routingReasonEnum = booking.assignmentReasonSortedByCreatedAt[0]?.reasonEnum ?? null;
const guestEmail = booking.attendees[0]?.email ?? "";
const hostEmail = booking.user?.email ?? "";
const hostName = booking.user?.name ?? null;
const {
control,
@@ -286,8 +312,9 @@ export function WrongAssignmentDialog(props: IWrongAssignmentDialog): JSX.Elemen
<RoutingInfoSection
routingReason={routingReason}
routingReasonEnum={routingReasonEnum}
noRoutingReasonText={t("no_routing_reason")}
routingReasonLabel={t("routing_reason")}
routingReasonLabel={t("first_assignment_reason")}
guestEmail={guestEmail}
whoBookedItLabel={t("who_booked_it")}
hostEmail={hostEmail}