5764d8f472
- Prestataire : entité/repo + ressource API Platform (RBAC directory.providers.*), ownership prestataire sur contacts/adresses/comptes-rendus (CHECK XOR à 3), DTO/service/drawer/fiche détail + onglet dédié dans le répertoire. - Prospect : société uniquement (suppression du champ name, company requis) ; migration de backfill, conversion prospect→client et MCP adaptés. - Champ site web sur client/prospect/prestataire (entités, DTO, onglet Information, MCP). - Validateurs front email / téléphone FR (0549200910) / URL sur Information et Contacts, enregistrement bloqué tant qu'un champ est invalide. - Autocomplete adresse branché sur la Base Adresse Nationale (api-adresse.data.gouv.fr) avec mode dégradé en saisie libre. - Administration : retrait de l'onglet Clients.
116 lines
3.3 KiB
Vue
116 lines
3.3 KiB
Vue
<template>
|
|
<MalioDrawer v-model="isOpen">
|
|
<template #header>
|
|
<h2 class="text-xl font-bold">{{ isEditing ? $t('prospects.editProspect') : $t('prospects.addProspect') }}</h2>
|
|
</template>
|
|
<form @submit.prevent="handleSubmit" class="flex flex-col gap-2">
|
|
<MalioInputText
|
|
v-model="form.company"
|
|
:label="$t('prospects.fields.company')"
|
|
input-class="w-full"
|
|
:error="touched.company && !form.company.trim() ? $t('prospects.validation.companyRequired') : ''"
|
|
@blur="touched.company = true"
|
|
/>
|
|
|
|
<div class="mt-6 flex items-center justify-between gap-2">
|
|
<MalioButton
|
|
v-if="isEditing && !isConverted"
|
|
:label="$t('prospects.convert')"
|
|
variant="secondary"
|
|
icon-name="mdi:account-convert"
|
|
icon-position="left"
|
|
button-class="w-auto px-4"
|
|
:disabled="isSubmitting"
|
|
@click="handleConvert"
|
|
/>
|
|
<span v-else-if="isConverted" class="text-sm text-green-700">
|
|
{{ $t('prospects.alreadyConverted') }}
|
|
</span>
|
|
<span v-else />
|
|
<MalioButton
|
|
:label="$t('common.save')"
|
|
button-class="w-auto px-6"
|
|
:disabled="isSubmitting"
|
|
@click="handleSubmit"
|
|
/>
|
|
</div>
|
|
</form>
|
|
</MalioDrawer>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { Prospect, ProspectWrite } from '~/modules/directory/services/dto/prospect'
|
|
import { useProspectService } from '~/modules/directory/services/prospects'
|
|
|
|
const props = defineProps<{
|
|
modelValue: boolean
|
|
prospect: Prospect | null
|
|
}>()
|
|
|
|
const emit = defineEmits<{
|
|
(e: 'update:modelValue', value: boolean): void
|
|
(e: 'saved'): void
|
|
}>()
|
|
|
|
const isOpen = computed({
|
|
get: () => props.modelValue,
|
|
set: (v) => emit('update:modelValue', v),
|
|
})
|
|
|
|
const isEditing = computed(() => !!props.prospect)
|
|
const isConverted = computed(() => !!props.prospect?.convertedClient)
|
|
const isSubmitting = ref(false)
|
|
|
|
const form = reactive({
|
|
company: '',
|
|
})
|
|
|
|
const touched = reactive({
|
|
company: false,
|
|
})
|
|
|
|
watch(() => props.modelValue, (open) => {
|
|
if (open) {
|
|
form.company = props.prospect?.company ?? ''
|
|
touched.company = false
|
|
}
|
|
})
|
|
|
|
const { create, update, convert } = useProspectService()
|
|
|
|
async function handleSubmit() {
|
|
touched.company = true
|
|
if (!form.company.trim()) return
|
|
|
|
isSubmitting.value = true
|
|
try {
|
|
const payload: ProspectWrite = {
|
|
company: form.company.trim(),
|
|
}
|
|
|
|
if (isEditing.value && props.prospect) {
|
|
await update(props.prospect.id, payload)
|
|
} else {
|
|
await create(payload)
|
|
}
|
|
|
|
emit('saved')
|
|
isOpen.value = false
|
|
} finally {
|
|
isSubmitting.value = false
|
|
}
|
|
}
|
|
|
|
async function handleConvert() {
|
|
if (!props.prospect) return
|
|
isSubmitting.value = true
|
|
try {
|
|
await convert(props.prospect.id)
|
|
emit('saved')
|
|
isOpen.value = false
|
|
} finally {
|
|
isSubmitting.value = false
|
|
}
|
|
}
|
|
</script>
|