diff --git a/public/images/attachment-icon.svg b/public/images/attachment-icon.svg
new file mode 100644
index 00000000..9f1284ee
--- /dev/null
+++ b/public/images/attachment-icon.svg
@@ -0,0 +1,4 @@
+
+
\ No newline at end of file
diff --git a/src/App.jsx b/src/App.jsx
index 111e2569..e34aba87 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -22,7 +22,6 @@ import { areOccurenciesEqual, createUserLists, encrypt, decrypt, getBrowser } fr
import { getCurrentSchoolYear } from "./utils/date";
import { getProxiedURL } from "./utils/requests";
import EdpuLogo from "./components/graphics/EdpuLogo";
-import { add } from "date-fns";
// CODE-SPLITTING - DYNAMIC IMPORTS
const Lab = lazy(() => import("./components/app/CoreApp").then((module) => { return { default: module.Lab } }));
@@ -72,7 +71,7 @@ function consoleLogEDPLogo() {
consoleLogEDPLogo();
const currentEDPVersion = "0.3.1";
-const apiVersion = "4.53.4";
+const apiVersion = "4.60.4";
// secret webhooks
const carpeConviviale = "CARPE_CONVIVIALE_WEBHOOK_URL";
@@ -1140,6 +1139,40 @@ export default function App() {
return sortedHomeworks
}
+
+ function sortMessages(messages) {
+ const sortedMessages = messages.messages.received.map((message) => { console.log("files:", message.files); return {
+ date: message.date,
+ files: structuredClone(message.files)?.map((file) => new File(file.id, file.type, file.libelle)),
+ from: message.from,
+ id: message.id,
+ read: message.read,
+ subject: message.subject,
+ content: null,
+ // ...
+ }});
+
+ return sortedMessages;
+ }
+
+ function sortMessageContent(messageContent) {
+ if (!messageContent) {
+ return;
+ }
+ const oldSortedMessages = useUserData("sortedMessages").get();
+ const targetMessageIdx = oldSortedMessages.findIndex((item) => item.id === messageContent.id);
+ oldSortedMessages[targetMessageIdx].read = true;
+ oldSortedMessages[targetMessageIdx].files = messageContent.files.map((file) => new File(file.id, file.type, file.libelle));
+ oldSortedMessages[targetMessageIdx].content = {
+ id: messageContent.id,
+ subject: messageContent.subject,
+ date: messageContent.subject,
+ content: messageContent.content
+ // ...
+ };
+ useUserData("sortedMessages").set(oldSortedMessages);
+ }
+
function sortSchoolLife(schoolLife, activeAccount) {
const sortedSchoolLife = {
delays: [],
@@ -1283,6 +1316,7 @@ export default function App() {
})
})
.then((response) => {
+ console.log(".then ~ response:", response)
// GESTION DATA
let statusCode = response.code;
if (statusCode === 200) {
@@ -1317,6 +1351,7 @@ export default function App() {
accountType: "P",
lastConnection: accounts.lastConnexion,
id: account.id,
+ familyId: accounts.id,
firstName: account.prenom,
lastName: account.nom,
email: email,
@@ -1363,9 +1398,6 @@ export default function App() {
if (error.name !== 'AbortError') {
messages.submitButtonText = "Échec de la connexion";
messages.submitErrorMessage = "Error: " + error.message;
- if (error.message === "Unexpected token 'P', \"Proxy error\" is not valid JSON") {
- setProxyError(true);
- }
}
})
.finally(() => {
@@ -1419,11 +1451,6 @@ export default function App() {
}
setTokenState((old) => (response?.token || old));
})
- .catch((error) => {
- if (error.message === "Unexpected token 'P', \"Proxy error\" is not valid JSON") {
- setProxyError(true);
- }
- })
.finally(() => {
abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
})
@@ -1472,11 +1499,6 @@ export default function App() {
}
setTokenState((old) => (response?.token || old));
})
- .catch((error) => {
- if (error.message === "Unexpected token 'P', \"Proxy error\" is not valid JSON") {
- setProxyError(true);
- }
- })
.finally(() => {
abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
})
@@ -1536,11 +1558,6 @@ export default function App() {
}
setTokenState((old) => (response?.token || old));
})
- .catch((error) => {
- if (error.message === "Unexpected token 'P', \"Proxy error\" is not valid JSON") {
- setProxyError(true);
- }
- })
.finally(() => {
abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
})
@@ -1602,10 +1619,6 @@ export default function App() {
requireLogin();
}
setTokenState(old => responseData?.token || old);
- } catch (error) {
- if (error.message === "Unexpected token 'P', \"Proxy error\" is not valid JSON") {
- setProxyError(true);
- }
} finally {
abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
}
@@ -1650,16 +1663,109 @@ export default function App() {
}
setTokenState((old) => (response?.token || old));
})
- .catch((error) => {
- if (error.message === "Unexpected token 'P', \"Proxy error\" is not valid JSON") {
- setProxyError(true);
+ .finally(() => {
+ abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
+ })
+ }
+
+
+ async function fetchMessages(controller = (new AbortController())) {
+ abortControllers.current.push(controller);
+ const userId = activeAccount;
+ const data = {
+ anneeMessages: getUserSettingValue("isSchoolYearEnabled") ? getUserSettingValue("schoolYear").join("-") : getCurrentSchoolYear().join("-"),
+ }
+ fetch(
+ getProxiedURL(`https://api.ecoledirecte.com/v3/${accountsListState[userId].accountType === "E" ? "eleves/" + accountsListState[userId].id : "familles/" + accountsListState[userId].familyId}/messages.awp?force=false&typeRecuperation=received&idClasseur=0&orderBy=date&order=desc&query=&onlyRead=&page=0&itemsPerPage=100&getAll=0&verbe=get&v=${apiVersion}`, true),
+ {
+ method: "POST",
+ headers: {
+ "x-token": tokenState
+ },
+ body: `data=${JSON.stringify(data)}`,
+ signal: controller.signal,
+ referrerPolicy: "no-referrer",
+ },
+ )
+ .then((response) => response.json())
+ .then((response) => {
+ console.log(".then ~ response:", response)
+ let code;
+ if (accountsListState[activeAccount].firstName === "Guest") {
+ code = 49969;
+ } else {
+ code = response.code;
+ }
+ if (code === 200) {
+ changeUserData("sortedMessages", sortMessages(response.data));
+ } else if (code === 520 || code === 525) {
+ // token invalide
+ requireLogin();
+ } else if (code === 49969) {
+ // TODO: add data/messages.json for guest user
+ // import("./data/messages.json").then((module) => {
+ // changeUserData("sortedMessages", sortMessages(module.data));;
+ // })
+ }
+ setTokenState((old) => (response?.token || old));
+ })
+ .finally(() => {
+ abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
+ })
+ }
+
+ async function fetchMessageContent(id, controller) {
+ const oldSortedMessages = useUserData("sortedMessages").get();
+ if (oldSortedMessages) {
+ const targetMessageIdx = oldSortedMessages.findIndex((item) => item.id === id);
+ if (oldSortedMessages[targetMessageIdx].content !== null) {
+ return;
+ }
+ }
+ abortControllers.current.push(controller);
+ const userId = activeAccount;
+ const data = {
+ anneeMessages: getUserSettingValue("isSchoolYearEnabled") ? getUserSettingValue("schoolYear").join("-") : getCurrentSchoolYear().join("-"),
+ }
+ fetch(
+ getProxiedURL(`https://api.ecoledirecte.com/v3/${accountsListState[userId].accountType === "E" ? "eleves/" + accountsListState[userId].id : "familles/" + accountsListState[userId].familyId}/messages/${id}.awp?verbe=get&mode=destinataire&v=${apiVersion}`, true),
+ {
+ method: "POST",
+ headers: {
+ "x-token": tokenState
+ },
+ body: `data=${JSON.stringify(data)}`,
+ signal: controller.signal,
+ referrerPolicy: "no-referrer",
+ },
+ )
+ .then((response) => response.json())
+ .then((response) => {
+ let code;
+ if (accountsListState[activeAccount].firstName === "Guest") {
+ code = 49969;
+ } else {
+ code = response.code;
+ }
+ if (code === 200) {
+ sortMessageContent(response.data)
+ } else if (code === 520 || code === 525) {
+ // token invalide
+ requireLogin();
+ } else if (code === 49969) {
+ // TODO: add data/messages.json for guest user
+ // import("./data/messages.json").then((module) => {
+ // sortMessageContent(module.data)
+ // })
}
+ setTokenState((old) => (response?.token || old));
})
.finally(() => {
abortControllers.current.splice(abortControllers.current.indexOf(controller), 1);
})
}
+
async function fetchSchoolLife(controller = (new AbortController())) {
abortControllers.current.push(controller);
const data = {
@@ -2062,7 +2168,7 @@ export default function App() {
path: "messaging"
},
{
- element:
{message.subject}
+{(new Date(message.date)).toLocaleDateString("fr-FR", { + month: "long", + day: "numeric", + hour: "2-digit", + minute: "2-digit" + })}
+Vous n'avez reçu aucun message. Profitez bien de votre isolement social ^^
+ ) + :content-loader
+ } +{message && message?.from?.name}
+{message && message?.date && (new Date(message.date).toLocaleDateString("fr-FR", { + month: "long", + day: "numeric", + hour: "2-digit", + minute: "2-digit" + }))}
+content-loader
+ :Sélectionnez un message dans votre boîte de réception pour le visualiser ici !
+ } +