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.timeout = 2500;
|
||||
|
||||
if (!!token) {
|
||||
api.defaults.headers.common['Authorization'] = `Token ${token}`;
|
||||
} else {
|
||||
api.defaults.headers.common['Authorization'] = undefined;
|
||||
}
|
||||
api.defaults.headers.common['Authorization'] = token
|
||||
? `Token ${token}`
|
||||
: undefined;
|
||||
|
||||
if (!!getCsrfCookie()) {
|
||||
api.defaults.withCredentials = true;
|
||||
|
@ -114,16 +114,14 @@ export function OptionsApiForm({
|
||||
props.pk,
|
||||
props.pathParams
|
||||
],
|
||||
queryFn: () =>
|
||||
api.options(url).then((res) => {
|
||||
let fields: Record<string, ApiFormFieldType> | null = {};
|
||||
|
||||
if (!props.ignorePermissionCheck) {
|
||||
fields = extractAvailableFields(res, props.method);
|
||||
}
|
||||
|
||||
return fields;
|
||||
}),
|
||||
queryFn: async () => {
|
||||
let response = await api.options(url);
|
||||
let fields: Record<string, ApiFormFieldType> | null = {};
|
||||
if (!props.ignorePermissionCheck) {
|
||||
fields = extractAvailableFields(response, props.method);
|
||||
}
|
||||
return fields;
|
||||
},
|
||||
throwOnError: (error: any) => {
|
||||
if (error.response) {
|
||||
invalidResponse(error.response.status);
|
||||
@ -134,7 +132,6 @@ export function OptionsApiForm({
|
||||
color: 'red'
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
@ -37,20 +37,22 @@ export function Header() {
|
||||
const notifications = useQuery({
|
||||
queryKey: ['notification-count'],
|
||||
queryFn: async () => {
|
||||
return api
|
||||
.get(apiUrl(ApiEndpoints.notifications_list), {
|
||||
try {
|
||||
const params = {
|
||||
params: {
|
||||
read: false,
|
||||
limit: 1
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
setNotificationCount(response.data.count);
|
||||
return response.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
return error;
|
||||
});
|
||||
};
|
||||
let response = await api.get(
|
||||
apiUrl(ApiEndpoints.notifications_list),
|
||||
params
|
||||
);
|
||||
setNotificationCount(response.data.count);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
},
|
||||
refetchInterval: 30000,
|
||||
refetchOnMount: true,
|
||||
|
Loading…
Reference in New Issue
Block a user