Event edit: fix event edit (setting the collection).

master
Tom Hacohen 4 years ago
parent 877171b2ea
commit 8e8c779fa6

@ -26,51 +26,46 @@ import ConfirmationDialog from "../widgets/ConfirmationDialog";
import TimezonePicker from "../widgets/TimezonePicker"; import TimezonePicker from "../widgets/TimezonePicker";
import Toast from "../widgets/Toast"; import Toast from "../widgets/Toast";
import { Location } from "history";
import { withRouter } from "react-router";
import * as uuid from "uuid"; import * as uuid from "uuid";
import * as ICAL from "ical.js"; import * as ICAL from "ical.js";
import * as EteSync from "etesync";
import { getCurrentTimezone } from "../helpers"; import { getCurrentTimezone } from "../helpers";
import { EventType, timezoneLoadFromName } from "../pim-types"; import { EventType, timezoneLoadFromName } from "../pim-types";
import RRule, { RRuleOptions } from "../widgets/RRule"; import RRule, { RRuleOptions } from "../widgets/RRule";
import { History } from "history"; import { History } from "history";
import { CachedCollection } from "../Pim/helpers";
interface PropsType { interface PropsType {
collections: EteSync.CollectionInfo[]; collections: CachedCollection[];
initialCollection?: string; initialCollection?: string;
item?: EventType; item?: EventType;
onSave: (event: EventType, journalUid: string, originalEvent?: EventType) => Promise<void>; onSave: (event: EventType, collectionUid: string, originalEvent?: EventType) => Promise<void>;
onDelete: (event: EventType, journalUid: string) => void; onDelete: (event: EventType, collectionUid: string) => void;
onCancel: () => void; onCancel: () => void;
location: Location<EventType>;
history: History; history: History;
duplicate: boolean; duplicate?: boolean;
} }
class EventEdit extends React.PureComponent<PropsType> { export default class EventEdit extends React.PureComponent<PropsType> {
public state: { public state: {
uid: string; uid: string;
title: string; title: string;
description: string;
allDay: boolean; allDay: boolean;
start?: Date; start?: Date;
end?: Date; end?: Date;
timezone: string | null; timezone: string | null;
rrule?: RRuleOptions; rrule?: RRuleOptions;
location: string; location: string;
description: string; collectionUid: string;
journalUid: string;
error?: string; error?: string;
showDeleteDialog: boolean; showDeleteDialog: boolean;
}; };
constructor(props: any) { constructor(props: PropsType) {
super(props); super(props);
this.state = { this.state = {
uid: "", uid: "",
@ -80,11 +75,11 @@ class EventEdit extends React.PureComponent<PropsType> {
description: "", description: "",
timezone: null, timezone: null,
journalUid: "", collectionUid: "",
showDeleteDialog: false, showDeleteDialog: false,
}; };
const locState = this.props.location.state; const locState = this.props.history.location.state as EventType;
if (locState) { if (locState) {
// FIXME: Hack to determine if all day. Should be passed as a proper state. // FIXME: Hack to determine if all day. Should be passed as a proper state.
this.state.allDay = (locState.start && this.state.allDay = (locState.start &&
@ -133,9 +128,9 @@ class EventEdit extends React.PureComponent<PropsType> {
this.state.timezone = this.state.timezone || getCurrentTimezone(); this.state.timezone = this.state.timezone || getCurrentTimezone();
if (props.initialCollection) { if (props.initialCollection) {
this.state.journalUid = props.initialCollection; this.state.collectionUid = props.initialCollection;
} else if (props.collections[0]) { } else if (props.collections[0]) {
this.state.journalUid = props.collections[0].uid; this.state.collectionUid = props.collections[0].collection.uid;
} }
this.onSubmit = this.onSubmit.bind(this); this.onSubmit = this.onSubmit.bind(this);
@ -238,7 +233,7 @@ class EventEdit extends React.PureComponent<PropsType> {
event.component.updatePropertyWithValue("last-modified", ICAL.Time.now()); event.component.updatePropertyWithValue("last-modified", ICAL.Time.now());
this.props.onSave(event, this.state.journalUid, this.props.item) this.props.onSave(event, this.state.collectionUid, this.props.item)
.then(() => { .then(() => {
this.props.history.goBack(); this.props.history.goBack();
}); });
@ -298,13 +293,13 @@ class EventEdit extends React.PureComponent<PropsType> {
Saving to Saving to
</InputLabel> </InputLabel>
<Select <Select
name="journalUid" name="collectionUid"
value={this.state.journalUid} value={this.state.collectionUid}
disabled={this.props.item !== undefined} disabled={this.props.item !== undefined}
onChange={this.handleInputChange} onChange={this.handleInputChange}
> >
{this.props.collections.map((x) => ( {this.props.collections.map((x) => (
<MenuItem key={x.uid} value={x.uid}>{x.displayName}</MenuItem> <MenuItem key={x.collection.uid} value={x.collection.uid}>{x.metadata.name}</MenuItem>
))} ))}
</Select> </Select>
</FormControl> </FormControl>
@ -438,5 +433,3 @@ class EventEdit extends React.PureComponent<PropsType> {
); );
} }
} }
export default withRouter(EventEdit);

Loading…
Cancel
Save