Guest User

Untitled

a guest
Jan 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. import React, {Component} from "react";
  2. import {Link} from "react-router";
  3. import {bindActionCreators} from "redux";
  4. import asyncConnect from "../helpers/asyncConnect";
  5. import * as dashboardActions from "../redux/modules/auth";
  6. import * as authActions from "../redux/modules/auth";
  7. import {getAdminCompany} from "../redux/modules/companies";
  8. import {setShowChatModal} from "../redux/modules/socket";
  9. import * as alertBarActions from "../redux/modules/alerts";
  10. import DashboardCard from "../components/dashboard/DashboardCard";
  11. import _ from "lodash";
  12. import moment from "moment";
  13. import {connect} from "react-redux";
  14.  
  15. function fetchData(store) {
  16. const {getState,dispatch}=store;
  17. /*If you want to get a state
  18. const state = getState();*/
  19. const promises = [];
  20. promises.push(dispatch(dashboardActions.getDashboard()));
  21. return Promise.all(promises);
  22. }
  23. @asyncConnect(
  24. store=>fetchData(store)
  25. )
  26.  
  27. @connect(
  28. state => ({
  29. user: state.auth.user,
  30. dashboard: state.auth.dashboard,
  31. dashStatistic: state.auth.dashStatistic,
  32. metadataList: state.athletes.metadataList
  33. }),
  34. dispatch => bindActionCreators({...dashboardActions, ...alertBarActions, ...authActions, setShowChatModal}, dispatch)
  35. )
  36.  
  37. export default class DashboardPage extends Component {
  38. constructor(props) {
  39. super(props);
  40. this.state = {
  41. isFiltred: false,
  42. dashCategory: 'all'
  43. }
  44. }
  45.  
  46. componentWillReceiveProps(nextProps) {
  47.  
  48. }
  49.  
  50. changeCategory(category) {
  51. this.setState({dashCategory: category});
  52. }
  53.  
  54.  
  55. filterDash(dashCategory) {
  56. const {dashboard} = this.props;
  57.  
  58. if (dashCategory === 'all') {
  59. return dashboard;
  60. } else if (dashCategory === 'active') {
  61. return _.filter(dashboard, (athlete)=> {
  62. return moment(athlete.lastWorkout).isAfter(moment().subtract(10, 'days'))
  63. })
  64. } else if (dashCategory === 'notActive') {
  65. return _.filter(dashboard, (athlete)=> {
  66. return moment(athlete.lastWorkout).isBefore(moment().subtract(10, 'days')) || !athlete.programId || !athlete.lastWorkout
  67. })
  68. } else if (dashCategory === 'withoutProgram') {
  69. return _.filter(dashboard, (athlete)=> {
  70. return athlete.programId === null
  71. })
  72. } else if (dashCategory === 'injury') {
  73. return _.filter(dashboard, (athlete)=> {
  74. return athlete.daysFeedbackStatusId === 2 || athlete.daysFeedbackStatusId === 4
  75. })
  76. }
  77.  
  78. }
  79.  
  80. handleMessageClick(athleteId) {
  81. this.props.setShowChatModal(athleteId, true);
  82. }
  83.  
  84. getEmptyMessage() {
  85. const {dashCategory} = this.state;
  86. switch (dashCategory) {
  87. case 'active' :
  88. return 'Your athletes do not have recent activity';
  89. break;
  90. case 'notActive':
  91. return 'You do not have any inactive athletes';
  92. break;
  93. case 'withoutProgram':
  94. return 'You do not have any athletes without a program';
  95. break;
  96. case 'injury':
  97. return 'You do not have injured athletes';
  98. break;
  99. default :
  100. return 'You do not have athletes =(';
  101. break
  102. }
  103. }
  104.  
  105.  
  106. render() {
  107. const {dashStatistic: {total, notActive, active, withoutProgram, injury}} = this.props;
  108. const {isFiltred, dashCategory} = this.state;
  109. let dashboard = this.filterDash(dashCategory);
  110.  
  111. return (
  112. <div >
  113.  
  114. <div className="">
  115. <div className="d-flex flex-row flex-wrap justify-content-center">
  116. <div onClick={this.changeCategory.bind(this, 'all')}
  117. className={`widget ${dashCategory === 'all' ? 'active' : ''}`}>
  118. <span className="statistic">{total}</span>
  119. <label className="label">Total</label>
  120. </div>
  121.  
  122. <div onClick={this.changeCategory.bind(this, 'active')}
  123. className={`widget ${dashCategory === 'active' ? 'active' : ''}`}>
  124. <span className="statistic">{active}</span>
  125. <label className="label">Active</label>
  126. </div>
  127.  
  128. <div onClick={this.changeCategory.bind(this, 'notActive')}
  129. className={`widget ${dashCategory === 'notActive' ? 'active' : ''}`}>
  130. <span className="statistic">{notActive}</span>
  131. <label className="label">Not active</label>
  132. </div>
  133.  
  134. <div onClick={this.changeCategory.bind(this, 'withoutProgram')}
  135. className={`widget ${dashCategory === 'withoutProgram' ? 'active' : ''}`}>
  136. <span className="statistic">{withoutProgram} <sub
  137. className="percentage">{(withoutProgram > 0) ? Math.floor(withoutProgram * 100 / total) + '%' : ''}</sub></span>
  138. <label className="label">Without program</label>
  139. </div>
  140. <div onClick={this.changeCategory.bind(this, 'injury')}
  141. className={`widget ${dashCategory === 'injury' ? 'active' : ''}`}>
  142. <span className="statistic">{injury} <sub
  143. className="percentage">{(injury > 0) ? Math.floor(injury * 100 / total) + '%' : ''}</sub> </span>
  144. <label className="label">Injury</label>
  145. </div>
  146. </div>
  147.  
  148. </div>
  149.  
  150.  
  151. <div className="d-flex flex-row justify-content-around flex-wrap">
  152. {dashboard && dashboard.length && dashboard.map((athlete, i)=> {
  153. return (
  154. <DashboardCard
  155. athlete={athlete}
  156. key={i}
  157. handleMessageClick={this.handleMessageClick.bind(this, athlete.id)}
  158. />
  159. )
  160. }) ||
  161. <div>
  162. {(dashCategory === 'all') && <div className="container p-0">
  163. <div className="card no-list">
  164. <div className="card-block text-center">
  165. <h2 className="text-main">Your athletes do not have recent activity. <Link
  166. to="/athletes/create"><span>Invite </span></Link>
  167. athletes!</h2>
  168. </div>
  169. </div>
  170. </div>}
  171. {(dashCategory !== 'all') && <div className="container">
  172. <div className="card no-list">
  173. <div className="card-block text-center">
  174. <h2 className="text-main">{this.getEmptyMessage()}</h2>
  175. </div>
  176. </div>
  177. </div>}
  178. </div>
  179. }
  180. </div>
  181.  
  182. <br/>
  183. <div className="new-dash">
  184.  
  185. </div>
  186.  
  187. </div>
  188. )
  189. }
  190. }
Add Comment
Please, Sign In to add comment