您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CalendarList.web.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // @flow
  2. import Button from '@atlaskit/button';
  3. import Spinner from '@atlaskit/spinner';
  4. import React, { Component } from 'react';
  5. import { connect } from 'react-redux';
  6. import { translate } from '../../base/i18n';
  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 BaseCalendarList from './BaseCalendarList';
  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 Component<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. BaseCalendarList
  67. ? <BaseCalendarList
  68. disabled = { disabled }
  69. renderListEmptyComponent
  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 = 'navigate-section-list-empty'>
  87. <div>{ t('calendarSync.noEvents') }</div>
  88. <Button
  89. appearance = 'primary'
  90. className = 'calendar-button'
  91. id = 'connect_calendar_button'
  92. onClick = { this._onRefreshEvents }
  93. type = 'button'>
  94. { t('calendarSync.refresh') }
  95. </Button>
  96. </div>
  97. );
  98. } else if (_hasIntegrationSelected && !_hasLoadedEvents) {
  99. return (
  100. <div className = 'navigate-section-list-empty'>
  101. <Spinner
  102. invertColor = { true }
  103. isCompleting = { false }
  104. size = 'medium' />
  105. </div>
  106. );
  107. }
  108. return (
  109. <div className = 'navigate-section-list-empty'>
  110. <p className = 'header-text-description'>
  111. { t('welcomepage.connectCalendarText', {
  112. app: interfaceConfig.APP_NAME
  113. }) }
  114. </p>
  115. <Button
  116. appearance = 'primary'
  117. className = 'calendar-button'
  118. id = 'connect_calendar_button'
  119. onClick = { this._onOpenSettings }
  120. type = 'button'>
  121. { t('welcomepage.connectCalendarButton') }
  122. </Button>
  123. </div>
  124. );
  125. }
  126. _onOpenSettings: () => void;
  127. /**
  128. * Opens {@code SettingsDialog}.
  129. *
  130. * @private
  131. * @returns {void}
  132. */
  133. _onOpenSettings() {
  134. sendAnalytics(createCalendarClickedEvent('calendar.connect'));
  135. this.props.dispatch(openSettingsDialog(SETTINGS_TABS.CALENDAR));
  136. }
  137. _onRefreshEvents: () => void;
  138. /**
  139. * Gets an updated list of calendar events.
  140. *
  141. * @private
  142. * @returns {void}
  143. */
  144. _onRefreshEvents() {
  145. this.props.dispatch(refreshCalendar(true));
  146. }
  147. }
  148. /**
  149. * Maps (parts of) the Redux state to the associated props for the
  150. * {@code CalendarList} component.
  151. *
  152. * @param {Object} state - The Redux state.
  153. * @private
  154. * @returns {{
  155. * _hasIntegrationSelected: boolean,
  156. * _hasLoadedEvents: boolean
  157. * }}
  158. */
  159. function _mapStateToProps(state) {
  160. const {
  161. events,
  162. integrationType,
  163. isLoadingEvents
  164. } = state['features/calendar-sync'];
  165. return {
  166. _hasIntegrationSelected: Boolean(integrationType),
  167. _hasLoadedEvents: Boolean(events) || !isLoadingEvents
  168. };
  169. }
  170. export default isCalendarEnabled()
  171. ? translate(connect(_mapStateToProps)(CalendarList))
  172. : undefined;