Skip to content

Commit

Permalink
Merge pull request #40 from the-collab-lab/sm-view-item-details
Browse files Browse the repository at this point in the history
View item details - issue #21
  • Loading branch information
sar-mko authored Sep 28, 2024
2 parents c46af99 + bf0762d commit ec4194d
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/components/ListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import './ListItem.css';
import { updateItem, deleteItem } from '../api';

export function ListItem({ item }) {
const { name, dateLastPurchased, id } = item;
const { name, dateLastPurchased, dateNextPurchased, totalPurchases, id } =
item;
const [checked, setChecked] = useState(false);
const [isActive, setIsActive] = useState(false);

const handleDelete = async () => {
try {
Expand Down Expand Up @@ -57,8 +59,31 @@ export function ListItem({ item }) {
onChange={handleChange}
disabled={checked}
/>
{name}
<h2 style={{ fontSize: '20px' }}>{name}</h2>

<button onClick={handleDelete}>Delete</button>
<button onClick={() => setIsActive(!isActive)}>
View Purchase Details
</button>

<div style={{ display: isActive ? 'block' : 'none' }}>
<ul style={{ fontSize: '15px' }}>
<li>
Last Purchase:
<span>
{' '}
{dateLastPurchased
? dateLastPurchased.toDate().toDateString()
: 'N/A'}
</span>
</li>
<li>
Next Purchase:
<span> {dateNextPurchased?.toDate().toDateString()}</span>
</li>
<li>Total Purchases: {totalPurchases}</li>
</ul>
</div>
</li>
);
}

0 comments on commit ec4194d

Please sign in to comment.