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
|
|
|
|
2018-09-01 01:03:35 +00:00
|
|
|
import {
|
|
|
|
createCalendarClickedEvent,
|
|
|
|
sendAnalytics
|
|
|
|
} from '../../analytics';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2022-11-08 10:24:32 +00:00
|
|
|
import { Icon, IconCalendar } from '../../base/icons';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { AbstractPage } from '../../base/react';
|
|
|
|
import { connect } from '../../base/redux';
|
2022-09-27 07:10:28 +00:00
|
|
|
import { SETTINGS_TABS, openSettingsDialog } from '../../settings';
|
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);
|
2021-06-10 12:48:44 +00:00
|
|
|
this._onKeyPressOpenSettings = this._onKeyPressOpenSettings.bind(this);
|
2018-08-27 15:13:59 +00:00
|
|
|
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'>
|
2020-10-19 07:37:19 +00:00
|
|
|
<div className = 'meetings-list-empty-image'>
|
2021-06-10 12:48:44 +00:00
|
|
|
<img
|
|
|
|
alt = { t('welcomepage.logo.calendar') }
|
|
|
|
src = './images/calendar.svg' />
|
2020-10-19 07:37:19 +00:00
|
|
|
</div>
|
|
|
|
<div 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
|
|
|
}) }
|
2020-10-19 07:37:19 +00:00
|
|
|
</div>
|
2018-10-22 18:49:18 +00:00
|
|
|
<div
|
2020-10-19 07:37:19 +00:00
|
|
|
className = 'meetings-list-empty-button'
|
2021-06-10 12:48:44 +00:00
|
|
|
onClick = { this._onOpenSettings }
|
|
|
|
onKeyPress = { this._onKeyPressOpenSettings }
|
2023-03-06 15:13:29 +00:00
|
|
|
role = 'button'
|
|
|
|
tabIndex = { 0 }>
|
2020-10-19 07:37:19 +00:00
|
|
|
<Icon
|
|
|
|
className = 'meetings-list-empty-icon'
|
2022-11-08 10:24:32 +00:00
|
|
|
src = { IconCalendar } />
|
2020-10-19 07:37:19 +00:00
|
|
|
<span>{ t('welcomepage.connectCalendarButton') }</span>
|
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() {
|
2021-11-09 10:20:40 +00:00
|
|
|
sendAnalytics(createCalendarClickedEvent('connect'));
|
2018-09-01 01:03:35 +00:00
|
|
|
|
2018-08-27 15:13:59 +00:00
|
|
|
this.props.dispatch(openSettingsDialog(SETTINGS_TABS.CALENDAR));
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:48:44 +00:00
|
|
|
_onKeyPressOpenSettings: (Object) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* KeyPress handler for accessibility.
|
|
|
|
*
|
|
|
|
* @param {Object} e - The key event to handle.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onKeyPressOpenSettings(e) {
|
|
|
|
if (e.key === ' ' || e.key === 'Enter') {
|
|
|
|
e.preventDefault();
|
|
|
|
this._onOpenSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-27 15:13:59 +00:00
|
|
|
_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));
|