Skip to content

Commit

Permalink
feat: fix bug empty tags
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeSlain committed Nov 27, 2024
1 parent f53b736 commit c753ab8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 62 deletions.
56 changes: 0 additions & 56 deletions src/components/Meeting/MeetingAdditionalInput.tsx

This file was deleted.

1 change: 1 addition & 0 deletions src/components/Meeting/MeetingTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function MeetingTags({ setContext, field, tags }) {
}
}

if (!tags) return null
return (
<>
{tags.map((tag, index) => {
Expand Down
20 changes: 15 additions & 5 deletions src/components/Meeting/ThemesAndAdminsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useGetInstitutions } from '@api'
import { Input } from '@codegouvfr/react-dsfr/Input'
import Fuse from 'fuse.js'
import { useSelector } from 'react-redux'
import type { RootState } from '@types'
import type { MeetingInputContext, RootState } from '@types'

const options = {
includeScore: true,
Expand All @@ -18,6 +18,12 @@ export function ThemesAndAdminsInput({
themes,
administrations,
showError,
}: {
field: any
themes: string[] | null
administrations: string[] | null
onTagSelect: (tag, fieldName) => void
showError: boolean
}) {
const [searchResults, setSearchResults] = useState([])
const [selectedValue, setSelectedValue] = useState('')
Expand Down Expand Up @@ -84,13 +90,17 @@ export function ThemesAndAdminsInput({

const isTagSelected = (tag) => {
return (
(field.name === 'themes' && themes.includes(tag)) ||
(field.name === 'administrations' && administrations.includes(tag))
(field.name === 'themes' && themes && themes.includes(tag)) ||
(field.name === 'administrations' &&
administrations &&
administrations.includes(tag))
)
}

const isFieldEmpty =
field.name === 'themes' ? themes.length === 0 : administrations.length === 0
field.name === 'themes'
? !themes || themes.length === 0
: !administrations || administrations.length === 0

return (
<div>
Expand All @@ -110,7 +120,7 @@ export function ThemesAndAdminsInput({
showError && isFieldEmpty ? `Le champ ${field.label} est obligatoire` : ''
}
/>
{field.name === 'administrations' && (
{field.name === 'administrations' && administrations && (
<div tabIndex={-1} className="fr-mb-2v">
{searchResults
.slice(0, 5)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Root/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function NavigationMenu() {
const menuItems = [
{ to: '/meeting', label: 'Poser une nouvelle question' },
{ to: '/history', label: 'Mes échanges' },
{ to: '/evaluations', label: 'Évaluer Albert' },
// { to: '/evaluations', label: 'Évaluer Albert' },
{ to: '/outils', label: 'Vos outils numériques' },
{ to: '/FAQ', label: 'Aide' },
{ to: '/contact', label: 'Contact' },
Expand Down

0 comments on commit c753ab8

Please sign in to comment.