Add loadng spinner to dashboard

This commit is contained in:
Kailash Nadh 2018-11-06 16:33:04 +05:30
parent 08717528c5
commit 6d96986b3a
1 changed files with 7 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { Col, Row, notification, Card, Tooltip, Icon } from "antd" import { Col, Row, notification, Card, Tooltip, Icon, Spin } from "antd"
import React from "react"; import React from "react";
import { Chart, Axis, Geom, Tooltip as BizTooltip } from 'bizcharts'; import { Chart, Axis, Geom, Tooltip as BizTooltip } from 'bizcharts';
@ -6,18 +6,19 @@ import * as cs from "./constants"
class Dashboard extends React.PureComponent { class Dashboard extends React.PureComponent {
state = { state = {
stats: null stats: null,
loading: true
} }
campaignTypes = ["running", "finished", "paused", "draft", "scheduled", "cancelled"] campaignTypes = ["running", "finished", "paused", "draft", "scheduled", "cancelled"]
componentDidMount = () => { componentDidMount = () => {
this.props.pageTitle("Dashboard") this.props.pageTitle("Dashboard")
this.props.request(cs.Routes.GetDashboarcStats, cs.MethodGet).then((resp) => { this.props.request(cs.Routes.GetDashboarcStats, cs.MethodGet).then((resp) => {
this.setState({ stats: resp.data.data }) this.setState({ stats: resp.data.data, loading: false })
}).catch(e => { }).catch(e => {
notification["error"]({ message: "Error", description: e.message }) notification["error"]({ message: "Error", description: e.message })
this.setState({ loading: false })
}) })
} }
@ -30,6 +31,7 @@ class Dashboard extends React.PureComponent {
<section className = "dashboard"> <section className = "dashboard">
<h1>Welcome</h1> <h1>Welcome</h1>
<hr /> <hr />
<Spin spinning={ this.state.loading }>
{ this.state.stats && { this.state.stats &&
<div className="stats"> <div className="stats">
<Row> <Row>
@ -120,6 +122,7 @@ class Dashboard extends React.PureComponent {
</Row> </Row>
</div> </div>
} }
</Spin>
</section> </section>
); );
} }