1 | import React from "react";
|
---|
2 | import { useLocation, useNavigate } from 'react-router-dom'
|
---|
3 | import CenteredContainer from "../UtilComponents/CenteredContainer";
|
---|
4 | import axios from "../../custom-axios/axios";
|
---|
5 | import '../UtilComponents/App.css'
|
---|
6 |
|
---|
7 | const PayDrive = (props) => {
|
---|
8 | const location = useLocation();
|
---|
9 | const navigate = useNavigate();
|
---|
10 |
|
---|
11 | const payDrive = async () => {
|
---|
12 | const driveId = location.state.driveId
|
---|
13 | const totalPriceToPay = location.state.totalSumToPay
|
---|
14 | const response = await axios.post(`/drive/pay/${driveId}`, null, { params: {
|
---|
15 | totalPriceToPay
|
---|
16 | }
|
---|
17 | });
|
---|
18 | const paymentId = response.data;
|
---|
19 | navigate("/tip-driver", {state: {paymentId: paymentId}})
|
---|
20 | }
|
---|
21 |
|
---|
22 | return (
|
---|
23 | <CenteredContainer>
|
---|
24 | <div className="card text-center">
|
---|
25 | <h4>You have travelled <br></br>
|
---|
26 | {location.state.kmTravelled} km <br></br>
|
---|
27 | with a price per km <br></br>
|
---|
28 | {location.state.driverPricePerKm} MKD</h4>
|
---|
29 | <br></br>
|
---|
30 | <h3 style={{color: "green"}}>Your total price to pay is <br></br>
|
---|
31 | {(Math.round(location.state.totalSumToPay * 100) / 100).toFixed(2)} MKD</h3>
|
---|
32 | <hr></hr>
|
---|
33 | <p style={{textAlign: 'center'}}>
|
---|
34 | <a type="submit" className="myButton btn btn-primary" style={{backgroundColor: "darkcyan", borderColor: 'black', color: 'white', width: '90%'}} onClick={() => payDrive()}>Pay Drive</a>
|
---|
35 | </p>
|
---|
36 | </div>
|
---|
37 | </CenteredContainer>
|
---|
38 | )
|
---|
39 | }
|
---|
40 |
|
---|
41 | export default PayDrive; |
---|