mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Code cleanup, convert promises to async/await. (#6726)
This commit is contained in:
parent
06c7ebfc21
commit
1d9b39ab33
@ -22,12 +22,9 @@ export function setApiDefaults() {
|
|||||||
|
|
||||||
api.defaults.baseURL = host;
|
api.defaults.baseURL = host;
|
||||||
api.defaults.timeout = 2500;
|
api.defaults.timeout = 2500;
|
||||||
|
api.defaults.headers.common['Authorization'] = token
|
||||||
if (!!token) {
|
? `Token ${token}`
|
||||||
api.defaults.headers.common['Authorization'] = `Token ${token}`;
|
: undefined;
|
||||||
} else {
|
|
||||||
api.defaults.headers.common['Authorization'] = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!getCsrfCookie()) {
|
if (!!getCsrfCookie()) {
|
||||||
api.defaults.withCredentials = true;
|
api.defaults.withCredentials = true;
|
||||||
|
@ -114,16 +114,14 @@ export function OptionsApiForm({
|
|||||||
props.pk,
|
props.pk,
|
||||||
props.pathParams
|
props.pathParams
|
||||||
],
|
],
|
||||||
queryFn: () =>
|
queryFn: async () => {
|
||||||
api.options(url).then((res) => {
|
let response = await api.options(url);
|
||||||
let fields: Record<string, ApiFormFieldType> | null = {};
|
let fields: Record<string, ApiFormFieldType> | null = {};
|
||||||
|
if (!props.ignorePermissionCheck) {
|
||||||
if (!props.ignorePermissionCheck) {
|
fields = extractAvailableFields(response, props.method);
|
||||||
fields = extractAvailableFields(res, props.method);
|
}
|
||||||
}
|
return fields;
|
||||||
|
},
|
||||||
return fields;
|
|
||||||
}),
|
|
||||||
throwOnError: (error: any) => {
|
throwOnError: (error: any) => {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
invalidResponse(error.response.status);
|
invalidResponse(error.response.status);
|
||||||
@ -134,7 +132,6 @@ export function OptionsApiForm({
|
|||||||
color: 'red'
|
color: 'red'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -37,20 +37,22 @@ export function Header() {
|
|||||||
const notifications = useQuery({
|
const notifications = useQuery({
|
||||||
queryKey: ['notification-count'],
|
queryKey: ['notification-count'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
return api
|
try {
|
||||||
.get(apiUrl(ApiEndpoints.notifications_list), {
|
const params = {
|
||||||
params: {
|
params: {
|
||||||
read: false,
|
read: false,
|
||||||
limit: 1
|
limit: 1
|
||||||
}
|
}
|
||||||
})
|
};
|
||||||
.then((response) => {
|
let response = await api.get(
|
||||||
setNotificationCount(response.data.count);
|
apiUrl(ApiEndpoints.notifications_list),
|
||||||
return response.data;
|
params
|
||||||
})
|
);
|
||||||
.catch((error) => {
|
setNotificationCount(response.data.count);
|
||||||
return error;
|
return response.data;
|
||||||
});
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
refetchInterval: 30000,
|
refetchInterval: 30000,
|
||||||
refetchOnMount: true,
|
refetchOnMount: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user