-
-
-
-
-
-
-
-
{{ countFilteredBenefits() }} aides disponibles pour la commune
- de {{ selectedCommune.nom }}
-
+
+
Total : {{ benefitsCount }} aides
+
+
+
+
+
+
+
+
+
+
+
+ {{ countFilteredBenefits() }} aides disponibles
+
+ pour la commune de {{ selectedCommune.nom }}
+
+
+ pour la recherche "{{ searchTerms }}"
+
+
+
+ Aucune aide trouvée
+ pour le code postal {{ zipCode }}
+ pour "{{ searchTerms }}"
+
+
+
{{ types[type] }}
@@ -94,9 +124,9 @@ import { Commune } from "@lib/types/commune.d.js"
import { capitalize } from "@lib/utils.js"
import BackButton from "@/components/buttons/back-button.vue"
-const zipCode = ref("")
-const selectedCommune = ref()
-const searchTerms = ref()
+const zipCode = ref(null)
+const selectedCommune = ref(null)
+const searchTerms = ref(null)
const benefitsCount = ref(process.env.VITE_BENEFIT_COUNT)
const types = {
national: "Aides nationales",
@@ -152,18 +182,31 @@ const institutionsGroups = computed(() => {
}
return institutionsBenefits
})
-async function computeDataSelected() {
- if (zipCode.value.match(/^[0-9]{5}$/)) {
+
+async function computeZipCode() {
+ if (zipCode.value && zipCode.value.length > 2) {
const res = await CommuneMethods.get(zipCode.value)
selectedCommune.value = res[0]
- } else {
- selectedCommune.value = null
- searchTerms.value = zipCode.value.toLowerCase()
}
}
-watch(zipCode, (newZipCode: string) => {
- if (newZipCode.length > 2) {
- computeDataSelected()
+
+async function computeKeywords() {
+ if (searchTerms.value && searchTerms.value.length > 2) {
+ const res = await CommuneMethods.get(searchTerms.value)
+ selectedCommune.value = res[0]
+ }
+}
+
+watch(zipCode, (newZipCode: string | null) => {
+ if (newZipCode && newZipCode.length > 2) {
+ computeZipCode()
+ searchTerms.value = null
+ }
+})
+watch(searchTerms, (newSearchTerms: string | null) => {
+ if (newSearchTerms && newSearchTerms.length > 2) {
+ computeKeywords()
+ zipCode.value = null
}
})
function countFilteredBenefits(): number {
@@ -178,4 +221,8 @@ function countFilteredBenefits(): number {
)
}, 0)
}
+
+const alertClass = computed(() =>
+ countFilteredBenefits() > 0 ? "fr-alert--success" : "fr-alert--error"
+)