-
Notifications
You must be signed in to change notification settings - Fork 6
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
Intégrer “Aucun” dans les mosaïques de réponses [NGC-1239] #747
Draft
florianpanchout
wants to merge
7
commits into
preprod
Choose a base branch
from
NGC-1239
base: preprod
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1198dc6
feat: add aucun to mosaic
florianpanchout bcc71d5
feat: put aucun option at the end of mosaic
florianpanchout 584a07d
feat: add possibility to add emoji to aucun option
florianpanchout 7cf9263
feat: new workflow for aucun answer
florianpanchout 5580702
fix: missing dependency
florianpanchout 83046f2
feat: use set instead of array
florianpanchout 3732918
fix: build
florianpanchout File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { questionClickSuggestion } from '@/constants/tracking/question' | ||
import Emoji from '@/design-system/utils/Emoji' | ||
import { useEngine, useRule } from '@/publicodes-state' | ||
import { FormattedSuggestion } from '@/publicodes-state/types' | ||
import { capitalizeString } from '@/utils/capitalizeString' | ||
import { trackEvent } from '@/utils/matomo/trackEvent' | ||
import { DottedName } from '@incubateur-ademe/nosgestesclimat' | ||
import { motion } from 'framer-motion' | ||
import { useEffect, useState } from 'react' | ||
import { twMerge } from 'tailwind-merge' | ||
|
||
type Props = { | ||
question: DottedName | ||
aucunOption: FormattedSuggestion | ||
questionsOfMosaic: DottedName[] | ||
} | ||
|
||
const buttonClassNames = { | ||
checked: 'border-primary-700 text-primary-700 border-2 cursor-pointer ', | ||
unchecked: 'border-primary-200 hover:bg-primary-50 border-2 cursor-pointer ', | ||
} | ||
const checkClassNames = { | ||
checked: 'border-primary-700', | ||
unchecked: 'border-primary-200', | ||
} | ||
|
||
const labelClassNames = { | ||
checked: 'text-primary-700', | ||
unchecked: 'text-primary-700', | ||
} | ||
|
||
export default function MosaicAucunOption({ | ||
question, | ||
aucunOption, | ||
questionsOfMosaic, | ||
}: Props) { | ||
const { setValue, isMissing } = useRule(question) | ||
|
||
const { getValue } = useEngine() | ||
|
||
const isMosaicChildrenSelected = questionsOfMosaic | ||
.map((question) => getValue(question)) | ||
.some((value) => value) | ||
|
||
const [isSelected, setIsSelected] = useState(false) | ||
const status = isSelected ? 'checked' : 'unchecked' | ||
|
||
useEffect(() => { | ||
if (isMissing) { | ||
return | ||
} | ||
setIsSelected(!isMosaicChildrenSelected) | ||
}, [isMosaicChildrenSelected, isMissing]) | ||
|
||
return ( | ||
<button | ||
className={twMerge( | ||
`relative flex h-full items-center gap-2 rounded-xl border bg-white px-4 py-2 text-left transition-colors`, | ||
buttonClassNames[status] | ||
)} | ||
onClick={() => { | ||
trackEvent( | ||
questionClickSuggestion({ question, answer: aucunOption.label }) | ||
) | ||
setValue(aucunOption.value, { foldedStep: question }) | ||
}}> | ||
<span | ||
className={`${checkClassNames[status]} flex h-5 w-5 items-center justify-center rounded-sm border-2 leading-4`}> | ||
{status === 'checked' ? ( | ||
<motion.div | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
transition={{ duration: 0.2 }} | ||
className={`font-mono text-2xl ${labelClassNames[status]}`}> | ||
✓ | ||
</motion.div> | ||
) : ( | ||
'' | ||
)} | ||
</span> | ||
<span | ||
className={`inline-block align-middle text-sm md:text-lg ${labelClassNames[status]}`}> | ||
<Emoji>{capitalizeString(aucunOption.label)}</Emoji> | ||
</span> | ||
</button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const aucunLabels = [ | ||
'aucun', | ||
'pas de chauffage', | ||
'aucun animal', | ||
'aucun sport', | ||
'aucun 🙅♂️', | ||
'pas de chauffage 🙅♂️', | ||
'aucun animal 🙅♂️', | ||
'aucun sport 🙅♂️', | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Better with a
Set