mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-30 00:13:21 +00:00
feat: Messagerie WIP [#17]
This commit is contained in:
@ -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);
|
||||
};
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user