feat: Add Order Lines

This commit is contained in:
2026-01-23 14:43:31 -05:00
parent fbec47f3b4
commit a1af01e463
10 changed files with 153 additions and 48 deletions

View File

@@ -23,14 +23,17 @@
top: 2rem; /* se queda pegada al hacer scroll */ top: 2rem; /* se queda pegada al hacer scroll */
height: fit-content; /* sólo el alto que necesite su contenido */ height: fit-content; /* sólo el alto que necesite su contenido */
background: rgba(255, 255, 255, 0.9); background: rgba(255, 255, 255, 0.9);
border: 1px solid darkviolet; border: 1px solid snow;
border-radius: 24px; border-radius: 24px;
box-shadow: 0 48px 56px rgba(0, 0, 0, 0.1); box-shadow: 0 48px 56px rgba(0, 0, 0, 0.1);
padding: 1.5rem; padding: 1.5rem;
transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
cursor: pointer;
} }
.order:hover { .order:hover {
border: 3px dotted darkviolet; transform: translateY(-8px) scale(1.02);
box-shadow: 0 36px 64px rgba(0, 0, 0, 0.15);
} }
/* Responsive: en pantallas estrechas se apilan */ /* Responsive: en pantallas estrechas se apilan */

View File

@@ -1,12 +1,13 @@
import { ProductCards } from "./components"; import { ProductCards } from "./components";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import type { Product } from "../../types"; import type { Product, ProductLine } from "../../types";
import Order from "./components/order/Order"; import Order from "./components/order/Order";
import styles from "./Catalog.module.css"; import styles from "./Catalog.module.css";
const Catalog = () => { const Catalog = () => {
const [products, setProducts] = useState<Product[]>([]); const [products, setProducts] = useState<Product[]>([]);
const [productLines, setProductLines] = useState<ProductLine[] | []>([]);
useEffect(() => { useEffect(() => {
async function fetchProducts(){ async function fetchProducts(){
@@ -21,14 +22,25 @@ const Catalog = () => {
fetchProducts(); fetchProducts();
}, []); }, []);
function addProductLine(product: Product, quantity: number){
const newProductLine: ProductLine = {
id: Date.now(),
product: product,
quantity: quantity,
unitPrice: product.price,
totalAmount: quantity * product.price,
};
setProductLines([...productLines, newProductLine]);
}
return ( return (
<div className={styles.layout}> <div className={styles.layout}>
<section className={styles.catalog}> <section className={styles.catalog}>
<ProductCards products={products}/> <ProductCards products={products} addProductLine={addProductLine}/>
</section> </section>
<aside className={styles.order}> <aside className={styles.order}>
<Order/> <Order productLines={productLines}/>
</aside> </aside>
</div> </div>
) )

View File

@@ -1,6 +1,13 @@
import OrderLine from './components/order_line/OrderLine';
import styles from './Order.module.css' import styles from './Order.module.css'
import type { ProductLine } from '../../../../types.ts'
type OrderProps = {
productLines: ProductLine[];
}
const Order = ({productLines = []} : OrderProps) => {
const Order = () => {
return ( return (
<div className={styles.container}> <div className={styles.container}>
<h1>Compra #5428</h1> <h1>Compra #5428</h1>
@@ -11,16 +18,16 @@ const Order = () => {
</div> </div>
<div> <div>
<p>Tomate Orgánico 500g 12000</p> { productLines.length > 0 ? (
<p>Espinaca Orgánica 250g 8500</p>
<p>Zanahoria Orgánica 1Kg 9500</p> productLines.map((line) => {
<p>Palta Orgánica 1U 4500</p> return <OrderLine key={line.id} line={line}/>
<p>Banano Orgánico 1Kg 5500</p> }
<p>Mango Orgánico 1U 3500</p>
<p>Fresa Orgánica 250g 12000</p> )) : (
<p>Pimentón Orgánico 500g 10500</p> <p>No hay productos en el pedido</p>
<p>Cebolla Orgánica 500g 5500</p> )
<p>Manzana Orgánica 500g 8000</p> }
</div> </div>
<div> <div>
@@ -28,10 +35,15 @@ const Order = () => {
<span>Domicilio: $10.000 COP</span><br/> <span>Domicilio: $10.000 COP</span><br/>
<span>Total: $210.000 COP</span> <span>Total: $210.000 COP</span>
</div> </div>
<div>
<label>Comentario:</label> <label>Comentario:</label>
<input type="text"/><br/> <input type="text"/>
</div>
<div>
<button>Pagar</button> <button>Pagar</button>
<button>Credito</button>
</div>
</div> </div>
) )
} }

View File

@@ -0,0 +1,20 @@
import type { ProductLine } from '../../../../../../types.ts'
type OrderLineProps = {
line: ProductLine;
}
const OrderLine = ( {line} : OrderLineProps ) => {
const { product, quantity, unitPrice, totalAmount } = line;
return (
<>
<p>{product.name} {quantity}{product.uomSymbol} {unitPrice} {totalAmount} <button>Eliminar</button></p>
</>
)
}
export default OrderLine;

View File

@@ -2,7 +2,7 @@
.container { .container {
display: flex; display: flex;
justify-content: center; justify-content: center;
border: 1px solid darkviolet; border: 1px solid snow;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
border-radius: 32px; border-radius: 32px;

View File

@@ -5,23 +5,15 @@ import styles from "./ProductCards.module.css"
type ProductCardProps = { type ProductCardProps = {
products: Product[]; products: Product[];
addProductLine: (product: Product, quantity: number) => void;
} }
const ProductCards = ({ products } : ProductCardProps) => { const ProductCards = ({ products, addProductLine } : ProductCardProps) => {
return ( return (
<div className={styles.container}> <div className={styles.container}>
{ products.map((product) => { { products.map((product) => {
return ( return (
<div key={product.id}> <Card key={product.id} product={product} addProductLine={addProductLine}/>
<Card
image={product.image}
name={product.name}
price={product.price}
description={ product.description}
cardId={product.id}
/>
</div>
) )
}) } }) }
</div> </div>

View File

@@ -6,26 +6,30 @@
border: 3px solid snow; border: 3px solid snow;
box-shadow: 0 24px 56px rgba(0, 0, 0, 0.1); box-shadow: 0 24px 56px rgba(0, 0, 0, 0.1);
width: 325px; width: 325px;
height: 500px; height: 530px;
padding: 10px; padding: 10px;
margin: 8px; margin: 8px;
transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
cursor: pointer;
} }
.container:hover { .container:hover {
border: 3px dotted pink; /* border: 3px dotted black; */
transform: translateY(-8px) scale(1.02);
box-shadow: 0 36px 64px rgba(0, 0, 0, 0.15);
} }
.button_container { .button_container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 16px gap: 8px
} }
.button_container button { .button_container button {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
font-weight: bold; font-weight: bold;
background-color: #667eea; background-color: #F54A27;
color: white; color: white;
border: none; border: none;
border-radius: 8px; border-radius: 8px;
@@ -37,5 +41,45 @@
} }
.button_container button:hover { .button_container button:hover {
background-color: #5a6fd8; background-color: #FF907D;
}
.product_name {
font-size: 1.5rem;
font-weight: 600;
color: #F54A27;
margin: 4px 0 8px 0;
text-align: center;
letter-spacing: -0.5px;
}
.price {
font-size: 1.8rem;
font-weight: 700;
color: #F54A27; /* Mismo color que tus botones para consistencia */
margin: 8px 0 16px 0;
text-align: center;
background: linear-gradient(120deg, #F54A27 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.description {
font-size: 0.95rem;
/* color: #666; */
text-align: center;
margin: 16px 0;
line-height: 1.4;
flex-grow: 1; /* Para que ocupe el espacio disponible */
}
.details {
margin: 8px 0 16px;
text-align: center;
font-size: 1rem;
/* color: #666; */
cursor: pointer;
} }

View File

@@ -1,25 +1,36 @@
import { useState } from 'react';
import type { Product } from '../../../../../../types';
import styles from './Card.module.css' import styles from './Card.module.css'
type CardProps = { type CardProps = {
image: string; product: Product;
name: string; addProductLine: (product: Product, quantity: number) => void;
price: number;
description: string;
cardId: number
} }
const Card = ({ image, name, price, description, cardId } : CardProps) => { const Card = ({ product, addProductLine } : CardProps) => {
const {id, name, price, description, image } = product;
const [quantity, setQuantity] = useState<number>(0);
return ( return (
<div className={styles.container} key={cardId}> <div className={styles.container} key={id}>
<img src={`${image}`} alt="Imagen"/> <p className={styles.product_name}>{name}</p>
<p>{name}</p>
<p>{price}</p> <img src={`${image}`} alt={`${description}`}/>
<p>{description}</p> <p className={styles.price}>${price} COP</p>
<details className={styles.details}>
<summary>Ver descripción</summary>
<p className={styles.description}>{description}</p>
</details>
<input type='number' value={quantity} onChange={
(event) => setQuantity(Number(event.target.value))
}/>
<div className={styles.button_container}> <div className={styles.button_container}>
<button>Conocer Origen</button> <button>Conocer Origen</button>
<button>Agregar</button> <button onClick={() => addProductLine(product, quantity)}>Agregar</button>
</div> </div>
</div> </div>
) )

View File

@@ -4,4 +4,15 @@ export type Product = {
price: number; price: number;
description: string; description: string;
image: string; image: string;
uomId: number;
uomSymbol: string;
unitPrice: number;
}; };
export type ProductLine = {
id: number;
product: Product;
quantity: number;
unitPrice: number;
totalAmount: number;
}