delete area
This commit is contained in:
@@ -32,6 +32,14 @@ export async function updateArea(id: string, request: UpdateAreaRequest): Promis
|
|||||||
return resp.data
|
return resp.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Каскадное удаление зоны: всё поддерево, достопримечательности (включая файлы в S3),
|
||||||
|
* наборы с составами и посещения пользователей. Необратимо.
|
||||||
|
*/
|
||||||
|
export async function deleteArea(id: string): Promise<void> {
|
||||||
|
await http.delete(`/admin/areas/${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
/** Публичный эндпоинт (permitAll) — источник имени зоны, когда путь в дереве не загружен. */
|
/** Публичный эндпоинт (permitAll) — источник имени зоны, когда путь в дереве не загружен. */
|
||||||
export async function fetchAreaName(id: string): Promise<string> {
|
export async function fetchAreaName(id: string): Promise<string> {
|
||||||
const resp = await http.get<{ id: string; name: string }>(`/areas/${id}`)
|
const resp = await http.get<{ id: string; name: string }>(`/areas/${id}`)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { Breadcrumb, Button, Empty, Form, Input, Modal, Space, Table, Typography } from 'antd'
|
import { Breadcrumb, Button, Empty, Form, Input, Modal, Popconfirm, Space, Table, Typography } from 'antd'
|
||||||
import type { ColumnsType } from 'antd/es/table'
|
import type { ColumnsType } from 'antd/es/table'
|
||||||
import { useSearchParams } from 'react-router-dom'
|
import { useSearchParams } from 'react-router-dom'
|
||||||
import { createArea, fetchArea, fetchAreas, updateArea } from '@/api/areas'
|
import { createArea, deleteArea, fetchArea, fetchAreas, updateArea } from '@/api/areas'
|
||||||
import { notifyApiError, notifySuccess } from '@/api/errors'
|
import { notifyApiError, notifySuccess } from '@/api/errors'
|
||||||
import type { Area } from '@/api/types'
|
import type { Area } from '@/api/types'
|
||||||
import { AreaTreeSelect } from '@/components/AreaTreeSelect'
|
import { AreaTreeSelect } from '@/components/AreaTreeSelect'
|
||||||
@@ -99,6 +99,15 @@ export function AreaListPage() {
|
|||||||
onError: (e) => notifyApiError(e, 'Не удалось обновить зону'),
|
onError: (e) => notifyApiError(e, 'Не удалось обновить зону'),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const deleteMutation = useMutation({
|
||||||
|
mutationFn: (area: Area) => deleteArea(area.id),
|
||||||
|
onSuccess: (_void, area) => {
|
||||||
|
notifySuccess('Зона удалена', area.name)
|
||||||
|
invalidate()
|
||||||
|
},
|
||||||
|
onError: (e) => notifyApiError(e, 'Не удалось удалить зону'),
|
||||||
|
})
|
||||||
|
|
||||||
const setParent = (value: string | null) => {
|
const setParent = (value: string | null) => {
|
||||||
setParentId(value)
|
setParentId(value)
|
||||||
setPage(0)
|
setPage(0)
|
||||||
@@ -124,15 +133,30 @@ export function AreaListPage() {
|
|||||||
{
|
{
|
||||||
title: 'Действия',
|
title: 'Действия',
|
||||||
key: 'actions',
|
key: 'actions',
|
||||||
width: 200,
|
width: 280,
|
||||||
render: (_, area) => (
|
render: (_, area) => (
|
||||||
<Space>
|
<Space size={4} wrap>
|
||||||
<Button size="small" onClick={() => setParent(area.id)}>
|
<Button size="small" onClick={() => setParent(area.id)}>
|
||||||
Внутрь
|
Внутрь
|
||||||
</Button>
|
</Button>
|
||||||
<Button size="small" onClick={() => setEditing(area)}>
|
<Button size="small" onClick={() => setEditing(area)}>
|
||||||
Изменить
|
Изменить
|
||||||
</Button>
|
</Button>
|
||||||
|
<Popconfirm
|
||||||
|
title="Удалить зону?"
|
||||||
|
description="Будут безвозвратно удалены все вложенные зоны, их достопримечательности (включая эталонные фото и медиа), наборы и посещения пользователей."
|
||||||
|
okText="Удалить"
|
||||||
|
okButtonProps={{ danger: true }}
|
||||||
|
onConfirm={() => deleteMutation.mutate(area)}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
danger
|
||||||
|
loading={deleteMutation.isPending && deleteMutation.variables?.id === area.id}
|
||||||
|
>
|
||||||
|
Удалить
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user