@@ -31,6 +31,7 @@ import { ReportBookingDialog } from "@components/dialog/ReportBookingDialog";
3131import { RerouteDialog } from "@components/dialog/RerouteDialog" ;
3232import { RescheduleDialog } from "@components/dialog/RescheduleDialog" ;
3333
34+ import type { BookingItemProps } from "../types" ;
3435import { useBookingActionsStoreContext } from "./BookingActionsStoreProvider" ;
3536import {
3637 getCancelEventAction ,
@@ -40,13 +41,14 @@ import {
4041 shouldShowEditActions ,
4142 type BookingActionContext ,
4243} from "./bookingActions" ;
43- import type { BookingItemProps } from "./types" ;
4444
4545interface BookingActionsDropdownProps {
4646 booking : BookingItemProps ;
47+ context : "booking-list-item" | "booking-details-sheet" ;
48+ size ?: "xs" | "sm" | "base" | "lg" ;
4749}
4850
49- export function BookingActionsDropdown ( { booking } : BookingActionsDropdownProps ) {
51+ export function BookingActionsDropdown ( { booking, context , size = "base" } : BookingActionsDropdownProps ) {
5052 const { t } = useLocale ( ) ;
5153 const utils = trpc . useUtils ( ) ;
5254
@@ -236,9 +238,11 @@ export function BookingActionsDropdown({ booking }: BookingActionsDropdownProps)
236238
237239 const cancelEventAction = getCancelEventAction ( actionContext ) ;
238240
241+ const shouldShowEdit = shouldShowEditActions ( actionContext ) ;
239242 const baseEditEventActions = getEditEventActions ( actionContext ) ;
240243 const editEventActions : ActionType [ ] = baseEditEventActions . map ( ( action ) => ( {
241244 ...action ,
245+ disabled : ! shouldShowEdit || action . disabled , // Disable all edit actions if shouldn't show edit actions
242246 onClick :
243247 action . id === "reschedule_request"
244248 ? ( ) => setIsOpenRescheduleDialog ( true )
@@ -494,99 +498,119 @@ export function BookingActionsDropdown({ booking }: BookingActionsDropdownProps)
494498 </ >
495499 ) ;
496500
497- // Don't render dropdown if edit actions shouldn't be shown
498- if ( ! shouldShowEditActions ( actionContext ) ) {
501+ // Check if there are any available actions across all action groups
502+ const hasAnyAvailableActions = ( ) => {
503+ // Check if any edit action is available
504+ const hasAvailableEditAction = editEventActions . some ( ( action ) => ! action . disabled ) ;
505+
506+ // Check if any after event action is available
507+ const hasAvailableAfterAction = afterEventActions . some ( ( action ) => ! action . disabled ) ;
508+
509+ // For booking-list-item context, only check edit and after event actions
510+ if ( context === "booking-list-item" ) {
511+ return hasAvailableEditAction || hasAvailableAfterAction ;
512+ }
513+
514+ // For booking-details-sheet context, also check report and cancel actions
515+ const isReportAvailable = ! reportActionWithHandler . disabled ;
516+ const isCancelAvailable = ! cancelEventAction . disabled ;
517+
518+ return hasAvailableEditAction || hasAvailableAfterAction || isReportAvailable || isCancelAvailable ;
519+ } ;
520+
521+ // Don't render dropdown if no actions are available
522+ if ( ! hasAnyAvailableActions ( ) ) {
499523 return dialogs ;
500524 }
501525
526+ const menuContent = (
527+ < DropdownMenuContent >
528+ < DropdownMenuLabel className = "px-2 pb-1 pt-1.5" > { t ( "edit_event" ) } </ DropdownMenuLabel >
529+ { editEventActions . map ( ( action ) => (
530+ < DropdownMenuItem className = "rounded-lg" key = { action . id } disabled = { action . disabled } >
531+ < DropdownItem
532+ type = "button"
533+ color = { action . color }
534+ StartIcon = { action . icon }
535+ href = { action . href }
536+ disabled = { action . disabled }
537+ onClick = { action . onClick }
538+ data-bookingid = { action . bookingId }
539+ data-testid = { action . id }
540+ className = { action . disabled ? "text-muted" : undefined } >
541+ { action . label }
542+ </ DropdownItem >
543+ </ DropdownMenuItem >
544+ ) ) }
545+ < DropdownMenuSeparator />
546+ < DropdownMenuLabel className = "px-2 pb-1 pt-1.5" > { t ( "after_event" ) } </ DropdownMenuLabel >
547+ { afterEventActions . map ( ( action ) => (
548+ < DropdownMenuItem className = "rounded-lg" key = { action . id } disabled = { action . disabled } >
549+ < DropdownItem
550+ type = "button"
551+ color = { action . color }
552+ StartIcon = { action . icon }
553+ href = { action . href }
554+ onClick = { action . onClick }
555+ disabled = { action . disabled }
556+ data-bookingid = { action . bookingId }
557+ data-testid = { action . id }
558+ className = { action . disabled ? "text-muted" : undefined } >
559+ { action . label }
560+ </ DropdownItem >
561+ </ DropdownMenuItem >
562+ ) ) }
563+ < >
564+ < DropdownMenuSeparator />
565+ < DropdownMenuItem
566+ className = "rounded-lg"
567+ key = { reportActionWithHandler . id }
568+ disabled = { reportActionWithHandler . disabled } >
569+ < DropdownItem
570+ type = "button"
571+ color = { reportActionWithHandler . color }
572+ StartIcon = { reportActionWithHandler . icon }
573+ onClick = { reportActionWithHandler . onClick }
574+ disabled = { reportActionWithHandler . disabled }
575+ data-testid = { reportActionWithHandler . id }
576+ className = { reportActionWithHandler . disabled ? "text-muted" : undefined } >
577+ { reportActionWithHandler . label }
578+ </ DropdownItem >
579+ </ DropdownMenuItem >
580+ </ >
581+ < DropdownMenuSeparator />
582+ < DropdownMenuItem
583+ className = "rounded-lg"
584+ key = { cancelEventAction . id }
585+ disabled = { cancelEventAction . disabled } >
586+ < DropdownItem
587+ type = "button"
588+ color = { cancelEventAction . color }
589+ StartIcon = { cancelEventAction . icon }
590+ href = { cancelEventAction . disabled ? undefined : cancelEventAction . href }
591+ onClick = { cancelEventAction . onClick }
592+ disabled = { cancelEventAction . disabled }
593+ data-bookingid = { cancelEventAction . bookingId }
594+ data-testid = { cancelEventAction . id }
595+ className = { cancelEventAction . disabled ? "text-muted" : undefined } >
596+ { cancelEventAction . label }
597+ </ DropdownItem >
598+ </ DropdownMenuItem >
599+ </ DropdownMenuContent >
600+ ) ;
601+
502602 return (
503603 < >
504604 { dialogs }
505- < Dropdown >
506- < DropdownMenuTrigger asChild >
507- < Button
508- type = "button"
509- color = "secondary"
510- variant = "icon"
511- StartIcon = "ellipsis"
512- data-testid = "booking-actions-dropdown"
513- />
605+ < Dropdown modal = { context === "booking-details-sheet" ? false : undefined } >
606+ < DropdownMenuTrigger asChild data-testid = "booking-actions-dropdown" >
607+ < Button type = "button" color = "secondary" variant = "icon" size = { size } StartIcon = "ellipsis" />
514608 </ DropdownMenuTrigger >
515- < DropdownMenuPortal >
516- < DropdownMenuContent >
517- < DropdownMenuLabel className = "p-2" > { t ( "edit_event" ) } </ DropdownMenuLabel >
518- { editEventActions . map ( ( action ) => (
519- < DropdownMenuItem className = "rounded-lg" key = { action . id } disabled = { action . disabled } >
520- < DropdownItem
521- type = "button"
522- color = { action . color }
523- StartIcon = { action . icon }
524- href = { action . href }
525- disabled = { action . disabled }
526- onClick = { action . onClick }
527- data-bookingid = { action . bookingId }
528- data-testid = { action . id }
529- className = { action . disabled ? "text-muted" : undefined } >
530- { action . label }
531- </ DropdownItem >
532- </ DropdownMenuItem >
533- ) ) }
534- < DropdownMenuSeparator className = "!my-1 bg-subtle" />
535- < DropdownMenuLabel className = "p-2" > { t ( "after_event" ) } </ DropdownMenuLabel >
536- { afterEventActions . map ( ( action ) => (
537- < DropdownMenuItem className = "rounded-lg" key = { action . id } disabled = { action . disabled } >
538- < DropdownItem
539- type = "button"
540- color = { action . color }
541- StartIcon = { action . icon }
542- href = { action . href }
543- onClick = { action . onClick }
544- disabled = { action . disabled }
545- data-bookingid = { action . bookingId }
546- data-testid = { action . id }
547- className = { action . disabled ? "text-muted" : undefined } >
548- { action . label }
549- </ DropdownItem >
550- </ DropdownMenuItem >
551- ) ) }
552- < >
553- < DropdownMenuSeparator className = "!my-1 bg-subtle" />
554- < DropdownMenuItem
555- className = "rounded-lg"
556- key = { reportActionWithHandler . id }
557- disabled = { reportActionWithHandler . disabled } >
558- < DropdownItem
559- type = "button"
560- color = { reportActionWithHandler . color }
561- StartIcon = { reportActionWithHandler . icon }
562- onClick = { reportActionWithHandler . onClick }
563- disabled = { reportActionWithHandler . disabled }
564- data-testid = { reportActionWithHandler . id }
565- className = { reportActionWithHandler . disabled ? "text-muted" : undefined } >
566- { reportActionWithHandler . label }
567- </ DropdownItem >
568- </ DropdownMenuItem >
569- </ >
570- < DropdownMenuSeparator className = "!my-1 bg-subtle" />
571- < DropdownMenuItem
572- className = "rounded-lg"
573- key = { cancelEventAction . id }
574- disabled = { cancelEventAction . disabled } >
575- < DropdownItem
576- type = "button"
577- color = { cancelEventAction . color }
578- StartIcon = { cancelEventAction . icon }
579- href = { cancelEventAction . disabled ? undefined : cancelEventAction . href }
580- onClick = { cancelEventAction . onClick }
581- disabled = { cancelEventAction . disabled }
582- data-bookingid = { cancelEventAction . bookingId }
583- data-testid = { cancelEventAction . id }
584- className = { cancelEventAction . disabled ? "text-muted" : undefined } >
585- { cancelEventAction . label }
586- </ DropdownItem >
587- </ DropdownMenuItem >
588- </ DropdownMenuContent >
589- </ DropdownMenuPortal >
609+ { context === "booking-details-sheet" ? (
610+ menuContent
611+ ) : (
612+ < DropdownMenuPortal > { menuContent } </ DropdownMenuPortal >
613+ ) }
590614 </ Dropdown >
591615 </ >
592616 ) ;
0 commit comments