-
Notifications
You must be signed in to change notification settings - Fork 4
Add support for variations on quiz results page #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for variations on quiz results page #228
Conversation
9fb0bb6 to
577ef88
Compare
534feb7 to
c0cfabc
Compare
Mudaafi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First review, I didn't take a look at the tests in-depth yet, but at a glance they look good. Implementation looks good as well, I just had a couple of questions/comments first
src/hooks/useResult.tsx
Outdated
| import { useCallback, useState } from 'react'; | ||
| import { GetQuizResultSwatchProps, QuizResultDataPartial } from '../types'; | ||
|
|
||
| const useResult = (result: QuizResultDataPartial, swatchImageKey?: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name this useResultCard instead to match the component it's tied to? I got confused with the Results component a couple of times but I might just be slow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| getNestedValueUsingDotNotation(result?.data, salePriceKey) | ||
| ); | ||
| const { faceOutResult, getQuizResultSwatchProps } = useResult(result, swatchImageKey); | ||
| const { data, value } = faceOutResult || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the defensive programming. Just curious, is there ever a case where faceOutResult would be null? From the types, it doesn't seem to be something we'd expect to happen.
| const style = { | ||
| background: `url(${ | ||
| swatchImageKey ? variation?.data?.[swatchImageKey] : variation?.data?.image_url | ||
| })`, | ||
| backgroundSize: 'fit-object', | ||
| backgroundPosition: 'center', | ||
| backgroundRepeat: 'no-repeat', | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than this being a style we inject into the ResultCardsSwatches later, would it be better to just return a custom class like cio-result-card-swatch .cio-result-card-swatch-selected?
I understand background can't be a static css and needs to be computed, so we can keep it as a style, but I'd also want to return the swatchImage as a separate prop itself so that custom renderFunctions can make use of it w/o needing to rely on background or navigate into the result object to retrieve it. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we can keep it as a style
Alternatively, the component can do the setting of the background style if we already return the image as a prop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { QuizResultDataPartial } from '../../types'; | ||
| import { QuizResultDataPartial, RenderResultCard } from '../../types'; | ||
| import { getNestedValueUsingDotNotation, validateNumberOrString } from '../../utils'; | ||
| import ResultCardSwatches from '../ResultCardSwatches/ResultCardSwatches'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change required, but it would be nice if we had an index.ts export file structure. We use this pattern throughout the repo so let's keep it as is until we have the time to refactor
| import { Meta, Markdown } from '@storybook/blocks'; | ||
| import UseResultDocs from './markdown/UseResultDocs.md'; | ||
|
|
||
| <Meta title="Quiz/useResult" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts? Felt a little weird having it just dangling there
| <Meta title="Quiz/useResult" /> | |
| <Meta title="Quiz/Other Hooks/useResult" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for variation-based quiz results, allowing updated content (image, price, IDs) based on the selected variation swatch and enabling tracking with the selected variation_id.
- Added new hook (useResult) and TypeScript types to manage variation selection.
- Updated components (ResultCard, ResultCardSwatches, Results, etc.), documentation, and tests to support the new swatch behavior.
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Added new types and updated options to include swatch-related props. |
| src/styles.css | Introduced CSS classes for quiz swatches and selected states. |
| src/stories/Quiz/** | Updated documentation and usage examples for useResult and render props. |
| src/services/index.ts | Adjusted tracking event to correctly read variation_id. |
| src/hooks/useResult.tsx | Created new hook managing variations and swatch props with minor styling. |
| src/components/** | Updated ResultCard and related components to use new hook and props. |
| spec/** | Extended tests to cover the new variation swatch behaviors and hook usage. |
| .github/workflows/spell-check.yml | Updated Node.js version for spell-checking. |
Co-authored-by: Ahmad Mudaafi' <ahmad.mudaafi@constructor.io>
Co-authored-by: Ahmad Mudaafi' <ahmad.mudaafi@constructor.io>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Ahmad Mudaafi' <ahmad.mudaafi@constructor.io>
Co-authored-by: Ahmad Mudaafi' <ahmad.mudaafi@constructor.io>
Mudaafi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Pull Request Checklist
Before you submit a pull request, please make sure you have to following:
PR Type
What kind of change does this PR introduce?
What are the changes?
How?
hooks/useResult.tsxuseResultfor detailed documentationUsage scenarios
Component
ResultCardSwatchescomponentRenderProps
getQuizResultSwatchPropsgetQuizResultSwatchPropsHooks
useResulthookuseResultfor detailed documentationBefore and After