@@ -2,8 +2,7 @@ import React, { useEffect, useState } from "react";
2
2
import { useRouter } from 'next/router'
3
3
import { getOptimizelyProjectsDataFile , getUserId } from "../utils/optimizelyConnector" ;
4
4
import { createInstance } from "@optimizely/optimizely-sdk" ;
5
- import BannerForPlpFilter from "../component/BannerForPlpFilter" ;
6
- import BannerForPlpSegments from "../component/BannerForPlpSegments" ;
5
+ import SegmentationAlgorithmFilter from "../component/SegmentationAlgorithmFilter" ;
7
6
8
7
const imageStyle = {
9
8
width : '100%'
@@ -13,12 +12,13 @@ const featureStyle = {
13
12
paddingBottom : '5rem'
14
13
} ;
15
14
15
+
16
+
16
17
export default function ProductListingPage ( { ...props } ) {
17
18
18
- const { datafile, clientId } = props ;
19
+ const { datafile, clientId, imageExists } = props ;
20
+ const imageFolder = imageExists ? clientId : 'default' ;
19
21
20
- const [ componentMessage , setComponentMessage ] = useState ( ) ;
21
- const [ discountAmount , setDiscountAmount ] = useState ( ) ;
22
22
const [ categoryFilterVersion , setCategoryFilterVersion ] = useState ( 0 ) ;
23
23
const [ sizeFilterVersion , setSizeFilterVersion ] = useState ( 0 ) ;
24
24
@@ -27,9 +27,8 @@ export default function ProductListingPage({...props}) {
27
27
} ) ;
28
28
29
29
const router = useRouter ( )
30
- const { segment = '' , utc_campaign = '' , algorithm = '' } = router . query
31
- console . log ( 'Segments' , segment )
32
- console . log ( 'UTC campaign' , utc_campaign )
30
+ const { algorithm = '' } = router . query
31
+ console . log ( 'imageExists' , imageExists )
33
32
34
33
// Demo of setting IDS to variations, useful for integration testing
35
34
const userId = algorithm || getUserId ( router ) ;
@@ -41,36 +40,23 @@ export default function ProductListingPage({...props}) {
41
40
42
41
// Passing attributes for personalization
43
42
{
44
- algorithm : algorithm ,
45
- segment : segment ,
46
- user : segment ,
47
- utc_campaign : utc_campaign
43
+ algorithm : algorithm
48
44
}
49
45
) ;
50
46
} ) ;
51
47
48
+
52
49
useEffect ( ( ) => {
53
50
optimizelyClient . onReady ( ) . then ( ( ) => {
54
51
55
- const personalisationDecision = optimizelyUserContext . decide ( 'personalisation' ) ;
56
- console . log ( 'personalisationDecision' , personalisationDecision ) ;
57
-
58
- const componentMessage = personalisationDecision . variables . component_message ;
59
- const discountAmount = personalisationDecision . variables . discount_amount ;
60
-
61
52
const filtertestDecision = optimizelyUserContext . decide ( 'plp_-_filter_tests' ) ;
62
53
console . log ( 'plp_-_filter_tests' , filtertestDecision ) ;
63
54
64
55
const categoryFilterVersion = filtertestDecision . variables . category_filter_version ;
65
56
const sizeFilterVersion = filtertestDecision . variables . size_filter_version ;
66
57
67
- if ( discountAmount && discountAmount >= 0 ) {
68
- setDiscountAmount ( discountAmount ) ;
69
- }
70
-
71
58
setCategoryFilterVersion ( categoryFilterVersion ) ;
72
59
setSizeFilterVersion ( sizeFilterVersion ) ;
73
- setComponentMessage ( componentMessage ) ;
74
60
} ) ;
75
61
} , [ optimizelyUserContext , optimizelyClient ] ) ;
76
62
@@ -81,9 +67,7 @@ export default function ProductListingPage({...props}) {
81
67
< section id = "feature" style = { featureStyle } >
82
68
< div className = "container" >
83
69
84
- < BannerForPlpFilter />
85
-
86
- < BannerForPlpSegments discount = { discountAmount } componentMessage = { componentMessage } />
70
+ < SegmentationAlgorithmFilter />
87
71
88
72
< div className = "row" >
89
73
< div id = "sidebar" className = "col-3 col-12-medium" >
@@ -100,23 +84,23 @@ export default function ProductListingPage({...props}) {
100
84
< div className = "col-4 col-6-medium col-12-small" >
101
85
< section >
102
86
< a href = "#" className = "image featured" >
103
- < img src = { `demo/${ clientId } /item.png` } alt = "Item 1" />
87
+ < img src = { `demo/${ imageFolder } /item.png` } alt = "Item 1" />
104
88
</ a >
105
89
< p > < img src = { `images/landing1.png` } alt = "Item 1" /> </ p >
106
90
</ section >
107
91
</ div >
108
92
< div className = "col-4 col-6-medium col-12-small" >
109
93
< section >
110
94
< a href = "#" className = "image featured" >
111
- < img src = { `demo/${ clientId } /item.png` } alt = "Item 2" />
95
+ < img src = { `demo/${ imageFolder } /item.png` } alt = "Item 2" />
112
96
</ a >
113
97
< p > < img src = { `images/landing2.png` } alt = "Item 2" /> </ p >
114
98
</ section >
115
99
</ div >
116
100
< div className = "col-4 col-6-medium col-12-small" >
117
101
< section >
118
102
< a href = "#" className = "image featured" >
119
- < img src = { `demo/${ clientId } /item.png` } alt = "Item 3" />
103
+ < img src = { `demo/${ imageFolder } /item.png` } alt = "Item 3" />
120
104
</ a >
121
105
< p > < img src = { `images/landing3.png` } alt = "Item 3" /> </ p >
122
106
</ section >
@@ -130,13 +114,27 @@ export default function ProductListingPage({...props}) {
130
114
)
131
115
}
132
116
117
+
118
+
133
119
export async function getServerSideProps ( context ) {
134
120
135
121
const datafile = await getOptimizelyProjectsDataFile ( ) ;
136
122
123
+ const isImageFound = async ( imageName ) => {
124
+ var result = await fetch ( `https://optimizely-demo.netlify.app/demo/${ imageName } /item.png` , {
125
+ method : "HEAD" ,
126
+ } ) ;
127
+
128
+ return result . status === 200
129
+ } ;
130
+
131
+ const userAgent = context . req . headers [ 'client' ] || null ;
132
+ const imageExists = await isImageFound ( userAgent ) ;
133
+
137
134
return {
138
135
props : {
139
- datafile
136
+ datafile,
137
+ imageExists
140
138
}
141
139
}
142
140
}
0 commit comments