Skip to content

Commit 43f3d04

Browse files
committed
nextjs and other packages updated to the latest version to ensure security best practices
1 parent 776ef29 commit 43f3d04

7 files changed

Lines changed: 5200 additions & 9954 deletions

File tree

app/product/[productSlug]/page.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@ interface ImageItem {
1919
image: string;
2020
}
2121

22+
interface SingleProductPageProps {
23+
params: Promise<{ productSlug: string, id: string }>;
24+
}
25+
2226
const SingleProductPage = async ({ params }: SingleProductPageProps) => {
27+
const paramsAwaited = await params;
2328
// sending API request for a single product with a given product slug
2429
const data = await fetch(
25-
`http://localhost:3001/api/slugs/${params.productSlug}`
30+
`http://localhost:3001/api/slugs/${paramsAwaited?.productSlug}`
2631
);
2732
const product = await data.json();
2833

2934
// sending API request for more than 1 product image if it exists
3035
const imagesData = await fetch(
31-
`http://localhost:3001/api/images/${product.id}`
36+
`http://localhost:3001/api/images/${paramsAwaited?.id}`
3237
);
3338
const images = await imagesData.json();
3439

@@ -68,7 +73,7 @@ const SingleProductPage = async ({ params }: SingleProductPageProps) => {
6873
<StockAvailabillity stock={94} inStock={product?.inStock} />
6974
<SingleProductDynamicFields product={product} />
7075
<div className="flex flex-col gap-y-2 max-[500px]:items-center">
71-
<AddToWishlistBtn product={product} slug={params.productSlug} />
76+
<AddToWishlistBtn product={product} slug={paramsAwaited.productSlug} />
7277
<p className="text-lg">
7378
SKU: <span className="ml-1">abccd-18</span>
7479
</p>

app/shop/[[...slug]]/page.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ const improveCategoryText = (text: string): string => {
2121
}
2222
};
2323

24-
const ShopPage = (slug: any) => {
24+
const ShopPage = async ({ params, searchParams }: { params: Promise<{ slug?: string[] }>, searchParams: Promise<{ [key: string]: string | string[] | undefined }> }) => {
25+
// Await both params and searchParams
26+
const awaitedParams = await params;
27+
const awaitedSearchParams = await searchParams;
2528

2629
return (
2730
<div className="text-black bg-white">
@@ -32,15 +35,15 @@ const ShopPage = (slug: any) => {
3235
<div>
3336
<div className="flex justify-between items-center max-lg:flex-col max-lg:gap-y-5">
3437
<h2 className="text-2xl font-bold max-sm:text-xl max-[400px]:text-lg uppercase">
35-
{slug?.params?.slug && slug?.params?.slug[0]?.length > 0
36-
? improveCategoryText(slug?.params?.slug[0])
38+
{awaitedParams?.slug && awaitedParams?.slug[0]?.length > 0
39+
? improveCategoryText(awaitedParams?.slug[0])
3740
: "All products"}
3841
</h2>
3942

4043
<SortBy />
4144
</div>
4245
<div className="divider"></div>
43-
<Products slug={slug} />
46+
<Products params={awaitedParams} searchParams={awaitedSearchParams} />
4447
<Pagination />
4548
</div>
4649
</div>

components/Products.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
// Name of the component: Products.tsx
44
// Developer: Aleksandar Kuzmanovic
55
// Version: 1.0
6-
// Component call: <Products slug={slug} />
7-
// Input parameters: { slug }: any
6+
// Component call: <Products params={params} searchParams={searchParams} />
7+
// Input parameters: { params, searchParams }: { params: { slug?: string[] }, searchParams: { [key: string]: string | string[] | undefined } }
88
// Output: products grid
99
// *********************
1010

1111
import React from "react";
1212
import ProductItem from "./ProductItem";
1313

14-
const Products = async ({ slug }: any) => {
14+
const Products = async ({ params, searchParams }: { params: { slug?: string[] }, searchParams: { [key: string]: string | string[] | undefined } }) => {
1515
// getting all data from URL slug and preparing everything for sending GET request
16-
const inStockNum = slug?.searchParams?.inStock === "true" ? 1 : 0;
17-
const outOfStockNum = slug?.searchParams?.outOfStock === "true" ? 1 : 0;
18-
const page = slug?.searchParams?.page ? Number(slug?.searchParams?.page) : 1;
16+
const inStockNum = searchParams?.inStock === "true" ? 1 : 0;
17+
const outOfStockNum = searchParams?.outOfStock === "true" ? 1 : 0;
18+
const page = searchParams?.page ? Number(searchParams?.page) : 1;
1919

2020
let stockMode: string = "lte";
2121

@@ -40,28 +40,18 @@ const Products = async ({ slug }: any) => {
4040
// sending API request with filtering, sorting and pagination for getting all products
4141
const data = await fetch(
4242
`http://localhost:3001/api/products?filters[price][$lte]=${
43-
slug?.searchParams?.price || 3000
43+
searchParams?.price || 3000
4444
}&filters[rating][$gte]=${
45-
Number(slug?.searchParams?.rating) || 0
45+
Number(searchParams?.rating) || 0
4646
}&filters[inStock][$${stockMode}]=1&${
47-
slug?.params?.slug?.length > 0
48-
? `filters[category][$equals]=${slug?.params?.slug}&`
47+
params?.slug?.length! > 0
48+
? `filters[category][$equals]=${params?.slug}&`
4949
: ""
50-
}sort=${slug?.searchParams?.sort}&page=${page}`
50+
}sort=${searchParams?.sort}&page=${page}`
5151
);
5252

5353
const products = await data.json();
5454

55-
/*
56-
const req = await fetch(
57-
`http://localhost:1337/api/products?populate=*&filters[price][$lte]=${
58-
searchParams?.price || 1000
59-
}${searchParams.women === "true" ? "&filters[category][$eq]=women" : ""}${searchParams.womenNewEdition === "true" ? "&filters[category][$eq]=women%20new%20edition" : ""}&filters[rating][$gte]=${
60-
searchParams?.rating || 1
61-
}`
62-
);
63-
const products = await req.json();
64-
*/
6555
return (
6656
<div className="grid grid-cols-3 justify-items-center gap-x-2 gap-y-5 max-[1300px]:grid-cols-3 max-lg:grid-cols-2 max-[500px]:grid-cols-1">
6757
{products.length > 0 ? (

0 commit comments

Comments
 (0)