Code cleanup, convert promises to async/await. (#6726)

This commit is contained in:
Xander Luciano 2024-03-16 15:21:52 -07:00 committed by GitHub
parent 06c7ebfc21
commit 1d9b39ab33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 27 deletions

View File

@ -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;

View File

@ -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;
}
});

View File

@ -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,