@@ -12,6 +12,7 @@ import { buildMergedDotColors, buildMergedDotBackground, describeMergedCalendars
1212import useIsMobile from '../hooks/useIsMobile.js' ;
1313import 'react-big-calendar/lib/css/react-big-calendar.css' ;
1414import MonthDayCell from './MonthDayCell.jsx' ;
15+ import ColorPickerPopover from './ColorPickerPopover.jsx' ;
1516
1617const localizer = momentLocalizer ( moment ) ;
1718
@@ -192,6 +193,7 @@ const CalendarWidget = ({
192193 const [ dayOfWeekSettings , setDayOfWeekSettings ] = useState ( { ...DEFAULT_CALENDAR_DAY_OF_WEEK_SETTINGS } ) ;
193194 const [ calendarSettingsLoaded , setCalendarSettingsLoaded ] = useState ( false ) ;
194195 const [ showColorPicker , setShowColorPicker ] = useState ( { background : false , text : false } ) ;
196+ const [ calendarColorPickerAnchor , setCalendarColorPickerAnchor ] = useState ( null ) ;
195197 const [ calendarSources , setCalendarSources ] = useState ( [ ] ) ;
196198 const [ dedupEnabled , setDedupEnabled ] = useState ( true ) ;
197199 const [ showCalendarDialog , setShowCalendarDialog ] = useState ( false ) ;
@@ -743,6 +745,7 @@ const CalendarWidget = ({
743745 await fetchCalendarSources ( ) ;
744746 await fetchCalendarEvents ( ) ;
745747 setShowCalendarDialog ( false ) ;
748+ setCalendarColorPickerAnchor ( null ) ;
746749 } catch ( error ) {
747750 console . error ( 'Error saving calendar:' , error ) ;
748751 setCalendarFormError ( error ?. response ?. data ?. error || 'Failed to save calendar. Please try again.' ) ;
@@ -1137,6 +1140,11 @@ const CalendarWidget = ({
11371140 ) ;
11381141 }
11391142
1143+ const closeColorPickerDialog = ( ) => {
1144+ setShowCalendarDialog ( false ) ;
1145+ setCalendarColorPickerAnchor ( null ) ;
1146+ } ;
1147+
11401148 return (
11411149 < Box sx = { {
11421150 height : '100%' ,
@@ -2281,7 +2289,7 @@ const CalendarWidget = ({
22812289
22822290 < Dialog
22832291 open = { showCalendarDialog }
2284- onClose = { ( ) => setShowCalendarDialog ( false ) }
2292+ onClose = { closeColorPickerDialog }
22852293 maxWidth = "sm"
22862294 fullWidth
22872295 slotProps = { {
@@ -2506,7 +2514,7 @@ const CalendarWidget = ({
25062514 borderRadius : 1 ,
25072515 cursor : 'pointer'
25082516 } }
2509- onClick = { ( ) => setShowColorPicker ( { ... showColorPicker , calendar : ! showColorPicker . calendar } ) }
2517+ onClick = { ( e ) => setCalendarColorPickerAnchor ( prev => ( prev ? null : e . currentTarget ) ) }
25102518 />
25112519 < TextField
25122520 size = "small"
@@ -2515,19 +2523,9 @@ const CalendarWidget = ({
25152523 sx = { { flex : 1 } }
25162524 />
25172525 </ Box >
2518- { showColorPicker . calendar && (
2519- < Box sx = { { position : 'absolute' , zIndex : 1000 , mt : 1 } } >
2520- < Box
2521- sx = { { position : 'fixed' , top : 0 , right : 0 , bottom : 0 , left : 0 } }
2522- onClick = { ( ) => setShowColorPicker ( { ...showColorPicker , calendar : false } ) }
2523- />
2524- < SketchPicker
2525- color = { calendarForm . color }
2526- onChange = { ( color ) => setCalendarForm ( { ...calendarForm , color : color . hex } ) }
2527- disableAlpha
2528- />
2529- </ Box >
2530- ) }
2526+ < ColorPickerPopover anchorEl = { calendarColorPickerAnchor } color = { calendarForm . color }
2527+ onChange = { ( color ) => setCalendarForm ( { ...calendarForm , color : color . hex } ) }
2528+ onClose = { ( ) => setCalendarColorPickerAnchor ( null ) } />
25312529 </ Box >
25322530
25332531 { editingCalendar && (
@@ -2551,7 +2549,9 @@ const CalendarWidget = ({
25512549 </ Box >
25522550 </ DialogContent >
25532551 < DialogActions >
2554- < Button type = "button" onClick = { ( ) => setShowCalendarDialog ( false ) } > Cancel</ Button >
2552+ < Button type = "button" onClick = { closeColorPickerDialog } >
2553+ Cancel
2554+ </ Button >
25552555 < Button
25562556 type = "submit"
25572557 variant = "contained"
0 commit comments