Skip to content

Commit

Permalink
changed styling for docker-render automation test
Browse files Browse the repository at this point in the history
  • Loading branch information
vokarl committed Aug 20, 2024
1 parent b3492cb commit aa69fce
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
100 changes: 100 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.4",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
47 changes: 47 additions & 0 deletions frontend/src/components/GetGroceriesById.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {Product} from "../models/product.tsx";
import {ChangeEvent, FormEvent, useState} from "react";
import ProductCard from "./ProductCard.tsx";


type GetGroceriesByIdProps = {
products: Product[],

}

export default function GetGroceriesById(props: Readonly<GetGroceriesByIdProps>){
const [searchText, setSearchText] = useState("");
const [submittedText, setSubmittedText]=useState("");

const handleSubmit =(event: FormEvent<HTMLFormElement>)=>{
event.preventDefault();
setSubmittedText(searchText);
}

const filteredProducts : Product[] = submittedText ? props.products.filter((product:Product) => product.name.toLowerCase().includes(submittedText.toLowerCase())):[];

const noProductsMessage = submittedText && filteredProducts.length === 0 ? (
<p className="no-products-found">No products found</p>
) : null;

return (
<div className="search-card">
<form onSubmit={handleSubmit}>
<input
type="text"
value={searchText}
onChange={(e: ChangeEvent<HTMLInputElement>) => setSearchText(e.target.value)}
placeholder="Search for a Product"
/>
<button type="submit">Search</button>
</form>
{submittedText && filteredProducts.length > 0 ? (
<div className="product-by-id">
<div>Found article(s):</div>
{filteredProducts.map(product => (
<ProductCard key={product.id} product={product} />
))}
</div>
) : noProductsMessage}
</div>
);
}
16 changes: 16 additions & 0 deletions frontend/src/components/ProductCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Product } from "../models/product.tsx";

type ProductCardProps = {
product: Product;
};

export default function ProductCard(props: Readonly<ProductCardProps>) {
return (
<div className="product-card">
<div className="product-card-info">
<h3>{props.product.name}</h3>
<p>Menge: {props.product.amount}</p>
</div>
</div>
);
}

0 comments on commit aa69fce

Please sign in to comment.