Skip to content

Commit

Permalink
fix: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
florianpanchout committed Sep 10, 2024
1 parent 833584a commit 29ddccf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/components/form/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export default function Question({
if (setTempValue) {
setTempValue(value)
}
console.log('set value via numberInput')
setValue(value, { foldedStep: question })
trackEvent(questionTypeAnswer({ question, answer: value }))
}}
Expand Down
10 changes: 5 additions & 5 deletions src/components/form/question/NumberInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Trans from '@/components/translation/Trans'
import { HTMLAttributes, SyntheticEvent } from 'react'
import { HTMLAttributes, SyntheticEvent, useRef } from 'react'
import { NumberFormatValues, NumericFormat } from 'react-number-format'
import { twMerge } from 'tailwind-merge'

Expand All @@ -23,7 +23,7 @@ export default function NumberInput({
id,
...props
}: HTMLAttributes<HTMLInputElement> & Props) {
let timeout: NodeJS.Timeout | null = null
const timeoutRef = useRef<NodeJS.Timeout>()

const handleValueChange = (
values: NumberFormatValues,
Expand All @@ -34,10 +34,10 @@ export default function NumberInput({
) => {
// If the value change because we typed something, we debounce it
if (sourceInfo.source === 'event') {
if (timeout) {
clearTimeout(timeout)
if (timeoutRef.current) {
clearTimeout(timeoutRef.current)
}
timeout = setTimeout(() => {
timeoutRef.current = setTimeout(() => {
setCorrectValue(values.value)
}, 300)
return
Expand Down
31 changes: 17 additions & 14 deletions src/components/form/question/Suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { questionClickSuggestion } from '@/constants/tracking/question'
import { useRule } from '@/publicodes-state'
import { Suggestion } from '@/publicodes-state/types'
import { FormattedSuggestion } from '@/publicodes-state/types'
import { trackEvent } from '@/utils/matomo/trackEvent'
import { DottedName, NodeValue } from '@incubateur-ademe/nosgestesclimat'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
Expand All @@ -23,12 +23,12 @@ export default function Suggestions({
}: Props) {
const { suggestions } = useRule(question)

const [selectedSuggestions, setSelectedSuggestions] = useState<Suggestion[]>(
[]
)
const [selectedSuggestions, setSelectedSuggestions] = useState<
FormattedSuggestion[]
>([])

const handleSuggestionClick = useCallback(
(suggestion: Suggestion) => {
(suggestion: FormattedSuggestion) => {
trackEvent(
questionClickSuggestion({ question, answer: suggestion.label })
)
Expand All @@ -54,22 +54,25 @@ export default function Suggestions({
break
}
},
[question, setValue, type]
[question, type]
)

const handleSuggestionDelete = useCallback((suggestion: Suggestion) => {
setSelectedSuggestions((prevSelectedSuggestions) =>
prevSelectedSuggestions.filter(
(prevSelectedSuggestion) =>
prevSelectedSuggestion.label !== suggestion.label
const handleSuggestionDelete = useCallback(
(suggestion: FormattedSuggestion) => {
setSelectedSuggestions((prevSelectedSuggestions) =>
prevSelectedSuggestions.filter(
(prevSelectedSuggestion) =>
prevSelectedSuggestion.label !== suggestion.label
)
)
)
}, [])
},
[]
)

const valueOfSelectedSuggestions = useMemo(
() =>
selectedSuggestions.reduce(
(acc, suggestion) => acc + suggestion.value,
(acc, suggestion) => acc + Number(suggestion.value),
0
),
[selectedSuggestions]
Expand Down
8 changes: 4 additions & 4 deletions src/components/form/question/suggestions/SuggestionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {
getTextCategoryColor,
} from '@/helpers/getCategoryColorClass'
import { useForm } from '@/publicodes-state'
import { Suggestion } from '@/publicodes-state/types'
import { FormattedSuggestion } from '@/publicodes-state/types'
import { capitalizeString } from '@/utils/capitalizeString'
import { twMerge } from 'tailwind-merge'

type Props = {
suggestion: Suggestion
suggestion: FormattedSuggestion
type: 'radio' | 'checkbox'
handleSuggestionClick: (suggestion: Suggestion) => void
handleSuggestionDelete: (suggestion: Suggestion) => void
handleSuggestionClick: (suggestion: FormattedSuggestion) => void
handleSuggestionDelete: (suggestion: FormattedSuggestion) => void
numberOfSelections: number
}

Expand Down

0 comments on commit 29ddccf

Please sign in to comment.