144a8a4685
LST-69 (3.2) front. Client portal UI on the phase-1 backend. - New frontend/modules/client-portal/ layer: /portal (project cards from the client's allowedProjects via /me), /portal/projects/[id] (tickets list, detail modal, create modal with document upload), client-tickets service + DTO, CT-XXX formatting. - Front tenancy: auth.global.ts redirects a pure ROLE_CLIENT to /portal and blocks internal routes; portal pages open to any authenticated user. - Admin: UserDrawer manages client accounts (ROLE_CLIENT + client + allowedProjects); new "Tickets client" admin tab (list, filters, status change with required comment on reject, detail modal). - Kanban/my-tasks: client-ticket icon + tooltip when task.clientTicket is set (data via task:read, no extra call). TaskDocument upload generalized with a clientTicketId prop. getContent uses native fetch (text response). - i18n portal/clientTicket keys; sidebar /portal item (module client-portal). nuxt build passes; /portal routes present, existing routes intact.
252 lines
8.0 KiB
Vue
252 lines
8.0 KiB
Vue
<template>
|
|
<MalioDrawer v-model="isOpen">
|
|
<template #header>
|
|
<h2 class="text-xl font-bold">{{ isEditing ? $t('users.editUser') : $t('users.addUser') }}</h2>
|
|
</template>
|
|
<form class="flex flex-col gap-2" @submit.prevent="handleSubmit">
|
|
<MalioInputText
|
|
v-model="form.username"
|
|
label="Nom d'utilisateur"
|
|
input-class="w-full"
|
|
:error="touched.username && !form.username.trim() ? 'Le nom est requis' : ''"
|
|
@blur="touched.username = true"
|
|
/>
|
|
<MalioInputText
|
|
v-model="form.firstName"
|
|
label="Prénom"
|
|
input-class="w-full"
|
|
/>
|
|
<MalioInputText
|
|
v-model="form.lastName"
|
|
label="Nom"
|
|
input-class="w-full"
|
|
/>
|
|
<MalioInputPassword
|
|
v-model="form.password"
|
|
label="Mot de passe"
|
|
input-class="w-full"
|
|
:hint="isEditing ? 'Laisser vide pour ne pas changer' : ''"
|
|
:error="touched.password && !isEditing && !form.password ? 'Le mot de passe est requis' : ''"
|
|
@blur="touched.password = true"
|
|
/>
|
|
<div class="mt-4">
|
|
<label class="text-sm font-semibold text-neutral-700">Rôles</label>
|
|
<div class="mt-2 flex flex-col gap-2">
|
|
<label
|
|
v-for="role in availableRoles"
|
|
:key="role"
|
|
class="flex items-center gap-2 text-sm text-neutral-700"
|
|
>
|
|
<input
|
|
v-model="form.roles"
|
|
type="checkbox"
|
|
:value="role"
|
|
class="rounded border-neutral-300"
|
|
/>
|
|
{{ role }}
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Compte client (portail) -->
|
|
<div v-if="isClient" class="mt-6 border-t border-neutral-200 pt-4">
|
|
<p class="mb-3 text-sm font-semibold text-neutral-700">{{ $t('users.clientAccount') }}</p>
|
|
<MalioSelect
|
|
v-model="form.client"
|
|
:options="clientOptions"
|
|
:label="$t('users.client')"
|
|
group-class="w-full"
|
|
empty-option-label="—"
|
|
/>
|
|
<div class="mt-3">
|
|
<MalioSelectCheckbox
|
|
v-model="form.allowedProjects"
|
|
:options="projectOptions"
|
|
:label="$t('users.allowedProjects')"
|
|
group-class="w-full"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- RH / Absences -->
|
|
<div class="mt-6 border-t border-neutral-200 pt-4">
|
|
<MalioCheckbox v-model="form.isEmployee" label="Employé (soumis à la gestion des absences)" />
|
|
<p v-if="form.isEmployee" class="mt-2 text-xs text-neutral-500">
|
|
Les informations RH (contrat, dates, CP…) se gèrent dans Absences équipe → onglet Employés.
|
|
</p>
|
|
</div>
|
|
|
|
<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 { UserData, UserWrite } from '~/services/dto/user-data'
|
|
import { useUserService } from '~/services/users'
|
|
import { useClientService } from '~/modules/directory/services/clients'
|
|
import { useProjectService } from '~/modules/project-management/services/projects'
|
|
|
|
const props = defineProps<{
|
|
modelValue: boolean
|
|
item: UserData | 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 availableRoles = ['ROLE_ADMIN', 'ROLE_USER', 'ROLE_CLIENT']
|
|
|
|
const isEditing = computed(() => !!props.item)
|
|
const isSubmitting = ref(false)
|
|
|
|
const form = reactive({
|
|
username: '',
|
|
firstName: '',
|
|
lastName: '',
|
|
password: '',
|
|
roles: [] as string[],
|
|
isEmployee: false,
|
|
client: null as string | null,
|
|
allowedProjects: [] as string[],
|
|
})
|
|
|
|
const isClient = computed(() => form.roles.includes('ROLE_CLIENT'))
|
|
|
|
const touched = reactive({
|
|
username: false,
|
|
password: false,
|
|
})
|
|
|
|
const clientOptions = ref<{ label: string, value: string | null }[]>([])
|
|
const projectOptions = ref<{ label: string, value: string }[]>([])
|
|
|
|
const { getAll: getClients } = useClientService()
|
|
const { getAll: getProjects } = useProjectService()
|
|
const { create, update, getById } = useUserService()
|
|
|
|
async function loadOptions() {
|
|
if (clientOptions.value.length && projectOptions.value.length) {
|
|
return
|
|
}
|
|
const [clients, projects] = await Promise.all([getClients(), getProjects()])
|
|
clientOptions.value = clients.map((c) => ({
|
|
label: c.name,
|
|
value: c['@id'] ?? `/api/clients/${c.id}`,
|
|
}))
|
|
projectOptions.value = projects.map((p) => ({
|
|
label: p.name,
|
|
value: p['@id'] ?? `/api/projects/${p.id}`,
|
|
}))
|
|
}
|
|
|
|
/** Normalize allowedProjects (embedded objects or bare IRIs) into IRI strings. */
|
|
function toProjectIris(allowed: UserData['allowedProjects'] | undefined): string[] {
|
|
if (!allowed) {
|
|
return []
|
|
}
|
|
return allowed.map((p) => {
|
|
if (typeof p === 'string') {
|
|
return p
|
|
}
|
|
return p['@id'] ?? `/api/projects/${p.id}`
|
|
})
|
|
}
|
|
|
|
function applyUser(user: UserData) {
|
|
form.username = user.username ?? ''
|
|
form.firstName = user.firstName ?? ''
|
|
form.lastName = user.lastName ?? ''
|
|
form.password = ''
|
|
form.roles = [...user.roles]
|
|
form.isEmployee = user.isEmployee ?? false
|
|
form.client = user.client ?? null
|
|
form.allowedProjects = toProjectIris(user.allowedProjects)
|
|
}
|
|
|
|
watch(() => props.modelValue, async (open) => {
|
|
if (!open) {
|
|
return
|
|
}
|
|
|
|
touched.username = false
|
|
touched.password = false
|
|
await loadOptions()
|
|
|
|
if (props.item) {
|
|
// The list payload (user:list) omits client / allowedProjects → fetch the full item.
|
|
applyUser(props.item)
|
|
try {
|
|
const full = await getById(props.item.id)
|
|
applyUser(full)
|
|
} catch {
|
|
// Keep the list data if the detailed fetch fails.
|
|
}
|
|
} else {
|
|
form.username = ''
|
|
form.firstName = ''
|
|
form.lastName = ''
|
|
form.password = ''
|
|
form.roles = ['ROLE_USER']
|
|
form.isEmployee = false
|
|
form.client = null
|
|
form.allowedProjects = []
|
|
}
|
|
})
|
|
|
|
async function handleSubmit() {
|
|
touched.username = true
|
|
touched.password = true
|
|
if (!form.username.trim()) return
|
|
if (!isEditing.value && !form.password) return
|
|
|
|
isSubmitting.value = true
|
|
try {
|
|
const payload: UserWrite = {
|
|
username: form.username.trim(),
|
|
firstName: form.firstName.trim() || null,
|
|
lastName: form.lastName.trim() || null,
|
|
roles: form.roles,
|
|
isEmployee: form.isEmployee,
|
|
}
|
|
if (form.password) {
|
|
payload.plainPassword = form.password
|
|
}
|
|
|
|
// Client portal fields: only relevant when the user is a client.
|
|
if (isClient.value) {
|
|
payload.client = form.client
|
|
payload.allowedProjects = form.allowedProjects
|
|
} else {
|
|
payload.client = null
|
|
payload.allowedProjects = []
|
|
}
|
|
|
|
if (isEditing.value && props.item) {
|
|
await update(props.item.id, payload)
|
|
} else {
|
|
await create(payload)
|
|
}
|
|
|
|
emit('saved')
|
|
isOpen.value = false
|
|
} finally {
|
|
isSubmitting.value = false
|
|
}
|
|
}
|
|
</script>
|