diff --git a/src/authorities.ts b/src/authorities.ts index b3b75ce..57e4423 100644 --- a/src/authorities.ts +++ b/src/authorities.ts @@ -8,6 +8,7 @@ export const AUTH = { PACK: "PACK", ADMIN: "ADMIN", STOCK: "STOCK", + INVENTORY_ADJUST: "INVENTORY_ADJUST", PURCHASE: "PURCHASE", STOCK_TAKE: "STOCK_TAKE", STOCK_IN_BIND: "STOCK_IN_BIND", diff --git a/src/components/InventorySearch/InventoryLotLineTable.tsx b/src/components/InventorySearch/InventoryLotLineTable.tsx index 436d786..46d8fdc 100644 --- a/src/components/InventorySearch/InventoryLotLineTable.tsx +++ b/src/components/InventorySearch/InventoryLotLineTable.tsx @@ -33,6 +33,8 @@ import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; import dayjs from "dayjs"; import CheckIcon from "@mui/icons-material/Check"; import { submitStockAdjustment, StockAdjustmentLineRequest } from "@/app/api/stockAdjustment/actions"; +import { useSession } from "next-auth/react"; +import { AUTH } from "@/authorities"; type AdjustmentEntry = InventoryLotLineResult & { adjustedQty: number; @@ -64,6 +66,10 @@ const InventoryLotLineTable: React.FC = ({ onStockAdjustmentSuccess, }) => { const { t } = useTranslation(["inventory"]); + const { data: session } = useSession(); + const abilities = session?.user?.abilities ?? []; + const canStockAdjust = + abilities.includes(AUTH.ADMIN) || abilities.includes(AUTH.INVENTORY_ADJUST); const PRINT_PRINTER_ID_KEY = 'inventoryLotLinePrintPrinterId'; const { setIsUploading } = useUploadContext(); const [stockTransferModalOpen, setStockTransferModalOpen] = useState(false); @@ -529,7 +535,7 @@ const prevAdjustmentModalOpenRef = useRef(false); {inventory ? `${t("Item selected")}: ${inventory.itemCode} | ${inventory.itemName} (${t(inventory.itemType)})` : t("No items are selected yet.")} -{inventory && ( +{inventory && canStockAdjust && ( } label={t("Stock Adjustment")}