aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/settings/ServicesScreen.js
blob: a657b6e6cde1ce42b214c3357a04e2c83705160c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Component } from 'react';
import PropTypes from 'prop-types';
import { inject, observer } from 'mobx-react';
import { RouterStore } from 'mobx-react-router';

// import RecipePreviewsStore from '../../stores/RecipePreviewsStore';
import UserStore from '../../stores/UserStore';
import ServiceStore from '../../stores/ServicesStore';

import ServicesDashboard from '../../components/settings/services/ServicesDashboard';
import ErrorBoundary from '../../components/util/ErrorBoundary';

@inject('stores', 'actions')
@observer
class ServicesScreen extends Component {
  componentWillUnmount() {
    this.props.actions.service.resetFilter();
    this.props.actions.service.resetStatus();
  }

  deleteService() {
    this.props.actions.service.deleteService();
    this.props.stores.services.resetFilter();
  }

  render() {
    const { user, services, router } = this.props.stores;
    const { toggleService, filter, resetFilter } = this.props.actions.service;
    const isLoading = services.allServicesRequest.isExecuting;

    let allServices = services.all;
    if (services.filterNeedle !== null) {
      allServices = services.filtered;
    }

    return (
      <ErrorBoundary>
        <ServicesDashboard
          user={user.data}
          services={allServices}
          status={services.actionStatus}
          deleteService={() => this.deleteService()}
          toggleService={toggleService}
          isLoading={isLoading}
          filterServices={filter}
          resetFilter={resetFilter}
          goTo={router.push}
          servicesRequestFailed={
            services.allServicesRequest.wasExecuted &&
            services.allServicesRequest.isError
          }
          retryServicesRequest={() => services.allServicesRequest.reload()}
          searchNeedle={services.filterNeedle}
        />
      </ErrorBoundary>
    );
  }
}

ServicesScreen.wrappedComponent.propTypes = {
  stores: PropTypes.shape({
    user: PropTypes.instanceOf(UserStore).isRequired,
    services: PropTypes.instanceOf(ServiceStore).isRequired,
    router: PropTypes.instanceOf(RouterStore).isRequired,
  }).isRequired,
  actions: PropTypes.shape({
    service: PropTypes.instanceOf(ServiceStore).isRequired,
  }).isRequired,
};

export default ServicesScreen;