<file_sep>import React, { Component } from 'react';
import { connect } from 'react-redux';
import * as actions from '../actions';
class Home extends Component {
  componentWillMount() {
    if (this.props.authenticated){
      window.location = '/#donation';
    }else{
      window.location = '/#signin';
    }
    
}
  render() {
    return (
      <div>
      <h1>Home</h1>
      </div>
    );
  }
}
function mapStateToProps({auth}){
  return {
      authenticated: auth.authenticated
  }
}
export default connect(mapStateToProps, actions)(Home)<file_sep>import {
    GET_DONATIONS,
    UPDATE_DONATION_GOOD,
    UPDATE_DONATION__FAIL,
    GET_DONATION_PER_STUDENT,
    ADD_DONATION,
    UPDATE_DONATION,
    DELETE_DONATION
} from '../actions/types';

let INITIAL_STATE = {
    data:[],
    dataByStud:[],
    donation:{}
}

export default function(state=INITIAL_STATE, action) {
    switch (action.type) {
        case GET_DONATIONS:
            return { ...state, data: action.payload }
            case ADD_DONATION:
            return {...state,donation:action.payload}

            case UPDATE_DONATION:
            return {...state}
       case DELETE_DONATION:
           return {...state}
        case GET_DONATION_PER_STUDENT:
       
        console.log(action.payload)
            return { ...state, dataByStud: action.payload }
        case UPDATE_DONATION__FAIL:
            return { ...state, updateProfileFailMsg: 'Incorrect Password' }
        default:
            return state
    }
}<file_sep>import React, {Component} from 'react';
import {connect} from 'react-redux';
import ReactDOM from "react-dom";
import {reduxForm, Field} from 'redux-form';
import {tryConnect, getUserProfile, updateUserProfile,getDonationData} from '../actions';
import CenterCard363 from './centerCard363';
import ReactTable from "react-table";
import * as Moment from "moment";
import Modal from "./popup";


class Account extends Component {
  constructor(){
    super();
    this.state = {
      editting: false,
      showModal:false,
      studentId:''
       
      
    }
  }
  componentWillMount() {
    this.props.tryConnect();
    this.props.getUserProfile();
    this.props.getDonationData();
  
   
  }
 
  render() {
    
    return (
      <CenterCard363>
        <div className='card border-secondary'>
        <h4 className="card-header">
          Donation
        </h4>
        <div className='card-body'>
      
          {this.props.data && this.renderDonationGrid()}
        </div>
        </div>
      </CenterCard363>
    );
  }
  
  
  onrowclick(e){
    
    console.log(e)
  }
  handleHideModal(){
 
    this.setState({showModal:false})
    this.props.getDonationData();
  
    
  }
  renderDonationGrid(){
    console.log(this.props.data)
    let {data} = this.props;
    
   
      return (
        <div>
          {this.state.showModal ? <Modal studentId={this.state.studentId} handleHideModal={this.handleHideModal.bind(this)}/> :null}
          
          <ReactTable
            data={data}
            getTrProps={(state, rowInfo) => {
              return {
                onClick: (e) => {
                  console.log(e);
                  console.log(rowInfo.row._original);
                 this.setState({studentId:rowInfo.row._original.id})
this.setState({showModal:true})
               
                }
               
              }
            }}
            columns={[
             
              {
                Header: "Student Name",
                accessor: "name"
              },
              {
                Header: "Father Name",
                accessor: "fatherName"
              },
              {
                Header: "DOB",
                id:"dob",
                accessor: d => {
                  return Moment(d.dob)
                    .local()
                    .format("DD-MM-YYYY")
                }
              },{
                Header: "Caste",
                accessor: "caste.name"
              },
              {
                Header: 'Scholarship',
                accessor: "scholarship"
              },
              {
                Header: 'Donation Amount',
                accessor: "donationamount"
              }

            ]}
            defaultPageSize={10}
            className="-striped -highlight"
          />
          <br />
         
        </div>
      );
  }
}

function mapStateToProps({auth, user, donation}) {

  return {
    data:donation.data.data
  
}
}


