si table connected to backend
This commit is contained in:
@@ -9,7 +9,7 @@ import { getRouteLang } from './getLanguage';
|
|||||||
// ─── Constants ─────────────────────────────────────────────────────────────────
|
// ─── Constants ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
// const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
|
// const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
|
||||||
const baseUrl = 'https://api.anti-plagiat.uz/api/v1';
|
const baseUrl = 'https://dev-api.anti-plagiat.uz/api/v1';
|
||||||
const DEFAULT_LOCALE = 'uz'; // fallback locale for redirect
|
const DEFAULT_LOCALE = 'uz'; // fallback locale for redirect
|
||||||
|
|
||||||
// ─── Token helpers ─────────────────────────────────────────────────────────────
|
// ─── Token helpers ─────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -7,4 +7,8 @@ export const links = {
|
|||||||
payment: (order_id: number) => `/users/payme/link/${order_id}/`,
|
payment: (order_id: number) => `/users/payme/link/${order_id}/`,
|
||||||
sertifikat: (document_id: number) =>
|
sertifikat: (document_id: number) =>
|
||||||
`/shared/certificate/${document_id}/pdf/`,
|
`/shared/certificate/${document_id}/pdf/`,
|
||||||
|
si: '/shared/ai_document/list/',
|
||||||
|
si_id: (si_id: number) => `/shared/ai_document/list/${si_id}/`,
|
||||||
|
si_payment: (document_id: number) => `/shared/ai_document/pay/${document_id}`,
|
||||||
|
si_create: '/shared/ai_document/create/',
|
||||||
};
|
};
|
||||||
|
|||||||
20
src/widgets/cabinet/lib/hooks/useSiHistory.ts
Normal file
20
src/widgets/cabinet/lib/hooks/useSiHistory.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
'use client';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { apiRequest } from '@/shared/request/apiRequest';
|
||||||
|
import { links } from '@/shared/request/links';
|
||||||
|
import type { SiDocument } from '../types';
|
||||||
|
|
||||||
|
export const useSiHistory = () => {
|
||||||
|
const { data, isLoading, isError, refetch } = useQuery({
|
||||||
|
queryKey: ['si-history'],
|
||||||
|
queryFn: () => apiRequest<SiDocument[]>('GET', links.si),
|
||||||
|
select: (res) => res.data,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
items: data ?? [],
|
||||||
|
isLoading,
|
||||||
|
isError,
|
||||||
|
refetch,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -45,6 +45,21 @@ export interface Payment {
|
|||||||
status: 'paid' | 'pending' | 'failed';
|
status: 'paid' | 'pending' | 'failed';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── SI Document (API) ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface SiDocument {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
file: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
result: null | unknown;
|
||||||
|
state: 'paid' | 'unpaid';
|
||||||
|
ai_order_id: string;
|
||||||
|
total_words: number;
|
||||||
|
si_percantage: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface CabinetStats {
|
export interface CabinetStats {
|
||||||
total: number;
|
total: number;
|
||||||
thisMonth: number;
|
thisMonth: number;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Sidebar } from './Sidebar';
|
|||||||
import { CabinetNav } from './CabinetNav';
|
import { CabinetNav } from './CabinetNav';
|
||||||
import { Dashboard } from './dashboard';
|
import { Dashboard } from './dashboard';
|
||||||
import { useCabinet } from '../lib/hooks/useCabinet';
|
import { useCabinet } from '../lib/hooks/useCabinet';
|
||||||
import { MOCK_USER, MOCK_STATS, MOCK_SI, MOCK_PAYMENTS } from '../lib/mock';
|
import { MOCK_USER, MOCK_STATS, MOCK_PAYMENTS } from '../lib/mock';
|
||||||
import type { CabinetSection } from '../lib/types';
|
import type { CabinetSection } from '../lib/types';
|
||||||
|
|
||||||
// ─── Lazy sections (separate JS chunks) ───────────────────────────────────────
|
// ─── Lazy sections (separate JS chunks) ───────────────────────────────────────
|
||||||
@@ -49,7 +49,7 @@ function SectionContent({ section }: { section: CabinetSection }) {
|
|||||||
case 'plagiat':
|
case 'plagiat':
|
||||||
return <PlagiatTable />;
|
return <PlagiatTable />;
|
||||||
case 'si':
|
case 'si':
|
||||||
return <SiTable data={MOCK_SI} />;
|
return <SiTable />;
|
||||||
case 'payments':
|
case 'payments':
|
||||||
return <PaymentsTable data={MOCK_PAYMENTS} />;
|
return <PaymentsTable data={MOCK_PAYMENTS} />;
|
||||||
case 'profile':
|
case 'profile':
|
||||||
|
|||||||
@@ -1,22 +1,37 @@
|
|||||||
|
'use client';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FileText, Clock, CheckCircle, XCircle } from 'lucide-react';
|
import { Download, CreditCard } from 'lucide-react';
|
||||||
import type { SiCheck } from '../../lib/types';
|
import { useMutation } from '@tanstack/react-query';
|
||||||
|
import { useSiHistory } from '../../lib/hooks/useSiHistory';
|
||||||
|
import { formatDate } from '@/widgets/history/lib/utils';
|
||||||
|
import { apiRequest } from '@/shared/request/apiRequest';
|
||||||
|
import { links } from '@/shared/request/links';
|
||||||
|
import { toast } from 'react-toastify';
|
||||||
|
import type { SiDocument } from '../../lib/types';
|
||||||
|
|
||||||
// ─── Helpers ───────────────────────────────────────────────────────────────────
|
// ─── State badge ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const STATUS_MAP = {
|
const StateBadge: React.FC<{ state: 'paid' | 'unpaid' }> = ({ state }) => {
|
||||||
completed: {
|
const isPaid = state === 'paid';
|
||||||
label: 'Yakunlandi',
|
return (
|
||||||
icon: CheckCircle,
|
<span
|
||||||
cls: 'text-emerald-600 bg-emerald-50',
|
className={[
|
||||||
},
|
'inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-semibold whitespace-nowrap select-none',
|
||||||
pending: {
|
isPaid ? 'bg-emerald-50 text-emerald-700' : 'bg-rose-50 text-rose-600',
|
||||||
label: 'Kutilmoqda',
|
].join(' ')}
|
||||||
icon: Clock,
|
>
|
||||||
cls: 'text-amber-600 bg-amber-50',
|
<span
|
||||||
},
|
className={[
|
||||||
failed: { label: 'Xato', icon: XCircle, cls: 'text-red-600 bg-red-50' },
|
'w-1.5 h-1.5 rounded-full shrink-0',
|
||||||
} as const;
|
isPaid ? 'bg-emerald-500' : 'bg-rose-500',
|
||||||
|
].join(' ')}
|
||||||
|
/>
|
||||||
|
{isPaid ? "To'langan" : "To'lanmagan"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ─── SI% badge ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const SiPercentBadge: React.FC<{ value: number }> = ({ value }) => {
|
const SiPercentBadge: React.FC<{ value: number }> = ({ value }) => {
|
||||||
const cls =
|
const cls =
|
||||||
@@ -34,95 +49,187 @@ const SiPercentBadge: React.FC<{ value: number }> = ({ value }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// ─── Component ─────────────────────────────────────────────────────────────────
|
// ─── Skeleton ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
interface SiTableProps {
|
const SkeletonRow = () => (
|
||||||
data: SiCheck[];
|
<tr>
|
||||||
}
|
{Array.from({ length: 7 }).map((_, i) => (
|
||||||
|
<td key={i} className="px-5 py-3.5">
|
||||||
|
<div
|
||||||
|
className="h-4 bg-slate-100 rounded animate-pulse"
|
||||||
|
style={{ width: i === 1 ? 120 : 60 }}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
|
||||||
export const SiTable: React.FC<SiTableProps> = ({ data }) => (
|
// ─── Empty / Error states ──────────────────────────────────────────────────────
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<h2 className="text-xl font-bold text-slate-900">SI detektor</h2>
|
|
||||||
<p className="text-sm text-slate-500 mt-0.5">
|
|
||||||
{data.length} ta tekshiruv
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="bg-white rounded-2xl border border-slate-100 shadow-sm overflow-hidden">
|
const EmptyState = () => (
|
||||||
<div className="overflow-x-auto">
|
<tr>
|
||||||
<table className="w-full text-sm">
|
<td colSpan={7} className="px-5 py-12 text-center text-slate-400 text-sm">
|
||||||
<thead>
|
Hozircha SI tekshiruvlar yo'q
|
||||||
<tr className="bg-slate-50 border-b border-slate-100">
|
</td>
|
||||||
{['#', 'Fayl', "So'z", 'SI%', 'Sana', 'Holat', 'Hisobot'].map(
|
</tr>
|
||||||
(h) => (
|
);
|
||||||
|
|
||||||
|
const ErrorState = () => (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={7} className="px-5 py-12 text-center text-red-400 text-sm">
|
||||||
|
Ma'lumotlarni yuklashda xatolik yuz berdi
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
|
||||||
|
// ─── Row ───────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const SiRow: React.FC<{ item: SiDocument; index: number }> = ({
|
||||||
|
item,
|
||||||
|
index,
|
||||||
|
}) => {
|
||||||
|
const pay = useMutation({
|
||||||
|
mutationKey: ['si-payment', item.id],
|
||||||
|
mutationFn: () =>
|
||||||
|
apiRequest<{ payment_link: string }>('POST', links.si_payment(item.id)),
|
||||||
|
onSuccess: (res) => {
|
||||||
|
window.open(res.data.payment_link, '_self');
|
||||||
|
},
|
||||||
|
onError: (err) => {
|
||||||
|
toast.error(err instanceof Error ? err.message : 'Xatolik yuz berdi');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tr className="hover:bg-slate-50/60 transition-colors">
|
||||||
|
{/* # */}
|
||||||
|
<td className="px-5 py-3.5 text-slate-400 font-mono text-xs">
|
||||||
|
{String(index).padStart(2, '0')}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Sarlavha */}
|
||||||
|
<td className="px-5 py-3.5">
|
||||||
|
<span className="text-slate-800 font-medium max-w-45 truncate block text-sm">
|
||||||
|
{item.title || '—'}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Fayl */}
|
||||||
|
<td className="px-5 py-3.5">
|
||||||
|
{item.file ? (
|
||||||
|
<a
|
||||||
|
href={item.file}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="inline-flex items-center gap-1.5 text-slate-500 hover:text-blue-600 transition-colors"
|
||||||
|
>
|
||||||
|
<Download size={14} />
|
||||||
|
<span className="text-xs font-medium">Fayl</span>
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<span className="text-slate-200 text-xs">—</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* So'z */}
|
||||||
|
<td className="px-5 py-3.5 text-slate-500 tabular-nums text-sm">
|
||||||
|
{item.total_words > 0 ? item.total_words.toLocaleString() : '—'}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* SI% */}
|
||||||
|
<td className="px-5 py-3.5">
|
||||||
|
{item.si_percantage != null && item.result != null ? (
|
||||||
|
<SiPercentBadge value={item.si_percantage} />
|
||||||
|
) : (
|
||||||
|
<span className="text-slate-300 text-xs">—</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Sana */}
|
||||||
|
<td className="px-5 py-3.5 text-slate-500 text-sm whitespace-nowrap">
|
||||||
|
{formatDate(item.created_at)}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Holat */}
|
||||||
|
<td className="px-5 py-3.5">
|
||||||
|
<StateBadge state={item.state} />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
{/* Amal */}
|
||||||
|
<td className="px-5 py-3.5 text-right">
|
||||||
|
{item.state === 'unpaid' ? (
|
||||||
|
<button
|
||||||
|
onClick={() => pay.mutate()}
|
||||||
|
disabled={pay.isPending}
|
||||||
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-violet-600 hover:bg-violet-700 active:scale-95 transition-all duration-150 disabled:opacity-60"
|
||||||
|
>
|
||||||
|
<CreditCard size={11} />
|
||||||
|
{pay.isPending ? '...' : "To'lash"}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<span className="text-slate-300 text-xs">—</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ─── SiTable ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const SiTable: React.FC = () => {
|
||||||
|
const { items, isLoading, isError } = useSiHistory();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex items-center">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-xl font-bold text-slate-900">SI detektor</h2>
|
||||||
|
<p className="text-sm text-slate-500 mt-0.5">
|
||||||
|
{isLoading ? '...' : `${items.length} ta tekshiruv`}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-white rounded-2xl border border-slate-100 shadow-sm overflow-hidden">
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="w-full text-sm">
|
||||||
|
<thead>
|
||||||
|
<tr className="bg-slate-50 border-b border-slate-100">
|
||||||
|
{[
|
||||||
|
'#',
|
||||||
|
'Sarlavha',
|
||||||
|
'Fayl',
|
||||||
|
"So'z",
|
||||||
|
'SI%',
|
||||||
|
'Sana',
|
||||||
|
'Holat',
|
||||||
|
'Amal',
|
||||||
|
].map((h) => (
|
||||||
<th
|
<th
|
||||||
key={h}
|
key={h}
|
||||||
className="text-left px-5 py-3 text-[11px] font-semibold text-slate-400 uppercase tracking-wider whitespace-nowrap last:text-center"
|
className="text-left px-5 py-3 text-[11px] font-semibold text-slate-400 uppercase tracking-wider whitespace-nowrap last:text-right"
|
||||||
>
|
>
|
||||||
{h}
|
{h}
|
||||||
</th>
|
</th>
|
||||||
),
|
))}
|
||||||
)}
|
</tr>
|
||||||
</tr>
|
</thead>
|
||||||
</thead>
|
<tbody className="divide-y divide-slate-50">
|
||||||
<tbody className="divide-y divide-slate-50">
|
{isLoading &&
|
||||||
{data.map((row) => {
|
Array.from({ length: 5 }).map((_, i) => (
|
||||||
const s = STATUS_MAP[row.status];
|
<SkeletonRow key={i} />
|
||||||
const Icon = s.icon;
|
))}
|
||||||
return (
|
{isError && <ErrorState />}
|
||||||
<tr
|
{!isLoading && !isError && items.length === 0 && <EmptyState />}
|
||||||
key={row.id}
|
{!isLoading &&
|
||||||
className="hover:bg-slate-50/60 transition-colors"
|
!isError &&
|
||||||
>
|
items.map((item, i) => (
|
||||||
<td className="px-5 py-3.5 text-slate-400 font-mono text-xs">
|
<SiRow key={item.id} item={item} index={i + 1} />
|
||||||
{String(row.id).padStart(2, '0')}
|
))}
|
||||||
</td>
|
</tbody>
|
||||||
<td className="px-5 py-3.5">
|
</table>
|
||||||
<span className="text-slate-800 font-medium max-w-[150px] truncate block">
|
</div>
|
||||||
{row.file}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td className="px-5 py-3.5 text-slate-500 tabular-nums">
|
|
||||||
{row.words.toLocaleString()}
|
|
||||||
</td>
|
|
||||||
<td className="px-5 py-3.5">
|
|
||||||
{row.status === 'pending' ? (
|
|
||||||
<span className="text-slate-300 text-xs">—</span>
|
|
||||||
) : (
|
|
||||||
<SiPercentBadge value={row.siPercent} />
|
|
||||||
)}
|
|
||||||
</td>
|
|
||||||
<td className="px-5 py-3.5 text-slate-500 whitespace-nowrap">
|
|
||||||
{row.date}
|
|
||||||
</td>
|
|
||||||
<td className="px-5 py-3.5">
|
|
||||||
<span
|
|
||||||
className={`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium ${s.cls}`}
|
|
||||||
>
|
|
||||||
<Icon size={12} />
|
|
||||||
{s.label}
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td className="px-5 py-3.5 text-center">
|
|
||||||
{row.reportUrl ? (
|
|
||||||
<a
|
|
||||||
href={row.reportUrl}
|
|
||||||
className="inline-flex items-center justify-center w-8 h-8 rounded-lg text-slate-400 hover:text-violet-600 hover:bg-violet-50 transition-colors"
|
|
||||||
aria-label="Hisobot"
|
|
||||||
>
|
|
||||||
<FileText size={15} />
|
|
||||||
</a>
|
|
||||||
) : (
|
|
||||||
<span className="text-slate-200 text-xs">—</span>
|
|
||||||
)}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
);
|
};
|
||||||
|
|||||||
@@ -4,18 +4,35 @@ import { useTranslations } from 'next-intl';
|
|||||||
import { useHistory } from '../lib/useHistory';
|
import { useHistory } from '../lib/useHistory';
|
||||||
import { HistoryTable } from './historyTable';
|
import { HistoryTable } from './historyTable';
|
||||||
import { Pagination } from './pagination';
|
import { Pagination } from './pagination';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { Plus } from 'lucide-react';
|
||||||
|
import { usePathname } from '@/shared/config/i18n/navigation';
|
||||||
|
|
||||||
// ─── Page Header ───────────────────────────────────────────────────────────────
|
// ─── Page Header ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const PageHeader: React.FC = () => {
|
const PageHeader: React.FC = () => {
|
||||||
const t = useTranslations('HistoryPage');
|
const t = useTranslations('HistoryPage');
|
||||||
|
const pathname = usePathname();
|
||||||
return (
|
return (
|
||||||
<div className="mb-6">
|
<div className="flex items-center gap-2 justify-between">
|
||||||
<h1 className="text-2xl font-semibold text-slate-900 tracking-tight">
|
<div className="mb-6">
|
||||||
{t('title')}
|
<h1 className="text-2xl font-semibold text-slate-900 tracking-tight">
|
||||||
</h1>
|
{t('title')}
|
||||||
<p className="mt-1 text-sm text-slate-500">{t('description')}</p>
|
</h1>
|
||||||
|
<p className="mt-1 text-sm text-slate-500">{t('description')}</p>
|
||||||
|
</div>
|
||||||
|
<Link
|
||||||
|
href={'/plagat'}
|
||||||
|
className={`${pathname === '/cabinet' ? 'flex' : 'hidden'}
|
||||||
|
items-center gap-2 px-2 py-1 group relative overflow-hidden rounded-sm bg-linear-to-br
|
||||||
|
from-blue-500 to-blue-600 text-left shadow-md hover:shadow-xl transition-all duration-200
|
||||||
|
hover:-translate-y-0.5 active:translate-y-0 active:shadow-md`}
|
||||||
|
>
|
||||||
|
<Plus size={15} className="text-white" />
|
||||||
|
<h3 className="text-white font-semibold text-base">
|
||||||
|
Plagiat tekshiruvi
|
||||||
|
</h3>
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user