Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47fe4ce1bb | |||
| f8b45cb30b | |||
| 0c0b57f898 | |||
| ef996c3672 | |||
| c6259a96cd | |||
| 40fdded7e2 | |||
| 0733a239a8 | |||
| cf645493c1 | |||
| 388d39a379 | |||
| d6d2144cc1 | |||
| 6a519874ed | |||
| 3804362546 | |||
| 9864dbc00f | |||
| be03f4e51a | |||
| 8cc2cea444 | |||
| f70e701854 |
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.131'
|
app.version: '0.1.134'
|
||||||
|
|||||||
@@ -526,7 +526,13 @@
|
|||||||
"toast": {
|
"toast": {
|
||||||
"error": "Une erreur est survenue. Réessayez.",
|
"error": "Une erreur est survenue. Réessayez.",
|
||||||
"exportError": "L'export du répertoire transporteurs a échoué. Réessayez.",
|
"exportError": "L'export du répertoire transporteurs a échoué. Réessayez.",
|
||||||
"createSuccess": "Transporteur créé avec succès"
|
"createSuccess": "Transporteur créé avec succès",
|
||||||
|
"integrateSuccess": "Transporteur QUALIMAT intégré",
|
||||||
|
"addressSaved": "Adresse enregistrée"
|
||||||
|
},
|
||||||
|
"containerType": {
|
||||||
|
"BENNE": "Benne",
|
||||||
|
"FOND_MOUVANT": "Fond mouvant"
|
||||||
},
|
},
|
||||||
"tab": {
|
"tab": {
|
||||||
"qualimat": "Qualimat",
|
"qualimat": "Qualimat",
|
||||||
@@ -543,10 +549,53 @@
|
|||||||
"main": {
|
"main": {
|
||||||
"name": "Nom",
|
"name": "Nom",
|
||||||
"certificationType": "Certification transport",
|
"certificationType": "Certification transport",
|
||||||
"isChartered": "Affréter"
|
"isChartered": "Affréter",
|
||||||
|
"indexationRate": "Indexation %",
|
||||||
|
"containerType": "Benne / Fond mouvant",
|
||||||
|
"volumeM3": "Volume m³",
|
||||||
|
"discharge": "Décharge",
|
||||||
|
"liotPlates": "Immatriculations LIOT",
|
||||||
|
"liotPlatesHint": "Séparées par « ; »"
|
||||||
|
},
|
||||||
|
"qualimat": {
|
||||||
|
"empty": "Aucun transporteur QUALIMAT trouvé.",
|
||||||
|
"searchHint": "Saisissez le nom du transporteur pour lancer la recherche.",
|
||||||
|
"columns": {
|
||||||
|
"name": "Nom",
|
||||||
|
"address": "Adresse",
|
||||||
|
"validityDate": "Date de validité"
|
||||||
|
},
|
||||||
|
"confirm": {
|
||||||
|
"title": "Intégration QUALIMAT",
|
||||||
|
"message": "Êtes-vous sûr de vouloir intégrer ce transporteur ?",
|
||||||
|
"cancel": "Annuler",
|
||||||
|
"confirm": "Intégrer"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"nameRequired": "Le nom du transporteur est obligatoire."
|
"nameRequired": "Le nom du transporteur est obligatoire.",
|
||||||
|
"certificationRequired": "Le type de certification est obligatoire.",
|
||||||
|
"dischargeRequired": "La décharge est obligatoire pour une certification « Autre ».",
|
||||||
|
"indexationRequired": "Le taux d'indexation est obligatoire pour un transporteur affrété.",
|
||||||
|
"containerTypeRequired": "Le type de contenant est obligatoire pour un transporteur affrété.",
|
||||||
|
"volumeRequired": "Le volume est obligatoire pour un transporteur affrété."
|
||||||
|
},
|
||||||
|
"address": {
|
||||||
|
"country": "Pays",
|
||||||
|
"postalCode": "Code postal",
|
||||||
|
"city": "Ville",
|
||||||
|
"street": "Adresse",
|
||||||
|
"streetComplement": "Adresse complémentaire",
|
||||||
|
"streetNotFound": "Adresse introuvable ? Saisissez-la directement.",
|
||||||
|
"add": "Nouvelle adresse",
|
||||||
|
"remove": "Supprimer l'adresse",
|
||||||
|
"degraded": "Service d'adresse indisponible : saisie de la ville et de l'adresse en mode libre."
|
||||||
|
},
|
||||||
|
"confirmDelete": {
|
||||||
|
"title": "Supprimer ce bloc",
|
||||||
|
"message": "Cette suppression est définitive. Confirmer ?",
|
||||||
|
"cancel": "Annuler",
|
||||||
|
"confirm": "Supprimer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,237 @@
|
|||||||
|
<template>
|
||||||
|
<div class="relative grid grid-cols-4 gap-x-[44px] gap-y-4 bg-white py-4 pl-[28px] pr-[60px] shadow-[0_4px_4px_0_rgba(0,0,0,0.25)]">
|
||||||
|
<!-- Suppression : modal de confirmation cote parent. -->
|
||||||
|
<MalioButtonIcon
|
||||||
|
v-if="removable && !readonly"
|
||||||
|
icon="mdi:delete-outline"
|
||||||
|
variant="ghost"
|
||||||
|
button-class="absolute top-3 right-3"
|
||||||
|
v-bind="{ ariaLabel: t('transport.carriers.form.address.remove') }"
|
||||||
|
@click="$emit('remove')"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Pays : prerempli « France » (RG-4.05). -->
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="model.country"
|
||||||
|
:options="countryOptions"
|
||||||
|
:label="t('transport.carriers.form.address.country')"
|
||||||
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.country"
|
||||||
|
@update:model-value="(v: string | number | null) => update('country', String(v ?? 'France'))"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Code postal (RG-4.06) : declenche l'autocomplete ville (BAN). -->
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="model.postalCode"
|
||||||
|
:label="t('transport.carriers.form.address.postalCode')"
|
||||||
|
:mask="POSTAL_CODE_MASK"
|
||||||
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.postalCode"
|
||||||
|
@update:model-value="onPostalCodeChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Ville : MalioSelect alimente par le code postal (BAN). Saisie libre si BAN indispo. -->
|
||||||
|
<MalioSelect
|
||||||
|
v-if="!degraded"
|
||||||
|
:model-value="model.city"
|
||||||
|
:options="cityOptions"
|
||||||
|
:label="t('transport.carriers.form.address.city')"
|
||||||
|
:readonly="readonly"
|
||||||
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.city"
|
||||||
|
@update:model-value="(v: string | number | null) => update('city', v === null ? null : String(v))"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-else
|
||||||
|
:model-value="model.city"
|
||||||
|
:label="t('transport.carriers.form.address.city')"
|
||||||
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.city"
|
||||||
|
@update:model-value="(v: string) => update('city', v)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Filler : aligne le debut de la ligne suivante sur la grille. -->
|
||||||
|
<div aria-hidden="true" />
|
||||||
|
|
||||||
|
<!-- Adresse (BAN) sur 2 colonnes + Adresse complementaire. allow-create : le
|
||||||
|
texte saisi est conserve si la BAN ne propose rien (saisie manuelle). -->
|
||||||
|
<div class="col-span-2">
|
||||||
|
<MalioInputAutocomplete
|
||||||
|
v-if="!readonly"
|
||||||
|
:model-value="model.street"
|
||||||
|
:options="addressOptions"
|
||||||
|
:loading="addressLoading"
|
||||||
|
:min-search-length="3"
|
||||||
|
:label="t('transport.carriers.form.address.street')"
|
||||||
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.street"
|
||||||
|
:allow-create="true"
|
||||||
|
:no-results-text="t('transport.carriers.form.address.streetNotFound')"
|
||||||
|
@update:model-value="(v: string | number | null) => update('street', v === null ? null : String(v))"
|
||||||
|
@search="onAddressSearch"
|
||||||
|
@select="onAddressSelect"
|
||||||
|
/>
|
||||||
|
<MalioInputText
|
||||||
|
v-else
|
||||||
|
:model-value="model.street"
|
||||||
|
:label="t('transport.carriers.form.address.street')"
|
||||||
|
:readonly="readonly"
|
||||||
|
:required="true"
|
||||||
|
:error="errors?.street"
|
||||||
|
@update:model-value="(v: string) => update('street', v)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<MalioInputText
|
||||||
|
:model-value="model.streetComplement"
|
||||||
|
:label="t('transport.carriers.form.address.streetComplement')"
|
||||||
|
:readonly="readonly"
|
||||||
|
:error="errors?.streetComplement"
|
||||||
|
@update:model-value="(v: string) => update('streetComplement', v)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useAddressAutocomplete, type AddressSuggestion } from '~/shared/composables/useAddressAutocomplete'
|
||||||
|
import type { CarrierAddressFormDraft } from '~/modules/transport/types/carrierForm'
|
||||||
|
|
||||||
|
interface RefOption {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Masque code postal FR : 5 chiffres.
|
||||||
|
const POSTAL_CODE_MASK = '#####'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
/** Brouillon de l'adresse (v-model). */
|
||||||
|
modelValue: CarrierAddressFormDraft
|
||||||
|
/** Pays disponibles (France par defaut). */
|
||||||
|
countryOptions: RefOption[]
|
||||||
|
removable?: boolean
|
||||||
|
readonly?: boolean
|
||||||
|
/** Erreurs serveur 422 de cette ligne, indexees par champ (ERP-101). */
|
||||||
|
errors?: Record<string, string>
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [value: CarrierAddressFormDraft]
|
||||||
|
'remove': []
|
||||||
|
/** Emis une fois quand le service d'autocompletion bascule en indisponible. */
|
||||||
|
'degraded': []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const autocomplete = useAddressAutocomplete()
|
||||||
|
|
||||||
|
const model = computed(() => props.modelValue)
|
||||||
|
|
||||||
|
// Repli saisie libre de la VILLE quand la BAN est indisponible (recuperable).
|
||||||
|
const degraded = ref(false)
|
||||||
|
let unavailableNotified = false
|
||||||
|
const banCityOptions = ref<RefOption[]>([])
|
||||||
|
const banAddressOptions = ref<RefOption[]>([])
|
||||||
|
|
||||||
|
// Options ville effectives : on garantit que la ville courante figure toujours
|
||||||
|
// dans la liste, sinon MalioSelect afficherait un champ vide en lecture seule.
|
||||||
|
const cityOptions = computed<RefOption[]>(() => {
|
||||||
|
const current = props.modelValue.city
|
||||||
|
if (current && !banCityOptions.value.some(o => o.value === current)) {
|
||||||
|
return [{ value: current, label: current }, ...banCityOptions.value]
|
||||||
|
}
|
||||||
|
return banCityOptions.value
|
||||||
|
})
|
||||||
|
|
||||||
|
// Meme garantie pour le champ Adresse : la rue courante doit toujours figurer
|
||||||
|
// dans les options, sinon MalioInputAutocomplete laisse le champ vide.
|
||||||
|
const addressOptions = computed<RefOption[]>(() => {
|
||||||
|
const current = props.modelValue.street
|
||||||
|
if (current && !banAddressOptions.value.some(o => o.value === current)) {
|
||||||
|
return [{ value: current, label: current }, ...banAddressOptions.value]
|
||||||
|
}
|
||||||
|
return banAddressOptions.value
|
||||||
|
})
|
||||||
|
const addressLoading = ref(false)
|
||||||
|
// Conserve les suggestions d'adresse pour retrouver ville/CP au moment du select.
|
||||||
|
let lastAddressSuggestions: AddressSuggestion[] = []
|
||||||
|
|
||||||
|
/** Emet un nouveau brouillon avec le champ modifie (immutabilite). */
|
||||||
|
function update<K extends keyof CarrierAddressFormDraft>(field: K, value: CarrierAddressFormDraft[K]): void {
|
||||||
|
emit('update:modelValue', { ...props.modelValue, [field]: value })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Previent le parent (toast unique) que l'autocompletion est indisponible. */
|
||||||
|
function notifyUnavailable(): void {
|
||||||
|
if (!unavailableNotified) {
|
||||||
|
unavailableNotified = true
|
||||||
|
emit('degraded')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Saisie du code postal → met a jour le champ + interroge la BAN pour la ville. */
|
||||||
|
async function onPostalCodeChange(value: string): Promise<void> {
|
||||||
|
update('postalCode', value)
|
||||||
|
|
||||||
|
const digits = (value ?? '').replace(/\D/g, '')
|
||||||
|
if (digits.length < 5) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const suggestions = await autocomplete.searchCity(digits)
|
||||||
|
banCityOptions.value = suggestions.map(s => ({ value: s.city, label: s.city }))
|
||||||
|
degraded.value = false
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
degraded.value = true
|
||||||
|
notifyUnavailable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Recherche d'adresse assistee (event de MalioInputAutocomplete). */
|
||||||
|
async function onAddressSearch(query: string): Promise<void> {
|
||||||
|
// La BAN exige au moins 3 caracteres : on n'envoie rien en deca (evite un 400).
|
||||||
|
if (query.trim().length < 3) {
|
||||||
|
banAddressOptions.value = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addressLoading.value = true
|
||||||
|
try {
|
||||||
|
const postalCode = (model.value.postalCode ?? '').replace(/\D/g, '') || undefined
|
||||||
|
const suggestions = await autocomplete.searchAddress(query, postalCode)
|
||||||
|
lastAddressSuggestions = suggestions
|
||||||
|
banAddressOptions.value = suggestions.map(s => ({ value: s.street, label: s.label }))
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// Erreur transitoire : on vide les suggestions, la prochaine frappe reessaie.
|
||||||
|
banAddressOptions.value = []
|
||||||
|
notifyUnavailable()
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
addressLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Selection d'une suggestion d'adresse → remplit rue + ville + CP. */
|
||||||
|
function onAddressSelect(option: { label: string, value: string | number } | null): void {
|
||||||
|
if (option === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const suggestion = lastAddressSuggestions.find(s => s.street === option.value)
|
||||||
|
if (!suggestion) {
|
||||||
|
update('street', String(option.value))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emit('update:modelValue', {
|
||||||
|
...props.modelValue,
|
||||||
|
street: suggestion.street,
|
||||||
|
city: suggestion.city,
|
||||||
|
postalCode: suggestion.postalCode,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
import { mount, flushPromises } from '@vue/test-utils'
|
||||||
|
import { defineComponent, h, ref, computed } from 'vue'
|
||||||
|
import { emptyCarrierAddress } from '~/modules/transport/types/carrierForm'
|
||||||
|
import CarrierAddressBlock from '../CarrierAddressBlock.vue'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests de l'autocomplétion BAN du bloc Adresse transporteur (ERP-167) — réutilise
|
||||||
|
* `useAddressAutocomplete` (M1/M2/M3). On vérifie le NOMINAL (CP → ville) et le
|
||||||
|
* DÉGRADÉ (BAN indisponible → saisie libre + event `degraded`).
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { searchCityMock, searchAddressMock } = vi.hoisted(() => ({
|
||||||
|
searchCityMock: vi.fn(),
|
||||||
|
searchAddressMock: vi.fn(),
|
||||||
|
}))
|
||||||
|
vi.mock('~/shared/composables/useAddressAutocomplete', () => ({
|
||||||
|
useAddressAutocomplete: () => ({
|
||||||
|
searchCity: searchCityMock,
|
||||||
|
searchAddress: searchAddressMock,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||||
|
vi.stubGlobal('ref', ref)
|
||||||
|
vi.stubGlobal('computed', computed)
|
||||||
|
|
||||||
|
const MalioInputTextStub = defineComponent({
|
||||||
|
name: 'MalioInputText',
|
||||||
|
props: { modelValue: { default: null }, label: { type: String, default: '' }, error: { type: String, default: '' } },
|
||||||
|
emits: ['update:modelValue'],
|
||||||
|
setup(props) {
|
||||||
|
return () => h('div', { 'data-testid': 'input-text', 'data-label': props.label, 'data-error': props.error })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const MalioSelectStub = defineComponent({
|
||||||
|
name: 'MalioSelect',
|
||||||
|
props: { modelValue: { default: null }, options: { type: Array as () => { value: string }[], default: () => [] }, label: { type: String, default: '' }, error: { type: String, default: '' } },
|
||||||
|
emits: ['update:modelValue'],
|
||||||
|
setup(props) {
|
||||||
|
return () => h('div', { 'data-testid': 'select', 'data-label': props.label, 'data-options': JSON.stringify(props.options.map(o => o.value)) })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const MalioInputAutocompleteStub = defineComponent({
|
||||||
|
name: 'MalioInputAutocomplete',
|
||||||
|
props: { modelValue: { default: null }, options: { type: Array as () => { value: string }[], default: () => [] }, loading: { type: Boolean, default: false }, allowCreate: { type: Boolean, default: false } },
|
||||||
|
emits: ['update:modelValue', 'search', 'select'],
|
||||||
|
setup(props) {
|
||||||
|
return () => h('div', { 'data-testid': 'addr-autocomplete', 'data-options': JSON.stringify(props.options.map(o => o.value)) })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function mountBlock(overrides: Record<string, unknown> = {}) {
|
||||||
|
return mount(CarrierAddressBlock, {
|
||||||
|
props: {
|
||||||
|
modelValue: { ...emptyCarrierAddress(), ...overrides },
|
||||||
|
countryOptions: [{ value: 'France', label: 'France' }],
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
stubs: {
|
||||||
|
MalioButtonIcon: true,
|
||||||
|
MalioInputText: MalioInputTextStub,
|
||||||
|
MalioSelect: MalioSelectStub,
|
||||||
|
MalioInputAutocomplete: MalioInputAutocompleteStub,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Récupère le composant MalioInputText d'un label donné. */
|
||||||
|
function inputTextByLabel(wrapper: ReturnType<typeof mountBlock>, label: string) {
|
||||||
|
return wrapper.findAllComponents(MalioInputTextStub).find(c => c.props('label') === label)
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('CarrierAddressBlock — autocomplétion ville (BAN) NOMINAL', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
searchCityMock.mockReset()
|
||||||
|
searchAddressMock.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('saisie d\'un CP à 5 chiffres → searchCity + peuple le select Ville', async () => {
|
||||||
|
searchCityMock.mockResolvedValueOnce([{ city: 'Poitiers', postalCode: '86000' }])
|
||||||
|
const wrapper = mountBlock()
|
||||||
|
|
||||||
|
const cp = inputTextByLabel(wrapper, 'transport.carriers.form.address.postalCode')
|
||||||
|
cp?.vm.$emit('update:modelValue', '86000')
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
expect(searchCityMock).toHaveBeenCalledWith('86000')
|
||||||
|
const citySelect = wrapper.findAllComponents(MalioSelectStub).find(c => c.props('label') === 'transport.carriers.form.address.city')
|
||||||
|
const options = JSON.parse(citySelect?.attributes('data-options') ?? '[]')
|
||||||
|
expect(options).toContain('Poitiers')
|
||||||
|
expect(wrapper.emitted('degraded')).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('n\'interroge pas la BAN sous 5 chiffres', async () => {
|
||||||
|
const wrapper = mountBlock()
|
||||||
|
inputTextByLabel(wrapper, 'transport.carriers.form.address.postalCode')?.vm.$emit('update:modelValue', '860')
|
||||||
|
await flushPromises()
|
||||||
|
expect(searchCityMock).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('CarrierAddressBlock — autocomplétion DÉGRADÉE', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
searchCityMock.mockReset()
|
||||||
|
searchAddressMock.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('BAN ville indisponible → bascule en saisie libre + émet « degraded »', async () => {
|
||||||
|
searchCityMock.mockRejectedValueOnce(new Error('BAN indisponible'))
|
||||||
|
const wrapper = mountBlock()
|
||||||
|
|
||||||
|
inputTextByLabel(wrapper, 'transport.carriers.form.address.postalCode')?.vm.$emit('update:modelValue', '86000')
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
expect(wrapper.emitted('degraded')).toHaveLength(1)
|
||||||
|
// En dégradé, la Ville devient un MalioInputText (plus de MalioSelect ville).
|
||||||
|
const citySelect = wrapper.findAllComponents(MalioSelectStub).find(c => c.props('label') === 'transport.carriers.form.address.city')
|
||||||
|
expect(citySelect).toBeUndefined()
|
||||||
|
expect(inputTextByLabel(wrapper, 'transport.carriers.form.address.city')).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('autocomplétion adresse : pas d\'appel BAN sous 3 caractères', async () => {
|
||||||
|
const wrapper = mountBlock()
|
||||||
|
wrapper.findComponent(MalioInputAutocompleteStub).vm.$emit('search', 'ab')
|
||||||
|
await flushPromises()
|
||||||
|
expect(searchAddressMock).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('autocomplétion adresse : émet « degraded » une seule fois malgré plusieurs erreurs', async () => {
|
||||||
|
searchAddressMock.mockRejectedValue(new Error('BAN indisponible'))
|
||||||
|
const wrapper = mountBlock()
|
||||||
|
const auto = wrapper.findComponent(MalioInputAutocompleteStub)
|
||||||
|
|
||||||
|
auto.vm.$emit('search', 'rue de la paix')
|
||||||
|
await flushPromises()
|
||||||
|
auto.vm.$emit('search', 'rue de la paixx')
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
expect(wrapper.emitted('degraded')).toHaveLength(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('active allow-create sur le champ Adresse (saisie manuelle libre)', () => {
|
||||||
|
const wrapper = mountBlock()
|
||||||
|
expect(wrapper.findComponent(MalioInputAutocompleteStub).props('allowCreate')).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -19,13 +19,14 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|||||||
|
|
||||||
const mockPost = vi.hoisted(() => vi.fn())
|
const mockPost = vi.hoisted(() => vi.fn())
|
||||||
const mockPatch = vi.hoisted(() => vi.fn())
|
const mockPatch = vi.hoisted(() => vi.fn())
|
||||||
|
const mockDelete = vi.hoisted(() => vi.fn())
|
||||||
|
|
||||||
vi.stubGlobal('useApi', () => ({
|
vi.stubGlobal('useApi', () => ({
|
||||||
get: vi.fn(),
|
get: vi.fn(),
|
||||||
post: mockPost,
|
post: mockPost,
|
||||||
put: vi.fn(),
|
put: vi.fn(),
|
||||||
patch: mockPatch,
|
patch: mockPatch,
|
||||||
delete: vi.fn(),
|
delete: mockDelete,
|
||||||
}))
|
}))
|
||||||
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||||
vi.stubGlobal('useToast', () => ({
|
vi.stubGlobal('useToast', () => ({
|
||||||
@@ -65,12 +66,85 @@ describe('useCarrierForm', () => {
|
|||||||
expect(form.mainErrors.errors.name).toBe('transport.carriers.form.errors.nameRequired')
|
expect(form.mainErrors.errors.name).toBe('transport.carriers.form.errors.nameRequired')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('front : certification vide (hors LIOT) → erreur inline sur certificationType, pas de POST', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
// certificationType laissé null → bloqué côté front (RG-4.01).
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(form.mainErrors.errors.certificationType).toBe('transport.carriers.form.errors.certificationRequired')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front : cas LIOT → certification non requise (aucune erreur de certification)', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 5, name: 'LIOT', certificationType: null })
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'LIOT'
|
||||||
|
form.main.liotPlates = 'AA-123-BB'
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(true)
|
||||||
|
expect(form.mainErrors.errors.certificationType).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front RG-4.02 : certification AUTRE sans décharge → erreur inline, pas de POST', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'AUTRE'
|
||||||
|
// dischargeDocumentIri null (upload non fourni).
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(form.mainErrors.errors.dischargeDocument).toBe('transport.carriers.form.errors.dischargeRequired')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front RG-4.03 : affrété sans indexation / contenant / volume → 3 erreurs inline, pas de POST', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
form.main.isChartered = true
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(form.mainErrors.errors.indexationRate).toBe('transport.carriers.form.errors.indexationRequired')
|
||||||
|
expect(form.mainErrors.errors.containerType).toBe('transport.carriers.form.errors.containerTypeRequired')
|
||||||
|
expect(form.mainErrors.errors.volumeM3).toBe('transport.carriers.form.errors.volumeRequired')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front RG-4.03 : affrété avec tous les champs remplis → POST envoyé', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 8, name: 'ACME', certificationType: 'GMP_PLUS' })
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
form.main.isChartered = true
|
||||||
|
form.main.indexationRate = '5'
|
||||||
|
form.main.containerType = 'BENNE'
|
||||||
|
form.main.volumeM3 = '30'
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(true)
|
||||||
|
expect(mockPost).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockPost.mock.calls[0]?.[1]).toMatchObject({
|
||||||
|
isChartered: true,
|
||||||
|
indexationRate: '5',
|
||||||
|
containerType: 'BENNE',
|
||||||
|
volumeM3: '30',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('POST /carriers avec Accept ld+json, verrouille et bascule sur Qualimat', async () => {
|
it('POST /carriers avec Accept ld+json, verrouille et bascule sur Qualimat', async () => {
|
||||||
mockPost.mockResolvedValueOnce({ id: 42, name: 'TRANSPORTS ACME', certificationType: 'GMP_PLUS' })
|
mockPost.mockResolvedValueOnce({ id: 42, name: 'TRANSPORTS ACME', certificationType: 'GMP_PLUS' })
|
||||||
const form = useCarrierForm()
|
const form = useCarrierForm()
|
||||||
form.main.name = 'Transports Acme'
|
form.main.name = 'Transports Acme'
|
||||||
form.main.certificationType = 'GMP_PLUS'
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
form.main.isChartered = true
|
|
||||||
|
|
||||||
const created = await form.submitMain()
|
const created = await form.submitMain()
|
||||||
|
|
||||||
@@ -81,7 +155,7 @@ describe('useCarrierForm', () => {
|
|||||||
expect(body).toEqual({
|
expect(body).toEqual({
|
||||||
name: 'Transports Acme',
|
name: 'Transports Acme',
|
||||||
certificationType: 'GMP_PLUS',
|
certificationType: 'GMP_PLUS',
|
||||||
isChartered: true,
|
isChartered: false,
|
||||||
})
|
})
|
||||||
expect(opts).toMatchObject({ toast: false, headers: { Accept: 'application/ld+json' } })
|
expect(opts).toMatchObject({ toast: false, headers: { Accept: 'application/ld+json' } })
|
||||||
|
|
||||||
@@ -89,19 +163,17 @@ describe('useCarrierForm', () => {
|
|||||||
// RG-4.13 : réaffiche le nom normalisé (UPPERCASE) renvoyé par le serveur.
|
// RG-4.13 : réaffiche le nom normalisé (UPPERCASE) renvoyé par le serveur.
|
||||||
expect(form.main.name).toBe('TRANSPORTS ACME')
|
expect(form.main.name).toBe('TRANSPORTS ACME')
|
||||||
expect(form.mainLocked.value).toBe(true)
|
expect(form.mainLocked.value).toBe(true)
|
||||||
expect(form.activeTab.value).toBe('qualimat')
|
// L'onglet Qualimat était déjà accessible (saisie assistée) ; le POST
|
||||||
expect(form.unlockedIndex.value).toBe(0)
|
// déverrouille Adresses (index 1) et bascule dessus.
|
||||||
|
expect(form.activeTab.value).toBe('addresses')
|
||||||
|
expect(form.unlockedIndex.value).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('payload : omet name et certificationType vides, garde isChartered', async () => {
|
it('buildMainPayload : omet certificationType vide, garde isChartered', () => {
|
||||||
mockPost.mockRejectedValueOnce({ response: { status: 422, _data: { violations: [] } } })
|
|
||||||
const form = useCarrierForm()
|
const form = useCarrierForm()
|
||||||
form.main.name = 'X' // nom présent pour passer le pré-check front
|
form.main.name = 'X'
|
||||||
// certificationType laissé null → omis pour que la 422 « obligatoire » porte.
|
|
||||||
|
|
||||||
await form.submitMain()
|
const body = form.buildMainPayload()
|
||||||
|
|
||||||
const body = mockPost.mock.calls[0]?.[1] as Record<string, unknown>
|
|
||||||
expect(body).toEqual({ name: 'X', isChartered: false })
|
expect(body).toEqual({ name: 'X', isChartered: false })
|
||||||
expect('certificationType' in body).toBe(false)
|
expect('certificationType' in body).toBe(false)
|
||||||
})
|
})
|
||||||
@@ -110,7 +182,7 @@ describe('useCarrierForm', () => {
|
|||||||
mockPost.mockRejectedValueOnce({ response: { status: 409 } })
|
mockPost.mockRejectedValueOnce({ response: { status: 409 } })
|
||||||
const form = useCarrierForm()
|
const form = useCarrierForm()
|
||||||
form.main.name = 'Doublon'
|
form.main.name = 'Doublon'
|
||||||
form.main.certificationType = 'AUTRE'
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
|
||||||
const created = await form.submitMain()
|
const created = await form.submitMain()
|
||||||
|
|
||||||
@@ -120,19 +192,23 @@ describe('useCarrierForm', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('422 : mappe les violations serveur inline par champ', async () => {
|
it('422 : mappe les violations serveur inline par champ', async () => {
|
||||||
|
// Contrainte re-validée uniquement back (ex. longueur du nom) : le pré-check
|
||||||
|
// front passe (nom rempli, certif choisie, non affrété), la 422 mappe inline
|
||||||
|
// sur le champ via son propertyPath.
|
||||||
mockPost.mockRejectedValueOnce({
|
mockPost.mockRejectedValueOnce({
|
||||||
response: {
|
response: {
|
||||||
status: 422,
|
status: 422,
|
||||||
_data: { violations: [{ propertyPath: 'certificationType', message: 'Le type de certification est obligatoire.' }] },
|
_data: { violations: [{ propertyPath: 'name', message: 'Le nom du transporteur ne peut dépasser 255 caractères.' }] },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
const form = useCarrierForm()
|
const form = useCarrierForm()
|
||||||
form.main.name = 'Sans Certif'
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
|
||||||
const created = await form.submitMain()
|
const created = await form.submitMain()
|
||||||
|
|
||||||
expect(created).toBe(false)
|
expect(created).toBe(false)
|
||||||
expect(form.mainErrors.errors.certificationType).toBe('Le type de certification est obligatoire.')
|
expect(form.mainErrors.errors.name).toBe('Le nom du transporteur ne peut dépasser 255 caractères.')
|
||||||
expect(form.mainLocked.value).toBe(false)
|
expect(form.mainLocked.value).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -140,8 +216,9 @@ describe('useCarrierForm', () => {
|
|||||||
expect(CARRIER_TAB_KEYS).toEqual(['qualimat', 'addresses', 'contacts', 'prices'])
|
expect(CARRIER_TAB_KEYS).toEqual(['qualimat', 'addresses', 'contacts', 'prices'])
|
||||||
const form = useCarrierForm()
|
const form = useCarrierForm()
|
||||||
expect(form.tabKeys.value).toEqual(['qualimat', 'addresses', 'contacts', 'prices'])
|
expect(form.tabKeys.value).toEqual(['qualimat', 'addresses', 'contacts', 'prices'])
|
||||||
// Tous verrouillés tant que le formulaire principal n'est pas validé.
|
// L'onglet Qualimat (index 0) est accessible dès le départ (saisie assistée) ;
|
||||||
expect(form.unlockedIndex.value).toBe(-1)
|
// Adresses / Contacts / Prix restent verrouillés jusqu'au POST principal.
|
||||||
|
expect(form.unlockedIndex.value).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('completeTab : déverrouille/avance, et signale le dernier onglet du flux', () => {
|
it('completeTab : déverrouille/avance, et signale le dernier onglet du flux', () => {
|
||||||
@@ -189,3 +266,292 @@ describe('useCarrierForm', () => {
|
|||||||
expect(mockPatch).toHaveBeenCalledWith('/carriers/9', { liotPlates: 'AA-123-BB' }, { toast: false })
|
expect(mockPatch).toHaveBeenCalledWith('/carriers/9', { liotPlates: 'AA-123-BB' }, { toast: false })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('useCarrierForm — champs conditionnels (ERP-166)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockPost.mockReset()
|
||||||
|
mockPatch.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('cas LIOT (insensible à la casse) : masque la certification, payload réduit', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'liot'
|
||||||
|
|
||||||
|
expect(form.isLiot.value).toBe(true)
|
||||||
|
expect(form.showCertification.value).toBe(false)
|
||||||
|
|
||||||
|
form.main.liotPlates = 'AA-123-BB ; CC-456-DD'
|
||||||
|
expect(form.buildMainPayload()).toEqual({
|
||||||
|
name: 'liot',
|
||||||
|
isChartered: false,
|
||||||
|
liotPlates: 'AA-123-BB ; CC-456-DD',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('LIOT masque les champs conditionnels (affrètement / décharge)', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'LIOT'
|
||||||
|
form.main.isChartered = true
|
||||||
|
form.main.certificationType = 'AUTRE'
|
||||||
|
|
||||||
|
expect(form.showCharteredFields.value).toBe(false)
|
||||||
|
expect(form.showDischarge.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('RG-4.03 affrété : indexation / contenant / volume visibles et dans le payload', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
form.main.isChartered = true
|
||||||
|
|
||||||
|
expect(form.showCharteredFields.value).toBe(true)
|
||||||
|
|
||||||
|
form.main.indexationRate = '5'
|
||||||
|
form.main.containerType = 'BENNE'
|
||||||
|
form.main.volumeM3 = '30'
|
||||||
|
|
||||||
|
expect(form.buildMainPayload()).toEqual({
|
||||||
|
name: 'Acme',
|
||||||
|
certificationType: 'GMP_PLUS',
|
||||||
|
isChartered: true,
|
||||||
|
indexationRate: '5',
|
||||||
|
containerType: 'BENNE',
|
||||||
|
volumeM3: '30',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('RG-4.03 affrété mais champs vides : omis du payload (422 NotBlank back)', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
form.main.isChartered = true
|
||||||
|
|
||||||
|
expect(form.buildMainPayload()).toEqual({
|
||||||
|
name: 'Acme',
|
||||||
|
certificationType: 'GMP_PLUS',
|
||||||
|
isChartered: true,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('RG-4.02 AUTRE : décharge visible + dischargeDocument dans le payload si IRI résolu', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'AUTRE'
|
||||||
|
|
||||||
|
expect(form.showDischarge.value).toBe(true)
|
||||||
|
|
||||||
|
form.main.dischargeDocumentIri = '/api/uploaded_documents/7'
|
||||||
|
expect(form.buildMainPayload()).toMatchObject({ dischargeDocument: '/api/uploaded_documents/7' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('useCarrierForm — copie QUALIMAT (ERP-166)', () => {
|
||||||
|
const QUALIMAT_ROW = {
|
||||||
|
'@id': '/api/qualimat_carriers/42',
|
||||||
|
id: '42',
|
||||||
|
name: 'TRANSPORTS QUALIMAT',
|
||||||
|
siret: '12345678900012',
|
||||||
|
address: '1 rue du Port',
|
||||||
|
postalCode: '86000',
|
||||||
|
city: 'Poitiers',
|
||||||
|
validityDate: '2027-01-15',
|
||||||
|
status: 'VALIDE',
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockPost.mockReset()
|
||||||
|
mockPatch.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('copie name + certificationType=QUALIMAT (readonly) + IRI + adresse, sans PATCH avant création', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
|
||||||
|
const ok = await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
expect(ok).toBe(true)
|
||||||
|
expect(mockPatch).not.toHaveBeenCalled()
|
||||||
|
expect(form.main.name).toBe('TRANSPORTS QUALIMAT')
|
||||||
|
expect(form.main.certificationType).toBe('QUALIMAT')
|
||||||
|
expect(form.main.qualimatCarrierIri).toBe('/api/qualimat_carriers/42')
|
||||||
|
expect(form.isQualimat.value).toBe(true)
|
||||||
|
expect(form.certificationReadonly.value).toBe(true)
|
||||||
|
expect(form.qualimatAddress.value).toEqual({
|
||||||
|
country: 'France',
|
||||||
|
postalCode: '86000',
|
||||||
|
city: 'Poitiers',
|
||||||
|
street: '1 rue du Port',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('après création : PATCH /carriers/{id} avec qualimatCarrier + name + certification', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 9, name: 'X', certificationType: 'GMP_PLUS' })
|
||||||
|
mockPatch.mockResolvedValueOnce({})
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'X'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
await form.submitMain()
|
||||||
|
|
||||||
|
const ok = await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
expect(ok).toBe(true)
|
||||||
|
expect(mockPatch).toHaveBeenCalledWith(
|
||||||
|
'/carriers/9',
|
||||||
|
{
|
||||||
|
qualimatCarrier: '/api/qualimat_carriers/42',
|
||||||
|
name: 'TRANSPORTS QUALIMAT',
|
||||||
|
certificationType: 'QUALIMAT',
|
||||||
|
},
|
||||||
|
{ toast: false },
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('après création : PATCH en échec → pas de copie locale (rollback) et retour false', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 9, name: 'X', certificationType: 'GMP_PLUS' })
|
||||||
|
mockPatch.mockRejectedValueOnce({ response: { status: 500, _data: {} } })
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'X'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
await form.submitMain()
|
||||||
|
|
||||||
|
const ok = await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
// Échec serveur : l'UI ne doit pas refléter une intégration QUALIMAT non persistée.
|
||||||
|
expect(ok).toBe(false)
|
||||||
|
expect(form.main.name).toBe('X')
|
||||||
|
expect(form.main.certificationType).toBe('GMP_PLUS')
|
||||||
|
expect(form.main.qualimatCarrierIri).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('buildMainPayload inclut qualimatCarrier + certificationType QUALIMAT après intégration', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
expect(form.buildMainPayload()).toMatchObject({
|
||||||
|
qualimatCarrier: '/api/qualimat_carriers/42',
|
||||||
|
certificationType: 'QUALIMAT',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('applyQualimatSelection pré-remplit le 1er bloc d\'adresse (RG-4.05)', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
|
||||||
|
await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
expect(form.addresses.value).toHaveLength(1)
|
||||||
|
expect(form.addresses.value[0]).toEqual({
|
||||||
|
id: null,
|
||||||
|
country: 'France',
|
||||||
|
postalCode: '86000',
|
||||||
|
city: 'Poitiers',
|
||||||
|
street: '1 rue du Port',
|
||||||
|
streetComplement: null,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('useCarrierForm — onglet Adresses (ERP-167)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockPost.mockReset()
|
||||||
|
mockPatch.mockReset()
|
||||||
|
mockDelete.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Transporteur créé, onglet Adresses accessible. */
|
||||||
|
function createdForm() {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.carrierId.value = 7
|
||||||
|
return form
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Remplit un bloc adresse complet (CP + ville + rue). */
|
||||||
|
function fillAddress(form: ReturnType<typeof useCarrierForm>, index = 0): void {
|
||||||
|
const a = form.addresses.value[index]
|
||||||
|
if (a) {
|
||||||
|
a.postalCode = '86100'
|
||||||
|
a.city = 'Châtellerault'
|
||||||
|
a.street = '1 rue du Test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it('canAddAddress : désactivé tant que la dernière adresse est incomplète', () => {
|
||||||
|
const form = createdForm()
|
||||||
|
expect(form.canAddAddress.value).toBe(false)
|
||||||
|
|
||||||
|
form.addAddress()
|
||||||
|
expect(form.addresses.value).toHaveLength(1) // no-op tant qu'incomplète
|
||||||
|
|
||||||
|
fillAddress(form)
|
||||||
|
expect(form.canAddAddress.value).toBe(true)
|
||||||
|
form.addAddress()
|
||||||
|
expect(form.addresses.value).toHaveLength(2)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('submitAddresses : POST des nouvelles adresses, capture l\'id, finalise l\'onglet', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 88 })
|
||||||
|
const form = createdForm()
|
||||||
|
fillAddress(form)
|
||||||
|
|
||||||
|
const ok = await form.submitAddresses(vi.fn())
|
||||||
|
|
||||||
|
expect(ok).toBe(true)
|
||||||
|
const [url, body, opts] = mockPost.mock.calls[0] ?? []
|
||||||
|
expect(url).toBe('/carriers/7/addresses')
|
||||||
|
expect(body).toEqual({
|
||||||
|
country: 'France',
|
||||||
|
postalCode: '86100',
|
||||||
|
city: 'Châtellerault',
|
||||||
|
street: '1 rue du Test',
|
||||||
|
streetComplement: null,
|
||||||
|
})
|
||||||
|
expect(opts).toMatchObject({ toast: false, headers: { Accept: 'application/ld+json' } })
|
||||||
|
expect(form.addresses.value[0]?.id).toBe(88)
|
||||||
|
expect(form.isValidated('addresses')).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('submitAddresses : PATCH des adresses existantes sur /carrier_addresses/{id}', async () => {
|
||||||
|
mockPatch.mockResolvedValueOnce({})
|
||||||
|
const form = createdForm()
|
||||||
|
fillAddress(form)
|
||||||
|
const first = form.addresses.value[0]
|
||||||
|
if (first) first.id = 88
|
||||||
|
|
||||||
|
await form.submitAddresses(vi.fn())
|
||||||
|
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(mockPatch).toHaveBeenCalledWith('/carrier_addresses/88', expect.objectContaining({ city: 'Châtellerault' }), { toast: false })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('submitAddresses : mappe les 422 PAR LIGNE et ne finalise pas l\'onglet (RG-4.05)', async () => {
|
||||||
|
mockPost.mockRejectedValueOnce({
|
||||||
|
response: {
|
||||||
|
status: 422,
|
||||||
|
_data: { violations: [{ propertyPath: 'city', message: 'La ville est obligatoire pour un transporteur affrété.' }] },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const form = createdForm()
|
||||||
|
fillAddress(form)
|
||||||
|
|
||||||
|
const ok = await form.submitAddresses(vi.fn())
|
||||||
|
|
||||||
|
expect(ok).toBe(false)
|
||||||
|
expect(form.addressErrors.value[0]?.city).toBe('La ville est obligatoire pour un transporteur affrété.')
|
||||||
|
expect(form.isValidated('addresses')).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('removeAddress : DELETE /carrier_addresses/{id} puis retrait du bloc', async () => {
|
||||||
|
mockDelete.mockResolvedValueOnce({})
|
||||||
|
const form = createdForm()
|
||||||
|
fillAddress(form)
|
||||||
|
const first = form.addresses.value[0]
|
||||||
|
if (first) first.id = 88
|
||||||
|
form.addAddress()
|
||||||
|
fillAddress(form, 1)
|
||||||
|
|
||||||
|
await form.removeAddress(0)
|
||||||
|
|
||||||
|
expect(mockDelete).toHaveBeenCalledWith('/carrier_addresses/88', {}, { toast: false })
|
||||||
|
expect(form.addresses.value).toHaveLength(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
import { useQualimatSearch, type QualimatCarrierRow } from '../useQualimatSearch'
|
||||||
|
|
||||||
|
const mockApiGet = vi.hoisted(() => vi.fn())
|
||||||
|
vi.stubGlobal('useApi', () => ({ get: mockApiGet }))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests de la saisie assistée QUALIMAT (M4 Transport, ERP-166 — RG-4.01).
|
||||||
|
*
|
||||||
|
* `useQualimatSearch` est une fine enveloppe de `usePaginatedList<QualimatCarrierRow>`
|
||||||
|
* sur `/qualimat_carriers`. La pagination générique est couverte par
|
||||||
|
* `usePaginatedList.test.ts` ; on vérifie ici le CONTRAT propre à la recherche :
|
||||||
|
* - ressource ciblée `/qualimat_carriers` + enveloppe Hydra + `Accept: application/ld+json` ;
|
||||||
|
* - le filtre `search` (branché sur le nom du transporteur) est transmis et
|
||||||
|
* retombe en page 1.
|
||||||
|
*/
|
||||||
|
describe('useQualimatSearch', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockApiGet.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
const PAGE: QualimatCarrierRow[] = [
|
||||||
|
{
|
||||||
|
'@id': '/api/qualimat_carriers/1',
|
||||||
|
id: '1',
|
||||||
|
name: 'TRANSPORTS ACME',
|
||||||
|
siret: '12345678900012',
|
||||||
|
address: '1 rue du Port',
|
||||||
|
postalCode: '86000',
|
||||||
|
city: 'Poitiers',
|
||||||
|
validityDate: '2027-01-15',
|
||||||
|
status: 'VALIDE',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
it('cible /qualimat_carriers, consomme l\'enveloppe Hydra et envoie l\'Accept ld+json', async () => {
|
||||||
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
||||||
|
const repo = useQualimatSearch()
|
||||||
|
|
||||||
|
await repo.fetch()
|
||||||
|
|
||||||
|
const [url, query, opts] = mockApiGet.mock.calls[0]
|
||||||
|
expect(url).toBe('/qualimat_carriers')
|
||||||
|
expect(query).toMatchObject({ page: 1, itemsPerPage: 10 })
|
||||||
|
expect(opts).toMatchObject({ toast: false, headers: { Accept: 'application/ld+json' } })
|
||||||
|
expect(repo.items.value).toEqual(PAGE)
|
||||||
|
expect(repo.totalItems.value).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('transmet le filtre `search` (nom du transporteur) et retombe en page 1', async () => {
|
||||||
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
||||||
|
const repo = useQualimatSearch()
|
||||||
|
await repo.fetch()
|
||||||
|
|
||||||
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
||||||
|
await repo.setFilters({ search: 'acme' })
|
||||||
|
|
||||||
|
expect(repo.currentPage.value).toBe(1)
|
||||||
|
const query = mockApiGet.mock.calls.at(-1)?.[1] as Record<string, unknown>
|
||||||
|
expect(query.search).toBe('acme')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,10 +1,21 @@
|
|||||||
import { reactive, ref } from 'vue'
|
import { computed, reactive, ref, type Ref } from 'vue'
|
||||||
import { useFormErrors } from '~/shared/composables/useFormErrors'
|
import { useFormErrors } from '~/shared/composables/useFormErrors'
|
||||||
|
import { extractApiErrorMessage, mapViolationsToRecord } from '~/shared/utils/api'
|
||||||
|
import { removeCollectionRow } from '~/shared/utils/collectionRow'
|
||||||
import {
|
import {
|
||||||
|
emptyCarrierAddress,
|
||||||
|
emptyCarrierAddressCopy,
|
||||||
emptyCarrierMain,
|
emptyCarrierMain,
|
||||||
|
type CarrierAddressCopy,
|
||||||
|
type CarrierAddressFormDraft,
|
||||||
type CarrierMainDraft,
|
type CarrierMainDraft,
|
||||||
type CarrierMainResponse,
|
type CarrierMainResponse,
|
||||||
} from '~/modules/transport/types/carrierForm'
|
} from '~/modules/transport/types/carrierForm'
|
||||||
|
import { buildCarrierAddressPayload, isCarrierAddressValid } from '~/modules/transport/utils/forms/carrierAddress'
|
||||||
|
import type { QualimatCarrierRow } from '~/modules/transport/composables/useQualimatSearch'
|
||||||
|
|
||||||
|
/** Nom du cas spécial « compte-propre » LIOT (comparaison insensible à la casse, RG-4.01). */
|
||||||
|
const LIOT_NAME = 'LIOT'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Workflow de l'écran « Ajouter un transporteur » (M4 Transport, ERP-165) —
|
* Workflow de l'écran « Ajouter un transporteur » (M4 Transport, ERP-165) —
|
||||||
@@ -46,14 +57,35 @@ export function useCarrierForm() {
|
|||||||
const carrierId = ref<number | null>(null)
|
const carrierId = ref<number | null>(null)
|
||||||
const mainLocked = ref(false)
|
const mainLocked = ref(false)
|
||||||
const mainSubmitting = ref(false)
|
const mainSubmitting = ref(false)
|
||||||
|
const tabSubmitting = ref(false)
|
||||||
|
|
||||||
// ── Formulaire principal ──────────────────────────────────────────────────
|
// ── Formulaire principal ──────────────────────────────────────────────────
|
||||||
const main = reactive<CarrierMainDraft>(emptyCarrierMain())
|
const main = reactive<CarrierMainDraft>(emptyCarrierMain())
|
||||||
|
|
||||||
|
// Adresse copiée depuis QUALIMAT à la sélection (alimente l'onglet Adresses,
|
||||||
|
// ticket ultérieur). Vide tant qu'aucun transporteur QUALIMAT n'est intégré.
|
||||||
|
const qualimatAddress = ref<CarrierAddressCopy>(emptyCarrierAddressCopy())
|
||||||
|
|
||||||
|
// ── Affichage conditionnel du formulaire principal (RG-4.01 / 4.02 / 4.03) ──
|
||||||
|
// Cas LIOT : nom == « LIOT » → seul `liotPlates` est pertinent, le reste masqué.
|
||||||
|
const isLiot = computed(() => main.name.trim().toUpperCase() === LIOT_NAME)
|
||||||
|
// Transporteur QUALIMAT : la FK est posée → certification figée à « QUALIMAT ».
|
||||||
|
const isQualimat = computed(() => main.qualimatCarrierIri !== null)
|
||||||
|
// Certification masquée en cas LIOT ; lecture seule si QUALIMAT (ou bloc verrouillé).
|
||||||
|
const showCertification = computed(() => !isLiot.value)
|
||||||
|
const certificationReadonly = computed(() => isQualimat.value || mainLocked.value)
|
||||||
|
// RG-4.03 : champs d'affrètement (indexation / contenant / volume) visibles et
|
||||||
|
// obligatoires si « Affréter » coché — masqués en cas LIOT.
|
||||||
|
const showCharteredFields = computed(() => main.isChartered && !isLiot.value)
|
||||||
|
// RG-4.02 : décharge visible et obligatoire si certification == AUTRE (hors LIOT).
|
||||||
|
const showDischarge = computed(() => main.certificationType === 'AUTRE' && !isLiot.value)
|
||||||
|
|
||||||
// ── Onglets : ordre + gating progressif ───────────────────────────────────
|
// ── Onglets : ordre + gating progressif ───────────────────────────────────
|
||||||
const tabKeys = ref<string[]>([...CARRIER_TAB_KEYS])
|
const tabKeys = ref<string[]>([...CARRIER_TAB_KEYS])
|
||||||
// Index du dernier onglet déverrouillé (-1 tant que le transporteur n'est pas créé).
|
// Index du dernier onglet déverrouillé. L'onglet Qualimat (index 0) est la saisie
|
||||||
const unlockedIndex = ref(-1)
|
// assistée du formulaire principal : accessible DÈS LE DÉPART (≠ Adresses /
|
||||||
|
// Contacts / Prix, déverrouillés seulement après le POST principal).
|
||||||
|
const unlockedIndex = ref(0)
|
||||||
const activeTab = ref<string>(CARRIER_TAB_KEYS[0])
|
const activeTab = ref<string>(CARRIER_TAB_KEYS[0])
|
||||||
// Onglets validés (passent en lecture seule).
|
// Onglets validés (passent en lecture seule).
|
||||||
const validated = reactive<Record<string, boolean>>({})
|
const validated = reactive<Record<string, boolean>>({})
|
||||||
@@ -71,10 +103,11 @@ export function useCarrierForm() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation FRONT du formulaire principal : seul le nom est requis côté front
|
* Validation FRONT du formulaire principal : seul le nom est requis côté front
|
||||||
* (RG-4.01). Le back reste la couche autoritaire (ERP-101) — la certification
|
* (ERP-101) : feedback immédiat sur tous les champs obligatoires (y compris
|
||||||
* obligatoire (sauf LIOT) et les RG conditionnelles sont re-validées serveur et
|
* conditionnels), alignés sur les RG du back (qui reste autoritaire) :
|
||||||
* remontées en 422 inline, sans pré-check front (qui devrait connaître le cas
|
* - RG-4.01 : nom requis ; certification requise hors cas LIOT (où tout est masqué) ;
|
||||||
* LIOT, hors périmètre ERP-165).
|
* - RG-4.02 : décharge requise si certification AUTRE ;
|
||||||
|
* - RG-4.03 : indexation + contenant + volume requis si « Affréter ».
|
||||||
*/
|
*/
|
||||||
function validateMainFront(): boolean {
|
function validateMainFront(): boolean {
|
||||||
let valid = true
|
let valid = true
|
||||||
@@ -82,6 +115,40 @@ export function useCarrierForm() {
|
|||||||
mainErrors.setError('name', t('transport.carriers.form.errors.nameRequired'))
|
mainErrors.setError('name', t('transport.carriers.form.errors.nameRequired'))
|
||||||
valid = false
|
valid = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cas LIOT : seul le nom compte, les autres champs sont masqués (RG-4.01).
|
||||||
|
if (isLiot.value) {
|
||||||
|
return valid
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-4.01 : certification obligatoire hors LIOT.
|
||||||
|
if (!main.certificationType) {
|
||||||
|
mainErrors.setError('certificationType', t('transport.carriers.form.errors.certificationRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-4.02 : décharge obligatoire si certification AUTRE.
|
||||||
|
if (main.certificationType === 'AUTRE' && !main.dischargeDocumentIri) {
|
||||||
|
mainErrors.setError('dischargeDocument', t('transport.carriers.form.errors.dischargeRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-4.03 : indexation / contenant / volume obligatoires si affrété.
|
||||||
|
if (main.isChartered) {
|
||||||
|
if (!main.indexationRate.trim()) {
|
||||||
|
mainErrors.setError('indexationRate', t('transport.carriers.form.errors.indexationRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
if (!main.containerType) {
|
||||||
|
mainErrors.setError('containerType', t('transport.carriers.form.errors.containerTypeRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
if (!main.volumeM3.trim()) {
|
||||||
|
mainErrors.setError('volumeM3', t('transport.carriers.form.errors.volumeRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,22 +159,53 @@ export function useCarrierForm() {
|
|||||||
* certification) sur le champ plutôt qu'une erreur de type.
|
* certification) sur le champ plutôt qu'une erreur de type.
|
||||||
*/
|
*/
|
||||||
function buildMainPayload(): Record<string, unknown> {
|
function buildMainPayload(): Record<string, unknown> {
|
||||||
const payload: Record<string, unknown> = {
|
// Cas LIOT (RG-4.01) : seul `liotPlates` est pertinent ; les autres champs
|
||||||
isChartered: main.isChartered,
|
// sont masqués côté front et non envoyés (le back stocke ce qu'il reçoit).
|
||||||
|
if (isLiot.value) {
|
||||||
|
const payload: Record<string, unknown> = { name: main.name, isChartered: false }
|
||||||
|
if (main.liotPlates.trim()) {
|
||||||
|
payload.liotPlates = main.liotPlates
|
||||||
|
}
|
||||||
|
return payload
|
||||||
}
|
}
|
||||||
if (main.name?.trim()) {
|
|
||||||
|
const payload: Record<string, unknown> = { isChartered: main.isChartered }
|
||||||
|
if (main.name.trim()) {
|
||||||
payload.name = main.name
|
payload.name = main.name
|
||||||
}
|
}
|
||||||
if (main.certificationType) {
|
if (main.certificationType) {
|
||||||
payload.certificationType = main.certificationType
|
payload.certificationType = main.certificationType
|
||||||
}
|
}
|
||||||
|
// FK QUALIMAT (saisie assistée, § 2.5) envoyée si une ligne a été intégrée.
|
||||||
|
if (main.qualimatCarrierIri) {
|
||||||
|
payload.qualimatCarrier = main.qualimatCarrierIri
|
||||||
|
}
|
||||||
|
// RG-4.02 : décharge envoyée seulement en certification AUTRE ; omise quand
|
||||||
|
// absente pour que la 422 « obligatoire » porte sur le champ.
|
||||||
|
if (main.certificationType === 'AUTRE' && main.dischargeDocumentIri) {
|
||||||
|
payload.dischargeDocument = main.dischargeDocumentIri
|
||||||
|
}
|
||||||
|
// RG-4.03 : indexation / contenant / volume envoyés seulement si affrété ;
|
||||||
|
// omis quand vides pour déclencher la 422 NotBlank inline sur le champ.
|
||||||
|
if (main.isChartered) {
|
||||||
|
if (main.indexationRate.trim()) {
|
||||||
|
payload.indexationRate = main.indexationRate
|
||||||
|
}
|
||||||
|
if (main.containerType) {
|
||||||
|
payload.containerType = main.containerType
|
||||||
|
}
|
||||||
|
if (main.volumeM3.trim()) {
|
||||||
|
payload.volumeM3 = main.volumeM3
|
||||||
|
}
|
||||||
|
}
|
||||||
return payload
|
return payload
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /carriers (groupe `carrier:write:main`). Pré-check front (nom), puis
|
* POST /carriers (groupe `carrier:write:main`). Pré-check front, puis création.
|
||||||
* création. Au succès : verrouille le bloc principal, déverrouille le 1er onglet
|
* Au succès : verrouille le bloc principal, déverrouille l'onglet Adresses et
|
||||||
* et bascule sur « Qualimat ». Retourne true si créé, false sinon.
|
* bascule dessus (l'onglet Qualimat, saisie assistée, était déjà accessible).
|
||||||
|
* Retourne true si créé, false sinon.
|
||||||
*/
|
*/
|
||||||
async function submitMain(): Promise<boolean> {
|
async function submitMain(): Promise<boolean> {
|
||||||
if (mainSubmitting.value) return false
|
if (mainSubmitting.value) return false
|
||||||
@@ -128,8 +226,9 @@ export function useCarrierForm() {
|
|||||||
main.certificationType = created.certificationType ?? main.certificationType
|
main.certificationType = created.certificationType ?? main.certificationType
|
||||||
|
|
||||||
mainLocked.value = true
|
mainLocked.value = true
|
||||||
unlockedIndex.value = 0
|
// Déverrouille l'onglet suivant (Adresses, index 1) et bascule dessus.
|
||||||
activeTab.value = tabKeys.value[0] ?? CARRIER_TAB_KEYS[0]
|
unlockedIndex.value = Math.max(unlockedIndex.value, 1)
|
||||||
|
activeTab.value = tabKeys.value[1] ?? CARRIER_TAB_KEYS[1]
|
||||||
toast.success({ title: t('transport.carriers.toast.createSuccess') })
|
toast.success({ title: t('transport.carriers.toast.createSuccess') })
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -162,6 +261,175 @@ export function useCarrierForm() {
|
|||||||
await api.patch(`/carriers/${carrierId.value}`, payload, { toast: false })
|
await api.patch(`/carriers/${carrierId.value}`, payload, { toast: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Remontée d'erreur de suppression immédiate d'une sous-ressource (toast dédié). */
|
||||||
|
function notifyRemovalError(error: unknown): void {
|
||||||
|
toast.error({
|
||||||
|
title: t('transport.carriers.toast.error'),
|
||||||
|
message: extractApiErrorMessage((error as { data?: unknown })?.data) || t('transport.carriers.toast.error'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Soumet TOUS les blocs d'une collection en collectant les erreurs PAR INDEX :
|
||||||
|
* on n'arrête pas au premier bloc en échec (décision ERP-101). Réinitialise la
|
||||||
|
* cible, tente chaque ligne via `saveRow`, mappe les 422 inline ou délègue le
|
||||||
|
* fallback à `onUnmappedError`. `shouldSkip` ignore les amorces vides. Retourne
|
||||||
|
* true si au moins un bloc a échoué. Miroir de `useProviderForm.submitRows`.
|
||||||
|
*/
|
||||||
|
async function submitRows<T>(
|
||||||
|
rows: T[],
|
||||||
|
target: Ref<Record<string, string>[]>,
|
||||||
|
saveRow: (row: T, index: number) => Promise<void>,
|
||||||
|
onUnmappedError: (error: unknown, index: number) => void,
|
||||||
|
shouldSkip?: (row: T, index: number) => boolean,
|
||||||
|
): Promise<boolean> {
|
||||||
|
target.value = []
|
||||||
|
let hasError = false
|
||||||
|
for (let index = 0; index < rows.length; index++) {
|
||||||
|
const row = rows[index] as T
|
||||||
|
if (shouldSkip?.(row, index)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await saveRow(row, index)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
const response = (error as { response?: { status?: number, _data?: unknown } })?.response
|
||||||
|
const mapped = response?.status === 422 ? mapViolationsToRecord(response._data) : {}
|
||||||
|
if (Object.keys(mapped).length > 0) {
|
||||||
|
target.value[index] = mapped
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
onUnmappedError(error, index)
|
||||||
|
}
|
||||||
|
hasError = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hasError
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Onglet Adresses (ERP-167) ─────────────────────────────────────────────
|
||||||
|
const addresses = ref<CarrierAddressFormDraft[]>([emptyCarrierAddress()])
|
||||||
|
// Erreurs 422 par ligne (alignées sur l'index du v-for), peuplées par submitRows.
|
||||||
|
const addressErrors = ref<Record<string, string>[]>([])
|
||||||
|
|
||||||
|
// « + Nouvelle adresse » désactivé tant que la dernière adresse n'est pas
|
||||||
|
// complète (CP + ville + rue — RG-4.05, gate d'ajout).
|
||||||
|
const canAddAddress = computed(() => {
|
||||||
|
const last = addresses.value[addresses.value.length - 1]
|
||||||
|
return last !== undefined && isCarrierAddressValid(last)
|
||||||
|
})
|
||||||
|
|
||||||
|
function addAddress(): void {
|
||||||
|
if (canAddAddress.value) {
|
||||||
|
addresses.value.push(emptyCarrierAddress())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Suppression immédiate d'une adresse existante (DELETE /carrier_addresses/{id}). */
|
||||||
|
async function removeAddress(index: number): Promise<void> {
|
||||||
|
await removeCollectionRow({
|
||||||
|
rows: addresses.value,
|
||||||
|
errors: addressErrors.value,
|
||||||
|
index,
|
||||||
|
endpoint: '/carrier_addresses',
|
||||||
|
deleteRow: url => api.delete(url, {}, { toast: false }),
|
||||||
|
makeEmpty: emptyCarrierAddress,
|
||||||
|
onError: notifyRemovalError,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valide l'onglet Adresses : POST des nouvelles adresses sur
|
||||||
|
* /carriers/{id}/addresses, PATCH des existantes sur /carrier_addresses/{id}
|
||||||
|
* (groupe carrier:write:addresses). Erreurs 422 collectées par ligne (RG-4.05
|
||||||
|
* « obligatoire si affrété » re-validée back). Retourne true si l'onglet a été
|
||||||
|
* validé (avancé/terminé).
|
||||||
|
*/
|
||||||
|
async function submitAddresses(onError: (error: unknown) => void): Promise<boolean> {
|
||||||
|
if (carrierId.value === null || tabSubmitting.value) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
tabSubmitting.value = true
|
||||||
|
try {
|
||||||
|
const hasError = await submitRows(
|
||||||
|
addresses.value,
|
||||||
|
addressErrors,
|
||||||
|
async (address) => {
|
||||||
|
const body = buildCarrierAddressPayload(address)
|
||||||
|
if (address.id === null) {
|
||||||
|
const created = await api.post<{ id: number }>(
|
||||||
|
`/carriers/${carrierId.value}/addresses`,
|
||||||
|
body,
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
address.id = created.id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await api.patch(`/carrier_addresses/${address.id}`, body, { toast: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError,
|
||||||
|
)
|
||||||
|
if (hasError) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
completeTab('addresses')
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tabSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intègre une ligne QUALIMAT sélectionnée dans l'onglet Qualimat (RG-4.01 /
|
||||||
|
* § 2.5) : copie le nom, force la certification à « QUALIMAT » (lecture seule),
|
||||||
|
* pose la FK `qualimatCarrier` (IRI) et copie l'adresse (pour l'onglet Adresses).
|
||||||
|
* Si le transporteur existe déjà (post-POST, cas nominal de l'onglet), persiste
|
||||||
|
* d'abord la copie via un PATCH partiel `carrier:write:main` : la copie locale
|
||||||
|
* (nom, certification figée « QUALIMAT », FK, adresse) n'est appliquée qu'en cas
|
||||||
|
* de succès, pour ne pas laisser l'UI dans un état QUALIMAT non sauvegardé si le
|
||||||
|
* PATCH échoue. Retourne true si l'intégration a abouti.
|
||||||
|
*/
|
||||||
|
async function applyQualimatSelection(row: QualimatCarrierRow): Promise<boolean> {
|
||||||
|
// Transporteur déjà créé : on persiste avant de refléter localement.
|
||||||
|
if (carrierId.value !== null) {
|
||||||
|
try {
|
||||||
|
await patchCarrier({
|
||||||
|
qualimatCarrier: row['@id'],
|
||||||
|
name: row.name,
|
||||||
|
certificationType: 'QUALIMAT',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
mainErrors.handleApiError(error, { fallbackMessage: t('transport.carriers.toast.error') })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main.name = row.name ?? ''
|
||||||
|
main.certificationType = 'QUALIMAT'
|
||||||
|
main.qualimatCarrierIri = row['@id']
|
||||||
|
qualimatAddress.value = {
|
||||||
|
country: 'France',
|
||||||
|
postalCode: row.postalCode ?? '',
|
||||||
|
city: row.city ?? '',
|
||||||
|
street: row.address ?? '',
|
||||||
|
}
|
||||||
|
// RG-4.05 : pré-remplit le 1er bloc de l'onglet Adresses par copie (la FK
|
||||||
|
// QUALIMAT survit, les champs restent éditables — § 2.5).
|
||||||
|
addresses.value = [{
|
||||||
|
id: null,
|
||||||
|
country: 'France',
|
||||||
|
postalCode: row.postalCode || null,
|
||||||
|
city: row.city || null,
|
||||||
|
street: row.address || null,
|
||||||
|
streetComplement: null,
|
||||||
|
}]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marque un onglet validé (passe en lecture seule), déverrouille et avance à
|
* Marque un onglet validé (passe en lecture seule), déverrouille et avance à
|
||||||
* l'onglet suivant. Retourne true si c'était le dernier onglet du flux (création
|
* l'onglet suivant. Retourne true si c'était le dernier onglet du flux (création
|
||||||
@@ -186,10 +454,19 @@ export function useCarrierForm() {
|
|||||||
return {
|
return {
|
||||||
// état
|
// état
|
||||||
main,
|
main,
|
||||||
|
qualimatAddress,
|
||||||
carrierId,
|
carrierId,
|
||||||
mainLocked,
|
mainLocked,
|
||||||
mainSubmitting,
|
mainSubmitting,
|
||||||
|
tabSubmitting,
|
||||||
mainErrors,
|
mainErrors,
|
||||||
|
// affichage conditionnel
|
||||||
|
isLiot,
|
||||||
|
isQualimat,
|
||||||
|
showCertification,
|
||||||
|
certificationReadonly,
|
||||||
|
showCharteredFields,
|
||||||
|
showDischarge,
|
||||||
// onglets
|
// onglets
|
||||||
tabKeys,
|
tabKeys,
|
||||||
activeTab,
|
activeTab,
|
||||||
@@ -197,11 +474,20 @@ export function useCarrierForm() {
|
|||||||
validated,
|
validated,
|
||||||
editMode,
|
editMode,
|
||||||
isValidated,
|
isValidated,
|
||||||
|
// adresses
|
||||||
|
addresses,
|
||||||
|
addressErrors,
|
||||||
|
canAddAddress,
|
||||||
|
addAddress,
|
||||||
|
removeAddress,
|
||||||
|
submitAddresses,
|
||||||
// actions
|
// actions
|
||||||
validateMainFront,
|
validateMainFront,
|
||||||
buildMainPayload,
|
buildMainPayload,
|
||||||
submitMain,
|
submitMain,
|
||||||
patchCarrier,
|
patchCarrier,
|
||||||
|
applyQualimatSelection,
|
||||||
completeTab,
|
completeTab,
|
||||||
|
submitRows,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { usePaginatedList } from '~/shared/composables/usePaginatedList'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ligne du référentiel QUALIMAT renvoyée par la saisie assistée (groupe
|
||||||
|
* `qualimat:read`). `@id` est l'IRI conservée comme FK `carrier.qualimatCarrier`
|
||||||
|
* (RG-4.01 / § 2.5) ; `validityDate` pilote le fond rouge de la colonne « Date de
|
||||||
|
* validité » (RG-4.04).
|
||||||
|
*/
|
||||||
|
export interface QualimatCarrierRow {
|
||||||
|
'@id': string
|
||||||
|
id: string
|
||||||
|
name: string | null
|
||||||
|
siret: string | null
|
||||||
|
address: string | null
|
||||||
|
postalCode: string | null
|
||||||
|
city: string | null
|
||||||
|
validityDate: string | null
|
||||||
|
status: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Filtre de la recherche QUALIMAT (branché sur le nom du transporteur). */
|
||||||
|
export interface QualimatSearchFilters {
|
||||||
|
search?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saisie assistée QUALIMAT (M4 Transport, ERP-166 — RG-4.01 / spec-back § 4.7).
|
||||||
|
*
|
||||||
|
* `GET /api/qualimat_carriers?search=` : référentiel en LECTURE SEULE, lignes
|
||||||
|
* actives uniquement (filtré côté serveur), recherche fuzzy nom + siret. Simple
|
||||||
|
* enveloppe de `usePaginatedList` (règle frontend : toute GetCollection passe par
|
||||||
|
* ce composable — pagination Hydra, état 100 % local) consommée par le
|
||||||
|
* `MalioDataTable` de l'onglet Qualimat. Le filtre `search` est piloté par le nom
|
||||||
|
* saisi dans le formulaire principal (pas de champ de recherche dédié).
|
||||||
|
*
|
||||||
|
* Volontairement PAR INSTANCE (état local à l'écran d'ajout).
|
||||||
|
*/
|
||||||
|
export function useQualimatSearch() {
|
||||||
|
return usePaginatedList<QualimatCarrierRow, QualimatSearchFilters>({ url: '/qualimat_carriers' })
|
||||||
|
}
|
||||||
@@ -13,11 +13,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ── Formulaire principal (pre-onglets) ─────────────────────────────
|
<!-- ── Formulaire principal (pre-onglets) ─────────────────────────────
|
||||||
Sans validation de ce bloc, les onglets restent inaccessibles. Au
|
Champs conditionnels (ERP-166) : cas LIOT (nom == LIOT) → seul
|
||||||
succes du POST, les champs passent en lecture seule et on bascule
|
« immatriculations » ; certification AUTRE → champ Decharge ; Affreter
|
||||||
automatiquement sur l'onglet Qualimat. Les champs conditionnels
|
coche → indexation / contenant / volume. La certification est en lecture
|
||||||
(indexation / benne / volume si affrete, decharge si AUTRE, cas LIOT)
|
seule pour un transporteur QUALIMAT (saisie assistee, onglet Qualimat). -->
|
||||||
et la saisie assistee QUALIMAT arrivent a ERP-166. -->
|
|
||||||
<div class="mt-[48px] grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
<div class="mt-[48px] grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
<MalioInputText
|
<MalioInputText
|
||||||
v-model="main.name"
|
v-model="main.name"
|
||||||
@@ -26,29 +25,96 @@
|
|||||||
:readonly="mainLocked"
|
:readonly="mainLocked"
|
||||||
:error="mainErrors.errors.name"
|
:error="mainErrors.errors.name"
|
||||||
/>
|
/>
|
||||||
<MalioSelect
|
|
||||||
:model-value="main.certificationType"
|
<!-- Cas LIOT : seul le champ immatriculations est pertinent. -->
|
||||||
:options="certificationOptions"
|
<MalioInputText
|
||||||
:label="t('transport.carriers.form.main.certificationType')"
|
v-if="isLiot"
|
||||||
empty-option-label=""
|
v-model="main.liotPlates"
|
||||||
|
:label="t('transport.carriers.form.main.liotPlates')"
|
||||||
|
:hint="t('transport.carriers.form.main.liotPlatesHint')"
|
||||||
:required="true"
|
:required="true"
|
||||||
:readonly="mainLocked"
|
:readonly="mainLocked"
|
||||||
:error="mainErrors.errors.certificationType"
|
:error="mainErrors.errors.liotPlates"
|
||||||
@update:model-value="(v: string | number | null) => main.certificationType = v === null ? null : String(v)"
|
|
||||||
/>
|
/>
|
||||||
<!-- Wrapper h-12 + centrage vertical : aligne la case a cocher sur la
|
|
||||||
ligne de champ des inputs/selects (qui posent un h-12 items-center
|
<!-- Cas standard : certification + affretement + champs conditionnels. -->
|
||||||
en interne). reserve-message-space=false pour un centrage exact. -->
|
<template v-if="!isLiot">
|
||||||
<div class="flex h-12 items-center">
|
<MalioSelect
|
||||||
<MalioCheckbox
|
:model-value="main.certificationType"
|
||||||
id="carrier-is-chartered"
|
:options="certificationOptions"
|
||||||
:label="t('transport.carriers.form.main.isChartered')"
|
:label="t('transport.carriers.form.main.certificationType')"
|
||||||
:model-value="main.isChartered"
|
empty-option-label=""
|
||||||
:readonly="mainLocked"
|
:required="true"
|
||||||
:reserve-message-space="false"
|
:readonly="certificationReadonly"
|
||||||
@update:model-value="(val: boolean) => main.isChartered = val"
|
:error="mainErrors.errors.certificationType"
|
||||||
|
@update:model-value="(v: string | number | null) => main.certificationType = v === null ? null : String(v)"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
<!-- Colonne 3 RÉSERVÉE à la Décharge (RG-4.02 : visible et obligatoire
|
||||||
|
si certification AUTRE). Si elle n'apparaît pas, on garde la colonne
|
||||||
|
vide (xl) pour qu'« Affréter » reste en colonne 4 de la ligne 1.
|
||||||
|
L'upload reel (File → IRI via useUpload) arrive a ERP-171. -->
|
||||||
|
<!-- TODO ERP-171 : brancher useUpload pour resoudre le File en IRI
|
||||||
|
(main.dischargeDocumentIri). Le champ est deja visible/obligatoire. -->
|
||||||
|
<MalioInputUpload
|
||||||
|
v-if="showDischarge"
|
||||||
|
:label="t('transport.carriers.form.main.discharge')"
|
||||||
|
accept="application/pdf,image/*"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:clearable="true"
|
||||||
|
:error="mainErrors.errors.dischargeDocument"
|
||||||
|
@clear="main.dischargeDocumentIri = null"
|
||||||
|
/>
|
||||||
|
<div v-else class="hidden xl:block"></div>
|
||||||
|
|
||||||
|
<!-- « Affréter » : toujours en colonne 4 de la ligne 1 (colonne 3
|
||||||
|
réservée à la décharge ci-dessus). Wrapper h-12 + centrage vertical
|
||||||
|
pour aligner la case sur la ligne de champ des inputs/selects. -->
|
||||||
|
<div class="flex h-12 items-center">
|
||||||
|
<MalioCheckbox
|
||||||
|
id="carrier-is-chartered"
|
||||||
|
:label="t('transport.carriers.form.main.isChartered')"
|
||||||
|
:model-value="main.isChartered"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:reserve-message-space="false"
|
||||||
|
@update:model-value="(val: boolean) => main.isChartered = val"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RG-4.03 : champs d'affretement (ligne 2) visibles + obligatoires si
|
||||||
|
« Affreter ». La ligne 1 étant pleine (4 colonnes), ils démarrent
|
||||||
|
naturellement en colonne 1 de la ligne 2. -->
|
||||||
|
<template v-if="showCharteredFields">
|
||||||
|
<MalioInputNumber
|
||||||
|
v-model="main.indexationRate"
|
||||||
|
:label="t('transport.carriers.form.main.indexationRate')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:error="mainErrors.errors.indexationRate"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Contenant : Benne / Fond mouvant (RG-4.03). -->
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="main.containerType"
|
||||||
|
:options="containerOptions"
|
||||||
|
:label="t('transport.carriers.form.main.containerType')"
|
||||||
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:error="mainErrors.errors.containerType"
|
||||||
|
@update:model-value="(v: string | number | null) => main.containerType = v === null ? null : String(v)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<MalioInputNumber
|
||||||
|
v-model="main.volumeM3"
|
||||||
|
:label="t('transport.carriers.form.main.volumeM3')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:error="mainErrors.errors.volumeM3"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="!mainLocked" class="mt-12 flex justify-center">
|
<div v-if="!mainLocked" class="mt-12 flex justify-center">
|
||||||
@@ -61,13 +127,89 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ── Onglets a validation incrementale ─────────────────────────────
|
<!-- ── Onglets a validation incrementale ─────────────────────────────
|
||||||
Barre Qualimat · Adresses · Contacts · Prix. Onglets verrouilles tant
|
Barre Qualimat · Adresses · Contacts · Prix. Onglet Qualimat = saisie
|
||||||
que le formulaire principal n'est pas valide (unlockedIndex = -1) puis
|
assistee (table de selection) ; Adresses / Contacts / Prix arrivent aux
|
||||||
deverrouilles progressivement. Le contenu de chaque onglet arrive aux
|
tickets suivants (placeholders « A venir »). -->
|
||||||
tickets suivants (ERP-166+) : placeholders « A venir » pour l'instant. -->
|
|
||||||
<MalioTabList v-model="activeTab" :tabs="tabs" class="mt-[60px]">
|
<MalioTabList v-model="activeTab" :tabs="tabs" class="mt-[60px]">
|
||||||
|
<!-- Onglet Qualimat : datatable paginé filtré par le NOM du transporteur
|
||||||
|
(pas de champ de recherche dédié — RG-4.01 / 4.04). -->
|
||||||
|
<template #qualimat>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<MalioDataTable
|
||||||
|
:columns="qualimatColumns"
|
||||||
|
:items="qualimatRows"
|
||||||
|
:total-items="qualimatTotalDisplay"
|
||||||
|
:page="qualimatPage"
|
||||||
|
:per-page="qualimatPerPage"
|
||||||
|
:per-page-options="qualimatPerPageOptions"
|
||||||
|
row-clickable
|
||||||
|
:empty-message="qualimatEmptyMessage"
|
||||||
|
@row-click="onQualimatRowClick"
|
||||||
|
@update:page="qualimatGoToPage"
|
||||||
|
@update:per-page="qualimatSetPerPage"
|
||||||
|
>
|
||||||
|
<!-- Radio reflétant la ligne QUALIMAT intégrée (lecture). -->
|
||||||
|
<template #cell-select="{ item }">
|
||||||
|
<MalioRadioButton
|
||||||
|
:model-value="main.qualimatCarrierIri"
|
||||||
|
name="qualimat-row"
|
||||||
|
:value="item.iri"
|
||||||
|
group-class="mt-0"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<!-- Date de validité : fond rouge si périmée (RG-4.04). -->
|
||||||
|
<template #cell-validityDate="{ item }">
|
||||||
|
<span
|
||||||
|
v-if="item.validityDate"
|
||||||
|
:class="isExpired(item.validityDate as string) ? 'inline-block rounded px-2 py-0.5 bg-m-danger text-white' : ''"
|
||||||
|
>
|
||||||
|
{{ formatDateFr(item.validityDate as string) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</MalioDataTable>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Onglet Adresses (ERP-167) : un bloc par adresse + BAN. RG-4.05
|
||||||
|
préremplissage si QUALIMAT ; RG-4.07 pas de Valider si QUALIMAT. -->
|
||||||
|
<template #addresses>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<CarrierAddressBlock
|
||||||
|
v-for="(address, index) in addresses"
|
||||||
|
:key="index"
|
||||||
|
:model-value="address"
|
||||||
|
:country-options="countryOptions"
|
||||||
|
:removable="isRowRemovable(addresses, index)"
|
||||||
|
:readonly="isQualimat || isValidated('addresses')"
|
||||||
|
:errors="addressErrors[index]"
|
||||||
|
@update:model-value="(v) => addresses[index] = v"
|
||||||
|
@remove="askRemoveAddress(index)"
|
||||||
|
@degraded="onAddressDegraded"
|
||||||
|
/>
|
||||||
|
<!-- RG-4.07 : pas de bouton Valider pour un transporteur QUALIMAT
|
||||||
|
(adresse copiée et persistée automatiquement). -->
|
||||||
|
<div v-if="!isQualimat && !isValidated('addresses')" class="flex justify-center gap-6">
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
icon-name="mdi:add-bold"
|
||||||
|
icon-position="left"
|
||||||
|
:label="t('transport.carriers.form.address.add')"
|
||||||
|
:disabled="!canAddAddress"
|
||||||
|
@click="addAddress"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
:label="t('transport.carriers.form.submit')"
|
||||||
|
:disabled="tabSubmitting || carrierId === null"
|
||||||
|
@click="onSubmitAddresses"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Contacts / Prix : contenu aux tickets suivants. -->
|
||||||
<template
|
<template
|
||||||
v-for="key in tabKeys"
|
v-for="key in placeholderTabs"
|
||||||
:key="key"
|
:key="key"
|
||||||
#[key]
|
#[key]
|
||||||
>
|
>
|
||||||
@@ -76,12 +218,61 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</MalioTabList>
|
</MalioTabList>
|
||||||
|
|
||||||
|
<!-- Modal de confirmation d'integration QUALIMAT (RG-4.01). -->
|
||||||
|
<MalioModal v-model="confirmOpen" modal-class="max-w-md">
|
||||||
|
<template #header>
|
||||||
|
<h2 class="text-[24px] font-bold">{{ t('transport.carriers.form.qualimat.confirm.title') }}</h2>
|
||||||
|
</template>
|
||||||
|
<p>{{ t('transport.carriers.form.qualimat.confirm.message') }}</p>
|
||||||
|
<template #footer>
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('transport.carriers.form.qualimat.confirm.cancel')"
|
||||||
|
@click="confirmOpen = false"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('transport.carriers.form.qualimat.confirm.confirm')"
|
||||||
|
@click="confirmIntegrate"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</MalioModal>
|
||||||
|
|
||||||
|
<!-- Modal de confirmation de suppression (bloc adresse). -->
|
||||||
|
<MalioModal v-model="deleteConfirm.open" modal-class="max-w-md">
|
||||||
|
<template #header>
|
||||||
|
<h2 class="text-[24px] font-bold">{{ t('transport.carriers.form.confirmDelete.title') }}</h2>
|
||||||
|
</template>
|
||||||
|
<p>{{ t('transport.carriers.form.confirmDelete.message') }}</p>
|
||||||
|
<template #footer>
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('transport.carriers.form.confirmDelete.cancel')"
|
||||||
|
@click="deleteConfirm.open = false"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="danger"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('transport.carriers.form.confirmDelete.confirm')"
|
||||||
|
@click="runDeleteConfirm"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</MalioModal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||||
|
import { debounce } from '~/shared/utils/debounce'
|
||||||
|
import { extractApiErrorMessage } from '~/shared/utils/api'
|
||||||
|
import { isRowRemovable } from '~/shared/utils/collectionRow'
|
||||||
|
import CarrierAddressBlock from '~/modules/transport/components/CarrierAddressBlock.vue'
|
||||||
import { useCarrierForm } from '~/modules/transport/composables/useCarrierForm'
|
import { useCarrierForm } from '~/modules/transport/composables/useCarrierForm'
|
||||||
|
import { useQualimatSearch, type QualimatCarrierRow } from '~/modules/transport/composables/useQualimatSearch'
|
||||||
|
|
||||||
interface SelectOption {
|
interface SelectOption {
|
||||||
value: string
|
value: string
|
||||||
@@ -89,7 +280,9 @@ interface SelectOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const api = useApi()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const toast = useToast()
|
||||||
const { can } = usePermissions()
|
const { can } = usePermissions()
|
||||||
|
|
||||||
useHead({ title: t('transport.carriers.form.title') })
|
useHead({ title: t('transport.carriers.form.title') })
|
||||||
@@ -102,24 +295,99 @@ if (!can('transport.carriers.manage')) {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
main,
|
main,
|
||||||
|
carrierId,
|
||||||
mainLocked,
|
mainLocked,
|
||||||
mainSubmitting,
|
mainSubmitting,
|
||||||
|
tabSubmitting,
|
||||||
mainErrors,
|
mainErrors,
|
||||||
|
isLiot,
|
||||||
|
isQualimat,
|
||||||
|
certificationReadonly,
|
||||||
|
showCharteredFields,
|
||||||
|
showDischarge,
|
||||||
tabKeys,
|
tabKeys,
|
||||||
activeTab,
|
activeTab,
|
||||||
unlockedIndex,
|
unlockedIndex,
|
||||||
|
isValidated,
|
||||||
|
addresses,
|
||||||
|
addressErrors,
|
||||||
|
canAddAddress,
|
||||||
|
addAddress,
|
||||||
|
removeAddress,
|
||||||
|
submitAddresses,
|
||||||
submitMain,
|
submitMain,
|
||||||
|
applyQualimatSelection,
|
||||||
} = useCarrierForm()
|
} = useCarrierForm()
|
||||||
|
|
||||||
// Certifications selectionnables manuellement (spec § Formulaire principal).
|
const {
|
||||||
// QUALIMAT n'est PAS dans cette liste : il est pose par la saisie assistee QUALIMAT
|
items: qualimatItems,
|
||||||
// (ERP-166), pas choisi a la main.
|
totalItems: qualimatTotal,
|
||||||
|
currentPage: qualimatPage,
|
||||||
|
itemsPerPage: qualimatPerPage,
|
||||||
|
itemsPerPageOptions: qualimatPerPageOptions,
|
||||||
|
goToPage: qualimatGoToPage,
|
||||||
|
setItemsPerPage: qualimatSetPerPage,
|
||||||
|
setFilters: qualimatSetFilters,
|
||||||
|
} = useQualimatSearch()
|
||||||
|
|
||||||
|
// Certifications selectionnables manuellement (spec § Formulaire principal) :
|
||||||
|
// GMP+ / OVOCOM / Compte-propre / Autre. QUALIMAT n'y figure PAS — il est posé par
|
||||||
|
// la saisie assistee (onglet Qualimat). On l'ajoute cependant aux options QUAND il
|
||||||
|
// est deja selectionne (transporteur QUALIMAT integre), uniquement pour AFFICHER
|
||||||
|
// son libelle dans le select en lecture seule.
|
||||||
const SELECTABLE_CERTIFICATIONS = ['GMP_PLUS', 'OVOCOM', 'COMPTE_PROPRE', 'AUTRE'] as const
|
const SELECTABLE_CERTIFICATIONS = ['GMP_PLUS', 'OVOCOM', 'COMPTE_PROPRE', 'AUTRE'] as const
|
||||||
|
|
||||||
const certificationOptions = computed<SelectOption[]>(() =>
|
const certificationOptions = computed<SelectOption[]>(() => {
|
||||||
SELECTABLE_CERTIFICATIONS.map(code => ({
|
const codes: string[] = [...SELECTABLE_CERTIFICATIONS]
|
||||||
|
if (main.certificationType === 'QUALIMAT') {
|
||||||
|
codes.unshift('QUALIMAT')
|
||||||
|
}
|
||||||
|
return codes.map(code => ({
|
||||||
value: code,
|
value: code,
|
||||||
label: t(`transport.carriers.certification.${code}`),
|
label: t(`transport.carriers.certification.${code}`),
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Colonnes du datatable de selection QUALIMAT (radio / Nom / Adresse / Validite).
|
||||||
|
const qualimatColumns = [
|
||||||
|
{ key: 'select', label: '' },
|
||||||
|
{ key: 'name', label: t('transport.carriers.form.qualimat.columns.name') },
|
||||||
|
{ key: 'address', label: t('transport.carriers.form.qualimat.columns.address') },
|
||||||
|
{ key: 'validityDate', label: t('transport.carriers.form.qualimat.columns.validityDate') },
|
||||||
|
]
|
||||||
|
|
||||||
|
// Le datatable n'affiche QUE des résultats de recherche : vide tant que le Nom n'est
|
||||||
|
// pas saisi (pas de liste complète par défaut). `main.name` pilote l'affichage.
|
||||||
|
const hasQualimatSearch = computed(() => main.name.trim() !== '')
|
||||||
|
|
||||||
|
// Lignes « plates » pour MalioDataTable (l'IRI sert au radio + à retrouver la ligne
|
||||||
|
// source au clic). Le détail QUALIMAT complet reste dans `qualimatItems`.
|
||||||
|
const qualimatRows = computed(() => {
|
||||||
|
if (!hasQualimatSearch.value) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return qualimatItems.value.map(row => ({
|
||||||
|
id: row.id,
|
||||||
|
iri: row['@id'],
|
||||||
|
name: row.name,
|
||||||
|
address: formatQualimatAddress(row),
|
||||||
|
validityDate: row.validityDate,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Total / message vide alignés sur « tableau vide tant qu'on n'a pas recherché ».
|
||||||
|
const qualimatTotalDisplay = computed(() => (hasQualimatSearch.value ? qualimatTotal.value : 0))
|
||||||
|
const qualimatEmptyMessage = computed(() => hasQualimatSearch.value
|
||||||
|
? t('transport.carriers.form.qualimat.empty')
|
||||||
|
: t('transport.carriers.form.qualimat.searchHint'))
|
||||||
|
|
||||||
|
// Contenant (RG-4.03) : Benne / Fond mouvant — select simple.
|
||||||
|
const CONTAINER_TYPES = ['BENNE', 'FOND_MOUVANT'] as const
|
||||||
|
|
||||||
|
const containerOptions = computed<SelectOption[]>(() =>
|
||||||
|
CONTAINER_TYPES.map(code => ({
|
||||||
|
value: code,
|
||||||
|
label: t(`transport.carriers.containerType.${code}`),
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -140,13 +408,172 @@ const tabs = computed(() => tabKeys.value.map((key, index) => ({
|
|||||||
disabled: index > unlockedIndex.value,
|
disabled: index > unlockedIndex.value,
|
||||||
})))
|
})))
|
||||||
|
|
||||||
|
// Onglets dont le contenu arrive aux tickets suivants (Contacts / Prix).
|
||||||
|
const placeholderTabs = computed(() => tabKeys.value.filter(key => key !== 'qualimat' && key !== 'addresses'))
|
||||||
|
|
||||||
|
// ── Onglet Adresses (ERP-167) ────────────────────────────────────────────────
|
||||||
|
// Pays : France garantie en tete meme si /countries echoue (resilience), pour
|
||||||
|
// rester preselectionnable par defaut sur chaque adresse (RG-4.05).
|
||||||
|
const countryOptions = ref<SelectOption[]>([{ value: 'France', label: 'France' }])
|
||||||
|
|
||||||
|
/** Charge le referentiel pays (/api/countries) ; conserve France par defaut si echec. */
|
||||||
|
async function loadCountries(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const data = await api.get<{ member?: { name: string }[] }>(
|
||||||
|
'/countries',
|
||||||
|
{ pagination: 'false' },
|
||||||
|
{ headers: { Accept: 'application/ld+json' }, toast: false },
|
||||||
|
)
|
||||||
|
const list = (data.member ?? []).map(c => ({ value: c.name, label: c.name }))
|
||||||
|
countryOptions.value = list.some(c => c.value === 'France')
|
||||||
|
? list
|
||||||
|
: [{ value: 'France', label: 'France' }, ...list]
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// Reste sur le fallback France (non bloquant).
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadCountries().catch(() => {})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Avertissement unique quand l'autocompletion d'adresse bascule en degrade.
|
||||||
|
const addressDegradedNotified = ref(false)
|
||||||
|
|
||||||
|
function onAddressDegraded(): void {
|
||||||
|
if (addressDegradedNotified.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addressDegradedNotified.value = true
|
||||||
|
toast.warning({
|
||||||
|
title: t('transport.carriers.toast.error'),
|
||||||
|
message: t('transport.carriers.form.address.degraded'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Message d'erreur affichable (toast) extrait d'une erreur API — jamais undefined. */
|
||||||
|
function apiErrorMessage(error: unknown): string {
|
||||||
|
const data = (error as { response?: { _data?: unknown } })?.response?._data
|
||||||
|
return extractApiErrorMessage(data) || t('transport.carriers.toast.error')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Valide l'onglet Adresses (POST/PATCH par ligne ; avance gere par le composable). */
|
||||||
|
async function onSubmitAddresses(): Promise<void> {
|
||||||
|
const ok = await submitAddresses(error => toast.error({
|
||||||
|
title: t('transport.carriers.toast.error'),
|
||||||
|
message: apiErrorMessage(error),
|
||||||
|
}))
|
||||||
|
if (ok) {
|
||||||
|
toast.success({ title: t('transport.carriers.toast.addressSaved') })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modal de confirmation de suppression (bloc adresse).
|
||||||
|
const deleteConfirm = reactive({ open: false, action: null as null | (() => void) })
|
||||||
|
|
||||||
|
function askRemoveAddress(index: number): void {
|
||||||
|
deleteConfirm.action = () => { void removeAddress(index) }
|
||||||
|
deleteConfirm.open = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function runDeleteConfirm(): void {
|
||||||
|
deleteConfirm.action?.()
|
||||||
|
deleteConfirm.action = null
|
||||||
|
deleteConfirm.open = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Saisie assistee QUALIMAT (onglet Qualimat) ───────────────────────────────
|
||||||
|
const confirmOpen = ref(false)
|
||||||
|
const pendingRow = ref<QualimatCarrierRow | null>(null)
|
||||||
|
|
||||||
|
// Le datatable QUALIMAT est filtré par le NOM saisi dans le formulaire principal
|
||||||
|
// (RG-4.01) — pas de champ de recherche dédié. Aucune recherche tant que le Nom est
|
||||||
|
// vide (tableau vide par défaut) ; sinon re-filtrage debouncé à chaque frappe.
|
||||||
|
const filterQualimatByName = debounce((term: string) => {
|
||||||
|
if (term.trim() === '') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
void qualimatSetFilters({ search: term })
|
||||||
|
}, 300)
|
||||||
|
|
||||||
|
watch(() => main.name, term => filterQualimatByName(term))
|
||||||
|
|
||||||
|
/** Adresse QUALIMAT condensee pour la colonne « Adresse » (voie · CP · ville). */
|
||||||
|
function formatQualimatAddress(row: QualimatCarrierRow): string {
|
||||||
|
return [row.address, row.postalCode, row.city].filter(Boolean).join(' · ')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** RG-4.04 : un agrement est perime si sa date de validite est < aujourd'hui. */
|
||||||
|
function isExpired(value: string): boolean {
|
||||||
|
const date = new Date(value)
|
||||||
|
if (Number.isNaN(date.getTime())) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const today = new Date()
|
||||||
|
today.setHours(0, 0, 0, 0)
|
||||||
|
date.setHours(0, 0, 0, 0)
|
||||||
|
return date.getTime() < today.getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Format court francais JJ-MM-AAAA (chaine vide si date absente / invalide). */
|
||||||
|
function formatDateFr(value: string | null | undefined): string {
|
||||||
|
if (!value) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
const date = new Date(value)
|
||||||
|
if (Number.isNaN(date.getTime())) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
|
return `${day}-${month}-${date.getFullYear()}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clic sur une ligne du datatable → retrouve la ligne QUALIMAT source + modal. */
|
||||||
|
function onQualimatRowClick(item: Record<string, unknown>): void {
|
||||||
|
const row = qualimatItems.value.find(r => r.id === item.id)
|
||||||
|
if (row) {
|
||||||
|
askIntegrate(row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ouvre la modal de confirmation d'integration pour une ligne QUALIMAT. */
|
||||||
|
function askIntegrate(row: QualimatCarrierRow): void {
|
||||||
|
pendingRow.value = row
|
||||||
|
confirmOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Confirme l'integration : copie + PATCH (cf. useCarrierForm.applyQualimatSelection). */
|
||||||
|
async function confirmIntegrate(): Promise<void> {
|
||||||
|
const row = pendingRow.value
|
||||||
|
confirmOpen.value = false
|
||||||
|
if (row === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const ok = await applyQualimatSelection(row)
|
||||||
|
if (ok) {
|
||||||
|
toast.success({ title: t('transport.carriers.toast.integrateSuccess') })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Retour vers le repertoire transporteurs (fleche d'en-tete). */
|
/** Retour vers le repertoire transporteurs (fleche d'en-tete). */
|
||||||
function goBack(): void {
|
function goBack(): void {
|
||||||
router.push('/carriers')
|
router.push('/carriers')
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Valide le formulaire principal (POST /carriers ; bascule gerée par le composable). */
|
/**
|
||||||
|
* Valide le formulaire principal (POST /carriers ; bascule geree par le composable).
|
||||||
|
* RG-4.07 : pour un transporteur QUALIMAT, l'adresse copiee est persistee
|
||||||
|
* automatiquement (pas de bouton Valider dans l'onglet Adresses).
|
||||||
|
*/
|
||||||
async function onSubmitMain(): Promise<void> {
|
async function onSubmitMain(): Promise<void> {
|
||||||
await submitMain()
|
const ok = await submitMain()
|
||||||
|
if (ok && isQualimat.value) {
|
||||||
|
await submitAddresses(error => toast.error({
|
||||||
|
title: t('transport.carriers.toast.error'),
|
||||||
|
message: apiErrorMessage(error),
|
||||||
|
}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,22 +1,36 @@
|
|||||||
/**
|
/**
|
||||||
* Types du workflow « Ajouter un transporteur » (M4 Transport, ERP-165).
|
* Types du workflow « Ajouter un transporteur » (M4 Transport, ERP-165 / ERP-166).
|
||||||
*
|
*
|
||||||
* Périmètre ERP-165 = formulaire PRINCIPAL (pré-onglets) uniquement : Nom +
|
* Périmètre :
|
||||||
* Certification + Affréter. Les champs conditionnels (indexation / benne / volume
|
* - ERP-165 : formulaire PRINCIPAL minimal (Nom + Certification + Affréter).
|
||||||
* si affrété, décharge si AUTRE, immatriculations LIOT) et la saisie assistée
|
* - ERP-166 : champs CONDITIONNELS du formulaire principal (indexation / benne /
|
||||||
* QUALIMAT arrivent à ERP-166 ; les onglets Adresses / Contacts / Prix aux tickets
|
* volume si affrété — RG-4.03 ; décharge si AUTRE — RG-4.02 ; immatriculations
|
||||||
* suivants. On garde donc volontairement ce draft minimal — il s'étendra.
|
* LIOT — RG-4.01) + saisie assistée QUALIMAT (copie name / certification /
|
||||||
|
* adresse + FK qualimatCarrier — RG-4.01 / § 2.5).
|
||||||
|
*
|
||||||
|
* L'upload réel de la décharge (file → IRI via useUpload) arrive à ERP-171 ; ici
|
||||||
|
* on porte seulement l'IRI résolu (`dischargeDocumentIri`).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Brouillon du formulaire principal. `certificationType` est un code enum back
|
* Brouillon du formulaire principal. Les décimales (indexation / volume) sont
|
||||||
* (GMP_PLUS | OVOCOM | COMPTE_PROPRE | AUTRE ; QUALIMAT sera posé par la saisie
|
* portées en `string` car `MalioInputNumber` émet une chaîne ; le serveur parse.
|
||||||
* assistée à ERP-166) ou `null` tant que rien n'est choisi.
|
* `certificationType` est un code enum back (GMP_PLUS | OVOCOM | COMPTE_PROPRE |
|
||||||
|
* AUTRE | QUALIMAT — ce dernier posé par la saisie assistée) ou `null`.
|
||||||
|
* `containerType` vaut `BENNE` | `FOND_MOUVANT` (radio) ou `null`.
|
||||||
*/
|
*/
|
||||||
export interface CarrierMainDraft {
|
export interface CarrierMainDraft {
|
||||||
name: string
|
name: string
|
||||||
certificationType: string | null
|
certificationType: string | null
|
||||||
isChartered: boolean
|
isChartered: boolean
|
||||||
|
indexationRate: string
|
||||||
|
containerType: string | null
|
||||||
|
volumeM3: string
|
||||||
|
liotPlates: string
|
||||||
|
/** IRI du document de décharge (résolu par useUpload — ERP-171). */
|
||||||
|
dischargeDocumentIri: string | null
|
||||||
|
/** IRI de la ligne QUALIMAT liée (saisie assistée — null si non QUALIMAT). */
|
||||||
|
qualimatCarrierIri: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Brouillon principal vide (état initial du formulaire de création). */
|
/** Brouillon principal vide (état initial du formulaire de création). */
|
||||||
@@ -25,6 +39,58 @@ export function emptyCarrierMain(): CarrierMainDraft {
|
|||||||
name: '',
|
name: '',
|
||||||
certificationType: null,
|
certificationType: null,
|
||||||
isChartered: false,
|
isChartered: false,
|
||||||
|
indexationRate: '',
|
||||||
|
containerType: null,
|
||||||
|
volumeM3: '',
|
||||||
|
liotPlates: '',
|
||||||
|
dischargeDocumentIri: null,
|
||||||
|
qualimatCarrierIri: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adresse copiée depuis le référentiel QUALIMAT à la sélection (RG-4.01 / § 2.5).
|
||||||
|
* Stockée dans l'état du formulaire pour alimenter l'onglet Adresses (ticket
|
||||||
|
* ultérieur) ; pré-remplie « France » côté pays par défaut.
|
||||||
|
*/
|
||||||
|
export interface CarrierAddressCopy {
|
||||||
|
country: string
|
||||||
|
postalCode: string
|
||||||
|
city: string
|
||||||
|
street: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adresse copiée vide. */
|
||||||
|
export function emptyCarrierAddressCopy(): CarrierAddressCopy {
|
||||||
|
return { country: 'France', postalCode: '', city: '', street: '' }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brouillon d'un bloc Adresse (onglet Adresses, ERP-167) — sous-ressource
|
||||||
|
* `CarrierAddress` (groupe `carrier:write:addresses`). Version SIMPLIFIÉE de
|
||||||
|
* l'adresse fournisseur (M2) / prestataire (M3) : pas de sites / catégories /
|
||||||
|
* contacts ni type d'adresse (les sites du M4 vivent dans l'onglet Prix).
|
||||||
|
*/
|
||||||
|
export interface CarrierAddressFormDraft {
|
||||||
|
/** Id serveur une fois l'adresse créée (null tant que non persistée). */
|
||||||
|
id: number | null
|
||||||
|
/** Pays (chaîne libre, défaut « France »). */
|
||||||
|
country: string
|
||||||
|
postalCode: string | null
|
||||||
|
city: string | null
|
||||||
|
street: string | null
|
||||||
|
streetComplement: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Brouillon d'adresse vide (pays France par défaut, RG-4.05). */
|
||||||
|
export function emptyCarrierAddress(): CarrierAddressFormDraft {
|
||||||
|
return {
|
||||||
|
id: null,
|
||||||
|
country: 'France',
|
||||||
|
postalCode: null,
|
||||||
|
city: null,
|
||||||
|
street: null,
|
||||||
|
streetComplement: null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* Helpers purs de l'onglet Adresse transporteur (M4 Transport, ERP-167) — miroir
|
||||||
|
* SIMPLIFIÉ de `providerAddress` (M3) / `SupplierAddressBlock` (M2), sans sites /
|
||||||
|
* catégories / contacts (les sites du M4 vivent dans l'onglet Prix). Testables
|
||||||
|
* sans Vue.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { CarrierAddressFormDraft } from '~/modules/transport/types/carrierForm'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RG-4.05 : gate du bouton « + Nouvelle adresse ». Une adresse est « complète »
|
||||||
|
* (donc on autorise l'ajout d'un nouveau bloc) dès qu'elle porte un code postal,
|
||||||
|
* une ville ET une rue. Les RG conditionnelles (obligatoire si affrété) restent
|
||||||
|
* validées par le back (422 inline) — ce gate empêche seulement d'empiler des
|
||||||
|
* blocs vides.
|
||||||
|
*/
|
||||||
|
export function isCarrierAddressValid(address: CarrierAddressFormDraft): boolean {
|
||||||
|
return Boolean(address.postalCode?.trim() && address.city?.trim() && address.street?.trim())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payload de la sous-ressource addresses (groupe `carrier:write:addresses`). Les
|
||||||
|
* scalaires sont nullable côté entité : on envoie `null` quand le champ est vide
|
||||||
|
* (le `CarrierAddressProcessor` re-valide la présence si affrété — RG-4.05 — et
|
||||||
|
* renvoie une 422 par champ).
|
||||||
|
*/
|
||||||
|
export function buildCarrierAddressPayload(address: CarrierAddressFormDraft): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
country: address.country,
|
||||||
|
postalCode: address.postalCode || null,
|
||||||
|
city: address.city || null,
|
||||||
|
street: address.street || null,
|
||||||
|
streetComplement: address.streetComplement || null,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user