This repository was archived by the owner on Aug 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtotal-sales-card.js
164 lines (161 loc) · 4.93 KB
/
total-sales-card.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { gql, graphql } from 'react-apollo';
import moment from 'moment';
import DashboardItemPlaceholder from './dashboard-item-placeholder';
import DashboardMetricCard from './dashboard-metric-card';
class TotalSalesCard extends Component {
static propTypes = {
data: PropTypes.shape({
loading: PropTypes.bool.isRequired,
orders: PropTypes.shape({
today: PropTypes.shape({
ordersValue: PropTypes.number.isRequired,
numberOfOrders: PropTypes.number.isRequired,
}).isRequired,
week: PropTypes.shape({
ordersValue: PropTypes.number.isRequired,
numberOfOrders: PropTypes.number.isRequired,
}).isRequired,
month: PropTypes.shape({
ordersValue: PropTypes.number.isRequired,
numberOfOrders: PropTypes.number.isRequired,
}).isRequired,
yesterday: PropTypes.shape({
ordersValue: PropTypes.number.isRequired,
}).isRequired,
lastWeek: PropTypes.shape({
ordersValue: PropTypes.number.isRequired,
}).isRequired,
lastMonth: PropTypes.shape({
ordersValue: PropTypes.number.isRequired,
}).isRequired,
}),
refetch: PropTypes.func.isRequired,
}),
registerRefreshListener: PropTypes.func.isRequired,
};
static defaultProps = {
data: {
loading: true,
refetch: Promise.resolve,
},
};
componentDidMount() {
this.props.registerRefreshListener(() => this.props.data.refetch());
}
render() {
if (this.props.data.loading) return <DashboardItemPlaceholder />;
return (
<DashboardMetricCard
title="Total Sales"
iconName="bar-chart"
todayValue={this.props.data.orders.today.ordersValue}
weekValue={this.props.data.orders.week.ordersValue}
monthValue={this.props.data.orders.month.ordersValue}
yesterdayValue={this.props.data.orders.yesterday.ordersValue}
lastWeekValue={this.props.data.orders.lastWeek.ordersValue}
lastMonthValue={this.props.data.orders.lastMonth.ordersValue}
numberOfOrdersToday={this.props.data.orders.today.numberOfOrders}
numberOfOrdersThisWeek={this.props.data.orders.week.numberOfOrders}
numberOfOrdersThisMonth={this.props.data.orders.month.numberOfOrders}
showNumberOfOrders={true}
showTrend={true}
/>
);
}
}
const TotalSalesFetch = gql`
query TotalSalesFetch (
$currency: String!
$projectKey: String!
$fromDateDay: String!
$fromDateYesterday: String!
$toDateYesterday: String!
$fromDateWeek: String!
$fromDateLastWeek: String!
$toDateLastWeek: String!
$fromDateMonth: String!
$fromDateLastMonth: String!
$toDateLastMonth: String!
) {
orders {
today: statistics (
currency: $currency
projectKey: $projectKey
range: { from: $fromDateDay }
) {
ordersValue
numberOfOrders
}
yesterday: statistics (
currency: $currency
projectKey: $projectKey
range: { from: $fromDateYesterday to: $toDateYesterday }
) {
ordersValue
}
week: statistics (
currency: $currency
projectKey: $projectKey
range: { from: $fromDateWeek }
) {
ordersValue
numberOfOrders
}
lastWeek: statistics (
currency: $currency
projectKey: $projectKey
range: { from: $fromDateLastWeek to: $toDateLastWeek }
) {
ordersValue
}
month: statistics (
currency: $currency
projectKey: $projectKey
range: { from: $fromDateMonth }
) {
ordersValue
numberOfOrders
}
lastMonth: statistics (
currency: $currency
projectKey: $projectKey
range: { from: $fromDateLastMonth to: $toDateLastMonth }
) {
ordersValue
}
}
}
`;
export default graphql(TotalSalesFetch, {
skip: ownProps => !ownProps.projectKey,
options: ownProps => ({
variables: {
target: 'dashboard',
currency: 'EUR',
projectKey: ownProps.projectKey,
fromDateDay: moment().startOf('day').toISOString(),
fromDateWeek: moment().startOf('week').toISOString(),
fromDateMonth: moment().startOf('month').toISOString(),
fromDateYesterday: moment()
.subtract(1, 'day')
.startOf('day')
.toISOString(),
toDateYesterday: moment().subtract(1, 'day').endOf('day').toISOString(),
fromDateLastWeek: moment()
.subtract(1, 'week')
.startOf('week')
.toISOString(),
toDateLastWeek: moment().subtract(1, 'week').endOf('week').toISOString(),
fromDateLastMonth: moment()
.subtract(1, 'month')
.startOf('month')
.toISOString(),
toDateLastMonth: moment()
.subtract(1, 'month')
.endOf('month')
.toISOString(),
},
}),
})(TotalSalesCard);