From 0944ccec8c503516a2936448a0011314cbfc5941 Mon Sep 17 00:00:00 2001 From: ReLoia Date: Fri, 19 Jun 2026 21:54:05 +0200 Subject: [PATCH] feat: add suggested team --- app/composables/useAuth.ts | 4 +- app/composables/useReports.ts | 20 ++++-- app/pages/operator/reports/[id].vue | 108 ++++++++++++++++++++-------- 3 files changed, 96 insertions(+), 36 deletions(-) diff --git a/app/composables/useAuth.ts b/app/composables/useAuth.ts index 076f1d9..af65e36 100644 --- a/app/composables/useAuth.ts +++ b/app/composables/useAuth.ts @@ -70,8 +70,8 @@ export const useAuth = () => { const res = await fetchCurrentUser() if (res.ok) { user.value = res.user - await refreshUnreadNotifications() - const path = currentPath ?? useNuxtApp().$router.currentRoute.value.path + await nuxtApp.runWithContext(() => refreshUnreadNotifications()) + const path = currentPath ?? nuxtApp.$router.currentRoute.value.path if (redirectOnSuccess && path.startsWith('/auth')) { await nuxtApp.runWithContext(() => navigateTo('/dashboard')) diff --git a/app/composables/useReports.ts b/app/composables/useReports.ts index d83aa98..faa919f 100644 --- a/app/composables/useReports.ts +++ b/app/composables/useReports.ts @@ -1,11 +1,17 @@ import type { CategoryListResponse, CreateReportRequest, - CreateReportResponse, FeedbackRequest, FlagRequest, FlagResponse, + CreateReportResponse, + FeedbackRequest, + FlagRequest, + FlagResponse, MediaUploadResponse, - MessageListResponse, MessageRequest, OkResponse, + MessageListResponse, + MessageRequest, + OkResponse, ReportDetailResponse, - ReportListResponse + ReportListResponse, + TeamListResponse } from "~/types/api"; export const useReports = () => { @@ -20,7 +26,7 @@ export const useReports = () => { const getReportDetail = (id: number) => useApiFetch(`/api/v1/reports/${id}`, { method: 'GET' }) - + const uploadMedia = (id: number, formData: FormData) => useApiFetch(`/api/v1/reports/${id}/media`, { method: 'POST', body: formData }) @@ -39,6 +45,9 @@ export const useReports = () => { const flagMessage = (reportId: number, messageId: number, body: FlagRequest) => useApiFetch(`/api/v1/reports/${reportId}/messages/${messageId}/flags`, { method: 'POST', body }) + const getTeamSuggestions = (id: number) => + useApiFetch(`/api/v1/reports/${id}/team-suggestions`, { method: 'GET' }) + return { getReports, getCategories, @@ -50,5 +59,6 @@ export const useReports = () => { addFeedback, flagReport, flagMessage, + getTeamSuggestions, } -} +} \ No newline at end of file diff --git a/app/pages/operator/reports/[id].vue b/app/pages/operator/reports/[id].vue index ddfd88f..db62355 100644 --- a/app/pages/operator/reports/[id].vue +++ b/app/pages/operator/reports/[id].vue @@ -16,7 +16,7 @@ if (!reportId) { navigateTo('/operator') } -const { getReportDetail, getMessages, addMessage, flagMessage, flagReport } = useReports() +const { getReportDetail, getMessages, addMessage, flagMessage, flagReport, getTeamSuggestions } = useReports() const { takeReport, getInterventionSummary, @@ -31,7 +31,9 @@ const { user } = useAuth() 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 { data: allTeamsData } = await useAsyncData('operator-teams', () => getTeams()) +const { data: suggestedTeamsData } = await useAsyncData(`op-team-suggestions-${reportId}`, () => getTeamSuggestions(reportId)) const report = computed(() => (reportData.value as any)?.report) const media = computed(() => (reportData.value as any)?.media || []) @@ -39,7 +41,14 @@ 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 allTeams = computed(() => (allTeamsData.value as any)?.teams || []) +const suggestedTeams = computed(() => (suggestedTeamsData.value as any)?.suggestions || []) + +const otherTeams = computed(() => { + const suggestedIds = new Set(suggestedTeams.value.map((t: any) => Number(t.id))) + return allTeams.value.filter((t: any) => !suggestedIds.has(Number(t.id))) +}) const currentUserId = computed(() => user.value?.id ?? null) const isTakenByCurrentOperator = computed(() => report.value?.assigned_operator_id === currentUserId.value) @@ -47,7 +56,7 @@ const isOpenAndUnassigned = computed(() => report.value?.status === 'OPEN' && !r const isReadOnlyPreview = computed(() => !isTakenByCurrentOperator.value) const canTakeReport = computed(() => isOpenAndUnassigned.value && !isTakenByCurrentOperator.value) const isFinalStatus = computed(() => ['REJECTED', 'RESOLVED', 'CLOSED'].includes(report.value?.status || '')) -const canAssignTeam = computed(() => !isReadOnlyPreview.value && !isFinalStatus.value && teams.value.length > 0) +const canAssignTeam = computed(() => !isReadOnlyPreview.value && !isFinalStatus.value && allTeams.value.length > 0) const canSendMessage = computed(() => !isReadOnlyPreview.value && !isFinalStatus.value) const canChangeStatus = computed(() => !isReadOnlyPreview.value && !isFinalStatus.value && selectableStatuses.value.length > 0) @@ -131,6 +140,26 @@ const reportFlagForm = reactive({ details: '' }) +// === GESTIONE SCROLL SCHERMO CON MODALI === +watch( + () => isAssignModalOpen.value || isFlagReportModalOpen.value || isRevokeInterventionModalOpen.value || isFlagMessageModalOpen.value, + (isOpen) => { + if (import.meta.client) { + if (isOpen) { + document.body.style.overflow = 'hidden' + } else { + document.body.style.overflow = '' + } + } + } +) + +onUnmounted(() => { + if (import.meta.client) { + document.body.style.overflow = '' + } +}) + watch(() => report.value?.status, (val) => { if (val) { const allowed = statusTransitions[val] || [] @@ -550,8 +579,8 @@ const formattedInterventionLinkExpiry = computed(() => {{ summary.assigned_operator_id ? `#${summary.assigned_operator_id}` : 'Nessuno' }}
  • - Team disponibili - {{ teams.length }} + Team suggeriti + {{ suggestedTeams.length }}
  • Allegati @@ -688,48 +717,69 @@ const formattedInterventionLinkExpiry = computed(() => - -