-
Notifications
You must be signed in to change notification settings - Fork 2
/
TaskTimeline.js
83 lines (75 loc) · 2.2 KB
/
TaskTimeline.js
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
72
73
74
75
76
77
78
79
80
81
82
83
// Dependency Imports
import React, { useEffect, useState } from "react";
import { Typography, Grid, Paper, Button } from "@material-ui/core";
import { apiPassword, apiURL, apiUsername } from "../../utils/api_secret";
import { Skeleton } from "@material-ui/lab";
import parse, { attributesToProps } from "html-react-parser";
import { Link } from "react-router-dom";
import PropTypes from "prop-types";
// Default function
const TaskTimeline = () => {
const [htmlData, setHtmlData] = useState("");
useEffect(() => {
const fetchData = async () => {
let data = await fetch(`${apiURL}/api/psa/internal/pages/1592`, {
headers: {
Authorization: `Basic ${Buffer.from(
apiUsername + ":" + apiPassword,
"binary"
).toString("base64")}`,
},
});
let response = await data.text();
setHtmlData(response);
};
fetchData();
}, []);
const options = {
replace: (domNode) => {
if (domNode.attribs && domNode.name === "a") {
const props = attributesToProps(domNode.attribs);
if (props.href.startsWith("https://onfarmtech.org/")) {
// domNode
console.log(domNode);
const relativeLink = props.href.replace("https://onfarmtech.org", "");
props.target = "_self";
return (
<Button
size="small"
component={Link}
to={relativeLink}
{...props}
variant="text"
style={{ textTransform: "capitalize" }}
>
{relativeLink.split("/").join("").split("-").join(" ")}
</Button>
);
}
}
},
trim: true,
};
return (
<Grid container>
<Grid item xs={12}>
<Typography variant="h5" align="left" gutterBottom>
Task Timeline
</Typography>
</Grid>
<Grid item xs={12}>
{!htmlData ? (
<Skeleton width="100%" height="50vh" />
) : (
<Paper style={{ padding: "1em" }} elevation={3}>
{parse(htmlData, options)}
</Paper>
)}
</Grid>
</Grid>
);
};
export default TaskTimeline;
TaskTimeline.propTypes = {
href: PropTypes.string,
};