pelagia-portal/App/pelagia-portal/components/layout/header.tsx
Hardik 2fcf35235a feat(cart): header cart icon with badge + fix PO pre-population from cart
Cart icon:
- CartIcon component in header: listens to cart-updated events, shows
  item count badge, navigates to /inventory/cart on click
- Visible for TECHNICAL, MANNING, SUPERUSER, MANAGER roles only

PO pre-population:
- /po/new page reads ?cart= searchParam, parses CartItem[] into
  LineItemInput[], passes as initialLineItems prop to NewPoForm
- NewPoForm accepts initialLineItems and seeds useState from them
  instead of always starting with one blank row
- Cart is cleared immediately when "Create Purchase Order" is clicked
  so re-visiting cart doesn't re-submit the same items

Cart fixes:
- Empty state and "Add more items" links corrected from /admin/products
  to /inventory/items and /inventory/vendors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 23:56:38 +05:30

44 lines
1.4 KiB
TypeScript

"use client";
import { signOut } from "next-auth/react";
import { LogOut } from "lucide-react";
import type { Role } from "@prisma/client";
import { CartIcon } from "./cart-icon";
const ROLE_LABELS: Record<Role, string> = {
TECHNICAL: "Technical",
MANNING: "Manning",
ACCOUNTS: "Accounts",
MANAGER: "Manager",
SUPERUSER: "SuperUser",
AUDITOR: "Auditor",
ADMIN: "Admin",
};
const CART_ROLES: Role[] = ["TECHNICAL", "MANNING", "SUPERUSER", "MANAGER"];
interface HeaderProps {
user: { name: string; email: string; role: Role };
}
export function Header({ user }: HeaderProps) {
return (
<header className="flex h-16 items-center justify-between border-b border-neutral-200 bg-white px-6">
<div />
<div className="flex items-center gap-2">
{CART_ROLES.includes(user.role) && <CartIcon />}
<div className="text-right ml-2">
<p className="text-sm font-medium text-neutral-900">{user.name}</p>
<p className="text-xs text-neutral-500">{ROLE_LABELS[user.role]}</p>
</div>
<button
onClick={() => signOut({ callbackUrl: "/login" })}
className="flex items-center gap-1.5 rounded-lg p-2 text-neutral-500 hover:bg-neutral-100 hover:text-neutral-700 transition-colors"
title="Sign out"
>
<LogOut className="h-4 w-4" />
</button>
</div>
</header>
);
}