UnlinkedPartners.jsx 3.15 KB
Newer Older
1
2
import React from "react";

3
4
import { connect } from "react-redux";
import { compose } from "recompose";
5
6
7
8
9
10

import PropTypes from "prop-types";
import Typography from "@material-ui/core/Typography";
import List from "@material-ui/core/List";
import ListItem from "@material-ui/core/ListItem";
import ListItemText from "@material-ui/core/ListItemText";
11
import APP_ROUTES from "../../config/appRoutes";
12
13
14
import CustomLink from "../common/CustomLink";
import getActions from "../../redux/api/getActions";
import CustomComponentForAPI from "../common/CustomComponentForAPI";
15
16
17
18
19
20
21
22
23
24

/**
 * Class to render notifications for important stuff
 *
 * @class UnlinkedPartners
 * @extends {CustomComponentForAPI}
 * @extends React.Component
 */
class UnlinkedPartners extends CustomComponentForAPI {
  customRender() {
25
26
27
    const unlinkedPartners = this.getLatestReadData("unlinkedUtcPartners");
    const nUnlinked = unlinkedPartners.length;
    const { variant } = this.props;
28
29
30
31

    if (variant === "detailed") {
      return (
        <>
32
33
          {nUnlinked > 0 ? (
            <>
34
              <Typography>
35
36
                {nUnlinked}
                &nbsp; partenaires sont dans ce cas. En voici la liste :
37
              </Typography>
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
              <List aria-label="List des partenaires qui ne sont pas encore disponibles sur la plateforme REX-DRI">
                {unlinkedPartners.map((nameOnEnt, idx) => (
                  // eslint-disable-next-line react/no-array-index-key
                  <ListItem key={idx}>
                    <ListItemText primary={nameOnEnt} />
                  </ListItem>
                ))}
              </List>
            </>
          ) : (
            <Typography>
              Actuellement, tous les partenaires de l'UTC sont disponibles sur
              la plateforme ! 🎉
            </Typography>
          )}
53
54
        </>
      );
55
56
    }
    if (variant === "summary") {
57
58
      return (
        <>
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
          {nUnlinked > 0 ? (
            <>
              <Typography variant="caption" color="primary">
&nbsp;
                {nUnlinked === 1
                  ? "1 université partenaire de l'UTC n'est pas encore pleinement disponible"
                  : `${nUnlinked} universités partenaires de l'UTC ne sont pas encore pleinement disponibles`}
                sur la plateforme. Plus d'informations&nbsp;
                <CustomLink to={APP_ROUTES.aboutUnlinkedPartners}>
                  <Typography variant="caption" color="primary">
                    ici
                  </Typography>
                </CustomLink>
                .
              </Typography>
            </>
          ) : (
            <></>
          )}
78
79
80
81
        </>
      );
    }

82
    return <></>;
83
84
85
86
  }
}

UnlinkedPartners.propTypes = {
87
  variant: PropTypes.oneOf(["summary", "detailed"]).isRequired
88
89
90
91
};

UnlinkedPartners.defaultProps = {};

92
93
94
const mapStateToProps = state => ({
  unlinkedUtcPartners: state.api.unlinkedUtcPartnersAll
});
95

96
97
98
99
100
101
const mapDispatchToProps = dispatch => ({
  api: {
    unlinkedUtcPartners: () =>
      dispatch(getActions("unlinkedUtcPartners").readAll())
  }
});
102
103

export default compose(
104
105
106
107
  connect(
    mapStateToProps,
    mapDispatchToProps
  )
108
)(UnlinkedPartners);