add appeals change status

This commit is contained in:
smanylov
2026-05-27 18:59:37 +07:00
parent c626b697e2
commit 05e04886c3
5 changed files with 108 additions and 34 deletions
+17 -6
View File
@@ -1,18 +1,29 @@
'use client'
import ContentModerationTable from '@/app/ui/content/content-moderation-table';
import ContentAppealsTable from '@/app/ui/content/content-appeals-table';
import { useEmployeInfo } from '@/app/hooks/react-query/useEmployeInfo';
export default function Page() {
const { getPermissionLevel } = useEmployeInfo();
const contentModerationPermissionLevel = getPermissionLevel('content_moderation');
return (
<div className="admin-content">
<div className="content-header">
<h3>Управление контентом</h3>
</div>
<div className="content-body">
<ContentModerationTable permission={3} />
</div>
<div className="content-body">
<ContentAppealsTable permission={3} />
</div>
{getPermissionLevel('content_moderation') > 0 && (
<>
<div className="content-body">
<ContentModerationTable permission={contentModerationPermissionLevel} />
</div>
<div className="content-body">
<ContentAppealsTable permission={contentModerationPermissionLevel} />
</div>
</>
)}
</div>
)
}
+48
View File
@@ -86,13 +86,20 @@ export async function changeModerationContentStatus(fileId?: string, fileStatus?
export async function downloadFile(fileId: string, fileName: string) {
const token = await getSessionData('token');
console.log('downloadFile');
/* ${API_DASHBOARD_URL} */
/* ${API_BASE_URL} */
const response = await fetch(`${API_DASHBOARD_URL}/api/v1/files/download/${fileId}`, {
headers: {
'Authorization': `Bearer ${token}`,
},
})
/* console.log(response); */
const text = await response.text();
console.log(text);
if (!response.ok) {
throw 'failed-to-download-file';
}
@@ -147,3 +154,44 @@ export async function fetchAppealsContentList(page?: number, size?: number, sort
return null;
}
}
export async function changeAppealContentStatus(appealId?: string, approve?: boolean, comment?: string) {
const token = await getSessionData('token');
try {
const response = await fetch(`${API_BASE_URL}/api/admin/control`, {
method: 'POST',
body: JSON.stringify({
version: 1,
msg_id: 40002,
message_body: {
action: 'review_appeal',
appeal_id: appealId,
approve: approve,
comment: comment
}
}),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
}
});
if (response.ok) {
const parsed = await response.json();
console.log(parsed);
if (parsed.message_code === 0) {
return parsed.message_body.message_body;
} else {
return null;
}
} else {
throw new Error(`${response.status}`);
}
} catch (error) {
return null;
}
}
@@ -9,7 +9,8 @@ export interface AppealsFile {
createdAt: string;
fileId: string;
resolvedAt: string;
status: 'BLOCKED' | 'APPROVED' | string;
fileName: string;
status: 'REJECTED' | 'APPROVED' | string;
}
export interface ContentForAppeals {
+33 -20
View File
@@ -4,8 +4,8 @@ import { useState } from 'react';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { toast } from 'sonner';
import DropDownList from '@/app/components/dropDownList';
/* import { changeAppealStatus } from '@/app/actions/contentActions'; */
import { AppealsFile } from '@/app/hooks/react-query/useContentForAppeals';
import { changeAppealContentStatus } from '@/app/actions/contentActions';
interface AppealModerationModalProps {
file: AppealsFile | null;
@@ -14,7 +14,7 @@ interface AppealModerationModalProps {
const getLabel = (status: string) => {
switch (status) {
case 'BLOCKED':
case 'REJECTED':
return 'Заблокировано';
case 'MODERATION':
return 'На модерации';
@@ -25,10 +25,23 @@ const getLabel = (status: string) => {
}
};
const getStatusValue = (label: string) => {
switch (label) {
case 'REJECTED':
return 'REJECTED';
case 'MODERATION':
return 'MODERATION';
case 'APPROVED':
return 'APPROVED';
default:
return 'MODERATION';
}
};
const StatusBadge = ({ status }: { status: string }) => {
const getBadgeClass = () => {
switch (status) {
case 'BLOCKED':
case 'REJECTED':
return 'status-badge--blocked';
case 'MODERATION':
return 'status-badge--moderation';
@@ -46,16 +59,16 @@ const StatusBadge = ({ status }: { status: string }) => {
};
export default function AppealModerationModal({ file, onClose }: AppealModerationModalProps) {
const [selectedStatus, setSelectedStatus] = useState<string>(file?.status || 'MODERATION');
const [selectedStatus, setSelectedStatus] = useState<string>(getLabel(file?.status || 'MODERATION'));
const [adminComment, setAdminComment] = useState<string>(file?.adminComment || '');
const queryClient = useQueryClient();
/* const changeStatusMutation = useMutation({
mutationFn: async ({ appealId, status, comment }: { appealId: string; status: string; comment: string }) => {
return await changeAppealStatus(appealId, status, comment);
const changeStatusMutation = useMutation({
mutationFn: async ({ appealId, approve, comment }: { appealId: string; approve: boolean; comment: string }) => {
return await changeAppealContentStatus(appealId, approve, comment);
},
onSuccess: (data) => {
if (data) {
if (data !== null && data !== undefined) {
toast.success('Статус апелляции успешно изменен');
queryClient.invalidateQueries({ queryKey: ['contentForAppeals'] });
onClose();
@@ -66,19 +79,21 @@ export default function AppealModerationModal({ file, onClose }: AppealModeratio
onError: () => {
toast.error('Произошла ошибка при изменении статуса');
},
}); */
});
const handleStatusChange = () => {
if (!file?.appealId) {
toast.error('ID апелляции не найден');
return;
}
const statusValue = getStatusValue(selectedStatus);
const approve = statusValue === 'APPROVED';
/* changeStatusMutation.mutate({
changeStatusMutation.mutate({
appealId: file.appealId,
status: selectedStatus,
approve: approve,
comment: adminComment,
}); */
});
};
if (!file) return null;
@@ -91,13 +106,12 @@ export default function AppealModerationModal({ file, onClose }: AppealModeratio
{/* Информация о файле */}
<div className="file-moderation-modal__info-section">
<label className="file-moderation-modal__label">Название файла</label>
{/* @ts-ignore */}
<p className="file-moderation-modal__value">{file?.fileName ? file?.fileName : '---'}</p>
</div>
<div className="file-moderation-modal__info-section">
<label className="file-moderation-modal__label">User ID</label>
{/* @ts-ignore */}
{/* @ts-ignore сейчас нету айди юзера возможно нужно будет удалить или добавить*/}
<p className="file-moderation-modal__value">{file?.userId ? file?.userId : '---'}</p>
</div>
@@ -151,8 +165,8 @@ export default function AppealModerationModal({ file, onClose }: AppealModeratio
value={getLabel(selectedStatus)}
callBack={(value: string) => setSelectedStatus(value)}
>
<li value="MODERATION">На модерации</li>
<li value="BLOCKED">Заблокировано</li>
{/* <li value="MODERATION">На модерации</li> */}
<li value="REJECTED">Заблокировано</li>
<li value="APPROVED">Одобрено</li>
</DropDownList>
</div>
@@ -162,17 +176,16 @@ export default function AppealModerationModal({ file, onClose }: AppealModeratio
<button
onClick={onClose}
className="btn btn-secondary"
/* disabled={changeStatusMutation.isPending} */
disabled={changeStatusMutation.isPending}
>
Отмена
</button>
<button
onClick={handleStatusChange}
className="btn btn-primary"
/* disabled={changeStatusMutation.isPending || selectedStatus === file.status} */
disabled={changeStatusMutation.isPending || selectedStatus === getLabel(file.status)}
>
{/* {changeStatusMutation.isPending ? 'Сохранение...' : 'Сохранить'} */}
Сохранить
{changeStatusMutation.isPending ? 'Сохранение...' : 'Сохранить'}
</button>
</div>
</div>
+8 -7
View File
@@ -54,7 +54,7 @@ const cutFileName = (fileName: string) => {
const StatusBadge = ({ status }: { status: string }) => {
const statusConfig: Record<string, { className: string; label: string }> = {
'BLOCKED': { className: 'bg-red-100 text-red-800', label: 'Заблокировано' },
'REJECTED': { className: 'bg-red-100 text-red-800', label: 'Заблокировано' },
'MODERATION': { className: 'bg-yellow-100 text-yellow-800', label: 'На модерации' },
'APPROVED': { className: 'bg-green-100 text-green-800', label: 'Одобрено' },
};
@@ -168,11 +168,11 @@ export default function ContentAppealsTable({ permission }: { permission: number
const columns = useMemo<ColumnDef<AppealsFile>[]>(() => {
const allColumns: ColumnDef<AppealsFile>[] = [
{
accessorKey: 'fileId',
accessorKey: 'fileName',
header: ({ column }) => (
<div className="column start">
<span>
fileId
fileName
</span>
<button
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
@@ -189,11 +189,12 @@ export default function ContentAppealsTable({ permission }: { permission: number
),
cell: ({ row }) => (
<div className="flex items-center space-x-2 table-item table-item-file-name">
<FileTypeIcon type={row.original.fileId} />
<FileTypeIcon type={row.original.fileName} />
<div>
<div className="font-medium w-full truncate" title={row.original.fileId}>
<div className="font-medium w-full truncate" title={row.original.fileName}>
<span className="font-semibold">
{cutFileName(row.original.fileId)}
{/* {cutFileName(row.original.fileName)} */}
{row.original.fileName}
</span>
</div>
</div>
@@ -419,7 +420,7 @@ export default function ContentAppealsTable({ permission }: { permission: number
<span className="pagination-info-pages">
{t('page')}{' '}
<strong>
{(appealsData?.currentPage ?? 0)} {t('out-of')} {appealsData?.totalPages ?? 1}
{(appealsData?.currentPage ?? 0) + 1} {t('out-of')} {appealsData?.totalPages ?? 1}
</strong>
</span>
<span className="pagination-info-files">