Add admin maintenance endpoints and file deletion functionality
- Introduced a new `/api/admin/maintenance` route for administrative maintenance tasks, requiring admin authorization. - Implemented the `DeleteAsync` method in `IFileStorage` to allow for the deletion of files associated with closed support tickets. - Updated API documentation to include details about the new maintenance operations and their effects on closed tickets. - Enhanced frontend routing to include the new maintenance section in the admin panel, improving navigation for administrators. - Added localization support for maintenance-related actions in both Russian and English.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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'
|
||||
|
||||
export const Route = createFileRoute('/admin/maintenance')({ component: AdminMaintenancePage })
|
||||
|
||||
function AdminMaintenancePage() {
|
||||
const { t } = useTranslation()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
const deleteClosedTicketsMutation = useMutation({
|
||||
mutationFn: deleteClosedTickets,
|
||||
onSuccess: async (data) => {
|
||||
toast.success(t('admin.maintenance.closedTickets.deleted', { count: data.deletedCount }))
|
||||
await queryClient.invalidateQueries({ queryKey: ['admin-tickets'] })
|
||||
},
|
||||
onError: () => toast.error(t('auth.genericError')),
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">{t('admin.maintenance.closedTickets.title')}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
<p className="text-sm text-muted-foreground">{t('admin.maintenance.closedTickets.description')}</p>
|
||||
<div>
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={deleteClosedTicketsMutation.isPending}
|
||||
onClick={() => {
|
||||
if (confirm(t('admin.maintenance.closedTickets.confirm'))) deleteClosedTicketsMutation.mutate()
|
||||
}}
|
||||
>
|
||||
{t('admin.maintenance.closedTickets.action')}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user