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