File tree 7 files changed +27
-34
lines changed
7 files changed +27
-34
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ const AlgoliaSearchBox = () => {
51
51
} }
52
52
/>
53
53
{ search && (
54
- < div className = "absolute" >
54
+ < div className = "absolute z-50 bg-white shadow-lg rounded-md mt-1 md:w-[18rem] " >
55
55
< Hits hitComponent = { SearchResults } />
56
56
</ div >
57
57
) }
Original file line number Diff line number Diff line change 1
1
import Link from 'next/link' ;
2
-
3
2
import { trimmedStringToLength } from '@/utils/functions/functions' ;
4
3
5
4
interface ISearchResultProps {
@@ -10,7 +9,7 @@ interface ISearchResultProps {
10
9
sale_price : string ;
11
10
on_sale : boolean ;
12
11
short_description : string ;
13
- objectID : number ;
12
+ slug : string ;
14
13
} ;
15
14
}
16
15
@@ -23,7 +22,6 @@ interface ISearchResultProps {
23
22
* @param {string } sale_price Price when on sale
24
23
* @param {boolean } on_sale Is the product on sale? True or false
25
24
* @param {string } short_description Short description of product
26
- * @param {number } objectID ID of product
27
25
}
28
26
*/
29
27
const SearchResults = ( {
@@ -34,17 +32,12 @@ const SearchResults = ({
34
32
sale_price,
35
33
on_sale,
36
34
short_description,
37
- objectID,
38
35
} ,
39
36
} : ISearchResultProps ) => {
40
- // Replace empty spaces with dash (-)
41
- const trimmedProductName = product_name . replace ( / / g, '-' ) ;
42
-
43
37
return (
44
38
< article className = "cursor-pointer hit" >
45
39
< Link
46
- href = "/produkt/[post]"
47
- as = { `/produkt/${ trimmedProductName } ?id=${ objectID } ` }
40
+ href = { `/produkt/${ product_name . replace ( / / g, '-' ) } ` }
48
41
passHref
49
42
>
50
43
< div className = "flex p-6 bg-white" >
Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ interface Variations {
23
23
24
24
interface RootObject {
25
25
__typename : string ;
26
- databaseId : number ;
27
26
name : string ;
28
27
onSale : boolean ;
29
28
slug : string ;
@@ -55,7 +54,6 @@ const DisplayProducts = ({ products }: IDisplayProductsProps) => (
55
54
{ products ? (
56
55
products . map (
57
56
( {
58
- databaseId,
59
57
name,
60
58
price,
61
59
regularPrice,
@@ -78,11 +76,7 @@ const DisplayProducts = ({ products }: IDisplayProductsProps) => (
78
76
79
77
return (
80
78
< div key = { uuidv4 ( ) } className = "group" >
81
- < Link
82
- href = { `/produkt/${ encodeURIComponent (
83
- slug ,
84
- ) } ?id=${ encodeURIComponent ( databaseId ) } `}
85
- >
79
+ < Link href = { `/produkt/${ encodeURIComponent ( slug ) } ` } >
86
80
< div className = "aspect-[3/4] relative overflow-hidden bg-gray-100" >
87
81
{ image ? (
88
82
< img
@@ -96,16 +90,14 @@ const DisplayProducts = ({ products }: IDisplayProductsProps) => (
96
90
id = "product-image"
97
91
className = "w-full h-full object-cover object-center transition duration-300 group-hover:scale-105"
98
92
alt = { name }
99
- src = { process . env . NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL }
93
+ src = {
94
+ process . env . NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL
95
+ }
100
96
/>
101
97
) }
102
98
</ div >
103
99
</ Link >
104
- < Link
105
- href = { `/produkt/${ encodeURIComponent (
106
- slug ,
107
- ) } ?id=${ encodeURIComponent ( databaseId ) } `}
108
- >
100
+ < Link href = { `/produkt/${ encodeURIComponent ( slug ) } ` } >
109
101
< span >
110
102
< div className = "mt-4" >
111
103
< p className = "text-2xl font-bold text-center cursor-pointer hover:text-gray-600 transition-colors" >
@@ -127,9 +119,7 @@ const DisplayProducts = ({ products }: IDisplayProductsProps) => (
127
119
</ span >
128
120
</ div >
129
121
) : (
130
- < span className = "text-lg text-gray-900" >
131
- { price }
132
- </ span >
122
+ < span className = "text-lg text-gray-900" > { price } </ span >
133
123
) }
134
124
</ div >
135
125
</ div >
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ const ProductCard = ({
33
33
return (
34
34
< div className = "group" >
35
35
< div className = "aspect-[3/4] overflow-hidden bg-gray-100 relative" >
36
- < Link href = { `/produkt/${ slug } ?id= ${ databaseId } ` } >
36
+ < Link href = { `/produkt/${ slug } ` } >
37
37
{ image ?. sourceUrl ? (
38
38
< Image
39
39
src = { image . sourceUrl }
@@ -51,7 +51,7 @@ const ProductCard = ({
51
51
</ Link >
52
52
</ div >
53
53
54
- < Link href = { `/produkt/${ slug } ?id= ${ databaseId } ` } >
54
+ < Link href = { `/produkt/${ slug } ` } >
55
55
< div className = "mt-4" >
56
56
< p className = "text-2xl font-bold text-center cursor-pointer hover:text-gray-600 transition-colors" >
57
57
{ name }
Original file line number Diff line number Diff line change @@ -36,8 +36,8 @@ const UserRegistration = () => {
36
36
} else {
37
37
throw new Error ( 'Failed to register customer' ) ;
38
38
}
39
- } catch ( err : unknown ) {
40
- console . error ( 'Registration error' ) ;
39
+ } catch ( error : unknown ) {
40
+ console . error ( 'Registration error:' , error ) ;
41
41
}
42
42
} ;
43
43
Original file line number Diff line number Diff line change @@ -48,11 +48,21 @@ const Produkt: NextPage = ({
48
48
export default withRouter ( Produkt ) ;
49
49
50
50
export const getServerSideProps : GetServerSideProps = async ( {
51
- query : { id } ,
51
+ params,
52
+ query,
53
+ res,
52
54
} ) => {
55
+ // Handle legacy URLs with ID parameter by removing it
56
+ if ( query . id ) {
57
+ res . setHeader ( 'Location' , `/produkt/${ params ?. slug } ` ) ;
58
+ res . statusCode = 301 ;
59
+ res . end ( ) ;
60
+ return { props : { } } ;
61
+ }
62
+
53
63
const { data, loading, networkStatus } = await client . query ( {
54
64
query : GET_SINGLE_PRODUCT ,
55
- variables : { id } ,
65
+ variables : { slug : params ?. slug } ,
56
66
} ) ;
57
67
58
68
return {
Original file line number Diff line number Diff line change 1
1
import { gql } from '@apollo/client' ;
2
2
3
3
export const GET_SINGLE_PRODUCT = gql `
4
- query Product($id : ID!) {
5
- product(id: $id , idType: DATABASE_ID ) {
4
+ query Product($slug : ID!) {
5
+ product(id: $slug , idType: SLUG ) {
6
6
id
7
7
databaseId
8
8
averageRating
You can’t perform that action at this time.
0 commit comments