export default connect(mapStateToProps, {tryConnect, getUserProfile, getDonationData})(Account);<file_sep>install mongodb comunity

//create db hsm

//create colleciton 'donations'

create indexes for donations colletions using mongodb compass tool -- no need of command
schema of user and donations tabel will be in model folder  -- hsmserver\models

coman to start client and server web server: npm run dev <file_sep>import token from '../services/token';
import Donation from '../models/donation';
import * as request from 'request';
import  autoIncrement  from "mongodb-autoincrement";

export default {

    addDonation:(req, res, next) =>{

   
        const { createdby, studentid, donationamount, createddate,id } = req.body;
    
   
    
    autoIncrement.getNextSequence(Donation.db,Donation.collection.collectionName,function (err, autoIndex) {
        console.log(autoIndex)
        const donation = new Donation({
            donationid:autoIndex,
            createdby: createdby,
            studentid: studentid,
            donationamount:donationamount,
            createddate:createddate
        })

        donation.save(function (err, donations) {
            if (err) {
                return next(err)
            }

            res.json({
                success: true,
                data:donations
            })
        })
    })
       
    },
    updateDonation:(req, res, next) =>{

   console.log(req.body)
        const { createdby, studentid, donationamount, createddate,donationid } = req.body;
        var myquery = { donationid: donationid };
        var newvalues = { $set: {donationamount: donationamount, createdby: createdby,createddate:createddate } };
        
Donation.updateOne(myquery, newvalues, function(err, record) {
    if (err) throw err;
    console.log("1 document updated");
  
    res.json({
        success: true,
        data:record
    })
  });
       
    },
    deleteDonation:(req, res, next) =>{

      //  console.log(req.body)
            
             var myquery = { donationid: req.query.donationid };
            console.log(myquery)
     Donation.remove(myquery, function(err, record) {
         if (err) throw err;
         console.log("1 document deleted");
       
         res.json({
             success: true,
             data:record
         })
       });
            
         },
    getdonationbystudent:(req, res, next) =>{

        Donation
        .find({
            studentid:req.query.id
        }, function (err, donations) {
            
            if (err) {return res.status(422).send(err);}
            else {
                
            res.json({
                success: true,
                data:donations
            })
   
            }
        })
    },
    getStudentList : (req, res, next) => {
		console.log('students...');
      

  Donation
.find({}, function (err, donations) {
    
    if (err) {return res.status(422).send(err);}
    else {
        request.get("http://localhost:8080/SCMServices/student/getallstudents",function(err,response,body){
       
        if(!err){

//donations merge witn student id need to do
var responseObj=JSON.parse(body);

    responseObj.forEach(element => {
        console.log(element);
let donationAmt=0;
        donations.forEach(val =>{
            console.log(val);
            if(val.studentid==element.id){
                donationAmt+=val.donationamount;
        
            }

        })
        element.donationamount=donationAmt;
    });


   
            res.json({
                success: true,
                data:responseObj
            })
          }else{
            res.status(422).send(err);
          }
      //console.log(body)
      
        })
       
}
    })
    

    

      
      
    }
    
    
}
<file_sep>import axios from 'axios';
import { 
    AUTH_USER,
    UNAUTH_USER,
    AUTH_ERROR,
    TRY_CONNECT,
    GET_USER_PROFILE,
    UPDATE_USER_PROFILE_GOOD,
    UPDATE_USER_PROFILE_FAIL ,
    GET_DONATIONS,
    GET_DONATION_PER_STUDENT,
    ADD_DONATION,
    UPDATE_DONATION,
    DELETE_DONATION
} from './types';
const ROOT_URL = 'http://localhost:8000';

axios.defaults.baseURL = ROOT_URL;
if (localStorage.getItem('auth_jwt_token')) {
    axios.defaults.headers.common['Authorization'] = localStorage.getItem('auth_jwt_token');
}
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

