11import { Dialog } from "@calcom/features/components/controlled-dialog" ;
22import { useCopy } from "@calcom/lib/hooks/useCopy" ;
33import { useLocale } from "@calcom/lib/hooks/useLocale" ;
4+ import type { AssignmentReasonEnum } from "@calcom/prisma/enums" ;
45import { trpc } from "@calcom/trpc/react" ;
56import { Alert } from "@calcom/ui/components/alert" ;
7+ import { Badge } from "@calcom/ui/components/badge" ;
68import { Button } from "@calcom/ui/components/button" ;
79import { DialogContent , DialogFooter , DialogHeader } from "@calcom/ui/components/dialog" ;
810import { Label , Select , TextArea } from "@calcom/ui/components/form" ;
@@ -12,15 +14,32 @@ import type { Dispatch, SetStateAction } from "react";
1214import type { Control , ControllerRenderProps } from "react-hook-form" ;
1315import { Controller , useForm } from "react-hook-form" ;
1416
17+ import assignmentReasonBadgeTitleMap from "@lib/booking/assignmentReasonBadgeTitleMap" ;
18+
19+ interface BookingData {
20+ uid : string ;
21+ eventType ?: {
22+ team ?: {
23+ id : number ;
24+ } | null ;
25+ } | null ;
26+ user ?: {
27+ email : string ;
28+ name : string | null ;
29+ } | null ;
30+ assignmentReasonSortedByCreatedAt : Array < {
31+ reasonString : string | null ;
32+ reasonEnum : AssignmentReasonEnum | null ;
33+ } > ;
34+ attendees : Array < {
35+ email : string ;
36+ } > ;
37+ }
38+
1539interface IWrongAssignmentDialog {
1640 isOpenDialog : boolean ;
1741 setIsOpenDialog : Dispatch < SetStateAction < boolean > > ;
18- bookingUid : string ;
19- routingReason : string | null ;
20- guestEmail : string ;
21- hostEmail : string ;
22- hostName : string | null ;
23- teamId : number | null ;
42+ booking : BookingData ;
2443}
2544
2645interface FormValues {
@@ -36,6 +55,7 @@ interface TeamMemberOption {
3655
3756interface RoutingInfoSectionProps {
3857 routingReason : string | null ;
58+ routingReasonEnum : AssignmentReasonEnum | null ;
3959 noRoutingReasonText : string ;
4060 routingReasonLabel : string ;
4161 guestEmail : string ;
@@ -48,8 +68,10 @@ interface RoutingInfoSectionProps {
4868}
4969
5070function RoutingInfoSection ( props : RoutingInfoSectionProps ) : JSX . Element {
71+ const { t } = useLocale ( ) ;
5172 const {
5273 routingReason,
74+ routingReasonEnum,
5375 noRoutingReasonText,
5476 routingReasonLabel,
5577 guestEmail,
@@ -79,9 +101,14 @@ function RoutingInfoSection(props: RoutingInfoSectionProps): JSX.Element {
79101 < div className = "-mt-2 mb-4 space-y-3" >
80102 < div >
81103 < Label className = "text-emphasis mb-1 block text-sm font-medium" > { routingReasonLabel } </ Label >
82- < p className = "text-default bg-muted rounded-md px-3 py-2 text-sm" >
83- { routingReason || noRoutingReasonText }
84- </ p >
104+ < div className = "text-default bg-muted flex items-center gap-2 rounded-md px-3 py-2 text-sm" >
105+ { routingReasonEnum && (
106+ < Badge variant = "gray" className = "shrink-0" >
107+ { t ( assignmentReasonBadgeTitleMap ( routingReasonEnum ) ) }
108+ </ Badge >
109+ ) }
110+ < span className = "flex-1" > { routingReason || noRoutingReasonText } </ span >
111+ </ div >
85112 </ div >
86113
87114 < div >
@@ -212,16 +239,15 @@ export function WrongAssignmentDialog(props: IWrongAssignmentDialog): JSX.Elemen
212239 const { t } = useLocale ( ) ;
213240 const utils = trpc . useUtils ( ) ;
214241 const { copyToClipboard, isCopied } = useCopy ( ) ;
215- const {
216- isOpenDialog,
217- setIsOpenDialog,
218- bookingUid,
219- routingReason,
220- guestEmail,
221- hostEmail,
222- hostName,
223- teamId,
224- } = props ;
242+ const { isOpenDialog, setIsOpenDialog, booking } = props ;
243+
244+ const bookingUid = booking . uid ;
245+ const teamId = booking . eventType ?. team ?. id ?? null ;
246+ const routingReason = booking . assignmentReasonSortedByCreatedAt [ 0 ] ?. reasonString ?? null ;
247+ const routingReasonEnum = booking . assignmentReasonSortedByCreatedAt [ 0 ] ?. reasonEnum ?? null ;
248+ const guestEmail = booking . attendees [ 0 ] ?. email ?? "" ;
249+ const hostEmail = booking . user ?. email ?? "" ;
250+ const hostName = booking . user ?. name ?? null ;
225251
226252 const {
227253 control,
@@ -286,8 +312,9 @@ export function WrongAssignmentDialog(props: IWrongAssignmentDialog): JSX.Elemen
286312
287313 < RoutingInfoSection
288314 routingReason = { routingReason }
315+ routingReasonEnum = { routingReasonEnum }
289316 noRoutingReasonText = { t ( "no_routing_reason" ) }
290- routingReasonLabel = { t ( "routing_reason " ) }
317+ routingReasonLabel = { t ( "first_assignment_reason " ) }
291318 guestEmail = { guestEmail }
292319 whoBookedItLabel = { t ( "who_booked_it" ) }
293320 hostEmail = { hostEmail }
0 commit comments