-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d573dbb
commit f72e23e
Showing
7 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
pruebas/02-bazar-universal/aiv4ro/src/app/items/[id]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<section className='flex flex-col justify-center gap-6 mt-5'> | ||
<header className='flex gap-3 items-center justify-center'> | ||
<picture className='w-full max-w-[250px] h-auto flex-1 aspect-square overflow-hidden rounded-full'> | ||
<img className='w-full h-full object-cover' src={mainImage} alt={product.title} /> | ||
</picture> | ||
<div className='flex flex-col gap-3'> | ||
{otherImages.map((image, index) => ( | ||
<picture key={index} className='w-16 h-16 overflow-hidden rounded-full'> | ||
<img className='h-full w-full object-cover' src={image} alt={product.title} /> | ||
</picture> | ||
))} | ||
</div> | ||
</header> | ||
<h2 className='text-center text-xl font-semibold'>{product.title} - {product.brand}</h2> | ||
<div className='flex items-center justify-center gap-5'> | ||
<div className='flex flex-col text-center'> | ||
<ProductPrice price={product.price} /> | ||
<span>{product.stock} disponibles</span> | ||
</div> | ||
<ProductRating rating={product.rating} /> | ||
</div> | ||
<p className='text-center'> | ||
{product.description} | ||
</p> | ||
<button className='px-10 py-3 text-xl font-semibold bg-zinc-800 hover:bg-zinc-700 rounded'> | ||
Comprar | ||
</button> | ||
</section> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const hostUrl = process.env.VERCEL_URL ?? 'http://localhost:3000' |
7 changes: 7 additions & 0 deletions
7
pruebas/02-bazar-universal/aiv4ro/src/services/get-product.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { hostUrl } from '@/constants/env' | ||
import { Product } from '@/types/product' | ||
|
||
export async function getProduct ({ id }: { id: string | number }): Promise<Product> { | ||
return await fetch(`${hostUrl}/api/items/${id}`) | ||
.then(async (res) => await res.json()) | ||
} |
3 changes: 2 additions & 1 deletion
3
pruebas/02-bazar-universal/aiv4ro/src/services/get-products.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { hostUrl } from '@/constants/env' | ||
import { Product } from '@/types/product' | ||
|
||
export async function getProducts ({ search = '' }: { search?: string } = {}): Promise<Product[]> { | ||
return await fetch(`/api/items?search=${search}`) | ||
return await fetch(`${hostUrl}/api/items?search=${search}`) | ||
.then(async res => await res.json()) | ||
} |