File tree Expand file tree Collapse file tree
src/components/SearchResult Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414 "test:watch" : " vitest"
1515 },
1616 "dependencies" : {
17+ "dayjs" : " ^1.11.10" ,
1718 "react" : " ^18.2.0" ,
1819 "react-dom" : " ^18.2.0"
1920 },
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import "./SearchResult.scss";
22import FakeBookings from "@/data/fakeBookings.json" ;
33import TableBody from "./TableBody" ;
44import TableHead from "./TableHead" ;
5+ import dayjs from "dayjs" ;
6+
57const Bookings = FakeBookings ;
68function 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 ) ;
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments