@@ -4,13 +4,16 @@ import ResultFavoritesButton from '../ResultFavoritesButton/ResultFavoritesButto
44import QuizContext from '../CioQuiz/context' ;
55import { QuizResultDataPartial } from '../../types' ;
66import { getNestedValueUsingDotNotation , validateNumberOrString } from '../../utils' ;
7+ import ResultCardSwatches from '../ResultCardSwatches/ResultCardSwatches' ;
8+ import useResult from './useResult' ;
79
810interface ResultCardOptions {
911 result : QuizResultDataPartial ;
1012 salePriceKey ?: string ;
1113 regularPriceKey ?: string ;
1214 ratingCountKey ?: string ;
1315 ratingScoreKey ?: string ;
16+ swatchImageKey ?: string ;
1417 resultPosition : number ;
1518 renderResultCardPriceDetails ?: ( result : QuizResultDataPartial ) => JSX . Element ;
1619 getResultCardImageUrl ?: ( result : QuizResultDataPartial ) => string ;
@@ -24,6 +27,7 @@ export default function ResultCard(props: ResultCardOptions) {
2427 resultPosition,
2528 ratingCountKey,
2629 ratingScoreKey,
30+ swatchImageKey,
2731 renderResultCardPriceDetails,
2832 getResultCardImageUrl,
2933 } = props ;
@@ -33,30 +37,40 @@ export default function ResultCard(props: ResultCardOptions) {
3337 getQuizResultButtonProps,
3438 getQuizResultLinkProps,
3539 } = useContext ( QuizContext ) ;
40+ const { faceOutResult, onVariationClick } = useResult ( result ) ;
3641
3742 const salePrice = validateNumberOrString (
38- getNestedValueUsingDotNotation ( result ?. data , salePriceKey )
43+ getNestedValueUsingDotNotation ( faceOutResult ?. data , salePriceKey )
3944 ) ;
4045 const regularPrice = validateNumberOrString (
41- getNestedValueUsingDotNotation ( result ?. data , regularPriceKey )
46+ getNestedValueUsingDotNotation ( faceOutResult ?. data , regularPriceKey )
4247 ) ;
4348 const ratingCount = validateNumberOrString (
44- getNestedValueUsingDotNotation ( result ?. data , ratingCountKey )
49+ getNestedValueUsingDotNotation ( faceOutResult ?. data , ratingCountKey )
4550 ) ;
4651 const ratingScore = validateNumberOrString (
47- getNestedValueUsingDotNotation ( result ?. data , ratingScoreKey )
52+ getNestedValueUsingDotNotation ( faceOutResult ?. data , ratingScoreKey )
4853 ) ;
4954
5055 const resultCardContent = ( ) => (
5156 < >
5257 < div className = 'cio-result-card-image' >
5358 < img
54- src = { getResultCardImageUrl ? getResultCardImageUrl ( result ) : result . data ?. image_url }
59+ src = {
60+ getResultCardImageUrl
61+ ? getResultCardImageUrl ( faceOutResult )
62+ : faceOutResult . data ?. image_url
63+ }
5564 alt = 'product'
5665 />
5766 </ div >
67+ < ResultCardSwatches
68+ swatchImageKey = { swatchImageKey }
69+ faceOutResult = { faceOutResult }
70+ onVariationClick = { onVariationClick }
71+ />
5872 < div className = 'cio-result-card-text' >
59- < p className = 'cio-result-card-title' > { result . value } </ p >
73+ < p className = 'cio-result-card-title' > { faceOutResult . value } </ p >
6074 < div className = 'cio-result-card-details' >
6175 < div className = 'cio-result-card-rating' >
6276 { ! ! ratingScore && (
@@ -68,7 +82,7 @@ export default function ResultCard(props: ResultCardOptions) {
6882 { ! ! ratingCount && < span className = 'cio-result-card-rating-count' > ({ ratingCount } )</ span > }
6983 </ div >
7084 { renderResultCardPriceDetails ? (
71- renderResultCardPriceDetails ( result )
85+ renderResultCardPriceDetails ( faceOutResult )
7286 ) : (
7387 < div className = 'cio-result-card-prices' >
7488 { ! ! salePrice && < span className = 'cio-result-card-sale-price' > ${ salePrice } </ span > }
@@ -87,7 +101,12 @@ export default function ResultCard(props: ResultCardOptions) {
87101
88102 const resultCardContentWithoutLink = ( ) =>
89103 getQuizResultButtonProps && (
90- < div { ...getQuizResultButtonProps ( { result, position : resultPosition , type : 'button' } ) } >
104+ < div
105+ { ...getQuizResultButtonProps ( {
106+ result : faceOutResult ,
107+ position : resultPosition ,
108+ type : 'button' ,
109+ } ) } >
91110 { resultCardContent ( ) }
92111 </ div >
93112 ) ;
@@ -98,18 +117,22 @@ export default function ResultCard(props: ResultCardOptions) {
98117 className = 'cio-result-card-anchor'
99118 rel = 'noreferrer'
100119 target = '_blank'
101- { ...getQuizResultLinkProps ( { result, position : resultPosition , type : 'link' } ) } >
120+ { ...getQuizResultLinkProps ( {
121+ result : faceOutResult ,
122+ position : resultPosition ,
123+ type : 'link' ,
124+ } ) } >
102125 { resultCardContent ( ) }
103126 </ a >
104127 ) ;
105128
106129 return (
107130 < div className = 'cio-result-card' >
108131 { customAddToFavoritesCallback && (
109- < ResultFavoritesButton item = { result } price = { salePrice || regularPrice } />
132+ < ResultFavoritesButton item = { faceOutResult } price = { salePrice || regularPrice } />
110133 ) }
111134 { ! customClickItemCallback ? resultCardContentWithLink ( ) : resultCardContentWithoutLink ( ) }
112- < ResultCtaButton item = { result } price = { salePrice || regularPrice } />
135+ < ResultCtaButton item = { faceOutResult } price = { salePrice || regularPrice } />
113136 </ div >
114137 ) ;
115138}
0 commit comments