replace axiosInstance with the get and post methods in the getFetchClient inside the fetchEmailSettings and postEmailTest utils

This commit is contained in:
Simone Taeggi 2023-02-07 14:09:23 +01:00
parent 62f1c3d04a
commit 4c8c7cf38f
2 changed files with 6 additions and 41 deletions

View File

@ -1,13 +1,16 @@
import axiosInstance from '../../../utils/axiosInstance';
import { getFetchClient } from '@strapi/helper-plugin';
const fetchEmailSettings = async () => {
const { data } = await axiosInstance.get('/email/settings');
const { get } = getFetchClient();
const { data } = await get('/email/settings');
return data.config;
};
const postEmailTest = async (body) => {
await axiosInstance.post('/email/test', body);
const { post } = getFetchClient();
await post('/email/test', body);
};
export { fetchEmailSettings, postEmailTest };

View File

@ -1,38 +0,0 @@
import axios from 'axios';
import { auth, wrapAxiosInstance } from '@strapi/helper-plugin';
const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
});
instance.interceptors.request.use(
async (config) => {
config.headers = {
Authorization: `Bearer ${auth.getToken()}`,
Accept: 'application/json',
'Content-Type': 'application/json',
};
return config;
},
(error) => {
Promise.reject(error);
}
);
instance.interceptors.response.use(
(response) => response,
(error) => {
// whatever you want to do with the error
if (error.response?.status === 401) {
auth.clearAppStorage();
window.location.reload();
}
throw error;
}
);
const wrapper = wrapAxiosInstance(instance);
export default wrapper;