@@ -12,10 +12,10 @@ import adaptivePlugin from "@fullcalendar/adaptive";
1212import dayGridPlugin from "@fullcalendar/daygrid" ;
1313import multiMonthPlugin from '@fullcalendar/multimonth' ;
1414import timeGridPlugin from "@fullcalendar/timegrid" ;
15- import interactionPlugin from "@fullcalendar/interaction" ;
15+ import interactionPlugin , { EventResizeDoneArg } from "@fullcalendar/interaction" ;
1616import listPlugin from "@fullcalendar/list" ;
1717import allLocales from "@fullcalendar/core/locales-all" ;
18- import { EventContentArg , DateSelectArg } from "@fullcalendar/core" ;
18+ import { EventContentArg , DateSelectArg , EventDropArg } from "@fullcalendar/core" ;
1919import momentPlugin from "@fullcalendar/moment" ;
2020
2121import ErrorBoundary from "./errorBoundary" ;
@@ -83,6 +83,7 @@ import {
8383 resourceTimeGridHeaderToolbar ,
8484} from "./calendarConstants" ;
8585import { EventOptionControl } from "./eventOptionsControl" ;
86+ import { EventImpl } from "@fullcalendar/core/internal" ;
8687
8788function fixOldData ( oldData : any ) {
8889 if ( ! Boolean ( oldData ) ) return ;
@@ -823,20 +824,34 @@ let CalendarBasicComp = (function () {
823824 showModal ( event , false ) ;
824825 } , [ editEvent , showModal ] ) ;
825826
826- const handleDrop = useCallback ( ( eventInfo : EventType ) => {
827+ const updateEventsOnDragOrResize = useCallback ( ( eventInfo : EventImpl ) => {
828+ const { extendedProps, title, ...event } = eventInfo . toJSON ( ) ;
829+
827830 let eventsList = [ ...props . events ] ;
828831 const eventIdx = eventsList . findIndex (
829- ( item : EventType ) => item . id === eventInfo . id
832+ ( item : EventType ) => item . id === event . id
830833 ) ;
831834 if ( eventIdx > - 1 ) {
832- eventsList [ eventIdx ] = eventInfo ;
835+ eventsList [ eventIdx ] = {
836+ label : title ,
837+ ...event ,
838+ ...extendedProps ,
839+ } ;
833840 handleEventDataChange ( eventsList ) ;
834841 }
842+ } , [ props . events , handleEventDataChange ] ) ;
843+
844+ const handleDrop = useCallback ( ( eventInfo : EventDropArg ) => {
845+ updateEventsOnDragOrResize ( eventInfo . event ) ;
835846
836847 if ( typeof props . onDropEvent === 'function' ) {
837848 props . onDropEvent ( "dropEvent" ) ;
838849 }
839- } , [ props . onDropEvent ] ) ;
850+ } , [ props . onDropEvent , updateEventsOnDragOrResize ] ) ;
851+
852+ const handleResize = useCallback ( ( eventInfo : EventResizeDoneArg ) => {
853+ updateEventsOnDragOrResize ( eventInfo . event ) ;
854+ } , [ props . onDropEvent , updateEventsOnDragOrResize ] ) ;
840855
841856 return (
842857 < Wrapper
@@ -854,7 +869,7 @@ let CalendarBasicComp = (function () {
854869 slotEventOverlap = { false }
855870 events = { events }
856871 dayHeaders = { true }
857- dayHeaderFormat = { { weekday : 'short' , month : 'numeric' , day : 'numeric' , omitCommas : true } }
872+ // dayHeaderFormat={{ weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }}
858873 expandRows = { true }
859874 multiMonthMinWidth = { 250 }
860875 nowIndicator = { true }
@@ -944,15 +959,8 @@ let CalendarBasicComp = (function () {
944959 props . onEvent ( "change" ) ;
945960 }
946961 } }
947- eventDrop = { ( info ) => {
948- const { extendedProps, ...event } = info . event . toJSON ( ) ;
949- if ( info . view ) {
950- handleDrop ( {
951- ...event ,
952- ...extendedProps ,
953- } ) ;
954- }
955- } }
962+ eventDrop = { handleDrop }
963+ eventResize = { handleResize }
956964 />
957965 </ ErrorBoundary >
958966 </ Wrapper >
0 commit comments