feat: Messagerie WIP [#17]

This commit is contained in:
Luc SORIGNET
2025-05-11 14:02:04 +02:00
parent c6d75281a1
commit 23a593dbc7
28 changed files with 1177 additions and 391 deletions

View File

@ -1,6 +1,7 @@
import {
BE_GESTIONMESSAGERIE_MESSAGES_URL,
BE_GESTIONMESSAGERIE_SEND_MESSAGE_URL,
BE_GESTIONMESSAGERIE_SEARCH_RECIPIENTS_URL,
} from '@/utils/Url';
const requestResponseHandler = async (response) => {
@ -8,8 +9,6 @@ const requestResponseHandler = async (response) => {
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;
@ -33,3 +32,13 @@ export const sendMessage = (data, csrfToken) => {
body: JSON.stringify(data),
}).then(requestResponseHandler);
};
export const searchRecipients = (establishmentId, query) => {
const url = `${BE_GESTIONMESSAGERIE_SEARCH_RECIPIENTS_URL}/?establishment_id=${establishmentId}&q=${encodeURIComponent(query)}`;
return fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}).then(requestResponseHandler);
};

View File

@ -15,8 +15,12 @@ const requestResponseHandler = async (response) => {
throw error;
};
export const fetchSmtpSettings = (csrfToken) => {
return fetch(`${BE_SETTINGS_SMTP_URL}/`, {
export const fetchSmtpSettings = (csrfToken, establishment_id = null) => {
let url = `${BE_SETTINGS_SMTP_URL}/`;
if (establishment_id) {
url += `?establishment_id=${establishment_id}`;
}
return fetch(`${url}`, {
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken,