diff --git a/client/src/pages/admin-info/index.ts b/client/src/pages/admin-info/index.ts deleted file mode 100644 index aeb45fa..0000000 --- a/client/src/pages/admin-info/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { AdminInfoPage } from './ui/AdminInfoPage' diff --git a/client/src/pages/admin-info/ui/AdminInfoPage.tsx b/client/src/pages/admin-info/ui/AdminInfoPage.tsx deleted file mode 100644 index 2c537e3..0000000 --- a/client/src/pages/admin-info/ui/AdminInfoPage.tsx +++ /dev/null @@ -1,216 +0,0 @@ -import Alert from '@mui/material/Alert' -import Box from '@mui/material/Box' -import Button from '@mui/material/Button' -import Dialog from '@mui/material/Dialog' -import DialogActions from '@mui/material/DialogActions' -import DialogContent from '@mui/material/DialogContent' -import DialogTitle from '@mui/material/DialogTitle' -import FormControlLabel from '@mui/material/FormControlLabel' -import Stack from '@mui/material/Stack' -import Switch from '@mui/material/Switch' -import Table from '@mui/material/Table' -import TableBody from '@mui/material/TableBody' -import TableCell from '@mui/material/TableCell' -import TableHead from '@mui/material/TableHead' -import TableRow from '@mui/material/TableRow' -import TextField from '@mui/material/TextField' -import Typography from '@mui/material/Typography' -import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' -import { Controller, useForm } from 'react-hook-form' -import { - createInfoBlock, - deleteInfoBlock, - fetchAdminInfoBlocks, - type InfoPageBlock, - updateInfoBlock, -} from '@/entities/info' -import { getErrorMessage } from '@/shared/lib/get-error-message' -import { invalidateQueryKeys } from '@/shared/lib/invalidate-query-keys' -import { useEditDialogState } from '@/shared/lib/use-edit-dialog-state' -import { EntityRowActions } from '@/shared/ui/EntityRowActions' - -type FormState = { - key: string - title: string - body: string - sort: string - published: boolean -} - -const emptyForm = (): FormState => ({ key: '', title: '', body: '', sort: '0', published: true }) - -export function AdminInfoPage() { - const qc = useQueryClient() - const { dialogOpen, editing, openCreateDialog, openEditDialog, closeDialog } = useEditDialogState() - const form = useForm({ defaultValues: emptyForm(), mode: 'onChange' }) - - const blocksQuery = useQuery({ - queryKey: ['admin', 'info-page', 'blocks'], - queryFn: fetchAdminInfoBlocks, - }) - - const saveMut = useMutation({ - mutationFn: async () => { - const values = form.getValues() - const payload = { - key: values.key.trim(), - title: values.title.trim(), - body: values.body.trim(), - sort: Number(values.sort || 0), - published: values.published, - } - if (editing) return updateInfoBlock(editing.id, payload) - return createInfoBlock(payload) - }, - onSuccess: async () => { - closeDialog() - form.reset(emptyForm()) - await invalidateQueryKeys(qc, [ - ['admin', 'info-page', 'blocks'], - ['info-page', 'public', 'blocks'], - ]) - }, - }) - - const deleteMut = useMutation({ - mutationFn: (id: string) => deleteInfoBlock(id), - onSuccess: async () => { - await invalidateQueryKeys(qc, [ - ['admin', 'info-page', 'blocks'], - ['info-page', 'public', 'blocks'], - ]) - }, - }) - - const openCreate = () => { - form.reset(emptyForm()) - openCreateDialog() - } - - const openEdit = (item: InfoPageBlock) => { - openEditDialog(item) - form.reset({ - key: item.key, - title: item.title, - body: item.body, - sort: String(item.sort), - published: item.published, - }) - } - - const items = blocksQuery.data?.items ?? [] - const err = saveMut.error ?? deleteMut.error - - return ( - - - Информационная страница - - - - - Управление блоками страницы с процессом покупки, оплаты и доставки. - - - {blocksQuery.isError && Не удалось загрузить блоки.} - {err && ( - - {getErrorMessage(err)} - - )} - - - - - Key - Заголовок - Порядок - Опубликован - Действия - - - - {items.map((item) => ( - - {item.key} - {item.title} - {item.sort} - {item.published ? 'Да' : 'Нет'} - - openEdit(item)} - onDelete={() => deleteMut.mutate(item.id)} - deleteDisabled={deleteMut.isPending} - /> - - - ))} - {items.length === 0 && !blocksQuery.isLoading && ( - - - Блоков пока нет. - - - )} - -
- - - {editing ? 'Редактировать блок' : 'Новый блок'} - - - } - /> - } - /> - ( - - )} - /> - } - /> - ( - field.onChange(v)} />} - label="Показывать на публичной странице" - /> - )} - /> - - - - - - - -
- ) -}