mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
fix refreshInstance type and remove return (#8478)
* fix refreshInstance type and remove return * Add seperate refresh function with promise as return --------- Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
parent
3a81e0380d
commit
ad6f8596eb
@ -8,7 +8,8 @@ import { type PathParams, apiUrl } from '../states/ApiState';
|
||||
export interface UseInstanceResult {
|
||||
instance: any;
|
||||
setInstance: (instance: any) => void;
|
||||
refreshInstance: () => Promise<QueryObserverResult<any, any>>;
|
||||
refreshInstance: () => void;
|
||||
refreshInstancePromise: () => Promise<QueryObserverResult<any, any>>;
|
||||
instanceQuery: any;
|
||||
requestStatus: number;
|
||||
isLoaded: boolean;
|
||||
@ -23,6 +24,7 @@ export interface UseInstanceResult {
|
||||
* To use this hook:
|
||||
* const { instance, refreshInstance } = useInstance(url: string, pk: number)
|
||||
*/
|
||||
|
||||
export function useInstance<T = any>({
|
||||
endpoint,
|
||||
pk,
|
||||
@ -112,12 +114,19 @@ export function useInstance<T = any>({
|
||||
);
|
||||
}, [instanceQuery]);
|
||||
|
||||
const refreshInstance = useCallback(() => instanceQuery.refetch(), []);
|
||||
const refreshInstance = useCallback(() => {
|
||||
instanceQuery.refetch();
|
||||
}, []);
|
||||
|
||||
const refreshInstancePromise = useCallback(() => {
|
||||
return instanceQuery.refetch();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
instance,
|
||||
setInstance,
|
||||
refreshInstance,
|
||||
refreshInstancePromise,
|
||||
instanceQuery,
|
||||
requestStatus,
|
||||
isLoaded
|
||||
|
@ -91,6 +91,7 @@ export default function StockDetail() {
|
||||
const {
|
||||
instance: stockitem,
|
||||
refreshInstance,
|
||||
refreshInstancePromise,
|
||||
instanceQuery,
|
||||
requestStatus
|
||||
} = useInstance({
|
||||
@ -617,7 +618,7 @@ export default function StockDetail() {
|
||||
},
|
||||
onFormSuccess: () => {
|
||||
const partId = stockitem.part;
|
||||
refreshInstance().catch(() => {
|
||||
refreshInstancePromise().catch(() => {
|
||||
// Part may have been deleted - redirect to the part detail page
|
||||
navigate(getDetailUrl(ModelType.part, partId));
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user