diff --git a/source/Provider.tsx b/source/Provider.tsx index 613dce56a..919167db2 100644 --- a/source/Provider.tsx +++ b/source/Provider.tsx @@ -95,9 +95,10 @@ export default class Provider extends PureComponent { this.props.tracker.disconnectFromHistory() } render() { - const iframeCouleur = new URLSearchParams( - document?.location.search.substring(1) - ).get('couleur') + const iframeCouleur = + new URLSearchParams(document?.location.search.substring(1)).get( + 'couleur' + ) ?? undefined return ( // If IE < 11 display nothing diff --git a/source/Tracker.ts b/source/Tracker.ts index dcd80230f..830ee274b 100644 --- a/source/Tracker.ts +++ b/source/Tracker.ts @@ -12,8 +12,8 @@ type PushType = (args: PushArgs) => void export default class Tracker { push: PushType - unlistenFromHistory: () => void - previousPath: string + unlistenFromHistory: (() => void) | undefined + previousPath: string | undefined constructor(pushFunction: PushType = args => window._paq.push(args)) { if (typeof window !== 'undefined') window._paq = window._paq || [] diff --git a/source/actions/actions.ts b/source/actions/actions.ts index 33c81d739..72800aa11 100644 --- a/source/actions/actions.ts +++ b/source/actions/actions.ts @@ -43,12 +43,17 @@ type DeletePreviousSimulationAction = { type: 'DELETE_PREVIOUS_SIMULATION' } -type SetExempleAction = { - type: 'SET_EXAMPLE' - name: null | string - situation?: object - dottedName?: string -} +type SetExempleAction = + | { + type: 'SET_EXAMPLE' + name: null + } + | { + type: 'SET_EXAMPLE' + name: string + situation: object + dottedName: DottedName + } type ResetSimulationAction = ReturnType type UpdateAction = ReturnType @@ -142,7 +147,8 @@ export const goBackToSimulation = (): ThunkResult => ( { history } ) => { dispatch({ type: 'SET_EXAMPLE', name: null }) - history.push(getState().simulation.url) + const url = getState().simulation?.url + url && history.push(url) } export function loadPreviousSimulation() { @@ -155,7 +161,7 @@ export function hideControl(id: string) { return { type: 'HIDE_CONTROL', id } as const } -export const explainVariable = (variableName = null) => +export const explainVariable = (variableName: DottedName | null = null) => ({ type: 'EXPLAIN_VARIABLE', variableName diff --git a/source/api/sirene.ts b/source/api/sirene.ts index 8df00bf7a..fb9fdd28a 100644 --- a/source/api/sirene.ts +++ b/source/api/sirene.ts @@ -30,7 +30,9 @@ export type Etablissement = { denomination?: string } -async function searchFullText(text: string): Promise> { +async function searchFullText( + text: string +): Promise | null> { const response = await fetch( `https://entreprise.data.gouv.fr/api/sirene/v1/full_text/${text}?per_page=5` ) diff --git a/source/components/CurrencyInput/CurrencyInput.tsx b/source/components/CurrencyInput/CurrencyInput.tsx index f8d892146..eb5dd5710 100644 --- a/source/components/CurrencyInput/CurrencyInput.tsx +++ b/source/components/CurrencyInput/CurrencyInput.tsx @@ -25,11 +25,11 @@ export default function CurrencyInput({ const [initialValue, setInitialValue] = useState(valueProp) const [currentValue, setCurrentValue] = useState(valueProp) const onChangeDebounced = useRef( - debounceTimeout ? debounce(debounceTimeout, onChange) : onChange + debounceTimeout && onChange ? debounce(debounceTimeout, onChange) : onChange ) // We need some mutable reference because the component doesn't provide // the DOM `event` in its custom `onValueChange` handler - const nextValue = useRef(null) + const nextValue = useRef('') const inputRef = useRef() @@ -51,8 +51,8 @@ export default function CurrencyInput({ ...event.target, value: nextValue.current } - nextValue.current = null - onChangeDebounced.current(event) + nextValue.current = '' + onChangeDebounced.current?.(event) } const { @@ -71,7 +71,7 @@ export default function CurrencyInput({
5 ? { style: { width } } : {})} - onClick={() => inputRef.current.focus()} + onClick={() => inputRef.current?.focus()} > {!currentValue && isCurrencyPrefixed && currencySymbol} void; onCancel: () => void } export default function FeedbackForm({ onEnd, onCancel }: Props) { - const formRef = useRef() + const formRef = useRef(null) const tracker = useContext(TrackerContext) const handleFormSubmit = (e: React.FormEvent): void => { @@ -14,7 +14,7 @@ export default function FeedbackForm({ onEnd, onCancel }: Props) { e.preventDefault() fetch('/', { method: 'POST', - body: new FormData(formRef.current) + body: new FormData(formRef.current ?? undefined) }) onEnd() } diff --git a/source/components/FindCompany.tsx b/source/components/FindCompany.tsx index 351b073ce..71c007abe 100644 --- a/source/components/FindCompany.tsx +++ b/source/components/FindCompany.tsx @@ -7,7 +7,9 @@ import { Etablissement, searchDenominationOrSiren } from '../api/sirene' import { debounce } from '../utils' export default function Search() { - const [searchResults, setSearchResults] = useState>() + const [searchResults, setSearchResults] = useState | null>() const [isLoading, setLoadingState] = useState(false) const handleSearch = useCallback( diff --git a/source/components/QuickLinks.tsx b/source/components/QuickLinks.tsx index bbcee1971..d4886f2e6 100644 --- a/source/components/QuickLinks.tsx +++ b/source/components/QuickLinks.tsx @@ -30,24 +30,26 @@ export default function QuickLinks() { toPairs )(quickLinks) + if (links.length < 1) { + return null + } + return ( - !!links.length && ( - - Questions : - {links.map(([label, dottedName]) => ( - - ))}{' '} - {/* */} - - ) + + Questions : + {links.map(([label, dottedName]) => ( + + ))}{' '} + {/* */} + ) } diff --git a/source/components/SalaryExplanation.tsx b/source/components/SalaryExplanation.tsx index e267652a0..add7f7459 100644 --- a/source/components/SalaryExplanation.tsx +++ b/source/components/SalaryExplanation.tsx @@ -34,7 +34,7 @@ export default function SalaryExplanation() { const showDistributionFirst = useSelector( (state: RootState) => !state.conversationSteps.foldedSteps.length ) - const distributionRef = useRef() + const distributionRef = useRef(null) return ( @@ -51,7 +51,7 @@ export default function SalaryExplanation() {