payment method over

This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-04-02 20:59:31 +05:00
parent e9c73c42e2
commit 0b125d05ee
8 changed files with 82 additions and 40 deletions

View File

@@ -210,5 +210,6 @@
"payButton": "Pay with Payme"
},
"unknownUser": "Username not found",
"file": "File"
"file": "File",
"upload":"Download certificate"
}

View File

@@ -210,5 +210,6 @@
"payButton": "Оплатить через Payme"
},
"unknownUser": "Имя пользователя не найдено",
"file":"Файл"
"file":"Файл",
"upload":"Скачать сертификат"
}

View File

@@ -214,5 +214,6 @@ declare const messages: {
};
unknownUser: 'Foydalanuvchi topilmadi';
file: 'Fayl';
upload: 'Sertifikatni yuklab olish';
};
export default messages;

View File

@@ -210,5 +210,6 @@
"payButton": "Payme orqali to'lash"
},
"unknownUser":"Foydalanuvchi topilmadi",
"file":"Fayl"
"file":"Fayl",
"upload":"Sertifikatni yuklab olish"
}

View File

@@ -4,4 +4,7 @@ export const links = {
plagiarismCheck: '/shared/documents/',
history: '/shared/documents/list/',
detail: (id: number) => `/shared/documents/${id}/`,
payment: (order_id: number) => `/users/payme/link/${order_id}/`,
sertifikat: (document_id: number) =>
`/shared/certificate/${document_id}/pdf/`,
};

View File

