feat: Preparation des modèles Settings pour l'enregistrement SMTP [#17]

This commit is contained in:
Luc SORIGNET
2025-05-05 09:25:07 +02:00
parent 99a882a64a
commit eda6f587fb
33 changed files with 468 additions and 74 deletions

View File

@ -9,6 +9,7 @@ const requestResponseHandler = async (response) => {
return body;
}
// Throw an error with the JSON body containing the form errors
const error = new Error(body?.errorMessage || 'Une erreur est survenue');
error.details = body;
throw error;

View File

@ -0,0 +1,37 @@
import { BE_SETTINGS_SMTP_URL } from '@/utils/Url';
export const PENDING = 'pending';
export const SUBSCRIBED = 'subscribed';
export const ARCHIVED = 'archived';
const requestResponseHandler = async (response) => {
const body = await response.json();
if (response.ok) {
return body;
}
// Throw an error with the JSON body containing the form errors
const error = new Error(body?.errorMessage || 'Une erreur est survenue');
error.details = body;
throw error;
};
export const fetchSmtpSettings = (csrfToken) => {
return fetch(`${BE_SETTINGS_SMTP_URL}/`, {
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken,
},
}).then(requestResponseHandler);
};
export const editSmtpSettings = (data, csrfToken) => {
return fetch(`${BE_SETTINGS_SMTP_URL}/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken,
},
body: JSON.stringify(data),
credentials: 'include',
}).then(requestResponseHandler);
};

View File

@ -7,6 +7,7 @@ import {
} from '@/utils/Url';
import { CURRENT_YEAR_FILTER } from '@/utils/constants';
import { useNotification } from '@/context/NotificationContext';
const requestResponseHandler = async (response) => {
const body = await response.json();
@ -16,6 +17,7 @@ const requestResponseHandler = async (response) => {
// Throw an error with the JSON body containing the form errors
const error = new Error(body?.errorMessage || 'Une erreur est survenue');
error.details = body;
showNotification('Une erreur inattendue est survenue.', 'error', 'Erreur');
throw error;
};