57ccd9a740
LST-58 (2.4) front. Completes the Directory module.
- New frontend/modules/directory/ layer (auto-detected): /directory page with
Clients and Prospects tabs.
- Client front moved into the layer (clients service + client DTO +
ClientDrawer). New prospects service, prospect DTO and ProspectDrawer (with
a "Convert to client" action calling POST /prospects/{id}/convert).
- Consumers repointed to ~/modules/directory/... (admin client tab, PM project
drawer + project pages + project DTO, time-tracking page + export drawer).
- Sidebar admin item /directory gated by the directory module; /directory
protected by the admin middleware. i18n keys added (directory.*, prospects.*).
nuxt build passes; routes preserved.
Adds the 2.4 plan doc.
140 lines
3.8 KiB
Vue
140 lines
3.8 KiB
Vue
<template>
|
|
<MalioDrawer v-model="isOpen">
|
|
<template #header>
|
|
<h2 class="text-xl font-bold">{{ isEditing ? $t('clients.editClient') : $t('clients.addClient') }}</h2>
|
|
</template>
|
|
<form @submit.prevent="handleSubmit" class="flex flex-col gap-2">
|
|
<MalioInputText
|
|
v-model="form.name"
|
|
label="Nom"
|
|
input-class="w-full"
|
|
:error="touched.name && !form.name.trim() ? 'Le nom est requis' : ''"
|
|
@blur="touched.name = true"
|
|
/>
|
|
<MalioInputText
|
|
v-model="form.email"
|
|
label="Email"
|
|
input-class="w-full"
|
|
/>
|
|
<MalioInputText
|
|
v-model="form.phone"
|
|
label="Téléphone"
|
|
input-class="w-full"
|
|
/>
|
|
<MalioInputText
|
|
v-model="form.street"
|
|
label="Rue"
|
|
input-class="w-full"
|
|
/>
|
|
<MalioInputText
|
|
v-model="form.city"
|
|
label="Ville"
|
|
input-class="w-full"
|
|
/>
|
|
<MalioInputText
|
|
v-model="form.postalCode"
|
|
label="Code Postal"
|
|
input-class="w-full"
|
|
/>
|
|
|
|
<div class="mt-6 flex justify-end">
|
|
<MalioButton
|
|
label="Enregistrer"
|
|
button-class="w-auto px-6"
|
|
:disabled="isSubmitting"
|
|
@click="handleSubmit"
|
|
/>
|
|
</div>
|
|
</form>
|
|
</MalioDrawer>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { Client, ClientWrite } from '~/modules/directory/services/dto/client'
|
|
import { useClientService } from '~/modules/directory/services/clients'
|
|
|
|
const props = defineProps<{
|
|
modelValue: boolean
|
|
client: Client | 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.client)
|
|
const isSubmitting = ref(false)
|
|
|
|
const form = reactive({
|
|
name: '',
|
|
email: '',
|
|
phone: '',
|
|
street: '',
|
|
city: '',
|
|
postalCode: '',
|
|
})
|
|
|
|
const touched = reactive({
|
|
name: false,
|
|
email: false,
|
|
})
|
|
|
|
watch(() => props.modelValue, (open) => {
|
|
if (open) {
|
|
if (props.client) {
|
|
form.name = props.client.name ?? ''
|
|
form.email = props.client.email ?? ''
|
|
form.phone = props.client.phone ?? ''
|
|
form.street = props.client.street ?? ''
|
|
form.city = props.client.city ?? ''
|
|
form.postalCode = props.client.postalCode ?? ''
|
|
} else {
|
|
form.name = ''
|
|
form.email = ''
|
|
form.phone = ''
|
|
form.street = ''
|
|
form.city = ''
|
|
form.postalCode = ''
|
|
}
|
|
touched.name = false
|
|
touched.email = false
|
|
}
|
|
})
|
|
|
|
const { create, update } = useClientService()
|
|
|
|
async function handleSubmit() {
|
|
touched.name = true
|
|
if (!form.name.trim()) return
|
|
|
|
isSubmitting.value = true
|
|
try {
|
|
const payload: ClientWrite = {
|
|
name: form.name.trim(),
|
|
email: form.email.trim() || null,
|
|
phone: form.phone.trim() || null,
|
|
street: form.street.trim() || null,
|
|
city: form.city.trim() || null,
|
|
postalCode: form.postalCode.trim() || null,
|
|
}
|
|
|
|
if (isEditing.value && props.client) {
|
|
await update(props.client.id, payload)
|
|
} else {
|
|
await create(payload)
|
|
}
|
|
|
|
emit('saved')
|
|
isOpen.value = false
|
|
} finally {
|
|
isSubmitting.value = false
|
|
}
|
|
}
|
|
</script>
|