Arquisoft / dede_es5a

ArquiSocks: la mayor variedad de calcetines. Disponible tanto en Heroku como en Azure: https://dede-es5a.herokuapp.com/ http://20.228.137.74:3000/
2 stars 0 forks source link

Warnings selección de talla #165

Closed UO250825 closed 2 years ago

UO250825 commented 2 years ago

He estado intentando arreglar este problema, pero no consigo eliminar los warnings.

imagen

UO250825 commented 2 years ago

export default function ImgMediaCard({ product, handleAddToCart }: Props) { const [size, setSize] = React.useState( product.disponibility.find((s) => s.size.toString() === '')?.size, )

const [available, setAvailable] = React.useState(true)

product.disponibility.sort((n1, n2) => n1.size - n2.size)

const sizesList = product.disponibility.map((s) => (

{s.size}

))

const handleSizeChange = (event: SelectChangeEvent) => { setSize((event.target.value as unknown) as number) var currentSize = product.disponibility.find((s) => s.size === size)

if (currentSize === undefined) {
  throw new TypeError('The value was promised to always be there!')
}

if (currentSize?.stock > 0) {
  setAvailable(true)
} else {
  setAvailable(false)
}

}

const [addable, setAddable] = React.useState(false)

const handleClick = () => { const addToCartProduct = { name: product.name, price: product.price, size: size as number, quantity: 0, image: product.image, _id: product._id, } handleAddToCart(addToCartProduct) setAddable(true) }

const handleClose = ( event?: React.SyntheticEvent | Event, reason?: string, ) => { if (reason === 'clickaway') { return } setAddable(false) }

const availabilityLabel = () => { if (available) { return } return <CancelIcon style={{ color: 'red' }} /> }

return (

{product.name.toLocaleUpperCase()} {product.brand} {product.description} Stock {availabilityLabel()} {product.price} € Size {product.name}, size {size} added to cart!

) }