Skip to content

Commit

Permalink
TableBody components props improved, CustomerProfile component added
Browse files Browse the repository at this point in the history
  • Loading branch information
fikretellek committed Mar 13, 2024
1 parent 72cfd36 commit e02e398
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
45 changes: 21 additions & 24 deletions src/components/SearchResults/SearchResults.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
// SearchResults.jsx
import React from "react";
import React, { useState } from "react";
import TableHead from "./TableHead";
import TableBody from "./TableBody";
import dayjs from "dayjs";
import CustomerProfile from "../CustomerProfile/CustomerProfile";

const SearchResults = ({ results }) => {
const SearchResults = ({ bookings }) => {
const [selectedProfile, setSelectedProfile] = useState(null);

function handleShowProfile(e) {
setSelectedProfile(Number(e.target.value));
}
return (
<table>
<thead>
<TableHead />
</thead>
<tbody>
{results.map((booking) => (
<TableBody
key={booking.id}
id={booking.id}
title={booking.title}
firstName={booking.firstName}
surName={booking.surname}
nights={dayjs(booking.checkOutDate)
.diff(dayjs(booking.checkInDate), "days")
.toString()
.padStart(2, "0")}
email={booking.email}
/>
))}
</tbody>
</table>
<>
<table>
<thead>
<TableHead />
</thead>
<tbody>
{bookings.map((booking) => (
<TableBody key={booking.id} booking={booking} handleShowProfile={handleShowProfile} />
))}
</tbody>
</table>
<CustomerProfile id={selectedProfile} bookings={bookings} />
</>
);
};

Expand Down
26 changes: 19 additions & 7 deletions src/components/SearchResults/TableBody.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import React from "react";
import dayjs from "dayjs";

const TableBody = ({ id, title, firstName, surName, email, nights }) => {
const TableBody = ({ booking, handleShowProfile }) => {
const testid = "showProfileButton" + booking.id;
return (
<tr>
<td>{id}</td>
<td>{title}</td>
<td>{firstName}</td>
<td>{surName}</td>
<td>{nights}</td>
<td>{email}</td>
<td>{booking.id}</td>
<td>{booking.title}</td>
<td>{booking.firstName}</td>
<td>{booking.surname}</td>
<td>
{dayjs(booking.checkOutDate)
.diff(dayjs(booking.checkInDate), "days")
.toString()
.padStart(2, "0")}
</td>
<td>{booking.email}</td>
<td>
<button data-testid={testid} value={booking.id} onClick={handleShowProfile}>
Show Profile
</button>
</td>
</tr>
);
};
Expand Down

0 comments on commit e02e398

Please sign in to comment.