payment method over
This commit is contained in:
@@ -210,5 +210,6 @@
|
|||||||
"payButton": "Pay with Payme"
|
"payButton": "Pay with Payme"
|
||||||
},
|
},
|
||||||
"unknownUser": "Username not found",
|
"unknownUser": "Username not found",
|
||||||
"file": "File"
|
"file": "File",
|
||||||
|
"upload":"Download certificate"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,5 +210,6 @@
|
|||||||
"payButton": "Оплатить через Payme"
|
"payButton": "Оплатить через Payme"
|
||||||
},
|
},
|
||||||
"unknownUser": "Имя пользователя не найдено",
|
"unknownUser": "Имя пользователя не найдено",
|
||||||
"file":"Файл"
|
"file":"Файл",
|
||||||
|
"upload":"Скачать сертификат"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,5 +214,6 @@ declare const messages: {
|
|||||||
};
|
};
|
||||||
unknownUser: 'Foydalanuvchi topilmadi';
|
unknownUser: 'Foydalanuvchi topilmadi';
|
||||||
file: 'Fayl';
|
file: 'Fayl';
|
||||||
|
upload: 'Sertifikatni yuklab olish';
|
||||||
};
|
};
|
||||||
export default messages;
|
export default messages;
|
||||||
|
|||||||
@@ -210,5 +210,6 @@
|
|||||||
"payButton": "Payme orqali to'lash"
|
"payButton": "Payme orqali to'lash"
|
||||||
},
|
},
|
||||||
"unknownUser":"Foydalanuvchi topilmadi",
|
"unknownUser":"Foydalanuvchi topilmadi",
|
||||||
"file":"Fayl"
|
"file":"Fayl",
|
||||||
|
"upload":"Sertifikatni yuklab olish"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,7 @@ export const links = {
|
|||||||
plagiarismCheck: '/shared/documents/',
|
plagiarismCheck: '/shared/documents/',
|
||||||
history: '/shared/documents/list/',
|
history: '/shared/documents/list/',
|
||||||
detail: (id: number) => `/shared/documents/${id}/`,
|
detail: (id: number) => `/shared/documents/${id}/`,
|
||||||
|
payment: (order_id: number) => `/users/payme/link/${order_id}/`,
|
||||||
|
sertifikat: (document_id: number) =>
|
||||||
|
`/shared/certificate/${document_id}/pdf/`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useState } from 'react';
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { links } from '@/shared/request/links';
|
import { links } from '@/shared/request/links';
|
||||||
import { apiRequest } from '@/shared/request/apiRequest';
|
import { apiRequest } from '@/shared/request/apiRequest';
|
||||||
|
import Sertifikat from './sertifikat';
|
||||||
|
|
||||||
// ── Types ────────────────────────────────────────────────────────────────────
|
// ── 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">
|
<span className="text-[11px] uppercase tracking-widest text-slate-400 font-semibold leading-snug">
|
||||||
{label}
|
{label}
|
||||||
</span>
|
</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)}
|
{String(value)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -293,7 +294,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
|
|||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-slate-50">
|
<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 />
|
<LoadingSkeleton />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -303,7 +304,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
|
|||||||
if (isError || !doc) {
|
if (isError || !doc) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-slate-50">
|
<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} />
|
<ErrorState message={(error as Error)?.message} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -385,22 +386,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
{doc.certificate && (
|
{doc.certificate && <Sertifikat document_id={Number(id)} />}
|
||||||
<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.file && (
|
{doc.file && (
|
||||||
<a
|
<a
|
||||||
href={doc.file}
|
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]}`}
|
className={`mt-8 flex items-center gap-3 rounded-xl border px-5 py-4 ${aiColors[aiRisk]}`}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
className="w-5 h-5 flex-shrink-0"
|
className="w-5 h-5 shrink-0"
|
||||||
fill="none"
|
fill="none"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
@@ -602,7 +588,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
|
|||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div
|
<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'
|
positive ? 'bg-red-500' : 'bg-slate-300'
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useState, useCallback } from 'react';
|
import { useState, useCallback, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
PlagiarismFormErrors,
|
PlagiarismFormErrors,
|
||||||
PlagiarismFormState,
|
PlagiarismFormState,
|
||||||
@@ -11,7 +11,6 @@ import { useUserPlagiatStore } from '@/shared/zustand/user';
|
|||||||
import { useMutation } from '@tanstack/react-query';
|
import { useMutation } from '@tanstack/react-query';
|
||||||
import { links } from '@/shared/request/links';
|
import { links } from '@/shared/request/links';
|
||||||
import { apiRequest } from '@/shared/request/apiRequest';
|
import { apiRequest } from '@/shared/request/apiRequest';
|
||||||
import { useRouter } from '@/shared/config/i18n/navigation';
|
|
||||||
|
|
||||||
// ─── Initial States ──────────────────────────────────────────────────────────
|
// ─── Initial States ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -32,12 +31,28 @@ const INITIAL_SUBMISSION: SubmissionState = {
|
|||||||
|
|
||||||
export function usePlagiarismForm() {
|
export function usePlagiarismForm() {
|
||||||
const user = useUserPlagiatStore((state) => state.user);
|
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 [form, setForm] = useState<PlagiarismFormState>(INITIAL_FORM);
|
||||||
const [errors, setErrors] = useState<PlagiarismFormErrors>({});
|
const [errors, setErrors] = useState<PlagiarismFormErrors>({});
|
||||||
const [isPaymentOpen, setIsPaymentOpen] = useState(false);
|
const [isPaymentOpen, setIsPaymentOpen] = useState(false);
|
||||||
const [submission, setSubmission] =
|
const [submission, setSubmission] =
|
||||||
useState<SubmissionState>(INITIAL_SUBMISSION);
|
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({
|
const checkdocumentRequest = useMutation({
|
||||||
mutationKey: ['plagiarismCheck'],
|
mutationKey: ['plagiarismCheck'],
|
||||||
@@ -47,9 +62,27 @@ export function usePlagiarismForm() {
|
|||||||
console.log('uploda: ', res);
|
console.log('uploda: ', res);
|
||||||
const resdata = res.data as { id: number; order_id: number };
|
const resdata = res.data as { id: number; order_id: number };
|
||||||
console.log('order_id:', resdata.id);
|
console.log('order_id:', resdata.id);
|
||||||
route.push(`/${resdata.id}`);
|
// setDocument_id(resdata.id);
|
||||||
|
setOrder_id(resdata.order_id);
|
||||||
setSubmission({ status: 'success', error: null });
|
setSubmission({ status: 'success', error: null });
|
||||||
setForm(INITIAL_FORM);
|
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);
|
setIsPaymentOpen(false);
|
||||||
},
|
},
|
||||||
onError: (err) => {
|
onError: (err) => {
|
||||||
@@ -84,7 +117,7 @@ export function usePlagiarismForm() {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
console.log('Form submitted user:', user); // Debugging log
|
console.log('Form submitted user:', user); // Debugging log
|
||||||
if (user === null) {
|
if (localUser === null) {
|
||||||
toast.error('Iltimos, avval tizimga kiring!');
|
toast.error('Iltimos, avval tizimga kiring!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -95,21 +128,21 @@ export function usePlagiarismForm() {
|
|||||||
return; // Don't open modal if invalid
|
return; // Don't open modal if invalid
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validation passed → open the payment modal
|
const fd = new FormData();
|
||||||
setIsPaymentOpen(true);
|
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],
|
[form],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSubmit = useCallback(async () => {
|
const handleSubmit = useCallback(async () => {
|
||||||
setSubmission({ status: 'loading', error: null });
|
setSubmission({ status: 'loading', error: null });
|
||||||
const fd = new FormData();
|
|
||||||
fd.append('title', form.title.trim());
|
payment.mutate({ order_id });
|
||||||
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, user]);
|
}, [form, user]);
|
||||||
|
|
||||||
const resetSubmission = useCallback(() => {
|
const resetSubmission = useCallback(() => {
|
||||||
|
|||||||
@@ -14,9 +14,15 @@ import { useLoginModal, useRegisterModal } from '@/shared/zustand/auth';
|
|||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useUserPlagiatStore } from '@/shared/zustand/user';
|
import { useUserPlagiatStore } from '@/shared/zustand/user';
|
||||||
import { LogOut } from 'lucide-react';
|
import { LogOut } from 'lucide-react';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
function AuthButtons() {
|
function AuthButtons() {
|
||||||
const t = useTranslations('Navbar');
|
const t = useTranslations('Navbar');
|
||||||
|
const [localUser, setLocalUser] = useState<{
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
surname: string;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
const auth = {
|
const auth = {
|
||||||
login: { title: t('login'), url: '#' },
|
login: { title: t('login'), url: '#' },
|
||||||
@@ -38,7 +44,17 @@ function AuthButtons() {
|
|||||||
};
|
};
|
||||||
console.log('Current user:', user);
|
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 (
|
return (
|
||||||
<div className="flex flex-row max-sm:items-center max-sm:justify-around gap-3">
|
<div className="flex flex-row max-sm:items-center max-sm:justify-around gap-3">
|
||||||
<div className="sm:flex hidden">
|
<div className="sm:flex hidden">
|
||||||
@@ -47,7 +63,7 @@ function AuthButtons() {
|
|||||||
<NavigationMenu>
|
<NavigationMenu>
|
||||||
<NavigationMenuItem>
|
<NavigationMenuItem>
|
||||||
<NavigationMenuTrigger className="text-xl">
|
<NavigationMenuTrigger className="text-xl">
|
||||||
{user.name} {user.surname}
|
{localUser.name} {localUser.surname}
|
||||||
</NavigationMenuTrigger>
|
</NavigationMenuTrigger>
|
||||||
<NavigationMenuContent className="bg-popover text-popover-foreground">
|
<NavigationMenuContent className="bg-popover text-popover-foreground">
|
||||||
{userItem.map((subItem) => (
|
{userItem.map((subItem) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user