forked from CodeYourFuture/React-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from areebsattar/main
updated
- Loading branch information
Showing
10 changed files
with
151 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,6 @@ module.exports = { | |
"warn", | ||
{ allowConstantExport: true }, | ||
], | ||
"react/prop-types": "off", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
function CustomerProfile({ id }) { | ||
const [customerProfileData, setCustomerProfileData] = useState(null); | ||
|
||
useEffect(() => { | ||
fetch(`https://cyf-hotel-api.netlify.app/customers/${id}`) | ||
.then((res) => res.json()) | ||
.then((data) => setCustomerProfileData(data)) | ||
.catch((error) => | ||
console.error("Error fetching customer profile:", error) | ||
); | ||
}, [id]); | ||
|
||
if (!customerProfileData) { | ||
return ( | ||
<tr className="customer-row"> | ||
<td colSpan={2}>Loading...</td> | ||
</tr> | ||
); | ||
} | ||
return ( | ||
<tr className="customer-row"> | ||
<td colSpan={2}>{customerProfileData.phoneNumber}</td> | ||
<td colSpan={2} className={customerProfileData.vip ? "vip-customer": ""}> | ||
{customerProfileData.vip ? `VIP Customer`: `Regular Customer`} | ||
</td> | ||
<td>ID: {customerProfileData.id}</td> | ||
</tr> | ||
); | ||
} | ||
|
||
export default CustomerProfile; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import CustomerProfile from "./CustomerProfile"; | ||
|
||
describe("CustomerProfile", () => { | ||
it("renders loading state initially", () => { | ||
render(<CustomerProfile id={1} />); | ||
const loadingText = screen.getByText("Loading..."); | ||
expect(loadingText).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders customer profile after data is fetched", async () => { | ||
global.fetch = () => | ||
Promise.resolve({ | ||
json: async () => ({ | ||
id: 1, | ||
phoneNumber: "+44 1632 960185", | ||
vip: true, | ||
}), | ||
}); | ||
|
||
render(<CustomerProfile id={1} />); | ||
|
||
await screen.findByText("+44 1632 960185"); | ||
|
||
const phoneNumber = screen.getByText("+44 1632 960185"); | ||
expect(phoneNumber).toBeInTheDocument(); | ||
expect(screen.getByText("VIP Customer")).toBeInTheDocument(); | ||
expect(screen.getByText("ID: 1")).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import React from "react"; | ||
import "./Footer.scss" | ||
import "./Footer.scss"; | ||
|
||
export default function Footer(props) { | ||
return ( | ||
<> | ||
<footer> | ||
<ul> | ||
{props.details.map((detail, id) => ( | ||
<li key={id}>{detail}</li> | ||
))} | ||
</ul> | ||
</footer> | ||
<ul> | ||
{props.details.map((detail, id) => ( | ||
<li key={id}>{detail}</li> | ||
))} | ||
</ul> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,18 @@ | ||
import "./SearchResult.scss"; | ||
import TableBody from "./TableBody"; | ||
import TableHead from "./TableHead"; | ||
import dayjs from "dayjs"; | ||
|
||
function SearchResult(props) { | ||
const Bookings = props.results; | ||
import CustomerProfile from "../CustomerProfile/CustomerProfile"; | ||
import Table from "./Table"; | ||
|
||
|
||
|
||
function SearchResult() { | ||
|
||
|
||
return ( | ||
<table> | ||
<thead> | ||
<TableHead /> | ||
</thead> | ||
<tbody> | ||
{Bookings.map((book) => { | ||
const stayNightsTotal = dayjs(book.checkOutDate).diff( | ||
dayjs(book.checkInDate), | ||
"day" | ||
); | ||
return ( | ||
<TableBody | ||
key={book.id} | ||
id={book.id} | ||
title={book.title} | ||
firstName={book.firstName} | ||
surName={book.surname} | ||
email={book.email} | ||
roomId={book.roomId} | ||
checkInDate={book.checkInDate} | ||
checkOutDate={book.checkOutDate} | ||
stayNights={stayNightsTotal} | ||
/> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
<> | ||
<Table /> | ||
<CustomerProfile /> | ||
</> | ||
); | ||
} | ||
export default SearchResult; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import TableBody from "./TableBody"; | ||
import TableHead from "./TableHead"; | ||
import dayjs from "dayjs"; | ||
import FakeBookings from "@/data/fakeBookings.json"; | ||
|
||
function Table() { | ||
const Bookings = FakeBookings; | ||
return ( | ||
<> | ||
<table> | ||
<thead> | ||
<TableHead /> | ||
</thead> | ||
<tbody> | ||
{Bookings.map((book) => { | ||
const stayNightsTotal = dayjs(book.checkOutDate).diff( | ||
dayjs(book.checkInDate), | ||
"day" | ||
); | ||
return ( | ||
<TableBody | ||
key={book.id} | ||
id={book.id} | ||
title={book.title} | ||
firstName={book.firstName} | ||
surName={book.surname} | ||
email={book.email} | ||
roomId={book.roomId} | ||
checkInDate={book.checkInDate} | ||
checkOutDate={book.checkOutDate} | ||
stayNights={stayNightsTotal} | ||
/> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
</> | ||
); | ||
} | ||
|
||
export default Table; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters