Skip to content
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

Refonte / Valeur pré remplie - Non supprimable (nb de personnes ds voiture par ex) (issue 1368) #70

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/form/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ type Props = {
onComplete?: () => void
}

//TODO: It should maayyybe be described in the model...
const questionsThatCantBeZero = [
'transport . voiture . saisie voyageurs',
'logement . saisie habitants',
'logement . surface',
]

export default function Navigation({ question, onComplete = () => '' }: Props) {
const { gotoPrevQuestion, gotoNextQuestion, noPrevQuestion, noNextQuestion } =
useForm()
const { isMissing, setDefaultAsValue } = useRule(question)
const { isMissing, setDefaultAsValue, numericValue } = useRule(question)
const [isSettingDefaultValue, setIsSettingDefaultValue] = useState(false)

const nextDisabled =
questionsThatCantBeZero.includes(question) && numericValue < 1
return (
<div className="flex justify-end gap-4">
{!noPrevQuestion ? (
Expand All @@ -36,7 +46,7 @@ export default function Navigation({ question, onComplete = () => '' }: Props) {
) : null}
<Button
color={isMissing ? 'secondary' : 'primary'}
disabled={isSettingDefaultValue}
disabled={isSettingDefaultValue || nextDisabled}
onClick={async () => {
if (isMissing) {
trackEvent(getMatomoEventClickDontKnow(question))
Expand Down
11 changes: 2 additions & 9 deletions src/components/form/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ type Props = {
question: string
}

//TODO: It should maayyybe be described in the model...
const questionsThatCantBeZero = [
'transport . voiture . saisie voyageurs',
'logement . saisie habitants',
'logement . surface',
]

export default function Question({ question }: Props) {
const {
type,
Expand All @@ -44,11 +37,11 @@ export default function Question({ question }: Props) {
unit={unit}
value={numericValue}
setValue={(value) => {
const limit = questionsThatCantBeZero.includes(question) ? 1 : 0
const limit = 0
setValue(value < limit ? limit : value, question)
}}
isMissing={isMissing}
min={questionsThatCantBeZero.includes(question) ? 1 : 0}
min={0}
/>
)}
{type === 'boolean' && (
Expand Down
Loading