fix UI 1
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
ProductTransformationResponse,
|
||||
ProductionStage,
|
||||
DeletionSummary,
|
||||
BulkStockResponse,
|
||||
} from '../types/inventory';
|
||||
import { ApiError } from '../client';
|
||||
|
||||
@@ -342,7 +343,7 @@ export const useAddStock = (
|
||||
options?: UseMutationOptions<StockResponse, ApiError, { tenantId: string; stockData: StockCreate }>
|
||||
) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
return useMutation<StockResponse, ApiError, { tenantId: string; stockData: StockCreate }>({
|
||||
mutationFn: ({ tenantId, stockData }) => inventoryService.addStock(tenantId, stockData),
|
||||
onSuccess: (data, { tenantId }) => {
|
||||
@@ -355,6 +356,30 @@ export const useAddStock = (
|
||||
});
|
||||
};
|
||||
|
||||
export const useBulkAddStock = (
|
||||
options?: UseMutationOptions<BulkStockResponse, ApiError, { tenantId: string; stocks: StockCreate[] }>
|
||||
) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<BulkStockResponse, ApiError, { tenantId: string; stocks: StockCreate[] }>({
|
||||
mutationFn: ({ tenantId, stocks }) => inventoryService.bulkAddStock(tenantId, stocks),
|
||||
onSuccess: (data, { tenantId }) => {
|
||||
// Invalidate all stock queries since multiple ingredients may have been affected
|
||||
queryClient.invalidateQueries({ queryKey: inventoryKeys.stock.lists() });
|
||||
queryClient.invalidateQueries({ queryKey: inventoryKeys.ingredients.lists() });
|
||||
// Invalidate per-ingredient stock queries
|
||||
data.results.forEach((result) => {
|
||||
if (result.success && result.stock) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: inventoryKeys.stock.byIngredient(tenantId, result.stock.ingredient_id)
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateStock = (
|
||||
options?: UseMutationOptions<
|
||||
StockResponse,
|
||||
|
||||
Reference in New Issue
Block a user