Enhance admin maintenance functionality with new endpoints and response types
- Added new DELETE endpoints for managing audit logs and disabled apps in the admin maintenance section. - Updated existing endpoint for closed tickets to use a unified response type, `MaintenanceCleanupResponseDto`. - Enhanced API documentation to reflect the new operations and their expected request/response formats. - Improved frontend integration with new functions for deleting old audit logs and disabled apps, including user confirmation prompts. - Added localization support for new maintenance actions in both Russian and English.
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
import { useState } from 'react'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { toast } from '@/shared/ui/toast-store'
|
||||
import { Button } from '@/shared/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/shared/ui/card'
|
||||
import { deleteClosedTickets } from '@/features/admin/maintenance/api'
|
||||
import { Input } from '@/shared/ui/input'
|
||||
import { deleteClosedTickets, deleteDisabledApps, deleteOldAuditLogs } from '@/features/admin/maintenance/api'
|
||||
|
||||
export const Route = createFileRoute('/admin/maintenance')({ component: AdminMaintenancePage })
|
||||
|
||||
const DEFAULT_AUDIT_RETENTION_DAYS = 90
|
||||
|
||||
function AdminMaintenancePage() {
|
||||
const { t } = useTranslation()
|
||||
const queryClient = useQueryClient()
|
||||
const [auditRetentionDays, setAuditRetentionDays] = useState(DEFAULT_AUDIT_RETENTION_DAYS)
|
||||
|
||||
const deleteClosedTicketsMutation = useMutation({
|
||||
mutationFn: deleteClosedTickets,
|
||||
@@ -21,6 +26,24 @@ function AdminMaintenancePage() {
|
||||
onError: () => toast.error(t('auth.genericError')),
|
||||
})
|
||||
|
||||
const deleteOldAuditLogsMutation = useMutation({
|
||||
mutationFn: () => deleteOldAuditLogs(auditRetentionDays),
|
||||
onSuccess: async (data) => {
|
||||
toast.success(t('admin.maintenance.audit.deleted', { count: data.deletedCount }))
|
||||
await queryClient.invalidateQueries({ queryKey: ['admin-audit'] })
|
||||
},
|
||||
onError: () => toast.error(t('auth.genericError')),
|
||||
})
|
||||
|
||||
const deleteDisabledAppsMutation = useMutation({
|
||||
mutationFn: deleteDisabledApps,
|
||||
onSuccess: async (data) => {
|
||||
toast.success(t('admin.maintenance.apps.deleted', { count: data.deletedCount }))
|
||||
await queryClient.invalidateQueries({ queryKey: ['admin-apps'] })
|
||||
},
|
||||
onError: () => toast.error(t('auth.genericError')),
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Card>
|
||||
@@ -42,6 +65,59 @@ function AdminMaintenancePage() {
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('admin.maintenance.audit.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
<p className="text-sm text-muted-foreground">{t('admin.maintenance.audit.description')}</p>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<label className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
{t('admin.maintenance.audit.olderThan')}
|
||||
<Input
|
||||
type="number"
|
||||
min={1}
|
||||
max={3650}
|
||||
value={auditRetentionDays}
|
||||
onChange={(e) => setAuditRetentionDays(Number(e.target.value))}
|
||||
className="w-20"
|
||||
/>
|
||||
{t('admin.maintenance.audit.days')}
|
||||
</label>
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={deleteOldAuditLogsMutation.isPending || auditRetentionDays < 1}
|
||||
onClick={() => {
|
||||
if (confirm(t('admin.maintenance.audit.confirm', { days: auditRetentionDays })))
|
||||
deleteOldAuditLogsMutation.mutate()
|
||||
}}
|
||||
>
|
||||
{t('admin.maintenance.audit.action')}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('admin.maintenance.apps.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
<p className="text-sm text-muted-foreground">{t('admin.maintenance.apps.description')}</p>
|
||||
<div>
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={deleteDisabledAppsMutation.isPending}
|
||||
onClick={() => {
|
||||
if (confirm(t('admin.maintenance.apps.confirm'))) deleteDisabledAppsMutation.mutate()
|
||||
}}
|
||||
>
|
||||
{t('admin.maintenance.apps.action')}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user