From 7b17a14a841e851af14acd5b7a19a316efee1927 Mon Sep 17 00:00:00 2001 From: Tal Leibman Date: Sat, 11 Jan 2020 13:11:33 +0200 Subject: [PATCH] components: EventEdit add RRule widget --- src/components/EventEdit.tsx | 53 +++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/components/EventEdit.tsx b/src/components/EventEdit.tsx index 8748bf9..a49d865 100644 --- a/src/components/EventEdit.tsx +++ b/src/components/EventEdit.tsx @@ -35,6 +35,7 @@ import { getCurrentTimezone } from '../helpers'; import { EventType, timezoneLoadFromName } from '../pim-types'; import RRuleEteSync, { RRuleOptions } from '../widgets/RRule'; + interface PropsType { collections: EteSync.CollectionInfo[]; initialCollection?: string; @@ -56,7 +57,7 @@ class EventEdit extends React.PureComponent { location: string; description: string; journalUid: string; - + rruleOptions?: RRuleOptions; error?: string; showDeleteDialog: boolean; }; @@ -70,7 +71,6 @@ class EventEdit extends React.PureComponent { location: '', description: '', timezone: null, - journalUid: '', showDeleteDialog: false, }; @@ -105,6 +105,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.rruleOptions = this.props.item?.component.getFirstPropertyValue('rrule'); } else { this.state.uid = uuid.v4(); } @@ -122,6 +123,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) { @@ -155,7 +158,16 @@ class EventEdit extends React.PureComponent { public toggleAllDay() { this.setState({ allDay: !this.state.allDay }); } + public toggleRecurring() { + const value = this.state.rruleOptions ? undefined : { freq: 'WEEKLY', interval: 1 }; + this.setState({ rruleOptions: value }); + } + + public handleRRuleChange(rrule: RRuleOptions): void { + this.setState({ rruleOptions: rrule }); + console.log(rrule); + } public onSubmit(e: React.FormEvent) { e.preventDefault(); @@ -191,7 +203,7 @@ class EventEdit extends React.PureComponent { this.props.item.clone() : new EventType() - ; + ; event.uid = this.state.uid; event.summary = this.state.title; event.startDate = startDate; @@ -233,21 +245,17 @@ class EventEdit extends React.PureComponent { }, }; - const recurring = this.props.item && this.props.item.isRecurring(); + if (this.props.item && this.props.item.isRecurring()) { + console.log(1); + } const differentTimezone = this.state.timezone && (this.state.timezone !== getCurrentTimezone()) && timezoneLoadFromName(this.state.timezone); + return ( <>

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

- {recurring && ( -
- IMPORTANT: - This is a recurring event, for now, only editing the whole series - (by editing the first instance) is supported. -
- )} {this.state.error && (
ERROR! {this.state.error}
)} @@ -336,7 +344,25 @@ class EventEdit extends React.PureComponent { value={this.state.description} onChange={this.handleInputChange} /> - + + + } + label="Recurring" + /> + + {this.state.rruleOptions && + + }
+ { onOk={() => this.props.onDelete(this.props.item!, this.props.initialCollection!)} onCancel={() => this.setState({ showDeleteDialog: false })} > - Are you sure you would like to delete this event? + Are you sure you would like to delete this event? );