Изменен компонент уведомлений о новых заявках на уведомления о непринятых поставках. Обновлен GraphQL запрос для получения количества ожидающих поставок. Оптимизирована логика отображения уведомлений в боковой панели.
This commit is contained in:
@ -10,7 +10,7 @@ import { useQuery } from "@apollo/client";
|
||||
import {
|
||||
GET_CONVERSATIONS,
|
||||
GET_INCOMING_REQUESTS,
|
||||
GET_SUPPLY_ORDERS,
|
||||
GET_PENDING_SUPPLIES_COUNT,
|
||||
} from "@/graphql/queries";
|
||||
import {
|
||||
Settings,
|
||||
@ -27,32 +27,21 @@ import {
|
||||
BarChart3,
|
||||
} from "lucide-react";
|
||||
|
||||
// Компонент для отображения уведомлений о новых заявках
|
||||
function NewOrdersNotification() {
|
||||
const { user } = useAuth();
|
||||
|
||||
// Загружаем заказы поставок для поставщика
|
||||
const { data: ordersData } = useQuery(GET_SUPPLY_ORDERS, {
|
||||
pollInterval: 30000, // Обновляем каждые 30 секунд для заявок
|
||||
// Компонент для отображения уведомлений о непринятых поставках
|
||||
function PendingSuppliesNotification() {
|
||||
const { data: pendingData } = useQuery(GET_PENDING_SUPPLIES_COUNT, {
|
||||
pollInterval: 30000, // Обновляем каждые 30 секунд
|
||||
fetchPolicy: "cache-first",
|
||||
errorPolicy: "ignore",
|
||||
skip: user?.organization?.type !== "WHOLESALE",
|
||||
});
|
||||
|
||||
if (user?.organization?.type !== "WHOLESALE") return null;
|
||||
const pendingCount = pendingData?.pendingSuppliesCount?.total || 0;
|
||||
|
||||
const orders = ordersData?.supplyOrders || [];
|
||||
// Считаем заявки в статусе PENDING (ожидают одобрения поставщика)
|
||||
const pendingOrders = orders.filter(
|
||||
(order) =>
|
||||
order.status === "PENDING" && order.partnerId === user?.organization?.id
|
||||
);
|
||||
|
||||
if (pendingOrders.length === 0) return null;
|
||||
if (pendingCount === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="absolute -top-1 -right-1 bg-red-500 text-white text-xs rounded-full min-w-[18px] h-[18px] flex items-center justify-center font-bold animate-pulse">
|
||||
{pendingOrders.length > 99 ? "99+" : pendingOrders.length}
|
||||
{pendingCount > 99 ? "99+" : pendingCount}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -447,12 +436,14 @@ export function Sidebar() {
|
||||
isSuppliesActive
|
||||
? "bg-white/20 text-white hover:bg-white/30"
|
||||
: "text-white/80 hover:bg-white/10 hover:text-white"
|
||||
} cursor-pointer`}
|
||||
} cursor-pointer relative`}
|
||||
onClick={handleSuppliesClick}
|
||||
title={isCollapsed ? "Мои поставки" : ""}
|
||||
>
|
||||
<Truck className="h-4 w-4 flex-shrink-0" />
|
||||
{!isCollapsed && <span className="ml-3">Мои поставки</span>}
|
||||
{/* Уведомление о непринятых поставках */}
|
||||
<PendingSuppliesNotification />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@ -504,7 +495,7 @@ export function Sidebar() {
|
||||
isSuppliesActive
|
||||
? "bg-white/20 text-white hover:bg-white/30"
|
||||
: "text-white/80 hover:bg-white/10 hover:text-white"
|
||||
} cursor-pointer`}
|
||||
} cursor-pointer relative`}
|
||||
onClick={handleSuppliesClick}
|
||||
title={isCollapsed ? "Входящие поставки" : ""}
|
||||
>
|
||||
@ -512,6 +503,8 @@ export function Sidebar() {
|
||||
{!isCollapsed && (
|
||||
<span className="ml-3">Входящие поставки</span>
|
||||
)}
|
||||
{/* Уведомление о непринятых поставках */}
|
||||
<PendingSuppliesNotification />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@ -569,10 +562,8 @@ export function Sidebar() {
|
||||
>
|
||||
<Truck className="h-4 w-4 flex-shrink-0" />
|
||||
{!isCollapsed && <span className="ml-3">Заявки</span>}
|
||||
{/* Уведомление о новых заявках */}
|
||||
{user?.organization?.type === "WHOLESALE" && (
|
||||
<NewOrdersNotification />
|
||||
)}
|
||||
{/* Уведомление о непринятых поставках */}
|
||||
<PendingSuppliesNotification />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@ -586,12 +577,14 @@ export function Sidebar() {
|
||||
isSuppliesActive
|
||||
? "bg-white/20 text-white hover:bg-white/30"
|
||||
: "text-white/80 hover:bg-white/10 hover:text-white"
|
||||
} cursor-pointer`}
|
||||
} cursor-pointer relative`}
|
||||
onClick={handleSuppliesClick}
|
||||
title={isCollapsed ? "Перевозки" : ""}
|
||||
>
|
||||
<Truck className="h-4 w-4 flex-shrink-0" />
|
||||
{!isCollapsed && <span className="ml-3">Перевозки</span>}
|
||||
{/* Уведомление о непринятых поставках */}
|
||||
<PendingSuppliesNotification />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
|
Reference in New Issue
Block a user