diff --git a/src/app/[locale]/pages/content/page.tsx b/src/app/[locale]/pages/content/page.tsx
index 856bd87..a9233bf 100644
--- a/src/app/[locale]/pages/content/page.tsx
+++ b/src/app/[locale]/pages/content/page.tsx
@@ -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 (
Управление контентом
-
-
-
-
-
-
+ {getPermissionLevel('content_moderation') > 0 && (
+ <>
+
+
+
+
+
+
+ >
+ )}
)
}
\ No newline at end of file
diff --git a/src/app/actions/contentActions.ts b/src/app/actions/contentActions.ts
index 592bc34..e3a99a7 100644
--- a/src/app/actions/contentActions.ts
+++ b/src/app/actions/contentActions.ts
@@ -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';
}
@@ -140,6 +147,47 @@ export async function fetchAppealsContentList(page?: number, size?: number, sort
return null;
}
+ } else {
+ throw new Error(`${response.status}`);
+ }
+ } catch (error) {
+ 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}`);
}
diff --git a/src/app/hooks/react-query/useContentForAppeals.ts b/src/app/hooks/react-query/useContentForAppeals.ts
index 3711766..0d36726 100644
--- a/src/app/hooks/react-query/useContentForAppeals.ts
+++ b/src/app/hooks/react-query/useContentForAppeals.ts
@@ -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 {
diff --git a/src/app/ui/content/AppealModerationModal.tsx b/src/app/ui/content/AppealModerationModal.tsx
index 6be4e07..f781e90 100644
--- a/src/app/ui/content/AppealModerationModal.tsx
+++ b/src/app/ui/content/AppealModerationModal.tsx
@@ -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(file?.status || 'MODERATION');
+ const [selectedStatus, setSelectedStatus] = useState(getLabel(file?.status || 'MODERATION'));
const [adminComment, setAdminComment] = useState(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
{/* Информация о файле */}
- {/* @ts-ignore */}
{file?.fileName ? file?.fileName : '---'}
- {/* @ts-ignore */}
+ {/* @ts-ignore сейчас нету айди юзера возможно нужно будет удалить или добавить*/}
{file?.userId ? file?.userId : '---'}
@@ -151,8 +165,8 @@ export default function AppealModerationModal({ file, onClose }: AppealModeratio
value={getLabel(selectedStatus)}
callBack={(value: string) => setSelectedStatus(value)}
>
- На модерации
- Заблокировано
+ {/* На модерации */}
+ Заблокировано
Одобрено
@@ -162,17 +176,16 @@ export default function AppealModerationModal({ file, onClose }: AppealModeratio
diff --git a/src/app/ui/content/content-appeals-table.tsx b/src/app/ui/content/content-appeals-table.tsx
index 6ec44b0..0ce2983 100644
--- a/src/app/ui/content/content-appeals-table.tsx
+++ b/src/app/ui/content/content-appeals-table.tsx
@@ -54,7 +54,7 @@ const cutFileName = (fileName: string) => {
const StatusBadge = ({ status }: { status: string }) => {
const statusConfig: Record = {
- '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[]>(() => {
const allColumns: ColumnDef[] = [
{
- accessorKey: 'fileId',
+ accessorKey: 'fileName',
header: ({ column }) => (
- fileId
+ fileName