add flag in param in component to show the cancelled option import { Alert,…
- User
add flag in param in component to show the cancelled option
import { Alert, Autocomplete, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, FormControlLabel, Grid, IconButton, MenuItem, Paper, Radio, RadioGroup, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, Typography } from "@mui/material"; import { IconTrash } from "@tabler/icons-react"; import Image from "next/image"; import { useCallback, useEffect, useState } from "react"; import { useAddTransfer, useGetOrgProducts } from "../../store/inventory.store"; import { useGetWarehouse } from "../../store/warehouse.store"; import { TRANSFER_STATUS_OPTIONS } from "../../utils/constants"; import { TruncatedText } from "../common/truncatedText"; import CustomFormLabel from "../forms/theme-elements/CustomFormLabel"; import CustomSelect from "../forms/theme-elements/CustomSelect";
interface InventoryStockTransferProps { open: boolean; onClose: () => void; onSuccess: () => void; productId?: string; }
const InventoryStockTransfer: React.FC = ({ open, onClose, productId, onSuccess }) => { const [selectedProducts, setSelectedProducts] = useState<DTO.ProductDetail[]>([]); const [searchValue, setSearchValue] = useState(""); const [searchResults, setSearchResults] = useState<DTO.ProductDetail[]>([]); const [productError, setProductError] = useState(); const [status, setStatus] = useState(""); const [fromWarehouseId, setFromWarehouseId] = useState(); const [toWarehouseId, setToWarehouseId] = useState(); const [notes, setNotes] = useState(""); // Added state for notes const { getOrgProducts, isLoading } = useGetOrgProducts(); const { getWarehouse, warehouses, isLoading: isLoadingWarehouse } = useGetWarehouse(); const { addTransfer, isLoading: isSaving } = useAddTransfer();
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 handleTransfer = () => { if (!fromWarehouseId || !toWarehouseId) { setProductError("Please choose warehouses to continue"); return; }
if (fromWarehouseId === toWarehouseId) { setProductError("From and To warehouse cannot be the same"); return; } if (selectedProducts.length < 1) { setProductError("Please add at least one product"); return; } addTransfer({ fromWarehouseId, toWarehouseId, status, notes, // Include notes in the transfer data items: selectedProducts.map((product) => ({ productId: product.id, qty: product.minQuantity || 1 })) }, { onSuccess: () => { onSuccess(); } }); - Assistant
- User
select Draft by default
- Assistant