import { useSelector } from 'react-redux'; import { toast } from 'react-toastify'; import { RootState } from '../../../../app/store'; import SingleSelect from '../../../../components/SingleSelect'; import Table from '../../../../components/Table'; import TableLoading from '../../../../components/TableLoading'; import { useGetProductsQuery, useUpdateStockActionMutation } from '../../../../features/products/productsApi'; import QuantityChange from './components/QuantityChange'; import StockToggler from './components/StockToggler'; type RequestBody = { backorders?: string; stock_status?: string; }; const StockTable = () => { const { query } = useSelector((state: RootState) => state.products); const { data, isLoading } = useGetProductsQuery(query, { refetchOnMountOrArgChange: true, }); const unmanagedActions = { instock: 'In Stock', outofstock: 'Out of Stock', onbackorder: 'On Backorder', }; const managedActions = { no: 'Do Not Allow', notify: 'Allow, Notify Customer', yes: 'Allow', }; const [updateStockAction, { isLoading: togglerStatusLoading }] = useUpdateStockActionMutation(); const handleStockAction = async (stockStatus: string, id: number, wcStock: string | boolean) => { const body: RequestBody = {}; if (wcStock) { body.backorders = stockStatus; } else { body.stock_status = stockStatus; } const result = await updateStockAction({ id, body, }).unwrap(); if (result) { toast.success('Stock Status Updated'); } }; return (