@@ -4,6 +4,7 @@ import { useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import { links } from '@/shared/request/links';
import { apiRequest } from '@/shared/request/apiRequest';
import Sertifikat from './sertifikat';
// ── Types ────────────────────────────────────────────────────────────────────
@@ -156,7 +157,7 @@ function StatCard({ label, value }: { label: string; value: string | number }) {
<span className="text-[11px] uppercase tracking-widest text-slate-400 font-semibold leading-snug">
{label}
</span>
<span className="text-slate-800 font-semibold text-sm break-words">
<span className="text-slate-800 font-semibold text-sm wrap-break-words">
{String(value)}
</span>
</div>
@@ -293,7 +294,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
if (isLoading) {
return (
<div className="min-h-screen bg-slate-50">
<header className="bg-white border-b border-slate-200 h-[65px]" />
<header className="bg-white border-b border-slate-200 h-16.25" />
<LoadingSkeleton />
</div>
);
@@ -303,7 +304,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
if (isError || !doc) {
return (
<div className="min-h-screen bg-slate-50">
<header className="bg-white border-b border-slate-200 h-[65px]" />
<header className="bg-white border-b border-slate-200 h-16.25" />
<ErrorState message={(error as Error)?.message} />
</div>
);
@@ -385,22 +386,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
</div>
<div className="flex items-center gap-3">
{doc.certificate && (
<span className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-emerald-50 border border-emerald-200 text-emerald-700 text-xs font-semibold">
<svg
className="w-3.5 h-3.5"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
fillRule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
clipRule="evenodd"
/>
</svg>
Certificate
</span>
)}
{doc.certificate && <Sertifikat document_id={Number(id)} />}
{doc.file && (
<a
href={doc.file}
@@ -510,7 +496,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
className={`mt-8 flex items-center gap-3 rounded-xl border px-5 py-4 ${aiColors[aiRisk]}`}
>
<svg
className="w-5 h-5 flex-shrink-0"
className="w-5 h-5 shrink-0"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
@@ -602,7 +588,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
}`}
>
<div
className={`w-2 h-2 rounded-full flex-shrink-0 ${
className={`w-2 h-2 rounded-full shrink-0 ${
positive ? 'bg-red-500' : 'bg-slate-300'
}`}
/>

View File

@@ -1,5 +1,5 @@
'use client';
import { useState, useCallback } from 'react';
import { useState, useCallback, useEffect } from 'react';
import {
PlagiarismFormErrors,
PlagiarismFormState,
@@ -11,7 +11,6 @@ import { useUserPlagiatStore } from '@/shared/zustand/user';
import { useMutation } from '@tanstack/react-query';
import { links } from '@/shared/request/links';
import { apiRequest } from '@/shared/request/apiRequest';
import { useRouter } from '@/shared/config/i18n/navigation';
// ─── Initial States ──────────────────────────────────────────────────────────
@@ -32,12 +31,28 @@ const INITIAL_SUBMISSION: SubmissionState = {
export function usePlagiarismForm() {
const user = useUserPlagiatStore((state) => state.user);
const [localUser, setLocalUser] = useState<{
id: number;
name: string;
surname: string;
} | null>(null);
useEffect(() => {
const data = localStorage.getItem('user');
if (data) {
setLocalUser(JSON.parse(data));
} else {
setLocalUser(null);
}
}, [user]);
const [form, setForm] = useState<PlagiarismFormState>(INITIAL_FORM);
const [errors, setErrors] = useState<PlagiarismFormErrors>({});
const [isPaymentOpen, setIsPaymentOpen] = useState(false);
const [submission, setSubmission] =
useState<SubmissionState>(INITIAL_SUBMISSION);
const route = useRouter();
// const route = useRouter();
// const [document_id, setDocument_id] = useState<number>(0);
const [order_id, setOrder_id] = useState<number>(0);
const checkdocumentRequest = useMutation({
mutationKey: ['plagiarismCheck'],
@@ -47,9 +62,27 @@ export function usePlagiarismForm() {
console.log('uploda: ', res);
const resdata = res.data as { id: number; order_id: number };
console.log('order_id:', resdata.id);
route.push(`/${resdata.id}`);
// setDocument_id(resdata.id);
setOrder_id(resdata.order_id);
setSubmission({ status: 'success', error: null });
setForm(INITIAL_FORM);
setIsPaymentOpen(true);
},
onError: (err) => {
const message =
err instanceof Error ? err.message : 'An unexpected error occurred.';
setSubmission({ status: 'error', error: message });
},
});
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) => {
@@ -84,7 +117,7 @@ export function usePlagiarismForm() {
e.preventDefault();
console.log('Form submitted user:', user); // Debugging log
if (user === null) {
if (localUser === null) {
toast.error('Iltimos, avval tizimga kiring!');
return;
}
@@ -95,21 +128,21 @@ export function usePlagiarismForm() {
return; // Don't open modal if invalid
}
// Validation passed → open the payment modal
setIsPaymentOpen(true);
const fd = new FormData();
fd.append('title', form.title.trim());
fd.append('text', `${user?.name} ${user?.surname}` || '');
fd.append('file', form.file!); // File object — multipart/form-data
fd.append('certificate', String(form.certificate));
fd.append('total_price', '41200');
checkdocumentRequest.mutate(fd);
},
[form],
);
const handleSubmit = useCallback(async () => {
setSubmission({ status: 'loading', error: null });
const fd = new FormData();
fd.append('title', form.title.trim());
fd.append('text', `${user?.name} ${user?.surname}` || '');
fd.append('file', form.file!); // File object — multipart/form-data
fd.append('certificate', String(form.certificate));
fd.append('total_price', '41200');
checkdocumentRequest.mutate(fd);
payment.mutate({ order_id });
}, [form, user]);
const resetSubmission = useCallback(() => {

View File

@@ -14,9 +14,15 @@ import { useLoginModal, useRegisterModal } from '@/shared/zustand/auth';
import { useTranslations } from 'next-intl';
import { useUserPlagiatStore } from '@/shared/zustand/user';
import { LogOut } from 'lucide-react';
import { useEffect, useState } from 'react';
function AuthButtons() {
const t = useTranslations('Navbar');
const [localUser, setLocalUser] = useState<{
id: number;
name: string;
surname: string;
} | null>(null);
const auth = {
login: { title: t('login'), url: '#' },
@@ -38,7 +44,17 @@ function AuthButtons() {
};
console.log('Current user:', user);
if (user) {
useEffect(() => {
const data = localStorage.getItem('user');
if (data) {
setLocalUser(JSON.parse(data));
} else {
setLocalUser(null);
}
}, [user]);
if (localUser) {
return (
<div className="flex flex-row max-sm:items-center max-sm:justify-around gap-3">
<div className="sm:flex hidden">
@@ -47,7 +63,7 @@ function AuthButtons() {
<NavigationMenu>
<NavigationMenuItem>
<NavigationMenuTrigger className="text-xl">
{user.name} {user.surname}
{localUser.name} {localUser.surname}
</NavigationMenuTrigger>
<NavigationMenuContent className="bg-popover text-popover-foreground">
{userItem.map((subItem) => (