feat(admin): add categories and teams management page
This commit is contained in:
@@ -17,19 +17,22 @@ if (!reportId) {
|
||||
}
|
||||
|
||||
const { getReportDetail, getMessages, addMessage, flagMessage } = useReports()
|
||||
const { getInterventionSummary, updateReportStatus, assignTeam } = useOperator()
|
||||
const { getInterventionSummary, updateReportStatus, assignTeam, getTeams } = useOperator()
|
||||
const { user } = useAuth()
|
||||
|
||||
// Dati principali
|
||||
const { data: reportData, refresh: refreshReport } = await useAsyncData(`op-report-${reportId}`, () => getReportDetail(reportId))
|
||||
const { data: messagesData, refresh: refreshMessages } = await useAsyncData(`op-messages-${reportId}`, () => getMessages(reportId))
|
||||
const { data: summaryData, refresh: refreshSummary } = await useAsyncData(`op-summary-${reportId}`, () => getInterventionSummary(reportId))
|
||||
const { data: teamsData } = await useAsyncData('operator-teams', () => getTeams())
|
||||
|
||||
const report = computed(() => (reportData.value as any)?.report)
|
||||
const media = computed(() => (reportData.value as any)?.media || [])
|
||||
const statusHistory = computed(() => (reportData.value as any)?.history || [])
|
||||
const messages = computed(() => (messagesData.value as any)?.messages || [])
|
||||
const summary = computed(() => (summaryData.value as any)?.summary)
|
||||
const summaryMedia = computed(() => (summaryData.value as any)?.media || [])
|
||||
const teams = computed(() => teamsData.value?.teams || [])
|
||||
const statusMeta: Record<string, string> = {
|
||||
OPEN: 'Aperta',
|
||||
UNDER_REVIEW: 'In revisione',
|
||||
@@ -47,9 +50,7 @@ const isUpdatingStatus = ref(false)
|
||||
|
||||
// Form Assegna Squadra
|
||||
const isAssignModalOpen = ref(false)
|
||||
const teamName = ref('')
|
||||
const assignNote = ref('')
|
||||
const estimatedDate = ref('')
|
||||
const selectedTeamId = ref<number | null>(null)
|
||||
const isAssigning = ref(false)
|
||||
|
||||
// Messaggi
|
||||
@@ -90,19 +91,15 @@ const handleStatusUpdate = async () => {
|
||||
}
|
||||
|
||||
const handleAssignTeam = async () => {
|
||||
if (!teamName.value) return
|
||||
if (!selectedTeamId.value) return
|
||||
isAssigning.value = true
|
||||
try {
|
||||
const res = await assignTeam(reportId, {
|
||||
assigned_to_team: teamName.value,
|
||||
estimated_resolution_date: estimatedDate.value || undefined,
|
||||
internal_notes: assignNote.value || undefined
|
||||
team_id: selectedTeamId.value
|
||||
})
|
||||
if (res.ok) {
|
||||
isAssignModalOpen.value = false
|
||||
teamName.value = ''
|
||||
assignNote.value = ''
|
||||
estimatedDate.value = ''
|
||||
selectedTeamId.value = null
|
||||
await Promise.all([refreshReport(), refreshSummary()])
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -152,6 +149,15 @@ const formatDate = (dateString: string) => {
|
||||
hour: '2-digit', minute: '2-digit'
|
||||
})
|
||||
}
|
||||
|
||||
const latestCitizenMessage = computed(() => {
|
||||
const reportUserId = report.value?.user_id
|
||||
if (!reportUserId) return null
|
||||
|
||||
return [...messages.value]
|
||||
.reverse()
|
||||
.find((message) => message.user_id === reportUserId) || null
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -257,29 +263,31 @@ const formatDate = (dateString: string) => {
|
||||
<div class="report-sidebar">
|
||||
<div class="card card-bg border-0 shadow-sm mb-4" v-if="summary">
|
||||
<div class="card-body">
|
||||
<h2 class="h6 mb-3">Riepilogo intervento</h2>
|
||||
<h2 class="h6 mb-3">Quadro operativo</h2>
|
||||
<ul class="report-summary-list list-unstyled mb-4">
|
||||
<li>
|
||||
<span>Operatore</span>
|
||||
<strong>{{ summary.operator_id ? `#${summary.operator_id}` : 'Nessuno' }}</strong>
|
||||
<strong>{{ summary.assigned_operator_id ? `#${summary.assigned_operator_id}` : 'Nessuno' }}</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span>Squadra</span>
|
||||
<strong>{{ summary.assigned_to_team || 'Nessuna' }}</strong>
|
||||
<span>Team disponibili</span>
|
||||
<strong>{{ teams.length }}</strong>
|
||||
</li>
|
||||
<li>
|
||||
<span>Data prevista</span>
|
||||
<strong>{{ summary.estimated_resolution_date ? formatDate(summary.estimated_resolution_date) : 'Non impostata' }}</strong>
|
||||
<span>Allegati</span>
|
||||
<strong>{{ summaryMedia.length || media.length }}</strong>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="report-description">
|
||||
<h3 class="h6 mb-2">Note interne</h3>
|
||||
<p class="small mb-0">{{ summary.internal_notes || 'Nessuna nota interna' }}</p>
|
||||
<h3 class="h6 mb-2">Ultimo messaggio cittadino</h3>
|
||||
<p class="small mb-0">
|
||||
{{ latestCitizenMessage?.body || 'Nessun messaggio del cittadino disponibile.' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body pt-0">
|
||||
<button class="btn btn-outline-primary w-100" @click="isAssignModalOpen = true">
|
||||
Gestisci Squadra e Note
|
||||
<button class="btn btn-outline-primary w-100" @click="isAssignModalOpen = true" :disabled="teams.length === 0">
|
||||
Assegna team
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -342,20 +350,21 @@ const formatDate = (dateString: string) => {
|
||||
<div class="modal-body">
|
||||
<form @submit.prevent="handleAssignTeam">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Squadra / Ditta Incaricata</label>
|
||||
<input type="text" class="form-control" v-model="teamName" placeholder="Es. Squadra Verde SPA" required />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Data Prevista Risoluzione (opzionale)</label>
|
||||
<input type="date" class="form-control" v-model="estimatedDate" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Note Interne (private)</label>
|
||||
<textarea class="form-control" v-model="assignNote" rows="3" placeholder="Note ad uso interno, non visibili al cittadino..."></textarea>
|
||||
<label class="form-label">Team incaricato</label>
|
||||
<select v-model.number="selectedTeamId" class="form-select" required>
|
||||
<option :value="null">Seleziona team</option>
|
||||
<option v-for="team in teams" :key="team.id" :value="team.id">
|
||||
{{ team.name }}<template v-if="team.category_name"> · {{ team.category_name }}</template>
|
||||
<template v-if="team.area_name"> · {{ team.area_name }}</template>
|
||||
</option>
|
||||
</select>
|
||||
<small v-if="teams.length === 0" class="form-text text-danger">
|
||||
Nessun team attivo disponibile.
|
||||
</small>
|
||||
</div>
|
||||
<div class="d-flex justify-content-end gap-2 mt-4">
|
||||
<button type="button" class="btn btn-outline-secondary" @click="isAssignModalOpen = false">Annulla</button>
|
||||
<button type="submit" class="btn btn-primary" :disabled="isAssigning || !teamName.trim()">
|
||||
<button type="submit" class="btn btn-primary" :disabled="isAssigning || !selectedTeamId">
|
||||
<span v-if="isAssigning" class="spinner-border spinner-border-sm me-2"></span>
|
||||
Salva Assegnazione
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user