feat(admin): add categories and teams management page

This commit is contained in:
gabdevele
2026-06-15 12:48:18 +02:00 Unverified
parent 48f0f65dc1
commit 8bf6f29561
13 changed files with 354 additions and 52 deletions
+6 -5
View File
@@ -8,7 +8,6 @@ import type {
} from "~/types/api";
export const useAuth = () => {
const route = useRoute()
const nuxtApp = useNuxtApp()
const token = useCookie<string | null>('auth_token', {
@@ -33,7 +32,8 @@ export const useAuth = () => {
tokenState.value = newVal || null
})
const syncUser = async (redirectOnSuccess = false) => {
const syncUser = async (options: { redirectOnSuccess?: boolean; currentPath?: string } = {}) => {
const { redirectOnSuccess = false, currentPath } = options
const tokenVal = tokenState.value || token.value
if (!tokenVal || isSyncingUser.value) return
@@ -42,10 +42,11 @@ export const useAuth = () => {
const res = await fetchCurrentUser()
if (res.ok) {
user.value = res.user
const path = currentPath ?? useNuxtApp().$router.currentRoute.value.path
if (res.user.must_change_password && route.path !== '/auth/change-password') {
if (res.user.must_change_password && path !== '/auth/change-password') {
await nuxtApp.runWithContext(() => navigateTo('/auth/change-password'))
} else if (redirectOnSuccess && route.path.startsWith('/auth')) {
} else if (redirectOnSuccess && path.startsWith('/auth')) {
await nuxtApp.runWithContext(() => navigateTo('/dashboard'))
}
}
@@ -65,7 +66,7 @@ export const useAuth = () => {
const handleLoginSuccess = async (jwtToken: string) => {
token.value = jwtToken
tokenState.value = jwtToken
await syncUser(true)
await syncUser({ redirectOnSuccess: true })
}
const logout = () => {
+6 -1
View File
@@ -3,6 +3,7 @@ import type {
InterventionSummaryResponse,
OkResponse,
PagedReportListResponse,
TeamListResponse,
UpdateStatusRequest
} from "~/types/api";
@@ -16,6 +17,9 @@ export const useOperator = () => {
const getOtherOperatorReports = (query?: { page?: number; per_page?: number }) =>
useApiFetch<PagedReportListResponse>('/api/v1/operator/reports/others', { method: 'GET', query })
const getTeams = () =>
useApiFetch<TeamListResponse>('/api/v1/operator/teams', { method: 'GET' })
const takeReport = (id: number) =>
useApiFetch<OkResponse>(`/api/v1/reports/${id}/take`, { method: 'POST' })
@@ -32,9 +36,10 @@ export const useOperator = () => {
getOpenReports,
getAssignedReports,
getOtherOperatorReports,
getTeams,
takeReport,
updateReportStatus,
assignTeam,
getInterventionSummary,
}
}
}
+6 -1
View File
@@ -1,4 +1,5 @@
import type {
CategoryListResponse,
CreateReportRequest,
CreateReportResponse, FeedbackRequest, FlagRequest, FlagResponse,
MediaUploadResponse,
@@ -11,6 +12,9 @@ export const useReports = () => {
const getReports = (query?: { area_id?: number; category_id?: number; status?: string }) =>
useApiFetch<ReportListResponse>('/api/v1/reports', { method: 'GET', query })
const getCategories = () =>
useApiFetch<CategoryListResponse>('/api/v1/report-categories', { method: 'GET' })
const createReport = (body: CreateReportRequest) =>
useApiFetch<CreateReportResponse>('/api/v1/reports', { method: 'POST', body })
@@ -37,6 +41,7 @@ export const useReports = () => {
return {
getReports,
getCategories,
createReport,
getReportDetail,
uploadMedia,
@@ -46,4 +51,4 @@ export const useReports = () => {
flagReport,
flagMessage,
}
}
}