refac, useApiClient for loader and actions

This commit is contained in:
Simon
2025-01-07 23:13:48 +07:00
parent d33917b541
commit daf09fcc33
64 changed files with 221 additions and 1248 deletions

View File

@@ -1,8 +1,4 @@
import defaultHeaders from '../../configuration/defaultHeaders';
import getApiUrl from '../../configuration/getApiUrl';
import getFetchCredentials from '../../configuration/getFetchCredentials';
import getCookie from '../../functions/getCookie';
import isDevEnvironment from '../../functions/isDevEnvironment';
import APIClient from '../../functions/APIClient';
export type TaskScheduleNameType =
| 'update_subscribed'
@@ -28,26 +24,10 @@ type ScheduleConfigType = {
};
const createTaskSchedule = async (taskName: TaskScheduleNameType, schedule: ScheduleConfigType) => {
const apiUrl = getApiUrl();
const csrfCookie = getCookie('csrftoken');
const response = await fetch(`${apiUrl}/api/task/schedule/${taskName}/`, {
return APIClient(`/api/task/schedule/${taskName}/`, {
method: 'POST',
headers: {
...defaultHeaders,
'X-CSRFToken': csrfCookie || '',
},
credentials: getFetchCredentials(),
body: JSON.stringify(schedule),
body: schedule,
});
const scheduledTask = await response.json();
if (isDevEnvironment()) {
console.log('createTaskSchedule', scheduledTask);
}
return scheduledTask;
};
export default createTaskSchedule;