mirror of
https://github.com/inventree/InvenTree.git
synced 2025-11-30 01:10:00 +00:00
[UI] Delete stock fix (#10868)
* Add helper func getOverviewUrl * Redirect to parent page when stock item is counted to zero
This commit is contained in:
@@ -7,6 +7,28 @@ import { cancelEvent } from './Events';
|
||||
export const getBaseUrl = (): string =>
|
||||
(window as any).INVENTREE_SETTINGS?.base_url || 'web';
|
||||
|
||||
/**
|
||||
* Returns the overview URL for a given model type.
|
||||
* This is the UI URL, not the API URL.
|
||||
*/
|
||||
export function getOverviewUrl(model: ModelType, absolute?: boolean): string {
|
||||
const modelInfo = ModelInformationDict[model];
|
||||
|
||||
if (modelInfo?.url_overview) {
|
||||
const url = modelInfo.url_overview;
|
||||
const base = getBaseUrl();
|
||||
|
||||
if (absolute && base) {
|
||||
return `/${base}${url}`;
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
console.error(`No overview URL found for model ${model}`);
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the detail view URL for a given model type.
|
||||
* This is the UI URL, not the API URL.
|
||||
|
||||
@@ -32,7 +32,7 @@ import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
||||
import { ModelType } from '@lib/enums/ModelType';
|
||||
import { UserRoles } from '@lib/enums/Roles';
|
||||
import { apiUrl } from '@lib/functions/Api';
|
||||
import { getDetailUrl } from '@lib/functions/Navigation';
|
||||
import { getDetailUrl, getOverviewUrl } from '@lib/functions/Navigation';
|
||||
import type { StockOperationProps } from '@lib/types/Forms';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { useBarcodeScanDialog } from '../../components/barcodes/BarcodeScanDialog';
|
||||
@@ -730,7 +730,20 @@ export default function StockDetail() {
|
||||
return {
|
||||
items: [stockitem],
|
||||
model: ModelType.stockitem,
|
||||
refresh: refreshInstance,
|
||||
refresh: () => {
|
||||
const location = stockitem?.location;
|
||||
refreshInstancePromise().then((response) => {
|
||||
if (response.status == 'error') {
|
||||
// If an error occurs refreshing the instance,
|
||||
// the stock likely has likely been depleted
|
||||
if (location) {
|
||||
navigate(getDetailUrl(ModelType.stocklocation, location));
|
||||
} else {
|
||||
navigate(getOverviewUrl(ModelType.stockitem));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
filters: {
|
||||
in_stock: true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user