Skip to content

Commit 1afd169

Browse files
committed
started approvals table task
1 parent e7cdaf5 commit 1afd169

File tree

8 files changed

+1140
-11
lines changed

8 files changed

+1140
-11
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": ["@babel/preset-env", "@babel/preset-react"]
2+
"presets": ["@babel/preset-env", "@babel/preset-react"],
3+
"plugins": [["@babel/plugin-transform-runtime"]]
34
}

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@
1313
"prepare": "husky install"
1414
},
1515
"dependencies": {
16-
"@reduxjs/toolkit": "^1.8.1",
16+
"@babel/plugin-transform-runtime": "^7.18.2",
1717
"@emotion/react": "^11.9.0",
1818
"@emotion/styled": "^11.8.1",
1919
"@mui/material": "^5.8.0",
2020
"@mui/styled-engine-sc": "^5.8.0",
21+
"@mui/x-data-grid": "^5.11.1",
22+
"@reduxjs/toolkit": "^1.8.1",
23+
"axios": "^0.27.2",
2124
"prop-types": "^15.8.1",
2225
"react": "^18.1.0",
2326
"react-dom": "^18.1.0",
2427
"react-redux": "^8.0.1",
2528
"react-router-dom": "^6.3.0",
29+
"react-test-renderer": "^18.1.0",
30+
"react-toastify": "^9.0.1",
2631
"redux": "^4.2.0",
2732
"redux-persist": "^6.0.0",
28-
"react-test-renderer": "^18.1.0",
2933
"sass": "^1.51.0",
34+
"save-dev": "^0.0.1-security",
3035
"styled-components": "^5.3.5"
3136
},
3237
"devDependencies": {

src/App.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import React from 'react';
22
import { Route, Routes } from 'react-router-dom';
33
import Home from './pages/index';
4+
import { ToastContainer } from 'react-toastify';
5+
import 'react-toastify/dist/ReactToastify.css'
46
import Welcome from './components/Welcome';
57
import AboutPage from './components/about/About';
8+
import TripApproval from './components/tripApproval/tripApproval'
69

710
function App() {
811
return (
12+
<>
913
<Routes>
1014
<Route path="/" element={<Home />} />
1115
<Route path="welcome" element={<Welcome />} />
1216
<Route path="about" element={<AboutPage />} />
17+
<Route path="tripApproval" element={<TripApproval />} />
1318
</Routes>
19+
<ToastContainer/>
20+
</>
1421
);
1522
}
1623

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import axios from 'axios';
2+
3+
const token =
4+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjo0LCJlbWFpbCI6Im5kaWN1bmd1eWVzdGV2ZTRAZ21haWwuY29tIiwicm9sZUlkIjoyfSwidG9rZW5JZCI6MTY1MzkyMTAyNzQ4MywiaWF0IjoxNjUzOTIxMDI3LCJleHAiOjExNjUzOTIxMDI3fQ.77CQpRirhvPUhkNBBxs4XBmZ3rPRjs8M-2kLt0d1w-0';
5+
const config = {
6+
headers: { Authorization: `Bearer ${token}` },
7+
};
8+
9+
const tripId = 8;
10+
11+
export const approveRequest = async () => {
12+
try {
13+
const res = await axios.patch(
14+
`http://localhost:3000/api/trip/request/approve/${tripId}`,
15+
{ status: 'approved' },
16+
config
17+
);
18+
console.log('In the response');
19+
console.log(res.data.data.response);
20+
return res.data;
21+
} catch (error) {
22+
return error;
23+
}
24+
};
25+
export const rejectRequest = async (tripId) => {
26+
console.log('In the req');
27+
try {
28+
const res = await axios.patch(
29+
`http://localhost:3000/api/trip/request/approve/${tripId}`,
30+
{ status: 'rejected' },
31+
config
32+
);
33+
return res.data;
34+
} catch (error) {
35+
return error;
36+
}
37+
};
38+
39+
40+
41+
42+
43+
44+
45+
46+
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import React, {useState, useEffect} from 'react'
2+
import './tripApproval.scss'
3+
import { toast } from 'react-toastify'
4+
import { useNavigate } from 'react-router-dom'
5+
import axios from 'axios';
6+
import { approveRequest, rejectRequest } from '../tripApproval/trip'
7+
8+
9+
function Approval() {
10+
const [data, setData] = useState([]);
11+
const [myStatus, setmyStatus] = useState('pending');
12+
const [hasApproved, setHasApproved] = useState(false);
13+
const [hasRejected, setHasRejected] = useState(false);
14+
const [stat, setStat] = useState();
15+
const [message, setMessage] = useState('');
16+
const tripId = 10;
17+
18+
const approve = async () => {
19+
const res = await approveRequest(tripId);
20+
setHasApproved(true);
21+
setMessage(res.data);
22+
if (res.status === 200) {
23+
setHasApproved(true);
24+
setMessage(res.data);
25+
setTimeout(() => {
26+
setMessage('');
27+
setStat('approved');
28+
}, 3000);
29+
30+
}
31+
};
32+
33+
const reject = async () => {
34+
const res = await rejectRequest(tripId);
35+
setHasRejected(true);
36+
setMessage(res.data);
37+
if (res.status === 200) {
38+
setHasRejected(true);
39+
setMessage(res.data);
40+
setTimeout(() => {
41+
setMessage('');
42+
setStat('rejected');
43+
}, 3000);
44+
45+
}
46+
47+
}
48+
49+
useEffect(() => {
50+
const renderState = async () => {
51+
const config = {
52+
headers: {
53+
authorization:
54+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjo0LCJlbWFpbCI6Im5kaWN1bmd1eWVzdGV2ZTRAZ21haWwuY29tIiwicm9sZUlkIjoyfSwidG9rZW5JZCI6MTY1MzkyMTAyNzQ4MywiaWF0IjoxNjUzOTIxMDI3LCJleHAiOjExNjUzOTIxMDI3fQ.77CQpRirhvPUhkNBBxs4XBmZ3rPRjs8M-2kLt0d1w-0',
55+
},
56+
};
57+
const response = await axios.get(
58+
`http://localhost:3000/api/trip/request/${tripId}/manager`,
59+
config
60+
);
61+
setData([response.data.response]);
62+
};
63+
renderState();
64+
}, []);
65+
66+
67+
console.log('This is response ---->>>>>>', data);
68+
69+
const navigate = useNavigate()
70+
71+
72+
return (
73+
74+
75+
76+
<div className='approvalPage'>
77+
78+
{ data.map((trips) => {
79+
{
80+
return (
81+
<div key={ trips.id }>
82+
<h1>Trip Request Approval</h1>
83+
<h2 className='requesterInformation'>Requester Information</h2>
84+
<p>Names: {trips.requester.firstName} {trips.requester.lastName} </p>
85+
<p>Email: {trips.requester.email}</p>
86+
<h2 className='tripInformation'>Trip Information</h2>
87+
<p>Accommodation: { trips.Accommodation.name }</p>
88+
<p>Departure place: { trips.departurePlace.city } , { trips.departurePlace.Country.name }</p>
89+
<p>Destination place: { trips.Destination.city } , { trips.Destination.Country.name }</p>
90+
<p>Departure date: {trips.departureDate}</p>
91+
<p>Return date: {trips.returnDate}</p>
92+
<p>Travel reason: { trips.travel_reason }</p>
93+
<div className="decide">
94+
<button className="approve" onClick={approve}>Approve</button>
95+
<button className="reject" onClick={reject}>Reject</button>
96+
</div>
97+
98+
</div>
99+
);}
100+
})}
101+
</div>
102+
)
103+
}
104+
export default Approval;
105+
106+
107+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@100;300;400;500;700;900&display=swap");
2+
3+
$mainColor: #64b2bc;
4+
5+
div.approvalPage{
6+
background-color: rgb(124, 122, 122);
7+
font-family: "Outfit", sans-serif;
8+
text-align: center;
9+
color: black;
10+
display: flex;
11+
flex-direction: column;
12+
justify-content: center;
13+
margin: auto;
14+
width: 500px;
15+
border-radius: 5px;
16+
17+
h1{
18+
border-bottom: 10px solid $mainColor;
19+
padding-bottom: 20px;
20+
font-weight: bolder;
21+
}
22+
23+
button{
24+
background-color: $mainColor;
25+
padding: 10px 40px 10px;
26+
border: 1px solid $mainColor;
27+
border-radius: 5px;
28+
transition: all 1s;
29+
}
30+
31+
button:hover{
32+
color: white;
33+
transform: scale(1.2,1.2);
34+
cursor: pointer;
35+
font-weight: bolder;
36+
}
37+
38+
button.reject{
39+
background-color: rgb(192, 18, 18);
40+
border: 1px solid rgb(192, 18, 18);
41+
}
42+
43+
button.viewProfile{
44+
margin: 30px 150px 30px;
45+
}
46+
47+
div.decide{
48+
display: flex;
49+
justify-content: space-around;
50+
margin-top: 30px;
51+
padding-bottom: 30px;
52+
}
53+
54+
p{
55+
line-height: 5px;
56+
}
57+
58+
h2.tripInformation{
59+
border-top: 10px solid $mainColor;
60+
padding-top: 20px;
61+
}
62+
}

0 commit comments

Comments
 (0)