diff --git a/pruebas/02-bazar-universal/aiv4ro/src/app/items/[id]/page.tsx b/pruebas/02-bazar-universal/aiv4ro/src/app/items/[id]/page.tsx new file mode 100644 index 000000000..9fb89c07c --- /dev/null +++ b/pruebas/02-bazar-universal/aiv4ro/src/app/items/[id]/page.tsx @@ -0,0 +1,47 @@ +import { ProductPrice } from '@/components/ProductPrice' +import { ProductRating } from '@/components/ProductRating' +import { getProduct } from '@/services/get-product' + +export default async function Page ({ + params +}: { + params: { + id: string + } +}) { + const product = await getProduct({ id: params.id }) + + const mainImage = product.images[0] + const otherImages = product.images.slice(1) + + return ( +
+
+ + {product.title} + +
+ {otherImages.map((image, index) => ( + + {product.title} + + ))} +
+
+

{product.title} - {product.brand}

+
+
+ + {product.stock} disponibles +
+ +
+

+ {product.description} +

+ +
+ ) +} diff --git a/pruebas/02-bazar-universal/aiv4ro/src/app/items/page.tsx b/pruebas/02-bazar-universal/aiv4ro/src/app/items/page.tsx index 035357b39..cf99368a5 100644 --- a/pruebas/02-bazar-universal/aiv4ro/src/app/items/page.tsx +++ b/pruebas/02-bazar-universal/aiv4ro/src/app/items/page.tsx @@ -1,16 +1,12 @@ -'use client' - import { SearchResults } from '@/components/SearchResults' -import { useSearchParams } from 'next/navigation' import { Suspense } from 'react' -export default function Page () { - const searchParams = useSearchParams() - const search = searchParams.get('search') - - if (search === null) { - throw new Error('Search param is required') - } +export default function Page ({ + searchParams +}: { + searchParams?: { [key: string]: string | string[] | undefined } +}) { + const search = typeof searchParams?.search === 'string' ? searchParams.search : '' return ( Loading...

}> diff --git a/pruebas/02-bazar-universal/aiv4ro/src/components/SearchResults.tsx b/pruebas/02-bazar-universal/aiv4ro/src/components/SearchResults.tsx index 4adc89111..f0aa0ba2a 100644 --- a/pruebas/02-bazar-universal/aiv4ro/src/components/SearchResults.tsx +++ b/pruebas/02-bazar-universal/aiv4ro/src/components/SearchResults.tsx @@ -7,7 +7,6 @@ export async function SearchResults ({ search: string }) { const products = await getProducts({ search }) - return (

Resultados de búsqueda de "{search}": {products.length}

diff --git a/pruebas/02-bazar-universal/aiv4ro/src/components/icons/HalfStar.tsx b/pruebas/02-bazar-universal/aiv4ro/src/components/icons/HalfStar.tsx index a91cbbc12..2b36b4524 100644 --- a/pruebas/02-bazar-universal/aiv4ro/src/components/icons/HalfStar.tsx +++ b/pruebas/02-bazar-universal/aiv4ro/src/components/icons/HalfStar.tsx @@ -3,8 +3,8 @@ export function HalfStar () { - - + + { + return await fetch(`${hostUrl}/api/items/${id}`) + .then(async (res) => await res.json()) +} diff --git a/pruebas/02-bazar-universal/aiv4ro/src/services/get-products.ts b/pruebas/02-bazar-universal/aiv4ro/src/services/get-products.ts index da528924e..a13958808 100644 --- a/pruebas/02-bazar-universal/aiv4ro/src/services/get-products.ts +++ b/pruebas/02-bazar-universal/aiv4ro/src/services/get-products.ts @@ -1,6 +1,7 @@ +import { hostUrl } from '@/constants/env' import { Product } from '@/types/product' export async function getProducts ({ search = '' }: { search?: string } = {}): Promise { - return await fetch(`/api/items?search=${search}`) + return await fetch(`${hostUrl}/api/items?search=${search}`) .then(async res => await res.json()) }