<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Route, Switch } from 'react-router-dom';
import AdminBooks from './AdminBooks';
import Navbar from './Navbar';
import PageFooter from './PageFooter';
import Preloader from './Preloader';
import { getBooks, deleteBook, addBook, editBook } from '../actions/books';
import BookForm from './BookForm';

class Admin extends Component {
  componentDidMount() {
    this.props.getBooks();
  }

  render() {
    const { match } = this.props;
    return (

            <Navbar />

Admin Dashboard

            <Switch>
                <Route exact path = { `${match.url}`} render= {() => (

                    { this.props.isFetching &&

                            <Preloader />

                    }
                    { this.props.error &&

 {`Oops! Couldn't fetch available books. ${this.props.error}`}

                    }
                    { this.props.books &&
                        <AdminBooks books = { this.props.books } {...this.props }/>
                    }

                )} />
                <Route exact path = { `${match.url}/addBook`} render= {() => (

                            <BookForm { ...this.props }/>

                )} />
            </Switch>

            <PageFooter />

    );
  }
}

const mapStateToProps = state => ({
  ...state.books,
});
const mapDispatchToProps = dispatch => ({
  getBooks: () => { dispatch(getBooks()); },
  deleteBook: (bookId, bookIndex) => { dispatch(deleteBook(bookId, bookIndex)); },
  editBook: (bookId, bookIndex, book) => { dispatch(editBook(bookId, bookIndex, book)); },
  addBook: (book) => { dispatch(addBook(book)); },
});
export default connect(mapStateToProps, mapDispatchToProps)(Admin);
<commit_msg>Add borrowBook request actions to admin component<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Route, Switch } from 'react-router-dom';
import AdminBooks from './AdminBooks';
import Navbar from './Navbar';
import PageFooter from './PageFooter';
import Preloader from './Preloader';
import { getBorrowRequests, handleBorrowRequest } from '../actions/borrowrequests';
import { getBooks, deleteBook, addBook, editBook } from '../actions/books';
import BookForm from './BookForm';
import AdminBorrowRequests from './AdminBorrowRequests';

class Admin extends Component {
  componentDidMount() {
    this.props.getBooks();
  }

  render() {
    const { match } = this.props;
    return (

            <Navbar />

Admin Dashboard

            <Switch>
                <Route exact path = { `${match.url}`} render= {() => (

                    { this.props.isFetching &&

                            <Preloader />

                    }
                    { this.props.error &&

 {`Oops! Couldn't fetch available books. ${this.props.error}`}

                    }
                    { this.props.books &&
                        <AdminBooks books = { this.props.books } {...this.props }/>
                    }

                )} />
                <Route exact path = { `${match.url}/addBook`} render= {() => (

                            <BookForm { ...this.props }/>

                )} />
                <Route exact path = { `${match.url}/borrowRequests`} render= {() => (

                        <AdminBorrowRequests borrowRequests = { this.props.borrowRequests } { ...this.props }/>

                )} />
            </Switch>

            <PageFooter />

    );
  }
}

const mapStateToProps = state => ({
  ...state.books,
  ...state.borrowRequests,
});
const mapDispatchToProps = dispatch => ({
  getBooks: () => { dispatch(getBooks()); },
  deleteBook: (bookId, bookIndex) => { dispatch(deleteBook(bookId, bookIndex)); },
  editBook: (bookId, bookIndex, book) => { dispatch(editBook(bookId, bookIndex, book)); },
  getBorrowRequests: () => { dispatch(getBorrowRequests()); },
  handleBorrowRequest: (action, userId, bookId, requestIndex) =>
    { dispatch(handleBorrowRequest(action, userId, bookId, requestIndex));
  },
  addBook: (book) => { dispatch(addBook(book)); },

});
export default connect(mapStateToProps, mapDispatchToProps)(Admin);
<|endoftext|>