在react-big-calendar中编辑事件

时间:2018-11-30 08:10:37

标签: reactjs redux

我有一个更改点击事件日期的方法。这是代码

 moveEvent({ event, start, end, isAllDay: droppedOnAllDaySlot }) {
        const { currentUser, editGoogleCalendarEvent, calendarEvents } = this.props;
        const { events } = this.state;
        let onlyDate = false;
    const idx = events.indexOf(event);
    const eventIndex = _.findIndex(calendarEvents.details.items, { id: event.id });
    let allDay = event.allDay;
    if (!event.allDay && droppedOnAllDaySlot) {
      allDay = true;
    } else if (event.allDay && !droppedOnAllDaySlot) {
      allDay = false;
    }

    const updatedEvent = { ...event, start, end, allDay };

    const nextEvents = [...events];
    nextEvents.splice(idx, 1, updatedEvent);
    if (eventIndex !== -1) {
      const item = calendarEvents.details.items[eventIndex];
      if (item.start.date && item.end.date) {
        updatedEvent.start = moment(start).format('YYYY-MM-DD');
        updatedEvent.end = moment(end).format('YYYY-MM-DD');
        onlyDate = true;
      }
    }

    this.setState({
      events: nextEvents,
    }, () => {
      editGoogleCalendarEvent({ ...updatedEvent, userId: currentUser.id, timezone: currentUser.timezone, onlyDate });
    });
  }

由于该方法,创建editEvent方法的正确方法是什么,它将编辑现有事件?

0 个答案:

没有答案