ktvmanager/client/src/components/accountTable.jsx

92 lines
3.0 KiB
React
Raw Normal View History

2021-02-21 11:22:57 +00:00
import React, { Component } from "react";
import axios from "axios"; // npm instal axios
import { forwardRef } from "react";
2021-02-21 10:04:25 +00:00
import MaterialTable from "material-table";
2021-02-21 11:22:57 +00:00
import ArrowDownward from "@material-ui/icons/ArrowDownward";
import ChevronLeft from "@material-ui/icons/ChevronLeft";
import ChevronRight from "@material-ui/icons/ChevronRight";
import Clear from "@material-ui/icons/Clear";
import FilterList from "@material-ui/icons/FilterList";
import FirstPage from "@material-ui/icons/FirstPage";
import LastPage from "@material-ui/icons/LastPage";
import Search from "@material-ui/icons/Search";
2021-02-21 10:04:25 +00:00
2021-02-21 11:22:57 +00:00
const tableIcons = {
// DetailPanel: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />),
FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
PreviousPage: forwardRef((props, ref) => (
<ChevronLeft {...props} ref={ref} />
)),
ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
SortArrow: forwardRef((props, ref) => <ArrowDownward {...props} ref={ref} />),
2021-02-21 10:04:25 +00:00
};
2021-02-21 11:22:57 +00:00
export default class MatDataTable extends Component {
constructor(props) {
super(props);
this.state = { person: [] };
}
componentDidMount(prevProps) {
2021-03-12 18:44:42 +00:00
const url = "http://" + process.env.URL + ":3001/getUserAccounts";
2021-02-21 11:22:57 +00:00
axios.get(url).then((results) => {
console.log(results);
console.log(results.data);
this.setState({ person: results.data });
var newArr = results.data.map(function (val) {
2021-02-22 11:15:14 +00:00
let date = new Date(val.expiaryDate * 1000);
let d = date.toGMTString();
2021-02-21 11:22:57 +00:00
return {
username: val.username,
streamName: val.streamName,
streamURL: val.streamURL,
2021-02-22 11:15:14 +00:00
expiaryDate: d,
2021-02-21 11:22:57 +00:00
};
});
console.log(results.data.results);
this.setState(
{
tableArray: newArr, //set state of the weather5days
},
() => {
console.log(this.state.tableArray);
console.log("this.tableArray ", this.state.tableArray);
}
);
});
}
render() {
return (
2021-02-22 11:15:14 +00:00
<div
style={{ maxWidth: "100%", marginLeft: "50px", marginRight: "50px" }}
>
2021-02-21 11:22:57 +00:00
<MaterialTable
icons={tableIcons}
options={{
grouping: false,
}}
columns={[
{
2021-02-22 11:15:14 +00:00
title: "Username",
2021-02-21 11:22:57 +00:00
field: "username",
type: "numeric",
align: "left",
},
2021-02-22 11:15:14 +00:00
{ title: "Stream Name", field: "streamName" },
{ title: "Stream URL", field: "streamURL" },
{ title: "Expiry Date", field: "expiaryDate", type: "numeric" },
2021-02-21 11:22:57 +00:00
]}
data={this.state.tableArray}
title="Stream Details"
/>
</div>
);
}
}