fix base_api error
This commit is contained in:
@@ -43,9 +43,9 @@ export function useCertificateModal({
|
||||
|
||||
const certificateMutation = useMutation({
|
||||
mutationFn: (payload: CertificatePayload) =>
|
||||
apiRequest('POST', links.sertifikat(document_id), payload).then(
|
||||
(res) => res.data as ArrayBuffer,
|
||||
),
|
||||
apiRequest<ArrayBuffer>('POST', links.sertifikat(document_id), payload, {
|
||||
responseType: 'arraybuffer',
|
||||
}).then((res) => res.data),
|
||||
onSuccess: (data: ArrayBuffer) => {
|
||||
if (data) {
|
||||
const blob = new Blob([data], { type: 'application/pdf' });
|
||||
@@ -54,7 +54,7 @@ export function useCertificateModal({
|
||||
a.href = objectUrl;
|
||||
a.download = `certificate-${document_id}.pdf`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
setTimeout(() => URL.revokeObjectURL(objectUrl), 1000);
|
||||
}
|
||||
setSuccess(true);
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -45,7 +45,7 @@ function extractErrorMessage(error: AxiosError): string {
|
||||
// ─── Constants ─────────────────────────────────────────────────────────────────
|
||||
|
||||
// const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
|
||||
const baseUrl = 'https://dev-api.anti-plagiat.uz/api/v1';
|
||||
const baseUrl = 'https://api.anti-plagiat.uz/api/v1';
|
||||
const DEFAULT_LOCALE = 'uz'; // fallback locale for redirect
|
||||
|
||||
// ─── Token helpers ─────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -18,7 +18,7 @@ function NavigationMenu({
|
||||
data-slot="navigation-menu"
|
||||
data-viewport={viewport}
|
||||
className={cn(
|
||||
'group/navigation-menu relative flex max-w-max flex-1 items-center justify-center',
|
||||
' relative flex max-w-max flex-1 items-center justify-center',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
|
||||
12
src/shared/zustand/cabinetNav.ts
Normal file
12
src/shared/zustand/cabinetNav.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { CabinetSection } from '@/widgets/cabinet/lib/types';
|
||||
import { create } from 'zustand';
|
||||
|
||||
type CabinetNavZustand = {
|
||||
navItem: CabinetSection;
|
||||
setNavItem: (item: string) => void;
|
||||
};
|
||||
|
||||
export const useCabinetNav = create<CabinetNavZustand>((set) => ({
|
||||
navItem: 'dashboard',
|
||||
setNavItem: (item: string) => set({ navItem: item || 'dash' }),
|
||||
}));
|
||||
@@ -1,14 +1,43 @@
|
||||
'use client';
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useCabinetNav } from '@/shared/zustand/cabinetNav';
|
||||
import type { CabinetSection } from '../types';
|
||||
|
||||
const VALID_SECTIONS: CabinetSection[] = [
|
||||
'dashboard',
|
||||
'plagiat',
|
||||
'si',
|
||||
'payments',
|
||||
'profile',
|
||||
];
|
||||
|
||||
export const useCabinet = () => {
|
||||
const { navItem, setNavItem } = useCabinetNav();
|
||||
const navItemZustrand = useCabinetNav((state) => state.navItem);
|
||||
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
|
||||
const [activeSection, setActiveSection] =
|
||||
useState<CabinetSection>('dashboard');
|
||||
const [isSidebarOpen, setIsSidebarOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (navItemZustrand) {
|
||||
const activeSection: CabinetSection = VALID_SECTIONS.includes(
|
||||
navItemZustrand as CabinetSection,
|
||||
)
|
||||
? (navItemZustrand as CabinetSection)
|
||||
: 'dashboard';
|
||||
setActiveSection(activeSection);
|
||||
} else {
|
||||
const activeSection: CabinetSection = VALID_SECTIONS.includes(
|
||||
navItem as CabinetSection,
|
||||
)
|
||||
? (navItem as CabinetSection)
|
||||
: 'dashboard';
|
||||
setActiveSection(activeSection);
|
||||
}
|
||||
}, [navItemZustrand]);
|
||||
|
||||
const navigate = (section: CabinetSection) => {
|
||||
setActiveSection(section);
|
||||
setNavItem(section);
|
||||
setIsSidebarOpen(false);
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import PaymentStatus from './paidStatus';
|
||||
import Sertifikat from '@/features/modals/sertificateModal/sertifikat';
|
||||
|
||||
// ── Types ────────────────────────────────────────────────────────────────────
|
||||
const baseUrl = 'https://dev-api.anti-plagiat.uz/api/v1';
|
||||
const baseUrl = 'https://api.anti-plagiat.uz/api/v1';
|
||||
interface AnalyzeText {
|
||||
[key: string]: number | string;
|
||||
}
|
||||
@@ -399,10 +399,25 @@ export default function DocumentDetailPage({ id }: { id: number }) {
|
||||
<PaymentStatus status={doc.state} />
|
||||
<Sertifikat document_id={Number(id)} />
|
||||
{doc.file && (
|
||||
<a
|
||||
href={`${baseUrl}${doc.file}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
<button
|
||||
onClick={async () => {
|
||||
const url = `${baseUrl}/shared/documents/${doc.id}/download`;
|
||||
const res = await apiRequest<ArrayBuffer>(
|
||||
'GET',
|
||||
url,
|
||||
undefined,
|
||||
{ responseType: 'arraybuffer', baseURL: baseUrl },
|
||||
);
|
||||
const blob = new Blob([res.data], {
|
||||
type: 'application/pdf',
|
||||
});
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = objectUrl;
|
||||
a.download = `document-${id}.pdf`;
|
||||
a.click();
|
||||
setTimeout(() => URL.revokeObjectURL(objectUrl), 1000);
|
||||
}}
|
||||
className="inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-slate-900 text-white text-xs font-semibold hover:bg-slate-700 transition-colors"
|
||||
>
|
||||
<svg
|
||||
@@ -419,7 +434,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
|
||||
/>
|
||||
</svg>
|
||||
{t('downloadPdf')}
|
||||
</a>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -486,7 +501,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
|
||||
<div className="bg-white rounded-2xl border border-slate-100 shadow-sm p-8">
|
||||
<div className="flex flex-wrap justify-around gap-8">
|
||||
<ScoreRing
|
||||
value={res.ai}
|
||||
value={res.originality}
|
||||
label={t('scoreOriginality')}
|
||||
color="#10b981"
|
||||
/>
|
||||
@@ -502,7 +517,7 @@ export default function DocumentDetailPage({ id }: { id: number }) {
|
||||
color="#6366f1"
|
||||
/>
|
||||
<ScoreRing
|
||||
value={res.originality}
|
||||
value={res.ai}
|
||||
label={t('scoreAiContent')}
|
||||
color="#ef4444"
|
||||
/>
|
||||
|
||||
@@ -4,4 +4,5 @@ export interface MenuItem {
|
||||
description?: string;
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
items?: MenuItem[];
|
||||
key: string;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
'use client';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { MenuItem } from '../lib/model';
|
||||
|
||||
const SubMenuLink = ({
|
||||
@@ -7,11 +9,17 @@ const SubMenuLink = ({
|
||||
item: MenuItem;
|
||||
logOut?: () => void;
|
||||
}) => {
|
||||
const pathname = usePathname();
|
||||
const isCabinet = pathname.includes('/cabinet');
|
||||
|
||||
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={() => {
|
||||
href={isCabinet && item.url === '/cabinet' ? undefined : item.url}
|
||||
onClick={(e) => {
|
||||
if (isCabinet && item.url === '/cabinet') {
|
||||
e.preventDefault();
|
||||
}
|
||||
if (logOut) {
|
||||
logOut();
|
||||
}
|
||||
|
||||
@@ -2,37 +2,70 @@
|
||||
import { Link } from '@/shared/config/i18n/navigation';
|
||||
import { Button } from '@/shared/ui/button';
|
||||
import {
|
||||
NavigationMenu,
|
||||
NavigationMenuContent,
|
||||
NavigationMenuItem,
|
||||
NavigationMenuLink,
|
||||
NavigationMenuList,
|
||||
NavigationMenuTrigger,
|
||||
} from '@/shared/ui/navigation-menu';
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/shared/ui/dropdown-menu';
|
||||
import SubMenuLink from './SubMenuLink';
|
||||
import { ChangeLang } from './ChangeLang';
|
||||
import { useLoginModal, useRegisterModal } from '@/shared/zustand/auth';
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { useUserPlagiatStore } from '@/shared/zustand/user';
|
||||
import { LogOut, User } from 'lucide-react';
|
||||
import {
|
||||
ChevronDown,
|
||||
LogOut,
|
||||
User,
|
||||
LayoutDashboard,
|
||||
FileSearch,
|
||||
BrainCircuit,
|
||||
CreditCard,
|
||||
} from 'lucide-react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useCabinetNav } from '@/shared/zustand/cabinetNav';
|
||||
|
||||
function AuthButtons() {
|
||||
const t = useTranslations('Navbar');
|
||||
const t_cab = useTranslations('Cabinet');
|
||||
const setNavItem = useCabinetNav((state) => state.setNavItem);
|
||||
const [localUser, setLocalUser] = useState<{
|
||||
id: number;
|
||||
name: string;
|
||||
surname: string;
|
||||
} | null>(null);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const auth = {
|
||||
login: { title: t('login'), url: '#' },
|
||||
signup: { title: t('signup'), url: '#' },
|
||||
};
|
||||
|
||||
const userItem = [
|
||||
{ title: t('profile'), url: '/cabinet', icon: User },
|
||||
{ title: t('logout'), url: '/', icon: LogOut },
|
||||
{ title: t('profile'), url: '/cabinet', icon: User, key: 'profile' },
|
||||
{
|
||||
url: '/cabinet',
|
||||
title: t_cab('dashboard'),
|
||||
icon: LayoutDashboard,
|
||||
key: 'dashboard',
|
||||
},
|
||||
{
|
||||
url: '/cabinet',
|
||||
title: t_cab('plagiat'),
|
||||
icon: FileSearch,
|
||||
key: 'plagiat',
|
||||
},
|
||||
{
|
||||
url: '/cabinet',
|
||||
title: t_cab('siNav'),
|
||||
icon: BrainCircuit,
|
||||
key: 'si',
|
||||
},
|
||||
{
|
||||
url: '/cabinet',
|
||||
title: t_cab('payments'),
|
||||
icon: CreditCard,
|
||||
key: 'payments',
|
||||
},
|
||||
{ title: t('logout'), url: '/', icon: LogOut, key: 'logout' },
|
||||
];
|
||||
|
||||
const toggleLoginModal = useLoginModal((state) => state.toggleLoginModal);
|
||||
@@ -51,7 +84,6 @@ function AuthButtons() {
|
||||
|
||||
useEffect(() => {
|
||||
const data = localStorage.getItem('user');
|
||||
|
||||
if (data) {
|
||||
setLocalUser(JSON.parse(data));
|
||||
} else {
|
||||
@@ -65,33 +97,29 @@ function AuthButtons() {
|
||||
<div className="sm:flex hidden">
|
||||
<ChangeLang />
|
||||
</div>
|
||||
<NavigationMenu viewport={true}>
|
||||
<NavigationMenuList>
|
||||
<NavigationMenuItem>
|
||||
<NavigationMenuTrigger className="text-lg">
|
||||
{localUser.name}
|
||||
</NavigationMenuTrigger>
|
||||
<NavigationMenuContent className="bg-popover text-popover-foreground">
|
||||
{userItem.map((subItem) => (
|
||||
<NavigationMenuLink
|
||||
asChild
|
||||
key={subItem.title}
|
||||
className="w-80"
|
||||
>
|
||||
<SubMenuLink
|
||||
logOut={() => {
|
||||
if (subItem.url !== '/cabinet') {
|
||||
clearTokens();
|
||||
}
|
||||
}}
|
||||
item={subItem}
|
||||
/>
|
||||
</NavigationMenuLink>
|
||||
))}
|
||||
</NavigationMenuContent>
|
||||
</NavigationMenuItem>
|
||||
</NavigationMenuList>
|
||||
</NavigationMenu>
|
||||
<DropdownMenu open={open} onOpenChange={setOpen}>
|
||||
<DropdownMenuTrigger className="inline-flex items-center gap-1 text-lg font-medium outline-none">
|
||||
{localUser.name}
|
||||
<ChevronDown className="size-4" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="">
|
||||
{userItem.map((subItem) => (
|
||||
<DropdownMenuItem key={subItem.title} asChild>
|
||||
<SubMenuLink
|
||||
logOut={() => {
|
||||
setOpen(false);
|
||||
if (subItem.url !== '/cabinet') {
|
||||
clearTokens();
|
||||
} else {
|
||||
setNavItem(subItem.key);
|
||||
}
|
||||
}}
|
||||
item={subItem}
|
||||
/>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user