diff --git a/src/shared/config/i18n/messages/en.json b/src/shared/config/i18n/messages/en.json index 8cb22cf..ec716b8 100644 --- a/src/shared/config/i18n/messages/en.json +++ b/src/shared/config/i18n/messages/en.json @@ -208,5 +208,7 @@ "total": "Total", "connecting": "Connecting to Payme…", "payButton": "Pay with Payme" - } + }, + "unknownUser": "Username not found", + "file": "File" } diff --git a/src/shared/config/i18n/messages/ru.json b/src/shared/config/i18n/messages/ru.json index 4734401..459bbee 100644 --- a/src/shared/config/i18n/messages/ru.json +++ b/src/shared/config/i18n/messages/ru.json @@ -208,5 +208,7 @@ "total": "Итого", "connecting": "Подключение к Payme…", "payButton": "Оплатить через Payme" - } + }, + "unknownUser": "Имя пользователя не найдено", + "file":"Файл" } diff --git a/src/shared/config/i18n/messages/uz.d.json.ts b/src/shared/config/i18n/messages/uz.d.json.ts index a204e27..230b72e 100644 --- a/src/shared/config/i18n/messages/uz.d.json.ts +++ b/src/shared/config/i18n/messages/uz.d.json.ts @@ -212,5 +212,7 @@ declare const messages: { connecting: 'Paymega ulanmoqda…'; payButton: "Payme orqali to'lash"; }; + unknownUser: 'Foydalanuvchi topilmadi'; + file: 'Fayl'; }; export default messages; diff --git a/src/shared/config/i18n/messages/uz.json b/src/shared/config/i18n/messages/uz.json index 386f63d..9f30bfa 100644 --- a/src/shared/config/i18n/messages/uz.json +++ b/src/shared/config/i18n/messages/uz.json @@ -208,5 +208,7 @@ "total": "Jami", "connecting": "Paymega ulanmoqda…", "payButton": "Payme orqali to'lash" - } + }, + "unknownUser":"Foydalanuvchi topilmadi", + "file":"Fayl" } diff --git a/src/widgets/history/lib/constants.ts b/src/widgets/history/lib/constants.ts index 819e00f..1e4dc3f 100644 --- a/src/widgets/history/lib/constants.ts +++ b/src/widgets/history/lib/constants.ts @@ -6,7 +6,6 @@ export const TABLE_COLUMNS = [ { key: 'senderFullName', labelKey: 'sender' }, { key: 'fileName', labelKey: 'file' }, { key: 'date', labelKey: 'date' }, - { key: 'paymentAmount', labelKey: 'amount' }, { key: 'result', labelKey: 'result' }, { key: 'actions', labelKey: 'actions' }, ] as const; @@ -38,10 +37,3 @@ export const RESULT_CONFIG: Record< // ─── Pagination ──────────────────────────────────────────────────────────────── export const DEFAULT_PAGE_SIZE = 10; - -// ─── API ─────────────────────────────────────────────────────────────────────── - -export const API_ENDPOINTS = { - HISTORY: '/api/plagiarism/history', - DETAIL: (id: string) => `/api/plagiarism/${id}`, -} as const; diff --git a/src/widgets/history/lib/mock.ts b/src/widgets/history/lib/mock.ts index 359882e..373ee02 100644 --- a/src/widgets/history/lib/mock.ts +++ b/src/widgets/history/lib/mock.ts @@ -1,71 +1,69 @@ -import { PlagiarismCheck } from './types'; - /** * Default mock items used to preview the history table design. * Replace with real API data in production via useHistory() hook. */ -export const DEFAULT_HISTORY_ITEMS: PlagiarismCheck[] = [ - { - id: '1', - senderFullName: 'Alijon Toshmatov', - fileName: 'thesis-final-v3.pdf', - date: '2024-03-15T10:30:00Z', - paymentAmount: 45000, - currency: 'UZS', - result: 'clean', - }, - { - id: '2', - senderFullName: 'Malika Yusupova', - fileName: 'research-paper-2024.docx', - date: '2024-03-14T09:15:00Z', - paymentAmount: 60000, - currency: 'UZS', - result: 'plagiarism_found', - }, - { - id: '3', - senderFullName: 'Bobur Rahimov', - fileName: 'coursework-economics.pdf', - date: '2024-03-13T14:45:00Z', - paymentAmount: 45000, - currency: 'UZS', - result: 'pending', - }, - { - id: '4', - senderFullName: 'Zulfiya Nazarova', - fileName: 'dissertation-chapter1.pdf', - date: '2024-03-12T11:20:00Z', - paymentAmount: 60000, - currency: 'UZS', - result: 'clean', - }, - { - id: '5', - senderFullName: 'Jasur Mirzayev', - fileName: 'lab-report-chemistry.docx', - date: '2024-03-11T16:10:00Z', - paymentAmount: 45000, - currency: 'UZS', - result: 'failed', - }, - { - id: '6', - senderFullName: 'Nilufar Karimova', - fileName: 'bachelor-thesis-law.pdf', - date: '2024-03-10T08:55:00Z', - paymentAmount: 60000, - currency: 'UZS', - result: 'plagiarism_found', - }, - { - id: '7', - senderFullName: 'Dilnoza Ergasheva', - fileName: 'essay-history-uzbekistan.pdf', - date: '2024-03-09T13:40:00Z', - paymentAmount: 45000, - currency: 'UZS', - result: 'clean', - }, -]; +// export const DEFAULT_HISTORY_ITEMS: PlagiarismCheck[] = [ +// { +// id: '1', +// senderFullName: 'Alijon Toshmatov', +// fileName: 'thesis-final-v3.pdf', +// date: '2024-03-15T10:30:00Z', +// paymentAmount: 45000, +// currency: 'UZS', +// result: 'clean', +// }, +// { +// id: '2', +// senderFullName: 'Malika Yusupova', +// fileName: 'research-paper-2024.docx', +// date: '2024-03-14T09:15:00Z', +// paymentAmount: 60000, +// currency: 'UZS', +// result: 'plagiarism_found', +// }, +// { +// id: '3', +// senderFullName: 'Bobur Rahimov', +// fileName: 'coursework-economics.pdf', +// date: '2024-03-13T14:45:00Z', +// paymentAmount: 45000, +// currency: 'UZS', +// result: 'pending', +// }, +// { +// id: '4', +// senderFullName: 'Zulfiya Nazarova', +// fileName: 'dissertation-chapter1.pdf', +// date: '2024-03-12T11:20:00Z', +// paymentAmount: 60000, +// currency: 'UZS', +// result: 'clean', +// }, +// { +// id: '5', +// senderFullName: 'Jasur Mirzayev', +// fileName: 'lab-report-chemistry.docx', +// date: '2024-03-11T16:10:00Z', +// paymentAmount: 45000, +// currency: 'UZS', +// result: 'failed', +// }, +// { +// id: '6', +// senderFullName: 'Nilufar Karimova', +// fileName: 'bachelor-thesis-law.pdf', +// date: '2024-03-10T08:55:00Z', +// paymentAmount: 60000, +// currency: 'UZS', +// result: 'plagiarism_found', +// }, +// { +// id: '7', +// senderFullName: 'Dilnoza Ergasheva', +// fileName: 'essay-history-uzbekistan.pdf', +// date: '2024-03-09T13:40:00Z', +// paymentAmount: 45000, +// currency: 'UZS', +// result: 'clean', +// }, +// ]; diff --git a/src/widgets/history/lib/types.ts b/src/widgets/history/lib/types.ts index c852077..4f6be3a 100644 --- a/src/widgets/history/lib/types.ts +++ b/src/widgets/history/lib/types.ts @@ -2,17 +2,18 @@ export type CheckResult = 'clean' | 'plagiarism_found' | 'pending' | 'failed'; -export interface PlagiarismCheck { - id: string; - senderFullName: string; - fileName: string; - date: string; // ISO 8601 - paymentAmount: number; - currency: string; - result: CheckResult; +export interface DocumentData { + id: number; + title: string; + text: string; + file: string; + certificate: boolean; + created_at: string; + updated_at: string; + results: []; } -export interface PlagiarismCheckDetail extends PlagiarismCheck { +export interface PlagiarismCheckDetail extends DocumentData { topic: string; plagiarismPercentage?: number; reportUrl?: string; @@ -22,7 +23,7 @@ export interface PlagiarismCheckDetail extends PlagiarismCheck { // ─── API Response Types ──────────────────────────────────────────────────────── export interface HistoryApiResponse { - items: PlagiarismCheck[]; + items: DocumentData[]; total: number; page: number; pageSize: number; @@ -31,12 +32,12 @@ export interface HistoryApiResponse { // ─── Component Props ─────────────────────────────────────────────────────────── export interface HistoryTableProps { - items: PlagiarismCheck[]; + items: DocumentData[]; isLoading: boolean; } export interface HistoryTableRowProps { - item: PlagiarismCheck; + item: DocumentData; } export interface ResultBadgeProps { @@ -56,7 +57,7 @@ export interface SkeletonRowProps { export type FetchStatus = 'idle' | 'loading' | 'success' | 'error'; export interface HistoryState { - items: PlagiarismCheck[]; + items: DocumentData[]; status: FetchStatus; error: string | null; } diff --git a/src/widgets/history/lib/useHistory.ts b/src/widgets/history/lib/useHistory.ts index 27f205b..3bf4fc2 100644 --- a/src/widgets/history/lib/useHistory.ts +++ b/src/widgets/history/lib/useHistory.ts @@ -1,11 +1,11 @@ 'use client'; import { useState, useEffect, useCallback } from 'react'; import { DEFAULT_PAGE_SIZE } from './constants'; -import { HistoryState } from './types'; -import { DEFAULT_HISTORY_ITEMS } from './mock'; +import { DocumentData, HistoryState } from './types'; import { useQuery } from '@tanstack/react-query'; import { links } from '@/shared/request/links'; import { apiRequest } from '@/shared/request/apiRequest'; +import { useUserPlagiatStore } from '@/shared/zustand/user'; interface UseHistoryReturn extends HistoryState { refetch: () => void; @@ -16,22 +16,21 @@ interface UseHistoryReturn extends HistoryState { export const useHistory = (pageSize = DEFAULT_PAGE_SIZE): UseHistoryReturn => { const [state, setState] = useState({ - items: DEFAULT_HISTORY_ITEMS, + items: [], status: 'idle', error: null, }); const [currentPage, setCurrentPage] = useState(1); const [total, setTotal] = useState(0); + const user = useUserPlagiatStore((state) => state.user); const { data, refetch } = useQuery({ queryKey: ['history'], queryFn: () => apiRequest('GET', links.history), select: (response) => { - const { results, total } = response.data as { - results: []; - total: number; - }; - return { results, total }; + console.log(response); + const results = response?.data as DocumentData[]; + return { results, total: results.length }; }, }); @@ -42,13 +41,13 @@ export const useHistory = (pageSize = DEFAULT_PAGE_SIZE): UseHistoryReturn => { status: 'success', error: null, }); - setTotal(data?.total || 0); + setTotal(data.total || 0); } }, [data]); useEffect(() => { refetch(); - }, [currentPage]); + }, [currentPage, user]); const goToPage = useCallback((page: number) => { setCurrentPage(page); diff --git a/src/widgets/history/lib/utils.ts b/src/widgets/history/lib/utils.ts index 8e6324f..ab04527 100644 --- a/src/widgets/history/lib/utils.ts +++ b/src/widgets/history/lib/utils.ts @@ -1,43 +1,3 @@ -// ─── API Functions ───────────────────────────────────────────────────────────── - -import { API_ENDPOINTS } from './constants'; -import { HistoryApiResponse, PlagiarismCheckDetail } from './types'; - -/** - * Fetches the paginated list of plagiarism checks for the current user. - */ -export const fetchPlagiarismHistory = async ( - page = 1, - pageSize = 10, -): Promise => { - const url = new URL(API_ENDPOINTS.HISTORY, window.location.origin); - url.searchParams.set('page', String(page)); - url.searchParams.set('pageSize', String(pageSize)); - - const response = await fetch(url.toString()); - - if (!response.ok) { - throw new Error(`Failed to load history (${response.status})`); - } - - return response.json() as Promise; -}; - -/** - * Fetches the full detail for a single plagiarism check. - */ -export const fetchPlagiarismDetail = async ( - id: string, -): Promise => { - const response = await fetch(API_ENDPOINTS.DETAIL(id)); - - if (!response.ok) { - throw new Error(`Failed to load record (${response.status})`); - } - - return response.json() as Promise; -}; - // ─── Formatting Utilities ────────────────────────────────────────────────────── /** diff --git a/src/widgets/history/ui/historyTableRow.tsx b/src/widgets/history/ui/historyTableRow.tsx index 3cad5a7..e21211f 100644 --- a/src/widgets/history/ui/historyTableRow.tsx +++ b/src/widgets/history/ui/historyTableRow.tsx @@ -2,26 +2,37 @@ import React from 'react'; import { useTranslations } from 'next-intl'; import { HistoryTableRowProps } from '../lib/types'; -import { formatDate, truncateFileName } from '../lib/utils'; +import { formatDate } from '../lib/utils'; import { ResultBadge } from './resultBadge'; import { useRouter } from '@/shared/config/i18n/navigation'; +import { useUserPlagiatStore } from '@/shared/zustand/user'; export const HistoryTableRow: React.FC = ({ item }) => { const router = useRouter(); const t = useTranslations('HistoryPage'); + const tUnknown = useTranslations(); + const user = useUserPlagiatStore((state) => state.user); + + const userName = user + ? `${user.name} ${user.surname}` + : tUnknown('unknownUser'); return ( {/* Sender */} - {item.senderFullName} + {userName} {/* File Name */} - + {/* Date */} - {formatDate(item.date)} + {formatDate(item.created_at)} {/* Amount */} - + {/* - {item.paymentAmount} + {item.} UZS - + */} {/* Result */} - + {/* View Button */}