Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CalendarList.web.tsx 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import React from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { createCalendarClickedEvent } from '../../analytics/AnalyticsEvents';
  5. import { sendAnalytics } from '../../analytics/functions';
  6. import { IReduxState } from '../../app/types';
  7. import { translate } from '../../base/i18n/functions';
  8. import Icon from '../../base/icons/components/Icon';
  9. import { IconCalendar } from '../../base/icons/svg';
  10. import AbstractPage from '../../base/react/components/AbstractPage';
  11. import Spinner from '../../base/ui/components/web/Spinner';
  12. import { openSettingsDialog } from '../../settings/actions.web';
  13. import { SETTINGS_TABS } from '../../settings/constants';
  14. import { refreshCalendar } from '../actions.web';
  15. import { ERRORS } from '../constants';
  16. import CalendarListContent from './CalendarListContent.web';
  17. /**
  18. * The type of the React {@code Component} props of {@link CalendarList}.
  19. */
  20. interface IProps extends WithTranslation {
  21. /**
  22. * The error object containing details about any error that has occurred
  23. * while interacting with calendar integration.
  24. */
  25. _calendarError?: { error: string; };
  26. /**
  27. * Whether or not a calendar may be connected for fetching calendar events.
  28. */
  29. _hasIntegrationSelected: boolean;
  30. /**
  31. * Whether or not events have been fetched from a calendar.
  32. */
  33. _hasLoadedEvents: boolean;
  34. /**
  35. * Indicates if the list is disabled or not.
  36. */
  37. disabled?: boolean;
  38. /**
  39. * The Redux dispatch function.
  40. */
  41. dispatch: Function;
  42. }
  43. /**
  44. * Component to display a list of events from the user's calendar.
  45. */
  46. class CalendarList extends AbstractPage<IProps> {
  47. /**
  48. * Initializes a new {@code CalendarList} instance.
  49. *
  50. * @inheritdoc
  51. */
  52. constructor(props: IProps) {
  53. super(props);
  54. // Bind event handlers so they are only bound once per instance.
  55. this._getRenderListEmptyComponent
  56. = this._getRenderListEmptyComponent.bind(this);
  57. this._onOpenSettings = this._onOpenSettings.bind(this);
  58. this._onKeyPressOpenSettings = this._onKeyPressOpenSettings.bind(this);
  59. this._onRefreshEvents = this._onRefreshEvents.bind(this);
  60. }
  61. /**
  62. * Implements React's {@link Component#render}.
  63. *
  64. * @inheritdoc
  65. */
  66. render() {
  67. const { disabled } = this.props;
  68. return (
  69. CalendarListContent
  70. ? <CalendarListContent
  71. disabled = { Boolean(disabled) }
  72. listEmptyComponent
  73. = { this._getRenderListEmptyComponent() } />
  74. : null
  75. );
  76. }
  77. /**
  78. * Returns a component for showing the error message related to calendar
  79. * sync.
  80. *
  81. * @private
  82. * @returns {React$Component}
  83. */
  84. _getErrorMessage() {
  85. const { _calendarError = { error: undefined }, t } = this.props;
  86. let errorMessageKey = 'calendarSync.error.generic';
  87. let showRefreshButton = true;
  88. let showSettingsButton = true;
  89. if (_calendarError.error === ERRORS.GOOGLE_APP_MISCONFIGURED) {
  90. errorMessageKey = 'calendarSync.error.appConfiguration';
  91. showRefreshButton = false;
  92. showSettingsButton = false;
  93. } else if (_calendarError.error === ERRORS.AUTH_FAILED) {
  94. errorMessageKey = 'calendarSync.error.notSignedIn';
  95. showRefreshButton = false;
  96. }
  97. return (
  98. <div className = 'meetings-list-empty'>
  99. <p className = 'description'>
  100. { t(errorMessageKey) }
  101. </p>
  102. <div className = 'calendar-action-buttons'>
  103. { showSettingsButton
  104. && <div
  105. className = 'button'
  106. onClick = { this._onOpenSettings }>
  107. { t('calendarSync.permissionButton') }
  108. </div>
  109. }
  110. { showRefreshButton
  111. && <div
  112. className = 'button'
  113. onClick = { this._onRefreshEvents }>
  114. { t('calendarSync.refresh') }
  115. </div>
  116. }
  117. </div>
  118. </div>
  119. );
  120. }
  121. /**
  122. * Returns a list empty component if a custom one has to be rendered instead
  123. * of the default one in the {@link NavigateSectionList}.
  124. *
  125. * @private
  126. * @returns {React$Component}
  127. */
  128. _getRenderListEmptyComponent() {
  129. const {
  130. _calendarError,
  131. _hasIntegrationSelected,
  132. _hasLoadedEvents,
  133. t
  134. } = this.props;
  135. if (_calendarError) {
  136. return this._getErrorMessage();
  137. } else if (_hasIntegrationSelected && _hasLoadedEvents) {
  138. return (
  139. <div className = 'meetings-list-empty'>
  140. <p className = 'description'>
  141. { t('calendarSync.noEvents') }
  142. </p>
  143. <div
  144. className = 'button'
  145. onClick = { this._onRefreshEvents }>
  146. { t('calendarSync.refresh') }
  147. </div>
  148. </div>
  149. );
  150. } else if (_hasIntegrationSelected && !_hasLoadedEvents) {
  151. return (
  152. <div className = 'meetings-list-empty'>
  153. <Spinner />
  154. </div>
  155. );
  156. }
  157. return (
  158. <div className = 'meetings-list-empty'>
  159. <div className = 'meetings-list-empty-image'>
  160. <img
  161. alt = { t('welcomepage.logo.calendar') }
  162. src = './images/calendar.svg' />
  163. </div>
  164. <div className = 'description'>
  165. { t('welcomepage.connectCalendarText', {
  166. app: interfaceConfig.APP_NAME,
  167. provider: interfaceConfig.PROVIDER_NAME
  168. }) }
  169. </div>
  170. <div
  171. className = 'meetings-list-empty-button'
  172. onClick = { this._onOpenSettings }
  173. onKeyPress = { this._onKeyPressOpenSettings }
  174. role = 'button'
  175. tabIndex = { 0 }>
  176. <Icon
  177. className = 'meetings-list-empty-icon'
  178. src = { IconCalendar } />
  179. <span>{ t('welcomepage.connectCalendarButton') }</span>
  180. </div>
  181. </div>
  182. );
  183. }
  184. /**
  185. * Opens {@code SettingsDialog}.
  186. *
  187. * @private
  188. * @returns {void}
  189. */
  190. _onOpenSettings() {
  191. sendAnalytics(createCalendarClickedEvent('connect'));
  192. this.props.dispatch(openSettingsDialog(SETTINGS_TABS.CALENDAR));
  193. }
  194. /**
  195. * KeyPress handler for accessibility.
  196. *
  197. * @param {Object} e - The key event to handle.
  198. *
  199. * @returns {void}
  200. */
  201. _onKeyPressOpenSettings(e: React.KeyboardEvent) {
  202. if (e.key === ' ' || e.key === 'Enter') {
  203. e.preventDefault();
  204. this._onOpenSettings();
  205. }
  206. }
  207. /**
  208. * Gets an updated list of calendar events.
  209. *
  210. * @private
  211. * @returns {void}
  212. */
  213. _onRefreshEvents() {
  214. this.props.dispatch(refreshCalendar(true));
  215. }
  216. }
  217. /**
  218. * Maps (parts of) the Redux state to the associated props for the
  219. * {@code CalendarList} component.
  220. *
  221. * @param {Object} state - The Redux state.
  222. * @private
  223. * @returns {{
  224. * _calendarError: Object,
  225. * _hasIntegrationSelected: boolean,
  226. * _hasLoadedEvents: boolean
  227. * }}
  228. */
  229. function _mapStateToProps(state: IReduxState) {
  230. const {
  231. error,
  232. events,
  233. integrationType,
  234. isLoadingEvents
  235. } = state['features/calendar-sync'];
  236. return {
  237. _calendarError: error,
  238. _hasIntegrationSelected: Boolean(integrationType),
  239. _hasLoadedEvents: Boolean(events) || !isLoadingEvents
  240. };
  241. }
  242. export default translate(connect(_mapStateToProps)(CalendarList));