payment bug fixed
This commit is contained in:
@@ -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 }) {
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<PaymentStatus status={doc.state} />
|
||||
{doc.certificate && <Sertifikat document_id={Number(id)} />}
|
||||
{doc.file && (
|
||||
<a
|
||||
|
||||
@@ -157,7 +157,9 @@ export function usePlagiarismForm() {
|
||||
form,
|
||||
errors,
|
||||
submission,
|
||||
senderFullName: user ? `${user?.name} ${user?.surname}` : null,
|
||||
senderFullName: localUser
|
||||
? `${localUser?.name} ${localUser?.surname}`
|
||||
: null,
|
||||
isLoading,
|
||||
setTopic,
|
||||
setFile,
|
||||
|
||||
@@ -6,7 +6,7 @@ export const TABLE_COLUMNS = [
|
||||
{ key: 'senderFullName', labelKey: 'sender' },
|
||||
{ key: 'fileName', labelKey: 'file' },
|
||||
{ key: 'date', labelKey: 'date' },
|
||||
{ key: 'result', labelKey: 'result' },
|
||||
{ key: 'state', labelKey: 'state' },
|
||||
{ key: 'actions', labelKey: 'actions' },
|
||||
] as const;
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ export interface DocumentData {
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
results: [];
|
||||
state: 'paid' | 'unpaid';
|
||||
order_id: number;
|
||||
}
|
||||
|
||||
export interface PlagiarismCheckDetail extends DocumentData {
|
||||
|
||||
@@ -1,104 +1,171 @@
|
||||
'use client';
|
||||
import React from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { HistoryTableRowProps } from '../lib/types';
|
||||
import { formatDate } from '../lib/utils';
|
||||
import { ResultBadge } from './resultBadge';
|
||||
import { useRouter } from '@/shared/config/i18n/navigation';
|
||||
import { useUserPlagiatStore } from '@/shared/zustand/user';
|
||||
import PaymentStatus from '@/widgets/detail/paidStatus';
|
||||
import { PaymentModal } from '@/widgets/paymentModal/ui/Paymentmodal';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { apiRequest } from '@/shared/request/apiRequest';
|
||||
import { links } from '@/shared/request/links';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export const HistoryTableRow: React.FC<HistoryTableRowProps> = ({ 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 (
|
||||
<tr className="border-b border-slate-100 hover:bg-slate-50/70 transition-colors duration-100 group">
|
||||
{/* Sender */}
|
||||
<td className="px-4 py-3.5">
|
||||
<span className="text-sm font-medium text-slate-800 whitespace-nowrap">
|
||||
{userName}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* File Name */}
|
||||
<td className="px-4 py-3.5">
|
||||
<a
|
||||
href={item.file}
|
||||
target="_blank"
|
||||
className="flex items-center gap-2 underline"
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.75"
|
||||
className="text-slate-400 shrink-0"
|
||||
>
|
||||
<path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
<span className="text-sm text-slate-600 font-mono" title={item.file}>
|
||||
{tUnknown('file')}
|
||||
<>
|
||||
<tr className="border-b border-slate-100 hover:bg-slate-50/70 transition-colors duration-100 group">
|
||||
{/* Sender */}
|
||||
<td className="px-4 py-3.5">
|
||||
<span className="text-sm font-medium text-slate-800 whitespace-nowrap">
|
||||
{userName}
|
||||
</span>
|
||||
</a>
|
||||
</td>
|
||||
</td>
|
||||
|
||||
{/* Date */}
|
||||
<td className="px-4 py-3.5">
|
||||
<span className="text-sm text-slate-500 whitespace-nowrap">
|
||||
{formatDate(item.created_at)}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* Amount */}
|
||||
{/* <td className="px-4 py-3.5">
|
||||
<span className="text-sm font-medium text-slate-700 whitespace-nowrap tabular-nums">
|
||||
{item.} UZS
|
||||
</span>
|
||||
</td> */}
|
||||
|
||||
{/* Result */}
|
||||
<td className="px-4 py-3.5">
|
||||
<ResultBadge result={'clean'} />
|
||||
</td>
|
||||
|
||||
{/* View Button */}
|
||||
<td className="px-4 py-3.5 text-right">
|
||||
<button
|
||||
onClick={() => router.push(`/${item.id}`)}
|
||||
aria-label={t('viewDetails', { sender: item.title })}
|
||||
className="
|
||||
inline-flex items-center gap-1.5 px-3 py-1.5
|
||||
text-xs font-medium text-slate-600
|
||||
bg-white border border-slate-200 rounded-lg
|
||||
hover:border-slate-300 hover:text-slate-900 hover:bg-slate-50
|
||||
active:scale-95
|
||||
transition-all duration-150
|
||||
focus:outline-none focus-visible:ring-2 focus-visible:ring-slate-300
|
||||
"
|
||||
>
|
||||
{t('view')}
|
||||
<svg
|
||||
width="11"
|
||||
height="11"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
{/* File Name */}
|
||||
<td className="px-4 py-3.5">
|
||||
<a
|
||||
href={item.file}
|
||||
target="_blank"
|
||||
className="flex items-center gap-2 underline"
|
||||
>
|
||||
<path d="M5 12h14M12 5l7 7-7 7" />
|
||||
</svg>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.75"
|
||||
className="text-slate-400 shrink-0"
|
||||
>
|
||||
<path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
<span
|
||||
className="text-sm text-slate-600 font-mono"
|
||||
title={item.file}
|
||||
>
|
||||
{tUnknown('file')}
|
||||
</span>
|
||||
</a>
|
||||
</td>
|
||||
|
||||
{/* Date */}
|
||||
<td className="px-4 py-3.5">
|
||||
<span className="text-sm text-slate-500 whitespace-nowrap">
|
||||
{formatDate(item.created_at)}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* State */}
|
||||
<td className="px-4 py-3.5">
|
||||
<span
|
||||
onClick={() => {
|
||||
if (item.state === 'unpaid') {
|
||||
setIsPaymentOpen(true);
|
||||
}
|
||||
}}
|
||||
className="text-sm font-medium text-slate-700 whitespace-nowrap tabular-nums"
|
||||
>
|
||||
<PaymentStatus status={item.state} />
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* View Button */}
|
||||
<td className="px-4 py-3.5 text-right">
|
||||
<button
|
||||
onClick={() => {
|
||||
if (item.state === 'paid') {
|
||||
router.push(`/${item.id}`);
|
||||
} else {
|
||||
toast.error(tPay('paymentRequired'));
|
||||
}
|
||||
}}
|
||||
aria-label={t('viewDetails', { sender: item.title })}
|
||||
className="
|
||||
inline-flex items-center gap-1.5 px-3 py-1.5
|
||||
text-xs font-medium text-slate-600
|
||||
bg-white border border-slate-200 rounded-lg
|
||||
hover:border-slate-300 hover:text-slate-900 hover:bg-slate-50
|
||||
active:scale-95
|
||||
transition-all duration-150
|
||||
focus:outline-none focus-visible:ring-2 focus-visible:ring-slate-300
|
||||
"
|
||||
>
|
||||
{t('view')}
|
||||
<svg
|
||||
width="11"
|
||||
height="11"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M5 12h14M12 5l7 7-7 7" />
|
||||
</svg>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<PaymentModal
|
||||
isOpen={isPaymentOpen}
|
||||
onClose={() => setIsPaymentOpen(false)}
|
||||
hasCertificate={false}
|
||||
onConfirmPayment={() => {
|
||||
handleSubmit({ document_id: Number(item.order_id) });
|
||||
}}
|
||||
isLoading={payment.isPending}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import { MenuItem } from '../lib/model';
|
||||
|
||||
const SubMenuLink = ({ item }: { item: MenuItem }) => {
|
||||
const SubMenuLink = ({
|
||||
item,
|
||||
logOut,
|
||||
}: {
|
||||
item: MenuItem;
|
||||
logOut: () => void;
|
||||
}) => {
|
||||
return (
|
||||
<a
|
||||
className="flex flex-row gap-4 rounded-md p-3 leading-none no-underline transition-colors outline-none select-none hover:bg-muted hover:text-accent-foreground"
|
||||
href={item.url}
|
||||
onClick={logOut}
|
||||
>
|
||||
<div className="text-foreground">
|
||||
{item.icon && <item.icon className="size-5 shrink-0" />}
|
||||
|
||||
@@ -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();
|
||||
}}
|
||||
>
|
||||
<SubMenuLink item={subItem} />
|
||||
<SubMenuLink logOut={clearTokens} item={subItem} />
|
||||
</NavigationMenuLink>
|
||||
))}
|
||||
</NavigationMenuContent>
|
||||
|
||||
Reference in New Issue
Block a user