add appeals change status
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user