From b32057a6af95dd5cd454ccfecddfe61c4abca928 Mon Sep 17 00:00:00 2001 From: "nabijonovdavronbek619@gmail.com" Date: Fri, 3 Apr 2026 20:37:09 +0500 Subject: [PATCH] payment bug fixed --- src/shared/config/i18n/messages/en.json | 6 +- src/shared/config/i18n/messages/ru.json | 6 +- src/shared/config/i18n/messages/uz.d.json.ts | 4 + src/shared/config/i18n/messages/uz.json | 6 +- src/widgets/detail/pageDetail.tsx | 3 + src/widgets/fileUpload/lib/usePlagiraism.ts | 4 +- src/widgets/history/lib/constants.ts | 2 +- src/widgets/history/lib/types.ts | 2 + src/widgets/history/ui/historyTableRow.tsx | 233 ++++++++++++------- src/widgets/navbar/ui/SubMenuLink.tsx | 9 +- src/widgets/navbar/ui/authButtons.tsx | 7 +- 11 files changed, 188 insertions(+), 94 deletions(-) diff --git a/src/shared/config/i18n/messages/en.json b/src/shared/config/i18n/messages/en.json index ec26c51..74e5772 100644 --- a/src/shared/config/i18n/messages/en.json +++ b/src/shared/config/i18n/messages/en.json @@ -62,6 +62,7 @@ "amount": "Amount", "result": "Result", "actions": "", + "state": "Payment status", "emptyMessage": "No plagiarism checks found.", "tryAgain": "Try again", "view": "View", @@ -121,7 +122,9 @@ "certificateId": "Certificate ID", "downloadCertificate": "Download Certificate", "unknownError": "Unknown error", - "words": "words" + "words": "words", + "aiProbabilityText": "Probability that the text was generated with AI has been detected", + "documentNumber": "Document subject" }, "Hero": { "badge": "Academic Integrity Platform", @@ -228,6 +231,7 @@ "serviceFee": "Service fee", "certificateLabel": "Certificate", "total": "Total", + "paymentRequired": "Payment not completed", "connecting": "Connecting to Payme…", "payButton": "Pay with Payme" }, diff --git a/src/shared/config/i18n/messages/ru.json b/src/shared/config/i18n/messages/ru.json index 91d5918..08d56a1 100644 --- a/src/shared/config/i18n/messages/ru.json +++ b/src/shared/config/i18n/messages/ru.json @@ -62,6 +62,7 @@ "amount": "Сумма", "result": "Результат", "actions": "", + "state": "Статус оплаты", "emptyMessage": "Проверки на плагиат не найдены.", "tryAgain": "Попробовать снова", "view": "Просмотр", @@ -121,7 +122,9 @@ "certificateId": "ID сертификата", "downloadCertificate": "Скачать сертификат", "unknownError": "Неизвестная ошибка", - "words": "слов" + "words": "слов", + "aiProbabilityText": "Обнаружена вероятность того, что текст создан с помощью ИИ", + "documentNumber": "Тема документа" }, "Hero": { "badge": "Платформа академической честности", @@ -228,6 +231,7 @@ "serviceFee": "Стоимость услуги", "certificateLabel": "Сертификат", "total": "Итого", + "paymentRequired": "Оплата не произведена", "connecting": "Подключение к Payme…", "payButton": "Оплатить через Payme" }, diff --git a/src/shared/config/i18n/messages/uz.d.json.ts b/src/shared/config/i18n/messages/uz.d.json.ts index adaa47b..1b6f044 100644 --- a/src/shared/config/i18n/messages/uz.d.json.ts +++ b/src/shared/config/i18n/messages/uz.d.json.ts @@ -65,6 +65,7 @@ declare const messages: { amount: 'Summa'; result: 'Natija'; actions: ''; + state: "To'lov holati"; emptyMessage: 'Plagiat tekshiruvlari topilmadi.'; tryAgain: "Qayta urinib ko'ring"; view: "Ko'rish"; @@ -125,6 +126,8 @@ declare const messages: { downloadCertificate: 'Sertifikatni yuklab olish'; unknownError: "Noma'lum xato"; words: "so'z"; + aiProbabilityText: 'Ai yordamida yaratilganlik ehtimoli aniqlandi'; + documentNumber: 'Dokument mavzusi'; }; Hero: { badge: 'Akademik halollik platformasi'; @@ -231,6 +234,7 @@ declare const messages: { serviceFee: "Xizmat to'lovi"; certificateLabel: 'Sertifikat'; total: 'Jami'; + paymentRequired: "To'lov qilinmagan"; connecting: 'Paymega ulanmoqda…'; payButton: "Payme orqali to'lash"; }; diff --git a/src/shared/config/i18n/messages/uz.json b/src/shared/config/i18n/messages/uz.json index 0e787fb..b9c9baa 100644 --- a/src/shared/config/i18n/messages/uz.json +++ b/src/shared/config/i18n/messages/uz.json @@ -62,6 +62,7 @@ "amount": "Summa", "result": "Natija", "actions": "", + "state": "To'lov holati", "emptyMessage": "Plagiat tekshiruvlari topilmadi.", "tryAgain": "Qayta urinib ko'ring", "view": "Ko'rish", @@ -121,7 +122,9 @@ "certificateId": "Sertifikat ID", "downloadCertificate": "Sertifikatni yuklab olish", "unknownError": "Noma'lum xato", - "words": "so'z" + "words": "so'z", + "aiProbabilityText":"Ai yordamida yaratilganlik ehtimoli aniqlandi", + "documentNumber":"Dokument mavzusi" }, "Hero": { "badge": "Akademik halollik platformasi", @@ -228,6 +231,7 @@ "serviceFee": "Xizmat to'lovi", "certificateLabel": "Sertifikat", "total": "Jami", + "paymentRequired":"To'lov qilinmagan", "connecting": "Paymega ulanmoqda…", "payButton": "Payme orqali to'lash" }, diff --git a/src/widgets/detail/pageDetail.tsx b/src/widgets/detail/pageDetail.tsx index 1d4ba32..2880f44 100644 --- a/src/widgets/detail/pageDetail.tsx +++ b/src/widgets/detail/pageDetail.tsx @@ -7,6 +7,7 @@ import { useParams } from 'next/navigation'; import { links } from '@/shared/request/links'; import { apiRequest } from '@/shared/request/apiRequest'; import Sertifikat from './sertifikat'; +import PaymentStatus from './paidStatus'; // ── Types ──────────────────────────────────────────────────────────────────── @@ -46,6 +47,7 @@ interface Document { text: string; created_at: string; updated_at: string; + state: 'paid' | 'unpaid'; results: Result[]; } @@ -394,6 +396,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
+ {doc.certificate && } {doc.file && ( = ({ item }) => { const router = useRouter(); const t = useTranslations('HistoryPage'); + const tPay = useTranslations('Payment'); const tUnknown = useTranslations(); const user = useUserPlagiatStore((state) => state.user); + const [isPaymentOpen, setIsPaymentOpen] = useState(false); + const [localUser, setLocalUser] = useState<{ + id: number; + name: string; + surname: string; + } | null>(null); - const userName = user - ? `${user.name} ${user.surname}` + useEffect(() => { + const data = localStorage.getItem('user'); + + if (data) { + setLocalUser(JSON.parse(data)); + } else { + setLocalUser(null); + } + }, [user]); + + const userName = localUser + ? `${localUser.name} ${localUser.surname}` : tUnknown('unknownUser'); + const payment = useMutation({ + mutationKey: ['payload'], + mutationFn: ({ order_id }: { order_id: number }) => + apiRequest<{ payment_link: string }>('POST', links.payment(order_id)), + onSuccess: (res) => { + console.log('payment res: ', res); + window.open(res.data.payment_link, '_self'); + //route.push(`/${document_id}`); + setIsPaymentOpen(false); + }, + onError: (err) => { + const message = + err instanceof Error ? err.message : 'An unexpected error occurred.'; + toast.error(message); + setIsPaymentOpen(false); + }, + }); + + const handleSubmit = ({ document_id }: { document_id: number }) => { + payment.mutate({ order_id: document_id }); + }; + return ( - - {/* Sender */} - - - {userName} - - - - {/* File Name */} - - - - - - - {tUnknown('file')} + <> + + {/* Sender */} + + + {userName} - - + - {/* Date */} - - - {formatDate(item.created_at)} - - - - {/* Amount */} - {/* - - {item.} UZS - - */} - - {/* Result */} - - - - - {/* View Button */} - - - - + + + + + {tUnknown('file')} + + + + + {/* Date */} + + + {formatDate(item.created_at)} + + + + {/* State */} + + { + if (item.state === 'unpaid') { + setIsPaymentOpen(true); + } + }} + className="text-sm font-medium text-slate-700 whitespace-nowrap tabular-nums" + > + + + + + {/* View Button */} + + + + + + setIsPaymentOpen(false)} + hasCertificate={false} + onConfirmPayment={() => { + handleSubmit({ document_id: Number(item.order_id) }); + }} + isLoading={payment.isPending} + /> + ); }; diff --git a/src/widgets/navbar/ui/SubMenuLink.tsx b/src/widgets/navbar/ui/SubMenuLink.tsx index 97360e5..cc8f2f2 100644 --- a/src/widgets/navbar/ui/SubMenuLink.tsx +++ b/src/widgets/navbar/ui/SubMenuLink.tsx @@ -1,10 +1,17 @@ import { MenuItem } from '../lib/model'; -const SubMenuLink = ({ item }: { item: MenuItem }) => { +const SubMenuLink = ({ + item, + logOut, +}: { + item: MenuItem; + logOut: () => void; +}) => { return (
{item.icon && } diff --git a/src/widgets/navbar/ui/authButtons.tsx b/src/widgets/navbar/ui/authButtons.tsx index 39afab4..c70a636 100644 --- a/src/widgets/navbar/ui/authButtons.tsx +++ b/src/widgets/navbar/ui/authButtons.tsx @@ -41,6 +41,7 @@ function AuthButtons() { localStorage.removeItem('access'); localStorage.removeItem('refresh'); localStorage.removeItem('user'); + clearUser(); }; console.log('Current user:', user); @@ -71,12 +72,8 @@ function AuthButtons() { asChild key={subItem.title} className="w-80" - onClick={() => { - clearTokens(); - clearUser(); - }} > - + ))}