add header

This commit is contained in:
smanylov
2025-11-26 14:01:35 +07:00
parent 7a8c2cee56
commit ebca795c1b
16 changed files with 618 additions and 41 deletions
+14
View File
@@ -1,5 +1,19 @@
'use server'
const FRUITS_URL = 'https://www.fruityvice.com/api/fruit/';
const ALL = 'all'
export async function fetchFruits() {
try {
const response = await fetch(FRUITS_URL + ALL, { 'method': 'GET' });
let parsed = await response.json();
return parsed;
} catch (error) {
console.error('Error:', error);
throw new Error('Failed to fetch fruits data.');
}
}
export async function testConnect() {
try {
const response = await fetch('http://localhost:8080/api/auth/register', {
+24
View File
@@ -0,0 +1,24 @@
'use client';
import { useEffect, RefObject } from 'react';
export function useClickOutside(
ref: RefObject<HTMLDivElement | null>,
callback: () => void
) {
useEffect(() => {
const handleClick = (event: MouseEvent) => {
if (!ref) {
return;
}
if (ref.current && !ref.current.contains(event.target as Node)) {
callback();
}
};
document.addEventListener('mousedown', handleClick);
return () => {
document.removeEventListener('mousedown', handleClick);
};
}, [ref, callback]);
}
+2 -1
View File
@@ -1,5 +1,6 @@
import type { Metadata } from "next";
import "./globals.css";
import "./styles/globals.css";
import "./styles/global-styles.scss"
export const metadata: Metadata = {
title: "No copy",
+4
View File
@@ -1,3 +1,7 @@
.mainContainter {
margin-left: 280px;
flex: 1;
padding: 30px;
background: #f8f9ff;
min-height: 100vh;
}
+8 -5
View File
@@ -1,5 +1,7 @@
import { Metadata } from 'next';
import Button from '@/app/ui/button'
import { Suspense } from 'react';
import ButtonTest from '@/app/ui/button-test'
import ProtectionOverview from '@/app/ui/dashboard/protection-overview';
export const metadata: Metadata = {
title: 'Dashboard',
@@ -9,10 +11,11 @@ export default function Home() {
return (
<div>
<main>
<div>
Dashboard
</div>
<Button/>
<Suspense fallback={<>...</>}>
<h1 className="page-title">Статистика</h1>
<ProtectionOverview/>
{/* <ButtonTest /> */}
</Suspense>
</main>
</div>
);
+7 -1
View File
@@ -1,11 +1,17 @@
import NavLinks from '@/app/ui/nav-links'
import styles from '@/app/page.module.scss'
import HeaderPanel from '../ui/header/headerPanel';
export default function Layout({ children }: { children: React.ReactNode }) {
return (
<div className="flex">
<NavLinks />
<div className={`${styles.mainContainter}`}>{children}</div>
<div className={`${styles.mainContainter}`}>
<HeaderPanel />
<main>
{children}
</main>
</div>
</div>
);
}
+30
View File
@@ -0,0 +1,30 @@
.page-title {
font-size: 28px;
font-weight: 600;
margin-bottom: 30px;
display: flex;
align-items: center;
color: #1f2937;
&::before {
content: '';
width: 8px;
height: 8px;
background: #6366f1;
border-radius: 50%;
margin-right: 15px;
}
}
.protection-overview {
h3 {
margin: 0 0 10px 0;
font-size: 20px;
}
p {
margin: 0;
opacity: 0.9;
font-size: 14px;
}
}
+2
View File
@@ -0,0 +1,2 @@
@use './header.scss';
@use './dashboard.scss';
+306
View File
@@ -0,0 +1,306 @@
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
background: white;
padding: 20px 30px;
border-radius: 20px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
.header-action {
display: flex;
align-items: center;
gap: 15px;
.icon-btn {
width: 40px;
height: 40px;
border-radius: 50%;
background: #f8f9fa;
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s;
position: relative;
&:hover {
background: #e9ecef;
transform: translateY(-2px);
}
}
}
.search-bar {
display: flex;
align-items: center;
background: #f8f9fa;
border-radius: 20px;
padding: 10px 20px;
width: 300px;
transition: all 0.3s;
input {
border: none;
outline: none;
flex: 1;
margin-left: 10px;
font-size: 14px;
background: transparent;
}
}
.notification-wrapper,
.user-menu,
.tokens-balance {
position: relative;
}
.tokens-balance {
margin-right: 15px;
}
.tokens-wrapper {
display: flex;
align-items: center;
gap: 6px;
background: white;
color: #6366f1;
border: 2px solid #6366f1;
padding: 8px 12px;
border-radius: 20px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
font-size: 12px;
font-weight: 600;
min-width: 110px;
}
.tokens-count {
font-weight: 700;
font-size: 14px;
letter-spacing: 0.5px;
}
.tokens-label {
font-weight: 500;
opacity: 0.9;
}
.notification-dropdown,
.user-dropdown {
position: absolute;
top: calc(100% + 10px);
right: 0;
background: white;
border-radius: 12px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
min-width: 320px;
opacity: 0;
visibility: hidden;
transform: translateY(-10px);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
z-index: 1000;
&.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
}
.notification-dropdown {
.notification-header {
padding: 15px 20px;
border-bottom: 1px solid #f3f4f6;
display: flex;
justify-content: space-between;
align-items: center;
h4 {
margin: 0;
font-size: 16px;
font-weight: 600;
color: #1f2937;
}
.notification-count {
font-size: 12px;
color: #6366f1;
font-weight: 500;
}
}
.notification-list {
max-height: 400px;
overflow-y: auto;
}
.notification-item {
display: flex;
gap: 12px;
padding: 15px 20px;
border-bottom: 1px solid #f9fafb;
transition: background-color 0.2s;
cursor: pointer;
}
.notification-title {
display: block;
font-size: 15px;
font-weight: 700;
color: #1f2937;
margin-bottom: 6px;
}
.notification-icon {
font-size: 24px;
flex-shrink: 0;
}
.notification-text {
font-size: 13px;
color: #4b5563;
margin-bottom: 4px;
font-weight: 500;
}
.notification-time {
font-size: 12px;
color: #9ca3af;
}
.notification-footer {
padding: 12px 20px;
border-top: 1px solid #f3f4f6;
text-align: center;
.notification-link {
color: #6366f1;
font-size: 14px;
font-weight: 500;
text-decoration: none;
}
}
}
.user-menu {
.user-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(45deg, #6366f1, #8b5cf6);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
}
.user-dropdown {
min-width: 280px;
}
.user-info-header {
padding: 20px;
border-bottom: 1px solid #f3f4f6;
display: flex;
gap: 15px;
align-items: center;
}
.user-avatar-large {
width: 50px;
height: 50px;
background: linear-gradient(135deg, #6366f1, #8b5cf6);
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: 600;
font-size: 20px;
flex-shrink: 0;
}
.user-details {
flex: 1;
min-width: 0;
}
.user-name {
font-weight: 600;
font-size: 15px;
color: #1f2937;
margin-bottom: 4px;
}
.user-email {
font-size: 13px;
color: #6b7280;
margin-bottom: 8px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.user-subscription {
display: inline-block;
}
.user-menu-items {
padding: 10px 0;
}
.user-menu-item {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #374151;
transition: background-color 0.2s;
svg {
width: 18px;
height: 18px;
margin-right: 12px;
}
}
.subscription-badge {
display: inline-block;
padding: 4px 10px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.user-menu-footer {
border-top: 1px solid #f3f4f6;
padding: 10px 0;
}
.user-menu-logout {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #dc2626;
transition: background-color 0.2s;
svg {
width: 18px;
height: 18px;
margin-right: 12px;
}
}
}
}
@@ -3,13 +3,12 @@
import { testConnect } from '@/app/api/action';
async function clickHandler() {
console.log('click');
testConnect();
}
export default function Button() {
export default function ButtonTest() {
return (
<button onClick={() => {
<button className='border-2 cursor-pointer' onClick={() => {
clickHandler();
}}>button</button>
);
@@ -0,0 +1,8 @@
export default function ProtectionOverview() {
return (
<div className="protection-overview">
<h3>Защита вашего контента</h3>
<p>Текущий статус защищенности и активности системы мониторинга</p>
</div>
)
}
+38
View File
@@ -0,0 +1,38 @@
import NotificationsButton from './notificationsButton';
import UserMenuButton from './userMenuButton';
import Link from 'next/link';
export default function HeaderPanel() {
return (
<header className="header">
<div className="search-bar">
<svg viewBox="0 0 24 24" fill="currentColor" style={{ width: "20px", height: "20px", color: "#9ca3af" }}>
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
</svg>
<input type="text" placeholder="Поиск контента..." id="global-search" />
</div>
<div className="header-action">
<div className="tokens-balance">
<div className="tokens-wrapper" title="Текущий баланс токенов для защиты файлов">
<svg viewBox="0 0 24 24" fill="currentColor" style={{ width: "16px", height: "16px" }}>
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 16c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4-1.79 4-4 4z"></path>
</svg>
<span className="tokens-count">800</span>
<span className="tokens-label">токенов</span>
</div>
</div>
<NotificationsButton />
<Link
className="icon-btn"
title="Быстрые настройки"
href="/pages/dashboard"
>
<svg viewBox="0 0 24 24" fill="currentColor" style={{ width: "20px", height: "20px" }}>
<path d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.82,11.69,4.82,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z"></path>
</svg>
</Link>
<UserMenuButton />
</div>
</header>
)
}
+87
View File
@@ -0,0 +1,87 @@
"use client"
import { useState, useRef } from 'react';
import { fetchFruits } from '@/app/api/action';
import { useClickOutside } from '@/app/hooks/useClickOutside';
import Link from 'next/link';
export default function NotificationsButton() {
const [isOpen, setIsOpen] = useState(false);
const [data, setData] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const menuRef = useRef<HTMLDivElement | null>(null);
useClickOutside(menuRef, () => {
setIsOpen(false);
});
const fetchData = async () => {
setLoading(true);
setError(null);
try {
const result = await fetchFruits();
setData("result");
setIsOpen(true);
} catch (err) {
setError('error message');
} finally {
setLoading(false);
}
};
const handleButtonClick = () => {
if (!isOpen) {
fetchData();
} else {
setIsOpen(false);
}
};
return (
<div className="notification-wrapper" ref={menuRef}>
<button
className="icon-btn"
id="notifications-btn"
title="Уведомления"
onClick={handleButtonClick}
>
<svg viewBox="0 0 24 24" fill="currentColor" style={{ width: "20px", height: "20px" }}>
<path d="M12 22c1.1 0 2-.9 2-2h-4c0 1.1.89 2 2 2zm6-6v-5c0-3.07-1.64-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.63 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2z"></path>
</svg>
</button>
<div className={`notification-dropdown ${isOpen ? 'show' : ''}`}>
{error ? (
<div className="p-4 text-red-500">{error}</div>
) : (
<>
<div className='notification-header'>
<h4>Уведомления</h4>
<span className="notification-count">Нет новых</span>
</div>
{data ? (
<div className="notification-list">
<div className="notification-item">
<div className="notification-icon"></div>
<div className="notification-content">
<div className="notification-title">🪙 Токены добавлены</div>
<div className="notification-text">На ваш баланс добавлено 100 токенов. Теперь вы можете защитить ещё больше файлов!</div>
<div className="notification-time">4 дн назад</div>
</div>
</div>
{JSON.stringify(data)}
</div>
) : (
<p>Нет данных</p>
)}
<div className="notification-footer">
<Link href="/pages/notifications.php" className="notification-link">Посмотреть все</Link>
</div>
</>
)}
</div>
</div>
)
}
+84
View File
@@ -0,0 +1,84 @@
'use client'
import { useState, useRef } from 'react';
import { useClickOutside } from '@/app/hooks/useClickOutside';
import Link from 'next/link';
export default function UserMenuButton() {
const [isOpen, setIsOpen] = useState(false);
const menuRef = useRef<HTMLDivElement | null>(null);
useClickOutside(menuRef, () => {
setIsOpen(false);
});
const handleButtonClick = () => {
if (!isOpen) {
setIsOpen(true);
} else {
setIsOpen(false);
}
};
return (
<div
className='user-menu'
onClick={handleButtonClick}
ref={menuRef}
>
<div className="user-avatar" id="user-menu-btn" title="Валерка">
User
</div>
<div className={`user-dropdown ${isOpen ? 'show' : ''}`} id="user-dropdown">
<div className="user-info-header">
<div className="user-avatar-large">User</div>
<div className="user-details">
<div className="user-name">Валерка</div>
<div className="user-email">va@no-copy.ru</div>
<div className="user-subscription">
<span className="subscription-badge">
СТАРТ</span>
</div>
</div>
</div>
<div className="user-menu-items">
<Link href="/pages/dashboard" className="user-menu-item">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z"></path>
</svg>
Главная
</Link>
<Link href="/pages/settings" className="user-menu-item">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.82,11.69,4.82,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z"></path>
</svg>
Настройки
</Link>
<Link href="/pages/content" className="user-menu-item">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M20 6h-2.18c.11-.31.18-.65.18-1a2.996 2.996 0 0 0-5.5-1.65l-.5.67-.5-.68C10.96 2.54 10 2 9 2 7.34 2 6 3.34 6 5c0 .35.07.69.18 1H4c-1.11 0-1.99.89-1.99 2L2 19c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V8c0-1.11-.89-2-2-2zm-5-2c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zM9 4c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1z"></path>
</svg>
Мой контент
</Link>
<Link href="/pages/faq" className="user-menu-item">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z"></path>
</svg>
Помощь
</Link>
</div>
<div className="user-menu-footer">
<Link href="/logout" className="user-menu-logout">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M17 7l-1.41 1.41L18.17 11H8v2h10.17l-2.58 2.58L17 17l5-5zM4 5h8V3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h8v-2H4V5z"></path>
</svg>
Выйти
</Link>
</div>
</div>
</div>
);
};