export function signUserIn(data) {
    return function (dispatch) {
        // Submit email/password to server
        axios
            .post(`/signin`, data)
            .then(res => {
                dispatch({type: AUTH_USER})
                localStorage.setItem('auth_jwt_token', res.data.token);
                window.location = '/#donation';
                axios.defaults.headers.common['Authorization'] = localStorage.getItem('auth_jwt_token');
            })
            .catch(error => {
                console.log(error);
                dispatch({type: AUTH_ERROR, payload: 'Server Error, try later.'})
            });
    }
}
export function updateDonationData(donation){
    
    return function (dispatch) {
        axios
            .put(`/api/updatedonation`,donation)
            .then(res => {
                console.log(res)
                dispatch({
                    type: UPDATE_DONATION,
                    payload: res
                })
            })
            .catch(error => console.log(error));
    }
}
export function deleteDonationData(donation){
    
    return function (dispatch) {
        axios
            .delete(`/api/deletedonation`,{params:{donationid:donation.donationid}})
            .then(res => {
                console.log(res)
                dispatch({
                    type: DELETE_DONATION,
                    payload: res
                })
            })
            .catch(error => console.log(error));
    }
}
export function getDonationData(){
    return function (dispatch) {
        axios
            .get(`/api/getdonations`)
            .then(res => {
                console.log(res)
                dispatch({
                    type: GET_DONATIONS,
                    payload: res.data
                })
            })
            .catch(error => console.log(error));
    }
}
export function addDonation(donation){
    return function (dispatch) {
        // Submit email/password to server
        axios
            .post(`/api/adddonation`, donation)
            .then(res => {
                dispatch({type: ADD_DONATION,
                    payload: res.data
                     })
                })
            .catch(error => {
                console.log(error);
                dispatch({type: AUTH_ERROR, payload: 'Server Error, try later.'})
            });
    }
}
export function getDonationDataByStudent(student){
    return function (dispatch) {
        console.log(student)
        axios
            .get(`/api/getdonationbystudent`,{params:{id:student}})
            .then(res => {
                console.log(res)
                dispatch({
                    type: GET_DONATION_PER_STUDENT,
                    payload: res.data
                })
            })
            .catch(error => console.log(error));
    }
}

export function signUserUp(userObj) {
    return function (dispatch) {
        // Submit email/password to server
        axios
            .post(`/signup`, userObj)
            .then(res => {
                dispatch({type: AUTH_USER})
                localStorage.setItem('auth_jwt_token', res.data.token);
                window.location = '/#donation';
                axios.defaults.headers.common['Authorization'] = localStorage.getItem('auth_jwt_token');
            })
            .catch(error => {
                console.log(error);
                dispatch({type: AUTH_ERROR, payload: 'Server Error, try later.'})
            });
    }
}

export function signUserOut() {
    return function (dispatch) {
        dispatch({type: UNAUTH_USER})
        localStorage.removeItem('auth_jwt_token');
        window.location = '/#signin';
    }
}

export function tryConnect() {
    return function (dispatch) {
        axios
            .get(`/api`)
            .then(res => {
                console.log(res)
                dispatch({
                    type: TRY_CONNECT,
                    payload: res.data
                })
            })
            .catch(error => console.log(error.response.data));
    }
}
export function getUserProfile() {
    return function (dispatch) {
        axios
            .get(`/api/userProfile`)
            .then(res => {
                dispatch({
                    type: GET_USER_PROFILE,
                    payload: res.data
                })
            })
            .catch(error => console.log(error.response.data));
    }
}

export function updateUserProfile(profile) {
    return function (dispatch) {
       
    }
}
<file_sep>import mongoose from 'mongoose';


// Define the model
const DonationSchema = new mongoose.Schema({
    donationid:{
        unique: true,
        type:Number
    },
    createdby: String,
    studentid:Number,
    donationamount:Number,
    createddate:Date
    
})



// Export the model
export default mongoose.model('Donation', DonationSchema);<file_sep>import React from 'react';

const CenterCard363 = (props) => (
  <div className="row">
    <div className="col-xs-12 col-sm-2 col-md-2"></div>
      <div className="col-sm-8 col-md-8">
        {props.children}
      </div>
    <div className="col-xs-12 col-sm-2 col-md-2"></div>
  </div>
)

export default CenterCard363;
