Skip to content

Commit 594162b

Browse files
committed
Added the column to calculate the total nights of stay
1 parent b4aeabf commit 594162b

5 files changed

Lines changed: 34 additions & 15 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/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)