mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +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 {
|
export interface UseInstanceResult {
|
||||||
instance: any;
|
instance: any;
|
||||||
setInstance: (instance: any) => void;
|
setInstance: (instance: any) => void;
|
||||||
refreshInstance: () => Promise<QueryObserverResult<any, any>>;
|
refreshInstance: () => void;
|
||||||
|
refreshInstancePromise: () => Promise<QueryObserverResult<any, any>>;
|
||||||
instanceQuery: any;
|
instanceQuery: any;
|
||||||
requestStatus: number;
|
requestStatus: number;
|
||||||
isLoaded: boolean;
|
isLoaded: boolean;
|
||||||
@ -23,6 +24,7 @@ export interface UseInstanceResult {
|
|||||||
* To use this hook:
|
* To use this hook:
|
||||||
* const { instance, refreshInstance } = useInstance(url: string, pk: number)
|
* const { instance, refreshInstance } = useInstance(url: string, pk: number)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function useInstance<T = any>({
|
export function useInstance<T = any>({
|
||||||
endpoint,
|
endpoint,
|
||||||
pk,
|
pk,
|
||||||
@ -112,12 +114,19 @@ export function useInstance<T = any>({
|
|||||||
);
|
);
|
||||||
}, [instanceQuery]);
|
}, [instanceQuery]);
|
||||||
|
|
||||||
const refreshInstance = useCallback(() => instanceQuery.refetch(), []);
|
const refreshInstance = useCallback(() => {
|
||||||
|
instanceQuery.refetch();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const refreshInstancePromise = useCallback(() => {
|
||||||
|
return instanceQuery.refetch();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
instance,
|
instance,
|
||||||
setInstance,
|
setInstance,
|
||||||
refreshInstance,
|
refreshInstance,
|
||||||
|
refreshInstancePromise,
|
||||||
instanceQuery,
|
instanceQuery,
|
||||||
requestStatus,
|
requestStatus,
|
||||||
isLoaded
|
isLoaded
|
||||||
|
@ -91,6 +91,7 @@ export default function StockDetail() {
|
|||||||
const {
|
const {
|
||||||
instance: stockitem,
|
instance: stockitem,
|
||||||
refreshInstance,
|
refreshInstance,
|
||||||
|
refreshInstancePromise,
|
||||||
instanceQuery,
|
instanceQuery,
|
||||||
requestStatus
|
requestStatus
|
||||||
} = useInstance({
|
} = useInstance({
|
||||||
@ -617,7 +618,7 @@ export default function StockDetail() {
|
|||||||
},
|
},
|
||||||
onFormSuccess: () => {
|
onFormSuccess: () => {
|
||||||
const partId = stockitem.part;
|
const partId = stockitem.part;
|
||||||
refreshInstance().catch(() => {
|
refreshInstancePromise().catch(() => {
|
||||||
// Part may have been deleted - redirect to the part detail page
|
// Part may have been deleted - redirect to the part detail page
|
||||||
navigate(getDetailUrl(ModelType.part, partId));
|
navigate(getDetailUrl(ModelType.part, partId));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user