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 IconChangeHistory from '@material-ui/icons/ChangeHistory'; import { withStyles } from '@material-ui/core/styles'; import { RouteComponentProps, withRouter } from 'react-router'; import * as EteSync from '../api/EteSync'; import { createSelector } from 'reselect'; import { pure } from 'recompose'; import { History } from 'history'; import { PimType, ContactType, EventType } from '../pim-types'; import Container from '../widgets/Container'; import JournalEntries from '../components/JournalEntries'; import ContactEdit from '../components/ContactEdit'; import Contact from '../components/Contact'; import EventEdit from '../components/EventEdit'; import Event from '../components/Event'; import PimMain from './PimMain'; import { routeResolver } from '../App'; import { store, CredentialsData, UserInfoData } from '../store'; import { SyncInfo } from '../SyncGate'; import { createJournalEntry } from '../etesync-helpers'; import { syncEntriesToItemMap, syncEntriesToCalendarItemMap } from '../journal-processors'; function objValues(obj: any) { return Object.keys(obj).map((x) => obj[x]); } const itemsSelector = createSelector( (props: {syncInfo: SyncInfo}) => props.syncInfo, (syncInfo) => { let collectionsAddressBook: Array = []; let collectionsCalendar: Array = []; let addressBookItems: {[key: string]: ContactType} = {}; let calendarItems: {[key: string]: EventType} = {}; syncInfo.forEach( (syncJournal) => { const syncEntries = syncJournal.entries; const collectionInfo = syncJournal.collection; if (collectionInfo.type === 'ADDRESS_BOOK') { addressBookItems = syncEntriesToItemMap(collectionInfo, syncEntries, addressBookItems); collectionsAddressBook.push(collectionInfo); } else if (collectionInfo.type === 'CALENDAR') { calendarItems = syncEntriesToCalendarItemMap(collectionInfo, syncEntries, calendarItems); collectionsCalendar.push(collectionInfo); } } ); return { collectionsAddressBook, collectionsCalendar, addressBookItems, calendarItems }; }, ); const ItemChangeLog = pure((props: any) => { const { syncInfo, items, uid, } = props; const journalItem = syncInfo.get(items[uid].journalUid); return (

Item Change History

); }); type CollectionRoutesPropsType = RouteComponentProps<{}> & { syncInfo: SyncInfo, routePrefix: string, collections: Array, componentEdit: any, componentView: any, items: {[key: string]: PimType}, onItemSave: (item: PimType, journalUid: string, originalContact?: PimType) => void; onItemDelete: (item: PimType, journalUid: string) => void; onItemCancel: () => void; classes: any; }; const styles = (theme: any) => ({ button: { marginLeft: theme.spacing.unit, }, leftIcon: { marginRight: theme.spacing.unit, }, }); const CollectionRoutes = withStyles(styles)(withRouter( class CollectionRoutesInner extends React.PureComponent { render() { const props = this.props; const { classes } = this.props; const ComponentEdit = props.componentEdit; const ComponentView = props.componentView; return ( ( )} /> ( {(match.params.itemUid in props.items) && } )} /> ( )} /> (
)} />
); } } )); class Pim extends React.PureComponent { props: { etesync: CredentialsData; userInfo: UserInfoData; syncInfo: SyncInfo; history: History; }; constructor(props: any) { super(props); this.onCancel = this.onCancel.bind(this); this.onItemDelete = this.onItemDelete.bind(this); this.onItemSave = this.onItemSave.bind(this); } onItemSave(item: PimType, journalUid: string, originalEvent?: PimType) { const syncJournal = this.props.syncInfo.get(journalUid); if (syncJournal === undefined) { return; } const journal = syncJournal.journal; let action = (originalEvent === undefined) ? EteSync.SyncEntryAction.Add : EteSync.SyncEntryAction.Change; let saveEvent = store.dispatch( createJournalEntry( this.props.etesync, this.props.userInfo, journal, syncJournal.journalEntries, action, item.toIcal())); (saveEvent as any).then(() => { this.props.history.goBack(); }); } onItemDelete(item: PimType, journalUid: string) { const syncJournal = this.props.syncInfo.get(journalUid); if (syncJournal === undefined) { return; } const journal = syncJournal.journal; let action = EteSync.SyncEntryAction.Delete; let deleteItem = store.dispatch( createJournalEntry( this.props.etesync, this.props.userInfo, journal, syncJournal.journalEntries, action, item.toIcal())); (deleteItem as any).then(() => { this.props.history.push(routeResolver.getRoute('pim')); }); } onCancel() { this.props.history.goBack(); } render() { const { collectionsAddressBook, collectionsCalendar, addressBookItems, calendarItems } = itemsSelector(this.props); return ( ( )} /> ( )} /> ( )} /> ); } } export default Pim;