ExternalDataUpdateInfo.jsx 1.49 KB
Newer Older
1
2
3
4
5
6
import React from "react";

import List from "@material-ui/core/List";
import ListItem from "@material-ui/core/ListItem";
import ListItemText from "@material-ui/core/ListItemText";
import Typography from "@material-ui/core/Typography";
7
import PropTypes from "prop-types";
8
import toDateFr from "../../utils/dateToFr";
9
import withNetworkWrapper, { NetWrapParam } from "../../hoc/withNetworkWrapper";
10
11

function getLabel(source) {
12
  if (source === "fixer") return "Données concernant les taux de change";
13
  if (source === "utc") return "Données issues de l'ENT";
14
15
16
17
  return "Donnée externe non connue";
}

/**
18
 * Component to render notifications for important stuff
19
 */
20
21
function ExternalDataUpdateInfo({ updates }) {
  updates.sort((a, b) => a.source.localeCompare(b.source));
22

23
  if (updates.length > 0) {
24
    return (
25
26
27
28
29
30
31
32
33
34
      <List aria-label="List of updates">
        {updates.map(el => (
          <ListItem key={el.source}>
            <ListItemText
              primary={getLabel(el.source)}
              secondary={toDateFr(el.timestamp)}
            />
          </ListItem>
        ))}
      </List>
35
    );
36
  }
37
38
39
40
41
42

  return (
    <Typography variant="caption" display="block">
      Aucune mise-à-jour ne semble avoir été réalisée.
    </Typography>
  );
43
44
}

45
46
47
ExternalDataUpdateInfo.propTypes = {
  updates: PropTypes.array.isRequired
};
48
49
50

ExternalDataUpdateInfo.defaultProps = {};

51
export default withNetworkWrapper([
52
  new NetWrapParam("externalDataUpdateInfo", "all", { propKey: "updates" })
53
])(ExternalDataUpdateInfo);