You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalendarList.web.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // @flow
  2. import Spinner from '@atlaskit/spinner';
  3. import React from 'react';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../base/i18n';
  6. import { AbstractPage } from '../../base/react';
  7. import { openSettingsDialog, SETTINGS_TABS } from '../../settings';
  8. import {
  9. createCalendarClickedEvent,
  10. sendAnalytics
  11. } from '../../analytics';
  12. import { refreshCalendar } from '../actions';
  13. import { isCalendarEnabled } from '../functions';
  14. import CalendarListContent from './CalendarListContent';
  15. declare var interfaceConfig: Object;
  16. /**
  17. * The type of the React {@code Component} props of {@link CalendarList}.
  18. */
  19. type Props = {
  20. /**
  21. * Whether or not a calendar may be connected for fetching calendar events.
  22. */
  23. _hasIntegrationSelected: boolean,
  24. /**
  25. * Whether or not events have been fetched from a calendar.
  26. */
  27. _hasLoadedEvents: boolean,
  28. /**
  29. * Indicates if the list is disabled or not.
  30. */
  31. disabled: boolean,
  32. /**
  33. * The Redux dispatch function.
  34. */
  35. dispatch: Function,
  36. /**
  37. * The translate function.
  38. */
  39. t: Function
  40. };
  41. /**
  42. * Component to display a list of events from the user's calendar.
  43. */
  44. class CalendarList extends AbstractPage<Props> {
  45. /**
  46. * Initializes a new {@code CalendarList} instance.
  47. *
  48. * @inheritdoc
  49. */
  50. constructor(props) {
  51. super(props);
  52. // Bind event handlers so they are only bound once per instance.
  53. this._getRenderListEmptyComponent
  54. = this._getRenderListEmptyComponent.bind(this);
  55. this._onOpenSettings = this._onOpenSettings.bind(this);
  56. this._onRefreshEvents = this._onRefreshEvents.bind(this);
  57. }
  58. /**
  59. * Implements React's {@link Component#render}.
  60. *
  61. * @inheritdoc
  62. */
  63. render() {
  64. const { disabled } = this.props;
  65. return (
  66. CalendarListContent
  67. ? <CalendarListContent
  68. disabled = { disabled }
  69. listEmptyComponent
  70. = { this._getRenderListEmptyComponent() } />
  71. : null
  72. );
  73. }
  74. _getRenderListEmptyComponent: () => Object;
  75. /**
  76. * Returns a list empty component if a custom one has to be rendered instead
  77. * of the default one in the {@link NavigateSectionList}.
  78. *
  79. * @private
  80. * @returns {React$Component}
  81. */
  82. _getRenderListEmptyComponent() {
  83. const { _hasIntegrationSelected, _hasLoadedEvents, t } = this.props;
  84. if (_hasIntegrationSelected && _hasLoadedEvents) {
  85. return (
  86. <div className = 'meetings-list-empty'>
  87. <div>{ t('calendarSync.noEvents') }</div>
  88. <div
  89. className = 'button'
  90. onClick = { this._onRefreshEvents }>
  91. { t('calendarSync.refresh') }
  92. </div>
  93. </div>
  94. );
  95. } else if (_hasIntegrationSelected && !_hasLoadedEvents) {
  96. return (
  97. <div className = 'meetings-list-empty'>
  98. <Spinner
  99. invertColor = { true }
  100. isCompleting = { false }
  101. size = 'medium' />
  102. </div>
  103. );
  104. }
  105. return (
  106. <div className = 'meetings-list-empty'>
  107. <p className = 'description'>
  108. { t('welcomepage.connectCalendarText', {
  109. app: interfaceConfig.APP_NAME
  110. }) }
  111. </p>
  112. <div
  113. className = 'button'
  114. onClick = { this._onOpenSettings }>
  115. { t('welcomepage.connectCalendarButton') }
  116. </div>
  117. </div>
  118. );
  119. }
  120. _onOpenSettings: () => void;
  121. /**
  122. * Opens {@code SettingsDialog}.
  123. *
  124. * @private
  125. * @returns {void}
  126. */
  127. _onOpenSettings() {
  128. sendAnalytics(createCalendarClickedEvent('calendar.connect'));
  129. this.props.dispatch(openSettingsDialog(SETTINGS_TABS.CALENDAR));
  130. }
  131. _onRefreshEvents: () => void;
  132. /**
  133. * Gets an updated list of calendar events.
  134. *
  135. * @private
  136. * @returns {void}
  137. */
  138. _onRefreshEvents() {
  139. this.props.dispatch(refreshCalendar(true));
  140. }
  141. }
  142. /**
  143. * Maps (parts of) the Redux state to the associated props for the
  144. * {@code CalendarList} component.
  145. *
  146. * @param {Object} state - The Redux state.
  147. * @private
  148. * @returns {{
  149. * _hasIntegrationSelected: boolean,
  150. * _hasLoadedEvents: boolean
  151. * }}
  152. */
  153. function _mapStateToProps(state) {
  154. const {
  155. events,
  156. integrationType,
  157. isLoadingEvents
  158. } = state['features/calendar-sync'];
  159. return {
  160. _hasIntegrationSelected: Boolean(integrationType),
  161. _hasLoadedEvents: Boolean(events) || !isLoadingEvents
  162. };
  163. }
  164. export default isCalendarEnabled()
  165. ? translate(connect(_mapStateToProps)(CalendarList))
  166. : undefined;