diff --git a/src/components/EventEdit.tsx b/src/components/EventEdit.tsx index 94cc579..8f55398 100644 --- a/src/components/EventEdit.tsx +++ b/src/components/EventEdit.tsx @@ -33,6 +33,8 @@ import * as EteSync from 'etesync'; import { getCurrentTimezone } from '../helpers'; import { EventType, timezoneLoadFromName } from '../pim-types'; +import RRule, { RRuleOptions } from '../widgets/RRule'; + interface PropsType { collections: EteSync.CollectionInfo[]; @@ -52,6 +54,7 @@ class EventEdit extends React.PureComponent { start?: Date; end?: Date; timezone: string | null; + rrule?: RRuleOptions; location: string; description: string; journalUid: string; @@ -104,6 +107,7 @@ class EventEdit extends React.PureComponent { this.state.location = event.location ? event.location : ''; this.state.description = event.description ? event.description : ''; this.state.timezone = event.timezone; + this.state.rrule = this.props.item?.component.getFirstPropertyValue('rrule')?.toJSON(); } else { this.state.uid = uuid.v4(); } @@ -121,6 +125,8 @@ class EventEdit extends React.PureComponent { this.handleInputChange = this.handleInputChange.bind(this); this.toggleAllDay = this.toggleAllDay.bind(this); this.onDeleteRequest = this.onDeleteRequest.bind(this); + this.toggleRecurring = this.toggleRecurring.bind(this); + this.handleRRuleChange = this.handleRRuleChange.bind(this); } public UNSAFE_componentWillReceiveProps(nextProps: any) { @@ -154,7 +160,15 @@ class EventEdit extends React.PureComponent { public toggleAllDay() { this.setState({ allDay: !this.state.allDay }); } + public toggleRecurring() { + const value = this.state.rrule ? undefined : { freq: 'WEEKLY', interval: 1 }; + this.setState({ rrule: value }); + } + + public handleRRuleChange(rrule: RRuleOptions): void { + this.setState({ rrule: rrule }); + } public onSubmit(e: React.FormEvent) { e.preventDefault(); @@ -191,6 +205,7 @@ class EventEdit extends React.PureComponent { : new EventType() ; + event.uid = this.state.uid; event.summary = this.state.title; event.startDate = startDate; @@ -204,6 +219,18 @@ class EventEdit extends React.PureComponent { event.endDate = event.endDate?.convertToZone(timezone); } } + if (this.state.rrule) { + const rruleData: ICAL.RecurData = {}; + for (const key of Object.keys(this.state.rrule)) { + const value = this.state.rrule[key]; + if ((value === undefined) || (value?.length === 0)) { + continue; + } + + rruleData[key] = value; + } + event.component.updatePropertyWithValue('rrule', new ICAL.Recur(rruleData)); + } event.component.updatePropertyWithValue('last-modified', ICAL.Time.now()); @@ -236,7 +263,7 @@ class EventEdit extends React.PureComponent { const differentTimezone = this.state.timezone && (this.state.timezone !== getCurrentTimezone()) && timezoneLoadFromName(this.state.timezone); return ( - + <>

{this.props.item ? 'Edit Event' : 'New Event'}

@@ -335,7 +362,25 @@ class EventEdit extends React.PureComponent { value={this.state.description} onChange={this.handleInputChange} /> - + + + } + label="Recurring" + /> + + {this.state.rrule && + + }