Our powerful JS Calendar component


Post by serman »

Hi,

I'm trying to update startDate & endDate of my bookings in Calendar when I drag them, but right now even console.log doesn't run during tests. I want to run my update function when I finish dragging.

My Calendar Declaration:

const Calendar = () => {
  const { props } = useBryntumProps()

  return (
    <>
      <BryntumCalendar {...props} />
      <BookingModal />
    </>
  )
}

useBryntumProps(in shortcut):

export const useBryntumProps = () => {
 
 //rest of implementation

 const dragFeature = useDragEvent()

  const props = {
    ...bryntumProps,
    listeners,
    eventMenuFeature,
    eventStore,
    eventTooltipFeature,
    resourceStore,
    assignmentStore,
    dragFeature
  }

  return {
    isLoading,
    props,
  }
}

and in useDragEvent:

export const useDragEvent = () => {
  const { update, isPending } = useMutate<BookingFromBackend>({
    endpoint: "/bookings",
    options: {
      queryKeysToInvalidate: [["bookings"]],
    },
  })

  const onDragMoveEnd = (data) => {
    console.log("Drag moving");
      
const updateData = { startDate: startDate.toISOString(), endDate: endDate.toISOString(), resourceId: resourceRecord?.id, }; update({ id: bookingId, update: updateData, }); } return true; }; return { onDragMoveEnd, isPending }; }

I'm not sure if I should use onDragMoveEnd or something else, so I'd also appreciate some information.


Post by Animal »

What is the underlying purpose of the app?

Dragging an event to a different time changes the startDate and endDate. There is no need to do anything.


Post by Animal »

Are you wanting to react to changes in the project?

https://bryntum.com/products/calendar/docs/api/Calendar/model/ProjectModel#event-change

Maybe like this?

Screenshot 2025-03-13 at 11.39.44.png
Screenshot 2025-03-13 at 11.39.44.png (243.05 KiB) Viewed 41 times

Post by serman »

Animal wrote: Thu Mar 13, 2025 12:43 pm

Are you wanting to react to changes in the project?

https://bryntum.com/products/calendar/docs/api/Calendar/model/ProjectModel#event-change

Maybe like this?

Screenshot 2025-03-13 at 11.39.44.png

Thanks to your screen I noticed I should add my code as listener without implementing dragFeature, Thanks!


Post by Animal »

So how are you passing updates to the backend?

What happens when you double click the event and edit it and change the dates and then click Save?

What about when you right click and COPY an event, then right click on another date and PASTE it there?


Post Reply