├── .gitignore ├── client ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html ├── src │ ├── components │ │ ├── Spinner.js │ │ └── DefaultLayout.js │ ├── setupTests.js │ ├── App.test.js │ ├── reportWebVitals.js │ ├── redux │ │ ├── reducers │ │ │ ├── alertsReducer.js │ │ │ ├── carsReducer.js │ │ │ └── bookingsReducer.js │ │ ├── store.js │ │ └── actions │ │ │ ├── bookingActions.js │ │ │ ├── userActions.js │ │ │ └── carsActions.js │ ├── index.js │ ├── App.css │ ├── App.js │ ├── pages │ │ ├── UserBookings.js │ │ ├── AddCar.js │ │ ├── Login.js │ │ ├── Register.js │ │ ├── EditCar.js │ │ ├── AdminHome.js │ │ ├── Home.js │ │ └── BookingCar.js │ ├── logo.svg │ └── index.css ├── .gitignore ├── package.json └── README.md ├── models ├── userModel.js ├── carModel.js └── bookingModel.js ├── db.js ├── package.json ├── server.js └── routes ├── usersRoute.js ├── carsRoute.js └── bookingsRoute.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /client/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /client/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sathyaprakash195/sheycars-udemy/HEAD/client/public/favicon.ico -------------------------------------------------------------------------------- /client/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sathyaprakash195/sheycars-udemy/HEAD/client/public/logo192.png -------------------------------------------------------------------------------- /client/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sathyaprakash195/sheycars-udemy/HEAD/client/public/logo512.png -------------------------------------------------------------------------------- /client/src/components/Spinner.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {Spin} from 'antd' 3 | function Spinner() { 4 | return ( 5 |
6 | 7 |
8 | ) 9 | } 10 | 11 | export default Spinner 12 | -------------------------------------------------------------------------------- /client/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /client/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /models/userModel.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const userSchema = new mongoose.Schema({ 4 | username : {type:String , required: true}, 5 | password : {type:String , required: true} 6 | }) 7 | 8 | const userModel = mongoose.model('users' , userSchema) 9 | 10 | module.exports = userModel -------------------------------------------------------------------------------- /client/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /client/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /client/src/redux/reducers/alertsReducer.js: -------------------------------------------------------------------------------- 1 | const initialData = { 2 | loading : false 3 | }; 4 | 5 | export const alertsReducer=(state=initialData , action)=>{ 6 | 7 | switch(action.type) 8 | { 9 | case 'LOADING' : { 10 | return{ 11 | ...state, 12 | loading : action.payload 13 | } 14 | } 15 | 16 | default : return state 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /client/src/redux/reducers/carsReducer.js: -------------------------------------------------------------------------------- 1 | const initialData = { 2 | cars : [], 3 | 4 | }; 5 | 6 | export const carsReducer = (state=initialData , action)=>{ 7 | 8 | switch(action.type) 9 | { 10 | case 'GET_ALL_CARS' : { 11 | return{ 12 | ...state, 13 | cars : action.payload 14 | } 15 | } 16 | 17 | default:return state 18 | } 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /client/src/redux/reducers/bookingsReducer.js: -------------------------------------------------------------------------------- 1 | const initialData = { 2 | bookings : [], 3 | 4 | }; 5 | 6 | export const bookingsReducer = (state=initialData , action)=>{ 7 | 8 | switch(action.type) 9 | { 10 | case 'GET_ALL_BOOKINGS' : { 11 | return{ 12 | ...state, 13 | bookings : action.payload 14 | } 15 | } 16 | 17 | default:return state 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /db.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | function connectDB(){ 4 | 5 | mongoose.connect('mongodb+srv://sathya:sathyapr@cluster0.dkuc0.mongodb.net/sheycars-udemy' , {useUnifiedTopology: true , useNewUrlParser: true}) 6 | 7 | const connection = mongoose.connection 8 | 9 | connection.on('connected' , ()=>{ 10 | console.log('Mongo DB Connection Successfull') 11 | }) 12 | 13 | connection.on('error' , ()=>{ 14 | console.log('Mongo DB Connection Error') 15 | }) 16 | 17 | 18 | } 19 | 20 | connectDB() 21 | 22 | module.exports = mongoose -------------------------------------------------------------------------------- /client/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /client/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | import store from './redux/store'; 7 | import {Provider} from 'react-redux' 8 | ReactDOM.render( 9 | 10 | 11 | , 12 | document.getElementById('root') 13 | ); 14 | 15 | // If you want to start measuring performance in your app, pass a function 16 | // to log results (for example: reportWebVitals(console.log)) 17 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 18 | reportWebVitals(); 19 | -------------------------------------------------------------------------------- /models/carModel.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const carSchema = new mongoose.Schema({ 4 | 5 | name : {type : String , required : true} , 6 | image : {type : String , required : true} , 7 | capacity : {type : Number , required : true}, 8 | fuelType : {type : String , required : true} , 9 | bookedTimeSlots : [ 10 | { 11 | from : {type : String , required : true}, 12 | to : {type : String , required : true} 13 | } 14 | ] , 15 | 16 | rentPerHour : {type : Number , required : true} 17 | 18 | 19 | }, {timestamps : true} 20 | 21 | ) 22 | const carModel = mongoose.model('cars' , carSchema) 23 | module.exports = carModel -------------------------------------------------------------------------------- /models/bookingModel.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const bookingSchema = new mongoose.Schema({ 4 | 5 | 6 | car : {type : mongoose.Schema.Types.ObjectID , ref:'cars'}, 7 | user : {type : mongoose.Schema.Types.ObjectID , ref:'users'}, 8 | bookedTimeSlots : { 9 | from : {type : String} , 10 | to : {type : String} 11 | } , 12 | totalHours : {type : Number}, 13 | totalAmount : {type : Number}, 14 | transactionId : {type : String}, 15 | driverRequired : {type : Boolean} 16 | 17 | 18 | }, 19 | {timestamps : true} 20 | ) 21 | 22 | const bookingModel = mongoose.model('bookings' , bookingSchema) 23 | 24 | module.exports = bookingModel -------------------------------------------------------------------------------- /client/src/redux/store.js: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware , combineReducers } from 'redux'; 2 | import { composeWithDevTools } from 'redux-devtools-extension'; 3 | import thunk from 'redux-thunk'; 4 | import { alertsReducer } from './reducers/alertsReducer'; 5 | import { carsReducer } from './reducers/carsReducer'; 6 | import { bookingsReducer } from './reducers/bookingsReducer'; 7 | const composeEnhancers = composeWithDevTools({}); 8 | 9 | const rootReducer = combineReducers({ 10 | carsReducer, 11 | alertsReducer, 12 | bookingsReducer, 13 | }) 14 | 15 | const store = createStore( 16 | rootReducer, 17 | composeEnhancers( 18 | applyMiddleware(thunk) 19 | 20 | ) 21 | ); 22 | 23 | export default store -------------------------------------------------------------------------------- /client/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sheycars", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "engines": { 7 | "node" : "15.7.0", 8 | "npm" : "7.4.3" 9 | }, 10 | "scripts": { 11 | "client-install": "npm install --prefix client", 12 | "server": "nodemon server.js", 13 | "client": "npm start --prefix client", 14 | "dev": "concurrently \"npm run server\" \"npm run client\"", 15 | "start": "node server.js", 16 | "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client" 17 | }, 18 | "author": "", 19 | "license": "ISC", 20 | "dependencies": { 21 | "express": "^4.17.1", 22 | "mongoose": "^6.0.11", 23 | "nodemon": "^2.0.14", 24 | "stripe": "^8.184.0", 25 | "uuid": "^8.3.2" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const app = express() 3 | const port = process.env.PORT || 5000 4 | const dbConnection = require('./db') 5 | app.use(express.json()) 6 | 7 | app.use('/api/cars/' , require('./routes/carsRoute')) 8 | app.use('/api/users/' , require('./routes/usersRoute')) 9 | app.use('/api/bookings/' , require('./routes/bookingsRoute')) 10 | 11 | 12 | const path = require('path') 13 | 14 | if(process.env.NODE_ENV==='production') 15 | { 16 | 17 | app.use('/' , express.static('client/build')) 18 | 19 | app.get('*' , (req , res)=>{ 20 | 21 | res.sendFile(path.resolve(__dirname, 'client/build/index.html')); 22 | 23 | }) 24 | 25 | } 26 | 27 | app.get('/', (req, res) => res.send('Hello World!')) 28 | 29 | 30 | 31 | 32 | 33 | app.listen(port, () => console.log(`Node JS Server Started in Port ${port}`)) -------------------------------------------------------------------------------- /routes/usersRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const User = require("../models/userModel") 4 | 5 | 6 | router.post("/login", async(req, res) => { 7 | 8 | const {username , password} = req.body 9 | 10 | try { 11 | const user = await User.findOne({username , password}) 12 | if(user) { 13 | res.send(user) 14 | } 15 | else{ 16 | return res.status(400).json(error); 17 | } 18 | } catch (error) { 19 | return res.status(400).json(error); 20 | } 21 | 22 | }); 23 | 24 | router.post("/register", async(req, res) => { 25 | 26 | 27 | 28 | try { 29 | const newuser = new User(req.body) 30 | await newuser.save() 31 | res.send('User registered successfully') 32 | } catch (error) { 33 | return res.status(400).json(error); 34 | } 35 | 36 | }); 37 | 38 | 39 | module.exports = router 40 | 41 | -------------------------------------------------------------------------------- /client/src/redux/actions/bookingActions.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import { message } from "antd"; 3 | export const bookCar = (reqObj) => async (dispatch) => { 4 | dispatch({ type: "LOADING", payload: true }); 5 | 6 | try { 7 | await axios.post("/api/bookings/bookcar" , reqObj); 8 | 9 | dispatch({ type: "LOADING", payload: false }); 10 | message.success("Your car booked successfully"); 11 | setTimeout(() => { 12 | window.location.href='/userbookings' 13 | }, 500); 14 | 15 | 16 | } catch (error) { 17 | console.log(error); 18 | dispatch({ type: "LOADING", payload: false }); 19 | message.error("Something went wrong , please try later"); 20 | } 21 | }; 22 | 23 | export const getAllBookings=()=>async dispatch=>{ 24 | 25 | dispatch({type: 'LOADING' , payload:true}) 26 | 27 | try { 28 | const response = await axios.get('/api/bookings/getallbookings') 29 | dispatch({type: 'GET_ALL_BOOKINGS', payload:response.data}) 30 | dispatch({type: 'LOADING' , payload:false}) 31 | } catch (error) { 32 | console.log(error) 33 | dispatch({type: 'LOADING' , payload:false}) 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@ant-design/icons": "^4.7.0", 7 | "@testing-library/jest-dom": "^5.14.1", 8 | "@testing-library/react": "^11.2.7", 9 | "@testing-library/user-event": "^12.8.3", 10 | "antd": "^4.16.13", 11 | "aos": "^2.3.4", 12 | "axios": "^0.23.0", 13 | "moment": "^2.29.1", 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-redux": "^7.2.5", 17 | "react-router-dom": "^5.3.0", 18 | "react-scripts": "4.0.3", 19 | "react-stripe-checkout": "^2.6.3", 20 | "redux": "^4.1.1", 21 | "redux-devtools-extension": "^2.13.9", 22 | "redux-thunk": "^2.3.0", 23 | "web-vitals": "^1.1.2" 24 | }, 25 | "scripts": { 26 | "start": "react-scripts start", 27 | "build": "react-scripts build", 28 | "test": "react-scripts test", 29 | "eject": "react-scripts eject" 30 | }, 31 | "eslintConfig": { 32 | "extends": [ 33 | "react-app", 34 | "react-app/jest" 35 | ] 36 | }, 37 | "browserslist": { 38 | "production": [ 39 | ">0.2%", 40 | "not dead", 41 | "not op_mini all" 42 | ], 43 | "development": [ 44 | "last 1 chrome version", 45 | "last 1 firefox version", 46 | "last 1 safari version" 47 | ] 48 | }, 49 | "proxy": "http://localhost:5000/" 50 | } 51 | -------------------------------------------------------------------------------- /client/src/redux/actions/userActions.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import {message} from 'antd' 3 | 4 | export const userLogin=(reqObj)=>async dispatch=>{ 5 | 6 | dispatch({type: 'LOADING' , payload:true}) 7 | 8 | try { 9 | const response = await axios.post('/api/users/login' , reqObj) 10 | localStorage.setItem('user' , JSON.stringify(response.data)) 11 | message.success('Login success') 12 | dispatch({type: 'LOADING' , payload:false}) 13 | setTimeout(() => { 14 | window.location.href='/' 15 | 16 | }, 500); 17 | } catch (error) { 18 | console.log(error) 19 | message.error('Something went wrong') 20 | dispatch({type: 'LOADING' , payload:false}) 21 | } 22 | } 23 | 24 | export const userRegister=(reqObj)=>async dispatch=>{ 25 | 26 | dispatch({type: 'LOADING' , payload:true}) 27 | 28 | try { 29 | const response = await axios.post('/api/users/register' , reqObj) 30 | message.success('Registration successfull') 31 | setTimeout(() => { 32 | window.location.href='/login' 33 | 34 | }, 500); 35 | 36 | dispatch({type: 'LOADING' , payload:false}) 37 | 38 | } catch (error) { 39 | console.log(error) 40 | message.error('Something went wrong') 41 | dispatch({type: 'LOADING' , payload:false}) 42 | } 43 | } -------------------------------------------------------------------------------- /routes/carsRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const Car = require("../models/carModel"); 4 | 5 | router.get("/getallcars", async (req, res) => { 6 | try { 7 | const cars = await Car.find(); 8 | res.send(cars); 9 | } catch (error) { 10 | return res.status(400).json(error); 11 | } 12 | }); 13 | 14 | router.post("/addcar", async (req, res) => { 15 | try { 16 | const newcar = new Car(req.body); 17 | await newcar.save(); 18 | res.send("Car added successfully"); 19 | } catch (error) { 20 | return res.status(400).json(error); 21 | } 22 | }); 23 | 24 | router.post("/editcar", async (req, res) => { 25 | try { 26 | const car = await Car.findOne({ _id: req.body._id }); 27 | car.name = req.body.name; 28 | car.image = req.body.image; 29 | car.fuelType = req.body.fuelType; 30 | car.rentPerHour = req.body.rentPerHour; 31 | car.capacity = req.body.capacity; 32 | 33 | await car.save(); 34 | 35 | res.send("Car details updated successfully"); 36 | } catch (error) { 37 | return res.status(400).json(error); 38 | } 39 | }); 40 | 41 | router.post("/deletecar", async (req, res) => { 42 | try { 43 | await Car.findOneAndDelete({ _id: req.body.carid }); 44 | 45 | res.send("Car deleted successfully"); 46 | } catch (error) { 47 | return res.status(400).json(error); 48 | } 49 | }); 50 | 51 | module.exports = router; 52 | -------------------------------------------------------------------------------- /client/src/App.js: -------------------------------------------------------------------------------- 1 | import logo from './logo.svg'; 2 | import './App.css'; 3 | import {Route , BrowserRouter , Redirect} from 'react-router-dom' 4 | import Home from './pages/Home' 5 | import Login from './pages/Login' 6 | import Register from './pages/Register' 7 | import BookingCar from './pages/BookingCar' 8 | import 'antd/dist/antd.css'; 9 | import UserBookings from './pages/UserBookings'; 10 | import AddCar from './pages/AddCar'; 11 | import AdminHome from './pages/AdminHome'; 12 | import EditCar from './pages/EditCar'; 13 | 14 | function App() { 15 | return ( 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 | ); 35 | } 36 | 37 | 38 | 39 | export default App; 40 | 41 | 42 | export function ProtectedRoute(props) 43 | { 44 | 45 | 46 | if(localStorage.getItem('user')) 47 | { 48 | return 49 | } 50 | else{ 51 | return 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /routes/bookingsRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const Booking = require("../models/bookingModel"); 4 | const Car = require("../models/carModel"); 5 | const { v4: uuidv4 } = require("uuid"); 6 | const stripe = require("stripe")( 7 | "sk_test_51IYnC0SIR2AbPxU0EiMx1fTwzbZXLbkaOcbc2cXx49528d9TGkQVjUINJfUDAnQMVaBFfBDP5xtcHCkZG1n1V3E800U7qXFmGf" 8 | ); 9 | router.post("/bookcar", async (req, res) => { 10 | const { token } = req.body; 11 | try { 12 | const customer = await stripe.customers.create({ 13 | email: token.email, 14 | source: token.id, 15 | }); 16 | 17 | const payment = await stripe.charges.create( 18 | { 19 | amount: req.body.totalAmount * 100, 20 | currency: "inr", 21 | customer: customer.id, 22 | receipt_email: token.email 23 | }, 24 | { 25 | idempotencyKey: uuidv4(), 26 | 27 | } 28 | ); 29 | 30 | if (payment) { 31 | req.body.transactionId = payment.source.id; 32 | const newbooking = new Booking(req.body); 33 | await newbooking.save(); 34 | const car = await Car.findOne({ _id: req.body.car }); 35 | console.log(req.body.car); 36 | car.bookedTimeSlots.push(req.body.bookedTimeSlots); 37 | 38 | await car.save(); 39 | res.send("Your booking is successfull"); 40 | } else { 41 | return res.status(400).json(error); 42 | } 43 | } catch (error) { 44 | console.log(error); 45 | return res.status(400).json(error); 46 | } 47 | }); 48 | 49 | 50 | router.get("/getallbookings", async(req, res) => { 51 | 52 | try { 53 | 54 | const bookings = await Booking.find().populate('car') 55 | res.send(bookings) 56 | 57 | } catch (error) { 58 | return res.status(400).json(error); 59 | } 60 | 61 | }); 62 | 63 | 64 | module.exports = router; 65 | -------------------------------------------------------------------------------- /client/src/components/DefaultLayout.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Menu, Dropdown, Button, Space , Row , Col } from "antd"; 3 | import {Link} from 'react-router-dom' 4 | 5 | function DefaultLayout(props) { 6 | const user = JSON.parse(localStorage.getItem('user')) 7 | const menu = ( 8 | 9 | 10 | 14 | Home 15 | 16 | 17 | 18 | 22 | Bookings 23 | 24 | 25 | 26 | 30 | Admin 31 | 32 | 33 | { 34 | localStorage.removeItem('user'); 35 | window.location.href='/login' 36 | }}> 37 |
  • Logout
  • 38 |
    39 |
    40 | ); 41 | return ( 42 |
    43 |
    44 | 45 | 46 |
    47 |

    SheyCars

    48 | 49 | 50 | 51 | 52 |
    53 | 54 |
    55 | 56 |
    57 |
    {props.children}
    58 | 59 |
    60 |
    61 | 62 |

    Desinged and Developed By

    63 | 64 | 65 | 66 |

    SHEY

    67 | 68 |
    69 |
    70 | ); 71 | } 72 | 73 | export default DefaultLayout; 74 | -------------------------------------------------------------------------------- /client/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | SheyCars Dev 28 | 29 | 30 | 31 | 32 |
    33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /client/src/pages/UserBookings.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import DefaultLayout from "../components/DefaultLayout"; 3 | import { useDispatch, useSelector } from "react-redux"; 4 | import { getAllBookings } from "../redux/actions/bookingActions"; 5 | import { Col, Row } from "antd"; 6 | import Spinner from '../components/Spinner'; 7 | import moment from "moment"; 8 | function UserBookings() { 9 | const dispatch = useDispatch(); 10 | const { bookings } = useSelector((state) => state.bookingsReducer); 11 | const {loading} = useSelector((state) => state.alertsReducer); 12 | const user = JSON.parse(localStorage.getItem("user")); 13 | useEffect(() => { 14 | dispatch(getAllBookings()); 15 | }, []); 16 | 17 | return ( 18 | 19 | {loading && ()} 20 |

    My Bookings

    21 | 22 | 23 | 24 | 25 | {bookings.filter(o=>o.user==user._id).map((booking) => { 26 | return 27 | 28 |

    {booking.car.name}

    29 |

    Total hours : {booking.totalHours}

    30 |

    Rent per hour : {booking.car.rentPerHour}

    31 |

    Total amount : {booking.totalAmount}

    32 | 33 | 34 | 35 |

    Transaction Id : {booking.transactionId}

    36 |

    From: {booking.bookedTimeSlots.from}

    37 |

    To: {booking.bookedTimeSlots.to}

    38 |

    Date of booking: {moment(booking.createdAt).format('MMM DD yyyy')}

    39 | 40 | 41 | 42 | 43 | 44 |
    ; 45 | })} 46 | 47 | 48 |
    49 |
    50 | ); 51 | } 52 | 53 | export default UserBookings; 54 | -------------------------------------------------------------------------------- /client/src/redux/actions/carsActions.js: -------------------------------------------------------------------------------- 1 | import { message } from 'antd'; 2 | import axios from 'axios'; 3 | 4 | export const getAllCars=()=>async dispatch=>{ 5 | 6 | dispatch({type: 'LOADING' , payload:true}) 7 | 8 | try { 9 | const response = await axios.get('/api/cars/getallcars') 10 | dispatch({type: 'GET_ALL_CARS', payload:response.data}) 11 | dispatch({type: 'LOADING' , payload:false}) 12 | } catch (error) { 13 | console.log(error) 14 | dispatch({type: 'LOADING' , payload:false}) 15 | } 16 | 17 | } 18 | 19 | export const addCar=(reqObj)=>async dispatch=>{ 20 | 21 | dispatch({type: 'LOADING' , payload:true}) 22 | 23 | try { 24 | await axios.post('/api/cars/addcar' , reqObj) 25 | 26 | dispatch({type: 'LOADING' , payload:false}) 27 | message.success('New car added successfully') 28 | setTimeout(() => { 29 | window.location.href='/admin' 30 | }, 500); 31 | } catch (error) { 32 | console.log(error) 33 | dispatch({type: 'LOADING' , payload:false}) 34 | } 35 | 36 | 37 | } 38 | 39 | export const editCar=(reqObj)=>async dispatch=>{ 40 | 41 | dispatch({type: 'LOADING' , payload:true}) 42 | 43 | try { 44 | await axios.post('/api/cars/editcar' , reqObj) 45 | 46 | dispatch({type: 'LOADING' , payload:false}) 47 | message.success('Car details updated successfully') 48 | setTimeout(() => { 49 | window.location.href='/admin' 50 | }, 500); 51 | } catch (error) { 52 | console.log(error) 53 | dispatch({type: 'LOADING' , payload:false}) 54 | } 55 | 56 | 57 | } 58 | 59 | export const deleteCar=(reqObj)=>async dispatch=>{ 60 | 61 | dispatch({type: 'LOADING' , payload:true}) 62 | 63 | try { 64 | await axios.post('/api/cars/deletecar' , reqObj) 65 | 66 | dispatch({type: 'LOADING' , payload:false}) 67 | message.success('Car deleted successfully') 68 | setTimeout(() => { 69 | window.location.reload() 70 | }, 500); 71 | } catch (error) { 72 | console.log(error) 73 | dispatch({type: 'LOADING' , payload:false}) 74 | } 75 | 76 | 77 | } -------------------------------------------------------------------------------- /client/src/pages/AddCar.js: -------------------------------------------------------------------------------- 1 | import { Col , Row , Form , Input} from 'antd' 2 | import React from 'react' 3 | import { useDispatch , useSelector } from 'react-redux' 4 | import DefaultLayout from '../components/DefaultLayout' 5 | import Spinner from '../components/Spinner' 6 | import { addCar } from '../redux/actions/carsActions' 7 | function AddCar() { 8 | 9 | const dispatch = useDispatch() 10 | const {loading} = useSelector(state=>state.alertsReducer) 11 | 12 | function onFinish(values){ 13 | 14 | values.bookedTimeSlots=[] 15 | 16 | dispatch(addCar(values)) 17 | console.log(values) 18 | } 19 | 20 | return ( 21 | 22 | {loading && ()} 23 | 24 | 25 |
    26 |

    Add New Car

    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 | export default AddCar 57 | -------------------------------------------------------------------------------- /client/src/pages/Login.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {Row , Col , Form , Input} from 'antd' 3 | import { Link } from 'react-router-dom' 4 | import {useDispatch , useSelector} from 'react-redux' 5 | import { userLogin } from '../redux/actions/userActions' 6 | import AOS from 'aos'; 7 | import Spinner from '../components/Spinner'; 8 | import 'aos/dist/aos.css'; // You can also use for styles 9 | // .. 10 | AOS.init(); 11 | function Login() { 12 | const dispatch = useDispatch() 13 | const {loading} = useSelector(state=>state.alertsReducer) 14 | function onFinish(values) { 15 | dispatch(userLogin(values)) 16 | console.log(values) 17 | 18 | } 19 | return ( 20 |
    21 | {loading && ()} 22 | 23 | 24 | 25 | 30 |

    SHEYCARS

    31 | 32 | 33 |
    34 |

    Login

    35 |
    36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
    46 | 47 | Click Here to Register 48 | 49 | 50 |
    51 | 52 | 53 |
    54 | 55 |
    56 | ) 57 | } 58 | 59 | export default Login -------------------------------------------------------------------------------- /client/src/pages/Register.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Row, Col, Form, Input } from "antd"; 3 | import { Link } from "react-router-dom"; 4 | import {useDispatch , useSelector} from 'react-redux' 5 | import { userRegister } from "../redux/actions/userActions"; 6 | import AOS from 'aos'; 7 | import Spinner from '../components/Spinner'; 8 | import 'aos/dist/aos.css'; // You can also use for styles 9 | // .. 10 | AOS.init() 11 | function Register() { 12 | const dispatch = useDispatch() 13 | const {loading} = useSelector(state=>state.alertsReducer) 14 | function onFinish(values) { 15 | dispatch(userRegister(values)) 16 | console.log(values) 17 | } 18 | 19 | return ( 20 |
    21 | {loading && ()} 22 | 23 | 24 | 29 |

    SHEYCARS

    30 | 31 | 32 |
    33 |

    Register

    34 |
    35 | 40 | 41 | 42 | 47 | 48 | 49 | 54 | 55 | 56 | 57 | 58 |
    59 | 60 | Click Here to Login 61 |
    62 | 63 |
    64 |
    65 | ); 66 | } 67 | 68 | export default Register; 69 | -------------------------------------------------------------------------------- /client/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /client/src/pages/EditCar.js: -------------------------------------------------------------------------------- 1 | import { Col, Row, Form, Input } from "antd"; 2 | import React, { useEffect, useState } from "react"; 3 | import { useDispatch, useSelector } from "react-redux"; 4 | import DefaultLayout from "../components/DefaultLayout"; 5 | import Spinner from "../components/Spinner"; 6 | import { addCar, editCar, getAllCars } from "../redux/actions/carsActions"; 7 | function EditCar({ match }) { 8 | const { cars } = useSelector((state) => state.carsReducer); 9 | const dispatch = useDispatch(); 10 | const { loading } = useSelector((state) => state.alertsReducer); 11 | const [car, setcar] = useState(); 12 | const [totalcars, settotalcars] = useState([]); 13 | useEffect(() => { 14 | if (cars.length == 0) { 15 | dispatch(getAllCars()); 16 | } else { 17 | settotalcars(cars); 18 | setcar(cars.find((o) => o._id == match.params.carid)); 19 | console.log(car); 20 | } 21 | }, [cars]); 22 | 23 | function onFinish(values) { 24 | values._id = car._id; 25 | 26 | dispatch(editCar(values)); 27 | console.log(values); 28 | } 29 | 30 | return ( 31 | 32 | {loading && } 33 | 34 | 35 | {totalcars.length > 0 && ( 36 |
    42 |

    Edit Car

    43 | 44 |
    45 | 50 | 51 | 52 | 57 | 58 | 59 | 64 | 65 | 66 | 71 | 72 | 73 | 78 | 79 | 80 | 81 |
    82 | 83 |
    84 |
    85 | )} 86 | 87 |
    88 |
    89 | ); 90 | } 91 | 92 | export default EditCar; 93 | -------------------------------------------------------------------------------- /client/src/pages/AdminHome.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { useSelector, useDispatch } from "react-redux"; 3 | import DefaultLayout from "../components/DefaultLayout"; 4 | import { deleteCar, getAllCars } from "../redux/actions/carsActions"; 5 | import { Col, Row, Divider, DatePicker, Checkbox, Edit } from "antd"; 6 | import { Link } from "react-router-dom"; 7 | import Spinner from "../components/Spinner"; 8 | import moment from "moment"; 9 | import { DeleteOutlined, EditOutlined } from "@ant-design/icons"; 10 | import { Popconfirm, message } from "antd"; 11 | const { RangePicker } = DatePicker; 12 | function AdminHome() { 13 | const { cars } = useSelector((state) => state.carsReducer); 14 | const { loading } = useSelector((state) => state.alertsReducer); 15 | const [totalCars, setTotalcars] = useState([]); 16 | const dispatch = useDispatch(); 17 | 18 | useEffect(() => { 19 | dispatch(getAllCars()); 20 | }, []); 21 | 22 | useEffect(() => { 23 | setTotalcars(cars); 24 | }, [cars]); 25 | 26 | return ( 27 | 28 | 29 | 30 |
    31 |

    Admin Panel

    32 | 35 |
    36 | 37 |
    38 | 39 | {loading == true && } 40 | 41 | 42 | {totalCars.map((car) => { 43 | return ( 44 | 45 |
    46 | 47 | 48 |
    49 |
    50 |

    {car.name}

    51 |

    Rent Per Hour {car.rentPerHour} /-

    52 |
    53 | 54 |
    55 | 56 | 60 | 61 | 62 | {dispatch(deleteCar({carid : car._id}))}} 65 | 66 | okText="Yes" 67 | cancelText="No" 68 | > 69 | 72 | 73 |
    74 |
    75 |
    76 | 77 | ); 78 | })} 79 |
    80 |
    81 | ); 82 | } 83 | 84 | export default AdminHome; 85 | -------------------------------------------------------------------------------- /client/src/index.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap'); 2 | body { 3 | margin: 0; 4 | font-family: 'Montserrat', sans-serif !important; 5 | -webkit-font-smoothing: antialiased; 6 | -moz-osx-font-smoothing: grayscale; 7 | background-color: azure; 8 | } 9 | body , html{ 10 | overflow-x: hidden !important; 11 | } 12 | code { 13 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 14 | monospace; 15 | } 16 | .bs1{ 17 | box-shadow: rgba(14, 30, 37, 0.12) 0px 2px 4px 0px, rgba(14, 30, 37, 0.32) 0px 2px 16px 0px; 18 | } 19 | .ant-row{ 20 | margin: 0 20 !important; 21 | } 22 | .spinner{ 23 | position: absolute; 24 | top: 50%; 25 | left: 50%; 26 | z-index: 9999; 27 | } 28 | h1{ 29 | font-size: 30px; 30 | font-weight: bold; 31 | color : orangered; 32 | } 33 | p{ 34 | margin: 5px !important; 35 | 36 | padding: 0; 37 | } 38 | .btn1{ 39 | box-shadow: none !important; 40 | background-color : white !important; 41 | color: orangered !important; 42 | border: 1px solid orangered !important; 43 | padding: 5px 15px !important; 44 | outline: none !important; 45 | } 46 | .bt1:focus{ 47 | border: none; 48 | } 49 | button{ 50 | padding: 3px 10px !important; 51 | } 52 | .header{ 53 | padding: 10px; 54 | 55 | } 56 | .header .ant-btn{ 57 | box-shadow: none !important; 58 | background-color : white !important; 59 | color: orangered !important; 60 | border: 1px solid orangered !important; 61 | padding: 5px 15px !important; 62 | outline: none !important; 63 | } 64 | .content{ 65 | min-height: 90vh; 66 | 67 | } 68 | .footer{ 69 | background-color: aliceblue; 70 | padding: 10px; 71 | } 72 | 73 | 74 | /* this is just for ui purpose , no functionality is related */ 75 | .car{ 76 | border-radius: 5px; 77 | margin-top: 100px; 78 | height: 160px; 79 | transition: 0.3s; 80 | } 81 | .car:hover{ 82 | height :220px; 83 | } 84 | .car:hover > .car-content{ 85 | 86 | opacity: 1; 87 | transform : translateY(-40px) 88 | 89 | } 90 | .carimg{ 91 | height:180px; 92 | width: auto; 93 | border-radius: 5px; 94 | transform: translateY(-50px); 95 | } 96 | .car-content{ 97 | transform: translateY(-200px); 98 | opacity: 0; 99 | transition: 0.3s; 100 | } 101 | .login{ 102 | background-color: black; 103 | padding-top: 50px; 104 | min-height: 100vh; 105 | } 106 | .login label , .login h1{ 107 | color: white !important; 108 | opacity: 0.6; 109 | } 110 | .login-form{ 111 | background-color: #1F1F1F; 112 | } 113 | .login-form input{ 114 | background-color: #333333 !important; 115 | border : none !important; 116 | color: white; 117 | opacity: 0.5; 118 | } 119 | .login-logo{ 120 | position: absolute; 121 | left:0; 122 | right:0; 123 | top: 60%; 124 | bottom: 50%; 125 | transform: translateY(-50% , -50%); 126 | font-size:45px; 127 | opacity: 0.2 !important; 128 | 129 | 130 | } 131 | .login a{ 132 | color: white !important; 133 | opacity: 0.5; 134 | } 135 | 136 | .carimg2{ 137 | height: 400px; 138 | border-radius: 10px; 139 | width: auto; 140 | } 141 | 142 | svg{ 143 | height:20px !important; 144 | width : 20px !important; 145 | } 146 | a{ 147 | color: orangered !important; 148 | } -------------------------------------------------------------------------------- /client/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /client/src/pages/Home.js: -------------------------------------------------------------------------------- 1 | import React , {useState,useEffect} from 'react' 2 | import { useSelector , useDispatch } from 'react-redux' 3 | import DefaultLayout from '../components/DefaultLayout' 4 | import { getAllCars } from '../redux/actions/carsActions' 5 | import { Col, Row , Divider , DatePicker, Checkbox} from 'antd' 6 | import {Link} from 'react-router-dom' 7 | import Spinner from '../components/Spinner'; 8 | import moment from 'moment' 9 | const {RangePicker} = DatePicker 10 | function Home() { 11 | const {cars} = useSelector(state=>state.carsReducer) 12 | const {loading} = useSelector(state=>state.alertsReducer) 13 | const [totalCars , setTotalcars] = useState([]) 14 | const dispatch = useDispatch() 15 | 16 | 17 | useEffect(() => { 18 | dispatch(getAllCars()) 19 | }, []) 20 | 21 | useEffect(() => { 22 | 23 | setTotalcars(cars) 24 | 25 | }, [cars]) 26 | 27 | 28 | function setFilter(values){ 29 | 30 | var selectedFrom = moment(values[0] , 'MMM DD yyyy HH:mm') 31 | var selectedTo = moment(values[1] , 'MMM DD yyyy HH:mm') 32 | 33 | var temp=[] 34 | 35 | for(var car of cars){ 36 | 37 | if(car.bookedTimeSlots.length == 0){ 38 | temp.push(car) 39 | } 40 | else{ 41 | 42 | for(var booking of car.bookedTimeSlots) { 43 | 44 | if(selectedFrom.isBetween(booking.from , booking.to) || 45 | selectedTo.isBetween(booking.from , booking.to) || 46 | moment(booking.from).isBetween(selectedFrom , selectedTo) || 47 | moment(booking.to).isBetween(selectedFrom , selectedTo) 48 | ) 49 | { 50 | 51 | } 52 | else{ 53 | temp.push(car) 54 | } 55 | 56 | } 57 | 58 | } 59 | 60 | } 61 | 62 | 63 | setTotalcars(temp) 64 | 65 | 66 | } 67 | 68 | return ( 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | {loading == true && ()} 82 | 83 | 84 | 85 | 86 | 87 | {totalCars.map(car=>{ 88 | return 89 |
    90 | 91 | 92 |
    93 | 94 |
    95 |

    {car.name}

    96 |

    Rent Per Hour {car.rentPerHour} /-

    97 |
    98 | 99 |
    100 | 101 |
    102 | 103 |
    104 |
    105 | 106 | })} 107 | 108 |
    109 | 110 |
    111 | ) 112 | } 113 | 114 | export default Home 115 | -------------------------------------------------------------------------------- /client/src/pages/BookingCar.js: -------------------------------------------------------------------------------- 1 | import { Col, Row, Divider, DatePicker, Checkbox, Modal } from "antd"; 2 | import React, { useState, useEffect } from "react"; 3 | import { useSelector, useDispatch } from "react-redux"; 4 | import DefaultLayout from "../components/DefaultLayout"; 5 | import Spinner from "../components/Spinner"; 6 | import { getAllCars } from "../redux/actions/carsActions"; 7 | import moment from "moment"; 8 | import { bookCar } from "../redux/actions/bookingActions"; 9 | import StripeCheckout from "react-stripe-checkout"; 10 | import AOS from 'aos'; 11 | 12 | import 'aos/dist/aos.css'; // You can also use for styles 13 | const { RangePicker } = DatePicker; 14 | function BookingCar({ match }) { 15 | const { cars } = useSelector((state) => state.carsReducer); 16 | const { loading } = useSelector((state) => state.alertsReducer); 17 | const [car, setcar] = useState({}); 18 | const dispatch = useDispatch(); 19 | const [from, setFrom] = useState(); 20 | const [to, setTo] = useState(); 21 | const [totalHours, setTotalHours] = useState(0); 22 | const [driver, setdriver] = useState(false); 23 | const [totalAmount, setTotalAmount] = useState(0); 24 | const [showModal, setShowModal] = useState(false); 25 | 26 | useEffect(() => { 27 | if (cars.length == 0) { 28 | dispatch(getAllCars()); 29 | } else { 30 | setcar(cars.find((o) => o._id == match.params.carid)); 31 | } 32 | }, [cars]); 33 | 34 | useEffect(() => { 35 | setTotalAmount(totalHours * car.rentPerHour); 36 | if (driver) { 37 | setTotalAmount(totalAmount + 30 * totalHours); 38 | } 39 | }, [driver, totalHours]); 40 | 41 | function selectTimeSlots(values) { 42 | setFrom(moment(values[0]).format("MMM DD yyyy HH:mm")); 43 | setTo(moment(values[1]).format("MMM DD yyyy HH:mm")); 44 | 45 | setTotalHours(values[1].diff(values[0], "hours")); 46 | } 47 | 48 | 49 | 50 | function onToken(token){ 51 | const reqObj = { 52 | token, 53 | user: JSON.parse(localStorage.getItem("user"))._id, 54 | car: car._id, 55 | totalHours, 56 | totalAmount, 57 | driverRequired: driver, 58 | bookedTimeSlots: { 59 | from, 60 | to, 61 | }, 62 | }; 63 | 64 | dispatch(bookCar(reqObj)); 65 | } 66 | 67 | return ( 68 | 69 | {loading && } 70 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | Car Info 82 | 83 |
    84 |

    {car.name}

    85 |

    {car.rentPerHour} Rent Per hour /-

    86 |

    Fuel Type : {car.fuelType}

    87 |

    Max Persons : {car.capacity}

    88 |
    89 | 90 | 91 | Select Time Slots 92 | 93 | 98 |
    99 | 107 | {from && to && ( 108 |
    109 |

    110 | Total Hours : {totalHours} 111 |

    112 |

    113 | Rent Per Hour : {car.rentPerHour} 114 |

    115 | { 117 | if (e.target.checked) { 118 | setdriver(true); 119 | } else { 120 | setdriver(false); 121 | } 122 | }} 123 | > 124 | Driver Required 125 | 126 | 127 |

    Total Amount : {totalAmount}

    128 | 129 | 136 | 139 | 140 | 141 | 142 |
    143 | )} 144 | 145 | 146 | {car.name && ( 147 | 153 |
    154 | {car.bookedTimeSlots.map((slot) => { 155 | return ( 156 | 159 | ); 160 | })} 161 | 162 |
    163 | 171 |
    172 |
    173 |
    174 | )} 175 |
    176 |
    177 | ); 178 | } 179 | 180 | export default BookingCar; 181 | --------------------------------------------------------------------------------