import { Alert, Autocomplete, Box, Button, CircularProgress, Dialog, DialogActions,…
- User
import { Alert, Autocomplete, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, Grid, IconButton, MenuItem, TextField, Typography } from "@mui/material"; import { IconTrash } from "@tabler/icons-react"; import Image from "next/image"; import { useCallback, useEffect, useState } from "react"; import { useAddAdjustment, useGetOrgProducts } from "../../store/inventory.store"; import { useGetWarehouse } from "../../store/warehouse.store"; import { REASON_OPTIONS } from "../../utils/constants"; import { TruncatedText } from "../common/truncatedText"; import CustomFormLabel from "../forms/theme-elements/CustomFormLabel"; import CustomSelect from "../forms/theme-elements/CustomSelect"; import CustomTextField from "../forms/theme-elements/CustomTextField";
interface InventoryStockAdjustmentProps { open: boolean; onClose: () => void; onSuccess: () => void; productId?: string; }
const InventoryStockAdjustment: React.FC = ({ open, onClose, productId, onSuccess }) => { const [selectedProduct, setSelectedProduct] = useState<DTO.ProductDetail | null>(null); const [searchValue, setSearchValue] = useState(""); const [searchResults, setSearchResults] = useState<DTO.ProductDetail[]>([]); const [productError, setProductError] = useState(); const [warehouseId, setWarehouseId] = useState(); const [reason, setReason] = useState(); const [quantity, setQuantity] = useState(1); const { getOrgProducts, isLoading } = useGetOrgProducts(); const { getWarehouse, warehouses, isLoading: isLoadingWarehouse } = useGetWarehouse(); const { addAdjustment, isLoading: isSaving } = useAddAdjustment();
useEffect(() => { getWarehouse(); }, []);
const debounce = (func, delay) => { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => func(...args), delay); }; };
const fetchProducts = useCallback( debounce(async (query) => { if (query.trim()) { await getOrgProducts({ searchText: query }, { onSuccess: (response) => { setSearchResults(response.data.data); }, }); } }, 500), [] );
const handleSearchInputChange = (event, newInputValue) => { if (event?.type === 'change') { setSearchValue(newInputValue); setSearchResults([]); fetchProducts(newInputValue); } };
const handleAdjustment = () => { if (!warehouseId) { setProductError("Please choose a warehouse to continue"); return; }
codeif (!selectedProduct) { setProductError("Please add a product"); return; } addAdjustment({ warehouseId, reasonCode: reason as number, productId: selectedProduct.id, quantity: quantity || 1, inventoryId: '' }, { onSuccess: () => { onSuccess(); } });};
const handleAddProduct = (product) => { setSelectedProduct(product); setSearchValue(""); setProductError(""); };
- Assistant
- User
use startAdornment of MUI to show positive negative in red green
- Assistant