2018-08-27 15:13:59 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import Spinner from '@atlaskit/spinner';
|
2018-09-25 12:48:03 +00:00
|
|
|
import React from 'react';
|
2018-08-27 15:13:59 +00:00
|
|
|
|
|
|
|
import { translate } from '../../base/i18n';
|
2018-09-25 12:48:03 +00:00
|
|
|
import { AbstractPage } from '../../base/react';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2018-08-27 15:13:59 +00:00
|
|
|
import { openSettingsDialog, SETTINGS_TABS } from '../../settings';
|
2018-09-01 01:03:35 +00:00
|
|
|
import {
|
|
|
|
createCalendarClickedEvent,
|
|
|
|
sendAnalytics
|
|
|
|
} from '../../analytics';
|
2018-08-27 15:13:59 +00:00
|
|
|
|
|
|
|
import { refreshCalendar } from '../actions';
|
2018-11-06 19:48:09 +00:00
|
|
|
import { ERRORS } from '../constants';
|
2018-08-27 15:13:59 +00:00
|
|
|
|
2018-09-25 12:48:03 +00:00
|
|
|
import CalendarListContent from './CalendarListContent';
|
2018-08-27 15:13:59 +00:00
|
|
|
|
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link CalendarList}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
2018-11-06 19:48:09 +00:00
|
|
|
/**
|
|
|
|
* The error object containing details about any error that has occurred
|
|
|
|
* while interacting with calendar integration.
|
|
|
|
*/
|
|
|
|
_calendarError: ?Object,
|
|
|
|
|
2018-08-27 15:13:59 +00:00
|
|
|
/**
|
|
|
|
* Whether or not a calendar may be connected for fetching calendar events.
|
|
|
|
*/
|
|
|
|
_hasIntegrationSelected: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not events have been fetched from a calendar.
|
|
|
|
*/
|
|
|
|
_hasLoadedEvents: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if the list is disabled or not.
|
|
|
|
*/
|
|
|
|
disabled: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux dispatch function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translate function.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to display a list of events from the user's calendar.
|
|
|
|
*/
|
2018-09-25 12:48:03 +00:00
|
|
|
class CalendarList extends AbstractPage<Props> {
|
2018-08-27 15:13:59 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code CalendarList} instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._getRenderListEmptyComponent
|
|
|
|
= this._getRenderListEmptyComponent.bind(this);
|
|
|
|
this._onOpenSettings = this._onOpenSettings.bind(this);
|
|
|
|
this._onRefreshEvents = this._onRefreshEvents.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { disabled } = this.props;
|
|
|
|
|
|
|
|
return (
|
2018-09-25 12:48:03 +00:00
|
|
|
CalendarListContent
|
|
|
|
? <CalendarListContent
|
2018-08-27 15:13:59 +00:00
|
|
|
disabled = { disabled }
|
2018-10-22 18:49:18 +00:00
|
|
|
listEmptyComponent
|
2018-08-27 15:13:59 +00:00
|
|
|
= { this._getRenderListEmptyComponent() } />
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-06 19:48:09 +00:00
|
|
|
/**
|
|
|
|
* Returns a component for showing the error message related to calendar
|
|
|
|
* sync.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {React$Component}
|
|
|
|
*/
|
|
|
|
_getErrorMessage() {
|
|
|
|
const { _calendarError = {}, t } = this.props;
|
|
|
|
|
|
|
|
let errorMessageKey = 'calendarSync.error.generic';
|
|
|
|
let showRefreshButton = true;
|
|
|
|
let showSettingsButton = true;
|
|
|
|
|
|
|
|
if (_calendarError.error === ERRORS.GOOGLE_APP_MISCONFIGURED) {
|
|
|
|
errorMessageKey = 'calendarSync.error.appConfiguration';
|
|
|
|
showRefreshButton = false;
|
|
|
|
showSettingsButton = false;
|
|
|
|
} else if (_calendarError.error === ERRORS.AUTH_FAILED) {
|
|
|
|
errorMessageKey = 'calendarSync.error.notSignedIn';
|
|
|
|
showRefreshButton = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className = 'meetings-list-empty'>
|
|
|
|
<p className = 'description'>
|
|
|
|
{ t(errorMessageKey) }
|
|
|
|
</p>
|
|
|
|
<div className = 'calendar-action-buttons'>
|
|
|
|
{ showSettingsButton
|
|
|
|
&& <div
|
|
|
|
className = 'button'
|
|
|
|
onClick = { this._onOpenSettings }>
|
|
|
|
{ t('calendarSync.permissionButton') }
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
{ showRefreshButton
|
|
|
|
&& <div
|
|
|
|
className = 'button'
|
|
|
|
onClick = { this._onRefreshEvents }>
|
|
|
|
{ t('calendarSync.refresh') }
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-08-27 15:13:59 +00:00
|
|
|
_getRenderListEmptyComponent: () => Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list empty component if a custom one has to be rendered instead
|
|
|
|
* of the default one in the {@link NavigateSectionList}.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {React$Component}
|
|
|
|
*/
|
|
|
|
_getRenderListEmptyComponent() {
|
2018-11-06 19:48:09 +00:00
|
|
|
const {
|
|
|
|
_calendarError,
|
|
|
|
_hasIntegrationSelected,
|
|
|
|
_hasLoadedEvents,
|
|
|
|
t
|
|
|
|
} = this.props;
|
2018-08-27 15:13:59 +00:00
|
|
|
|
2018-11-06 19:48:09 +00:00
|
|
|
if (_calendarError) {
|
|
|
|
return this._getErrorMessage();
|
|
|
|
} else if (_hasIntegrationSelected && _hasLoadedEvents) {
|
2018-08-27 15:13:59 +00:00
|
|
|
return (
|
2018-10-22 18:49:18 +00:00
|
|
|
<div className = 'meetings-list-empty'>
|
2018-11-06 19:48:09 +00:00
|
|
|
<p className = 'description'>
|
|
|
|
{ t('calendarSync.noEvents') }
|
|
|
|
</p>
|
2018-10-22 18:49:18 +00:00
|
|
|
<div
|
|
|
|
className = 'button'
|
|
|
|
onClick = { this._onRefreshEvents }>
|
2018-08-27 15:13:59 +00:00
|
|
|
{ t('calendarSync.refresh') }
|
2018-10-22 18:49:18 +00:00
|
|
|
</div>
|
2018-08-27 15:13:59 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (_hasIntegrationSelected && !_hasLoadedEvents) {
|
|
|
|
return (
|
2018-10-22 18:49:18 +00:00
|
|
|
<div className = 'meetings-list-empty'>
|
2018-08-27 15:13:59 +00:00
|
|
|
<Spinner
|
|
|
|
invertColor = { true }
|
|
|
|
isCompleting = { false }
|
|
|
|
size = 'medium' />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-10-22 18:49:18 +00:00
|
|
|
<div className = 'meetings-list-empty'>
|
|
|
|
<p className = 'description'>
|
2018-08-27 15:13:59 +00:00
|
|
|
{ t('welcomepage.connectCalendarText', {
|
2019-03-15 11:07:45 +00:00
|
|
|
app: interfaceConfig.APP_NAME,
|
|
|
|
provider: interfaceConfig.PROVIDER_NAME
|
2018-08-27 15:13:59 +00:00
|
|
|
}) }
|
|
|
|
</p>
|
2018-10-22 18:49:18 +00:00
|
|
|
<div
|
|
|
|
className = 'button'
|
|
|
|
onClick = { this._onOpenSettings }>
|
2018-08-27 15:13:59 +00:00
|
|
|
{ t('welcomepage.connectCalendarButton') }
|
2018-10-22 18:49:18 +00:00
|
|
|
</div>
|
2018-08-27 15:13:59 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onOpenSettings: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens {@code SettingsDialog}.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onOpenSettings() {
|
2018-09-01 01:03:35 +00:00
|
|
|
sendAnalytics(createCalendarClickedEvent('calendar.connect'));
|
|
|
|
|
2018-08-27 15:13:59 +00:00
|
|
|
this.props.dispatch(openSettingsDialog(SETTINGS_TABS.CALENDAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
_onRefreshEvents: () => void;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an updated list of calendar events.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onRefreshEvents() {
|
|
|
|
this.props.dispatch(refreshCalendar(true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
* {@code CalendarList} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
2018-11-06 19:48:09 +00:00
|
|
|
* _calendarError: Object,
|
2018-08-27 15:13:59 +00:00
|
|
|
* _hasIntegrationSelected: boolean,
|
|
|
|
* _hasLoadedEvents: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
const {
|
2018-11-06 19:48:09 +00:00
|
|
|
error,
|
2018-08-27 15:13:59 +00:00
|
|
|
events,
|
|
|
|
integrationType,
|
|
|
|
isLoadingEvents
|
|
|
|
} = state['features/calendar-sync'];
|
|
|
|
|
|
|
|
return {
|
2018-11-06 19:48:09 +00:00
|
|
|
_calendarError: error,
|
2018-08-27 15:13:59 +00:00
|
|
|
_hasIntegrationSelected: Boolean(integrationType),
|
|
|
|
_hasLoadedEvents: Boolean(events) || !isLoadingEvents
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-28 13:32:29 +00:00
|
|
|
export default translate(connect(_mapStateToProps)(CalendarList));
|