Trying to upgrade to Nextjs v15

This commit is contained in:
2024-10-23 10:02:02 +05:30
parent 543533d6e0
commit c0a53993ee
5 changed files with 85 additions and 78 deletions

View File

@ -28,7 +28,7 @@ export default function MyCartComponent() {
<h3 className='font-semibold'>
{item.product_title} ({item.variant_title})
</h3>
<p className='text-sm text-gray-600'>${item.unit_price}</p>
<p className='text-sm text-gray-600'>{item.unit_price}</p>
</div>
<div className='flex items-center'>
<Button variant='outline' size='icon' onClick={() => updateQuantity(item.id, item.quantity - 1)}>
@ -56,18 +56,18 @@ export default function MyCartComponent() {
<div className='space-y-1'>
<div className='flex justify-between'>
<span>Subtotal</span>
<span>${cart?.subtotal}</span>
<span>{cart?.subtotal?.toFixed(2)}</span>
</div>
<div className='flex justify-between'>
<span>Tax</span>
<span>${cart?.tax_total}</span>
<span>{cart?.tax_total?.toFixed(2)}</span>
</div>
</div>
</CardContent>
<Separator />
<CardFooter className='justify-between'>
<span className='font-semibold'>Total</span>
<span className='font-semibold'>${cart?.total}</span>
<span className='font-semibold'>{cart?.total?.toFixed(2)}</span>
</CardFooter>
</Card>
<Button className='w-full mt-4' size='lg'>

View File

@ -21,6 +21,7 @@ async function fetchProduct(handle: string, region: HttpTypes.StoreRegion | unde
handle: handle,
fields: `*variants.calculated_price`,
region_id: region?.id || (process.env.NEXT_PUBLIC_DEFAULT_REGION_ID as string),
country_code: 'in',
});
const response = await fetch(
// const products: HttpTypes.StoreProduct[] = await fetch(

View File

@ -7,6 +7,7 @@ async function fetchProducts() {
const params = new URLSearchParams({
fields: `*variants.prices.*`,
region_id: process.env.NEXT_PUBLIC_DEFAULT_REGION_ID as string,
country_code: 'in',
});
const response = await fetch(`${process.env.NEXT_PRIVATE_BASE_URL}/store/products?${params}`, {
@ -24,6 +25,7 @@ async function fetchProducts() {
}
const data = await response.json();
console.log(JSON.stringify(data.products));
return data.products;
}
@ -50,7 +52,7 @@ export default async function ProductsPage() {
<img
src={product.images?.[0].url as string}
alt={product.title as string}
className='w-full h-auto flex-grow group-hover:opacity-80 transition-opacity duration-1000 group-hover:rounded-lg group-hover:shadow-lg'
className='w-full h-auto flex-grow group-hover:opacity-80 transition-opacity duration-1000 group-hover:rounded-lg'
/>
<button className='bg-black text-white px-4 py-2 rounded hover:bg-gray-800 transition-colors duration-300 absolute bottom-4 left-1/2 transform -translate-x-1/2 opacity-0 group-hover:opacity-100'>
Add to Cart