1- import { forwardRef , useEffect } from "react" ;
1+ import { forwardRef , useEffect , useMemo } from "react" ;
22import { twMerge } from "tailwind-merge" ;
3- import { dataAttributes } from "@/constants" ;
3+ import { SeatStatus , dataAttributes , seatStatusColors } from "@/constants" ;
44import { d3Extended } from "@/utils" ;
55
66export const seatSize = 28 ;
@@ -14,12 +14,22 @@ const Seat = forwardRef(({ x, y, id, label, categories, category, status, ...pro
1414
1515 if ( labelLength >= 2 ) textX -= ( seatLabelFontSize / 2.75 ) * ( labelLength - 1 ) ;
1616
17- const categoryObject = categories ?. find ?. ( ( c ) => c . id === category ) ;
17+ const categoryObject = useMemo ( ( ) => categories ?. find ?. ( ( c ) => c . id === category ) , [ categories , category ] ) ;
1818
1919 useEffect ( ( ) => {
20- if ( ref . current && categoryObject ) {
21- d3Extended . select ( ref . current ) . style ( "color" , categoryObject . color , "important" ) ;
22- d3Extended . selectById ( `${ id } -label` ) . style ( "stroke" , categoryObject . textColor , "important" ) ;
20+ if ( ref . current ) {
21+ const seat = d3Extended . select ( ref . current ) ;
22+ const seatLabel = d3Extended . selectById ( `${ id } -label` ) ;
23+ const status = seat . attr ( dataAttributes . status ) ;
24+ if ( status === SeatStatus . Unavailable || status === SeatStatus . Reserved ) {
25+ seat . style ( "color" , seatStatusColors [ status ] . background , "important" ) ;
26+ seatLabel ?. style ( "stroke" , seatStatusColors [ status ] . label , "important" ) ;
27+ } else {
28+ if ( categoryObject ) {
29+ seat . style ( "color" , categoryObject . color , "important" ) ;
30+ seatLabel ?. style ( "stroke" , categoryObject . textColor , "important" ) ;
31+ }
32+ }
2333 }
2434 } , [ ref , categoryObject ] ) ;
2535
0 commit comments