import React, {useMemo, useState} from "react"; import {useAppStore} from "../appstore"; import {Box, Button, Stack, Collapsible} from "@chakra-ui/react"; import {toast} from "../components/ui/toaster"; import {PrimaryButton} from "../components/primaryButton"; import {LuChevronDown, LuChevronUp, LuTriangleAlert} from "react-icons/lu"; export function NotificationsArea() { const { unresolvedSkus, setUnresolvedSkus, orderList, capQuantitiesToStock, } = useAppStore(); const [lowStockDismissed, setLowStockDismissed] = useState(false); const [isExpanded, setIsExpanded] = useState(true); const lowStockItems = useMemo(() => { return orderList.filter(item => item.stock_quantity != null && item.quantity > item.stock_quantity ); }, [orderList]); const hasUnresolvedSkus = unresolvedSkus.length > 0; const hasLowStock = lowStockItems.length > 0 && !lowStockDismissed; const notificationCount = [hasLowStock, hasUnresolvedSkus].filter(Boolean).length; if (notificationCount === 0) { return null; } return ( {/* @ts-expect-error chakra dialog typing issue */} {hasUnresolvedSkus && ( {unresolvedSkus.length} SKU(s) could not be resolved {unresolvedSkus.slice(0, 10).map((sku, i) => ( {sku} ))} {unresolvedSkus.length > 10 && ( …and {unresolvedSkus.length - 10} more )} )} {hasLowStock && ( Low stock warning {lowStockItems.length} item{lowStockItems.length > 1 ? 's' : ''} exceed{lowStockItems.length === 1 ? 's' : ''} available stock { const adjustedCount = capQuantitiesToStock(); toast({ type: "success", title: "Quantities adjusted", description: `${adjustedCount} item${adjustedCount > 1 ? 's' : ''} set to available stock`, }); }} > Set all to available {lowStockItems.slice(0, 10).map((item, i) => ( { const row = document.querySelector(`[data-sku="${item.sku}"]`) as HTMLElement; if (row) { row.scrollIntoView({behavior: "smooth", block: "center"}); // Add highlight animation row.style.animation = "none"; setTimeout(() => { row.style.animation = "highlight 1.5s ease-out"; }, 10); // Remove animation after it completes setTimeout(() => { row.style.animation = ""; }, 1600); } }} > {item.sku} (need {item.quantity}, have {item.stock_quantity}) ))} {lowStockItems.length > 10 && ( …and {lowStockItems.length - 10} more )} )} ); }