Enhance show deletion functionality to support media removal option
Updated the DeleteShowCommand and its handler to include an optional parameter for media deletion, allowing users to remove associated media files when deleting a show. Refactored related components and API calls to accommodate this new feature, ensuring a seamless user experience. Additionally, updated localization strings to reflect the new functionality and adjusted tests to verify the correct behavior of the deletion process with and without media.
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
SHOW_AUDIENCES,
|
||||
type ShowAudience,
|
||||
type ShowKind,
|
||||
type ShowSummaryDto,
|
||||
} from '@/shared/api/types'
|
||||
import { useApiError } from '@/shared/lib/use-api-error'
|
||||
import { Badge } from '@/shared/ui/badge'
|
||||
@@ -19,6 +20,7 @@ import { sortRows, useTableSort } from '@/shared/lib/table-sort'
|
||||
import { SortHeader } from '@/shared/ui/sortable'
|
||||
import { listGenres } from '@/features/admin/genres/api'
|
||||
import { createShow, deleteShow, listShows } from './api'
|
||||
import { DeleteShowDialog } from './DeleteShowDialog'
|
||||
import { BulkTagBar } from './BulkTagBar'
|
||||
|
||||
const PAGE_SIZE = 20
|
||||
@@ -110,7 +112,17 @@ export function ShowsPanel() {
|
||||
},
|
||||
onError,
|
||||
})
|
||||
const deleteMutation = useMutation({ mutationFn: deleteShow, onSuccess: invalidate, onError })
|
||||
// Шоу к удалению: сначала спрашиваем про файлы, и только потом удаляем.
|
||||
const [toDelete, setToDelete] = useState<ShowSummaryDto | null>(null)
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: ({ id, withMedia }: { id: string; withMedia: boolean }) =>
|
||||
deleteShow(id, withMedia),
|
||||
onSuccess: () => {
|
||||
setToDelete(null)
|
||||
invalidate()
|
||||
},
|
||||
onError,
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
@@ -309,11 +321,7 @@ export function ShowsPanel() {
|
||||
<td className="px-4 py-2 text-muted-foreground">{show.seasonCount}</td>
|
||||
<td className="px-4 py-2 text-muted-foreground">{show.episodeCount}</td>
|
||||
<td className="px-4 py-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() => deleteMutation.mutate(show.id)}
|
||||
>
|
||||
<Button size="sm" variant="destructive" onClick={() => setToDelete(show)}>
|
||||
{t('common.delete')}
|
||||
</Button>
|
||||
</td>
|
||||
@@ -324,6 +332,15 @@ export function ShowsPanel() {
|
||||
</div>
|
||||
|
||||
<Pager page={page} totalPages={totalPages} onChange={setPage} />
|
||||
|
||||
{toDelete && (
|
||||
<DeleteShowDialog
|
||||
show={toDelete}
|
||||
pending={deleteMutation.isPending}
|
||||
onConfirm={(withMedia) => deleteMutation.mutate({ id: toDelete.id, withMedia })}
|
||||
onClose={() => setToDelete(null)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user