Skip to content

Commit 766836a

Browse files
authored
Merge pull request #35 from areebsattar/FeatureCalculateDuration
NW-6 | AREEB-SATTAR | REACT| React Module Project - FeatureCalculateDuration | WEEK-1
2 parents c75143d + 48b962f commit 766836a

9 files changed

Lines changed: 56 additions & 23 deletions

File tree

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"test:watch": "vitest"
1515
},
1616
"dependencies": {
17+
"dayjs": "^1.11.10",
1718
"react": "^18.2.0",
1819
"react-dom": "^18.2.0"
1920
},

src/components/App/App.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import Bookings from "@/components/Bookings/Bookings.jsx";
22
import "./App.scss";
3-
4-
import Deck from "../Deck/Deck";
5-
63
import Footer from "../Footer/Footer";
74
import Deck from "../Deck/Deck";
85
import AppHeader from "../AppHeader/AppHeader";
6+
97
const App = () => (
108
<div className="app">
11-
<header className="app__header">
12-
<h1 className="app__heading">CYF Hotel</h1>
13-
</header>
14-
<AppHeader />
9+
<div className="header">
10+
<header className="app__header">
11+
<h1 className="app__heading">CYF Hotel</h1>
12+
</header>
13+
<AppHeader />
14+
</div>
1515
<Bookings />
1616

1717
<Deck />

src/components/App/App.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
.app__heading {
1616
margin: 0;
17+
margin-top: 30%;
1718
}
1819

1920
.footer {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import Logo from "@/assets/spa-logo.png";
22
import "./AppHeader.scss";
3-
const AppHeader = () => <img src={Logo}></img>;
3+
const AppHeader = () => <img className="LogoImg" src={Logo}></img>;
44
export default AppHeader;

src/components/AppHeader/AppHeader.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@
77
max-width: 100px;
88
}
99
}
10+
11+
.header {
12+
margin-right: 35%;
13+
margin-left: 35%;
14+
display: flex;
15+
flex-direction: row-reverse;
16+
justify-content: space-evenly;
17+
}
18+
19+
.LogoImg {
20+
height: 150px;
21+
width: 150px;
22+
}

src/components/SearchResult/SearchResult.jsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import "./SearchResult.scss";
22
import FakeBookings from "@/data/fakeBookings.json";
33
import TableBody from "./TableBody";
44
import TableHead from "./TableHead";
5+
import dayjs from "dayjs";
6+
57
const Bookings = FakeBookings;
68
function SearchResult() {
79
return (
@@ -10,21 +12,28 @@ function SearchResult() {
1012
<TableHead />
1113
</thead>
1214
<tbody>
13-
{Bookings.map((book) => (
14-
<>
15-
<TableBody
16-
key={book.id}
17-
id={book.id}
18-
title={book.title}
19-
firstName={book.firstName}
20-
surName={book.surname}
21-
email={book.email}
22-
roomId={book.roomId}
23-
checkInDate={book.checkInDate}
24-
checkOutDate={book.checkOutDate}
25-
/>
26-
</>
27-
))}
15+
{Bookings.map((book) => {
16+
const stayNightsTotal = dayjs(book.checkOutDate).diff(
17+
dayjs(book.checkInDate),
18+
"day"
19+
);
20+
return (
21+
<>
22+
<TableBody
23+
key={book.id}
24+
id={book.id}
25+
title={book.title}
26+
firstName={book.firstName}
27+
surName={book.surname}
28+
email={book.email}
29+
roomId={book.roomId}
30+
checkInDate={book.checkInDate}
31+
checkOutDate={book.checkOutDate}
32+
stayNights={stayNightsTotal}
33+
/>
34+
</>
35+
);
36+
})}
2837
</tbody>
2938
</table>
3039
);

src/components/SearchResult/TableBody.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function TableBody(props) {
1111
roomId,
1212
checkInDate,
1313
checkOutDate,
14+
stayNights,
1415
} = props;
1516
return (
1617
<>
@@ -23,6 +24,7 @@ function TableBody(props) {
2324
<td>{roomId}</td>
2425
<td>{checkInDate}</td>
2526
<td>{checkOutDate}</td>
27+
<td>{stayNights}</td>
2628
</tr>
2729
</>
2830
);

src/components/SearchResult/TableHead.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function TableHead() {
1010
<th>Room id</th>
1111
<th>Check in date</th>
1212
<th>Check out date</th>
13+
<th>Total Nights to Stay</th>
1314
</tr>
1415
</>
1516
);

0 commit comments

Comments
 (0)