-
Notifications
You must be signed in to change notification settings - Fork 1
fix: 1101 correctifs etape 3 (formattage adresse) #1284
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
Open
olivier-rabot
wants to merge
6
commits into
main
Choose a base branch
from
fix/1101-bilan-annees-etape-trois
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c341019
fix: 1101 correctifs etape 3 (formattage adresse)
olivier-rabot e3d0e45
fix: 1101 correctifs saisie adresse plus validation
olivier-rabot 2cdc70a
fix: 1101 correctifs saisie adresse plus validation (retours bot)
olivier-rabot bf4a5c0
fix: 1101 correctifs saisie adresse plus validation (retours bot)
olivier-rabot 5ba2028
fix: 1101 correctifs saisie adresse plus validation (add test)
olivier-rabot 23b4903
fix: 1101 correctifs saisie adresse plus validation (retours pr)
olivier-rabot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,9 +15,9 @@ | |||||
| </div> | ||||||
| <AgrementBilanHebergementDetail | ||||||
| v-for="(hebergement, index) in paginatedHebergements" | ||||||
| :key="`${hebergement.agrBilanAnnuelId}-${hebergement.adresseId}-${index}`" | ||||||
| :key="`${hebergement.agrBilanAnnuelId}-${hebergement.agrBilanAnnuelId}-${index}`" | ||||||
| :hebergement="hebergement" | ||||||
| :statut="props.statut" | ||||||
| :statut="props.statut || AGREMENT_STATUT.BROUILLON" | ||||||
| @update=" | ||||||
| (updatedHebergement) => | ||||||
| handleHebergementUpdate(index, updatedHebergement) | ||||||
|
|
@@ -57,7 +57,10 @@ | |||||
| </div> | ||||||
| <div class="fr-mt-6v"> | ||||||
| <p class="fr-mb-0">Période</p> | ||||||
| <AgrementBilanSelectMonths :default-selected="props.bilanHebergement?.mois" :modifiable="props.modifiable" @update:selected="handleMonths" /> | ||||||
| <AgrementBilanSelectMonths | ||||||
| :modifiable="props.modifiable" | ||||||
| @update:selected="handleMonths" | ||||||
| /> | ||||||
| <p | ||||||
| v-if="periodeMeta.touched && periodeErrorMessage" | ||||||
| class="fr-error-text" | ||||||
|
|
@@ -100,59 +103,58 @@ | |||||
| </div> | ||||||
| </template> | ||||||
|
|
||||||
| <script setup> | ||||||
| <script setup lang="ts"> | ||||||
| import { computed, ref, watch } from "vue"; | ||||||
| import type { BilanHebergementDto } from "@vao/shared-bridge/src/dto/agrement.dto"; | ||||||
| import type { AdresseDto } from "@vao/shared-bridge/src/dto/adresse.dto"; | ||||||
| import SearchAddress from "@/components/address/search-address.vue"; | ||||||
| import { useField, useForm } from "vee-validate"; | ||||||
| import { useToaster } from "@vao/shared-ui"; | ||||||
| import { normalizeAdresse, AGREMENT_STATUT } from "@vao/shared-bridge"; | ||||||
| import * as yup from "yup"; | ||||||
|
|
||||||
| const props = defineProps({ | ||||||
| bilanHebergement: { | ||||||
| type: Array, | ||||||
| required: false, | ||||||
| default: () => [], | ||||||
| }, | ||||||
| statut: { | ||||||
| type: String, | ||||||
| required: false, | ||||||
| default: "BROUILLON", | ||||||
| }, | ||||||
| modifiable: { type: Boolean, required: false, default: false }, | ||||||
| }); | ||||||
| const log = logger("components/AgrementBilanHebergements"); | ||||||
|
|
||||||
| const props = defineProps<{ | ||||||
| bilanHebergement?: BilanHebergementDto[]; | ||||||
| statut?: string; | ||||||
| modifiable?: boolean; | ||||||
| }>(); | ||||||
|
|
||||||
| const toaster = useToaster(); | ||||||
|
|
||||||
| const localHebergements = ref([...props.bilanHebergement]); | ||||||
| const localHebergements = ref<BilanHebergementDto[]>([ | ||||||
| ...(props.bilanHebergement ?? []), | ||||||
| ]); | ||||||
|
|
||||||
| const isFirstLoad = ref(true); | ||||||
| const isFirstLoad = ref<boolean>(true); | ||||||
|
|
||||||
| watch( | ||||||
| () => props.bilanHebergement, | ||||||
| (newBilanHebergement) => { | ||||||
| if (isFirstLoad.value) { | ||||||
| localHebergements.value = [...newBilanHebergement]; | ||||||
| localHebergements.value = [...(newBilanHebergement ?? [])]; | ||||||
| isFirstLoad.value = false; | ||||||
| } | ||||||
| }, | ||||||
| { immediate: true, deep: true }, | ||||||
| ); | ||||||
|
|
||||||
| const ITEMS_PER_PAGE = 10; | ||||||
| const currentPage = ref(0); | ||||||
| const currentPage = ref<number>(0); | ||||||
|
|
||||||
| const showForm = ref(false); | ||||||
| const showForm = ref<boolean>(false); | ||||||
|
|
||||||
| function toggleForm() { | ||||||
| function toggleForm(): void { | ||||||
| showForm.value = !showForm.value; | ||||||
| } | ||||||
|
|
||||||
| const totalPages = computed(() => { | ||||||
| const totalPages = computed<number>(() => { | ||||||
| return Math.ceil(localHebergements.value.length / ITEMS_PER_PAGE); | ||||||
| }); | ||||||
|
|
||||||
| const pages = computed(() => { | ||||||
| const pageArray = []; | ||||||
| const pages = computed<{ title: string; href: string; label: string }[]>(() => { | ||||||
| const pageArray: { title: string; href: string; label: string }[] = []; | ||||||
| for (let i = 1; i <= totalPages.value; i++) { | ||||||
| pageArray.push({ | ||||||
| title: `Lien vers la page ${i}`, | ||||||
|
|
@@ -163,18 +165,21 @@ const pages = computed(() => { | |||||
| return pageArray; | ||||||
| }); | ||||||
|
|
||||||
| const paginatedHebergements = computed(() => { | ||||||
| const paginatedHebergements = computed<BilanHebergementDto[]>(() => { | ||||||
| const start = currentPage.value * ITEMS_PER_PAGE; | ||||||
| const end = start + ITEMS_PER_PAGE; | ||||||
| return localHebergements.value.slice(start, end); | ||||||
| }); | ||||||
|
|
||||||
| function handleHebergementUpdate(index, updatedHebergement) { | ||||||
| function handleHebergementUpdate( | ||||||
| index: number, | ||||||
| updatedHebergement: BilanHebergementDto, | ||||||
| ): void { | ||||||
| const actualIndex = currentPage.value * ITEMS_PER_PAGE + index; | ||||||
| localHebergements.value[actualIndex] = { ...updatedHebergement }; | ||||||
| } | ||||||
|
|
||||||
| function handleHebergementDelete(index) { | ||||||
| function handleHebergementDelete(index: number): void { | ||||||
| const actualIndex = currentPage.value * ITEMS_PER_PAGE + index; | ||||||
| localHebergements.value.splice(actualIndex, 1); | ||||||
|
|
||||||
|
|
@@ -209,57 +214,65 @@ const { | |||||
| errorMessage: nomHebergementErrorMessage, | ||||||
| handleChange: onNomHebergementChange, | ||||||
| meta: nomHebergementMeta, | ||||||
| } = useField("nomHebergement"); | ||||||
| } = useField<string>("nomHebergement"); | ||||||
|
|
||||||
| const { | ||||||
| value: nbJours, | ||||||
| errorMessage: nbJoursErrorMessage, | ||||||
| handleChange: onNbJoursChange, | ||||||
| meta: nbJoursMeta, | ||||||
| } = useField("nbJours"); | ||||||
| } = useField<number>("nbJours"); | ||||||
|
|
||||||
| const { value: adresse, errorMessage: adresseErrorMessage } = | ||||||
| useField("adresse"); | ||||||
| useField<any>("adresse"); | ||||||
|
|
||||||
| const { | ||||||
| value: periode, | ||||||
| errorMessage: periodeErrorMessage, | ||||||
| meta: periodeMeta, | ||||||
| } = useField("periode"); | ||||||
| } = useField<string[]>("periode"); | ||||||
|
|
||||||
| function handleMonths(monthsArray) { | ||||||
| function handleMonths(monthsArray: string[]): void { | ||||||
| periode.value = monthsArray; | ||||||
| } | ||||||
|
|
||||||
| const selectedAdresseObject = ref(null); | ||||||
| const selectedAdresseObject = ref<AdresseDto | { label: string } | null>(null); | ||||||
|
|
||||||
| function onAdresseSelect(selectedAddress) { | ||||||
| adresse.value = selectedAddress.label; | ||||||
| function onAdresseSelect( | ||||||
| selectedAddress: AdresseDto | { label: string }, | ||||||
| ): void { | ||||||
| adresse.value = selectedAddress.label || ""; | ||||||
| selectedAdresseObject.value = selectedAddress; | ||||||
| } | ||||||
|
|
||||||
| const onSubmitAddSejour = handleSubmit( | ||||||
| (values) => { | ||||||
| const adresseObject = selectedAdresseObject.value | ||||||
| ? { | ||||||
| label: selectedAdresseObject.value.label, | ||||||
| codeInsee: selectedAdresseObject.value.codeInsee || null, | ||||||
| codePostal: selectedAdresseObject.value.codePostal || null, | ||||||
| long: selectedAdresseObject.value.long || null, | ||||||
| lat: selectedAdresseObject.value.lat || null, | ||||||
| departement: selectedAdresseObject.value.departement || null, | ||||||
| } | ||||||
| : { label: values.adresse }; | ||||||
| (values: Record<string, any>) => { | ||||||
| const adresseObject: AdresseDto | { label: string } = | ||||||
| selectedAdresseObject.value | ||||||
| ? selectedAdresseObject.value | ||||||
| : { label: values.adresse }; | ||||||
|
|
||||||
| let adresseNorm: AdresseDto; | ||||||
| try { | ||||||
| adresseNorm = normalizeAdresse(adresseObject); | ||||||
| } catch (e) { | ||||||
| log.w("Erreur de normalisation de l'adresse :", e); | ||||||
| toaster.error({ | ||||||
| description: "L'adresse saisie est incomplète ou invalide.", | ||||||
| }); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| const agrBilanAnnuelId = | ||||||
| props.bilanHebergement[0]?.agrBilanAnnuelId || null; | ||||||
| (props.bilanHebergement && props.bilanHebergement[0]?.agrBilanAnnuelId) || | ||||||
| null; | ||||||
|
|
||||||
| const newHebergement = { | ||||||
| const newHebergement: BilanHebergementDto = { | ||||||
| agrBilanAnnuelId, | ||||||
| nomHebergement: values.nomHebergement, | ||||||
| adresse: adresseObject, | ||||||
| adresse: adresseNorm, | ||||||
| nbJours: parseInt(values.nbJours), | ||||||
| mois: values.periode.map((m) => parseInt(m)), | ||||||
| agrBilanAnnuelId, | ||||||
| mois: values.periode.map((m: string) => parseInt(m)), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
toujours spécifié le radix dans un parseInt ! |
||||||
| }; | ||||||
|
|
||||||
| localHebergements.value.push(newHebergement); | ||||||
|
|
@@ -273,19 +286,19 @@ const onSubmitAddSejour = handleSubmit( | |||||
| description: "Le séjour a été ajouté avec succès.", | ||||||
| }); | ||||||
| }, | ||||||
| (errors) => { | ||||||
| (errors: any) => { | ||||||
| console.warn("Erreurs de validation :", errors); | ||||||
| }, | ||||||
| ); | ||||||
|
|
||||||
| function validateHebergements() { | ||||||
| function validateHebergements(): boolean { | ||||||
| let isValid = true; | ||||||
| const errors = []; | ||||||
| const errors: string[] = []; | ||||||
|
|
||||||
| localHebergements.value.forEach((hebergement, index) => { | ||||||
| if ( | ||||||
| !hebergement.nomHebergement || | ||||||
| hebergement.nomHebergement.trim() === "" | ||||||
| hebergement.nomHebergement?.trim?.() === "" | ||||||
| ) { | ||||||
| errors.push(`Hébergement ${index + 1}: Le nom est obligatoire`); | ||||||
| isValid = false; | ||||||
|
|
@@ -328,7 +341,7 @@ function validateHebergements() { | |||||
| return isValid; | ||||||
| } | ||||||
|
|
||||||
| function getHebergements() { | ||||||
| function getHebergements(): BilanHebergementDto[] { | ||||||
| return localHebergements.value; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
olivier-rabot marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.