Implement Event copying.

Fixes #51.
master
Ramzan 4 years ago committed by Tom Hacohen
parent 205d7a3e1b
commit 2b43463fb0

@ -55,6 +55,7 @@ export const routeResolver = new RouteResolver({
_id: {
_base: ':itemUid',
edit: 'edit',
copy: 'copy',
log: 'log',
},
new: 'new',

@ -5,6 +5,7 @@ import * as React from 'react';
import { Route, Switch } from 'react-router';
import Button from '@material-ui/core/Button';
import IconEdit from '@material-ui/icons/Edit';
import IconCopy from '@material-ui/icons/FileCopy';
import IconChangeHistory from '@material-ui/icons/ChangeHistory';
import { withStyles } from '@material-ui/core/styles';
@ -189,6 +190,34 @@ const CollectionRoutes = withStyles(styles)(withRouter(
);
}}
/>
{props.routePrefix === 'pim.events' &&
<Route
path={routeResolver.getRoute(props.routePrefix + '._id.copy')}
exact
render={({ match }) => {
const itemUid = decodeURIComponent(match.params.itemUid);
if (this.itemUndefined(itemUid)) {
return PageNotFound();
}
return (
<Container style={{ maxWidth: '30rem' }}>
{(itemUid in props.items) &&
<ComponentEdit
initialCollection={(props.items[itemUid] as any).journalUid}
item={props.items[itemUid]}
collections={props.collections}
onSave={props.onItemSave}
onDelete={props.onItemDelete}
onCancel={props.onItemCancel}
history={props.history}
copy
/>
}
</Container>
);
}}
/>
}
<Route
path={routeResolver.getRoute(props.routePrefix + '._id.log')}
exact
@ -246,6 +275,24 @@ const CollectionRoutes = withStyles(styles)(withRouter(
<IconEdit className={classes.leftIcon} />
Edit
</Button>
{props.routePrefix === 'pim.events' &&
<Button
color="secondary"
variant="contained"
disabled={!props.componentEdit}
className={classes.button}
style={{ marginLeft: 15 }}
onClick={() =>
history.push(routeResolver.getRoute(
props.routePrefix + '._id.copy',
{ itemUid: match.params.itemUid }))
}
>
<IconCopy className={classes.leftIcon} />
Copy
</Button>
}
</div>
<ComponentView item={props.items[decodeURIComponent(match.params.itemUid)]} />
</Container>

@ -50,6 +50,7 @@ interface PropsType {
onCancel: () => void;
location: Location;
history: History;
copy: boolean;
}
class EventEdit extends React.PureComponent<PropsType> {
@ -105,8 +106,12 @@ class EventEdit extends React.PureComponent<PropsType> {
endDate.adjust(-1, 0, 0, 0);
}
this.state.uid = event.uid;
this.state.title = event.title ? event.title : '';
if (this.props.copy) {
this.state.title = event.title ? `Copy of ${event.title}` : '';
} else {
this.state.uid = event.uid;
this.state.title = event.title ? event.title : '';
}
this.state.allDay = allDay;
this.state.start = event.startDate.convertToZone(ICAL.Timezone.localTimezone).toJSDate();
this.state.end = endDate.convertToZone(ICAL.Timezone.localTimezone).toJSDate();
@ -120,7 +125,8 @@ class EventEdit extends React.PureComponent<PropsType> {
this.state.rrule.until = rruleProp.until;
}
}
} else {
}
if (this.props.copy || this.props.item === undefined) {
this.state.uid = uuid.v4();
}
@ -222,7 +228,7 @@ class EventEdit extends React.PureComponent<PropsType> {
return;
}
const event = (this.props.item) ?
const event = (this.props.item && !this.props.copy) ?
this.props.item.clone()
:
new EventType()
@ -281,7 +287,7 @@ class EventEdit extends React.PureComponent<PropsType> {
return (
<>
<h2>
{this.props.item ? 'Edit Event' : 'New Event'}
{(this.props.item && !this.props.copy) ? 'Edit Event' : 'New Event'}
</h2>
{recurring && (
<div>

Loading…
Cancel
Save