mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
chore: application prettier
This commit is contained in:
@ -8,22 +8,22 @@ import { fr } from 'date-fns/locale';
|
||||
* @returns
|
||||
*/
|
||||
export function parseDate(dateString, format) {
|
||||
const formatParts = format.split(/[- :]/);
|
||||
const dateParts = dateString.split(/[- :]/);
|
||||
const dateMap = {};
|
||||
const formatParts = format.split(/[- :]/);
|
||||
const dateParts = dateString.split(/[- :]/);
|
||||
const dateMap = {};
|
||||
|
||||
formatParts.forEach((part, index) => {
|
||||
dateMap[part] = parseInt(dateParts[index], 10);
|
||||
});
|
||||
formatParts.forEach((part, index) => {
|
||||
dateMap[part] = parseInt(dateParts[index], 10);
|
||||
});
|
||||
|
||||
return new Date(
|
||||
dateMap['YYYY'] || 0,
|
||||
(dateMap['MM'] || 1) - 1,
|
||||
dateMap['DD'] || 1,
|
||||
dateMap['hh'] || 0,
|
||||
dateMap['mm'] || 0,
|
||||
dateMap['ss'] || 0
|
||||
);
|
||||
return new Date(
|
||||
dateMap['YYYY'] || 0,
|
||||
(dateMap['MM'] || 1) - 1,
|
||||
dateMap['DD'] || 1,
|
||||
dateMap['hh'] || 0,
|
||||
dateMap['mm'] || 0,
|
||||
dateMap['ss'] || 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,18 +32,18 @@ export function parseDate(dateString, format) {
|
||||
* @param {*} toFormat
|
||||
* @returns
|
||||
*/
|
||||
export function formatDate (date, toFormat) {
|
||||
const padZero = (num) => (num < 10 ? '0' + num : num);
|
||||
const formatMap = {
|
||||
'DD': padZero(date.getDate()),
|
||||
'MM': padZero(date.getMonth() + 1),
|
||||
'YYYY': date.getFullYear(),
|
||||
'hh': padZero(date.getHours()),
|
||||
'mm': padZero(date.getMinutes()),
|
||||
'ss': padZero(date.getSeconds())
|
||||
};
|
||||
export function formatDate(date, toFormat) {
|
||||
const padZero = (num) => (num < 10 ? '0' + num : num);
|
||||
const formatMap = {
|
||||
DD: padZero(date.getDate()),
|
||||
MM: padZero(date.getMonth() + 1),
|
||||
YYYY: date.getFullYear(),
|
||||
hh: padZero(date.getHours()),
|
||||
mm: padZero(date.getMinutes()),
|
||||
ss: padZero(date.getSeconds()),
|
||||
};
|
||||
|
||||
return toFormat.replace(/DD|MM|YYYY|hh|mm|ss/g, (match) => formatMap[match]);
|
||||
return toFormat.replace(/DD|MM|YYYY|hh|mm|ss/g, (match) => formatMap[match]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,9 +53,13 @@ export function formatDate (date, toFormat) {
|
||||
* @param {*} toFormat
|
||||
* @returns
|
||||
*/
|
||||
export function swapFormatDate(dateString, fromFormat = 'DD-MM-YYYY hh:mm:ss', toFormat = 'DD/MM/YYYY') {
|
||||
const date = parseDate(dateString, fromFormat);
|
||||
return formatDate(date, toFormat);
|
||||
export function swapFormatDate(
|
||||
dateString,
|
||||
fromFormat = 'DD-MM-YYYY hh:mm:ss',
|
||||
toFormat = 'DD/MM/YYYY'
|
||||
) {
|
||||
const date = parseDate(dateString, fromFormat);
|
||||
return formatDate(date, toFormat);
|
||||
}
|
||||
// ...existing code...
|
||||
|
||||
@ -77,12 +81,13 @@ export function toCalendarFormat(date) {
|
||||
* Vérifie si deux dates sont le même jour
|
||||
*/
|
||||
export function isSameDay(date1, date2) {
|
||||
return date1.getFullYear() === date2.getFullYear() &&
|
||||
date1.getMonth() === date2.getMonth() &&
|
||||
date1.getDate() === date2.getDate();
|
||||
return (
|
||||
date1.getFullYear() === date2.getFullYear() &&
|
||||
date1.getMonth() === date2.getMonth() &&
|
||||
date1.getDate() === date2.getDate()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export const getWeekDays = (date) => {
|
||||
const start = startOfWeek(date, { locale: fr, weekStartsOn: 1 });
|
||||
const end = endOfWeek(date, { locale: fr, weekStartsOn: 1 });
|
||||
@ -90,8 +95,7 @@ export const getWeekDays = (date) => {
|
||||
return eachDayOfInterval({ start, end });
|
||||
};
|
||||
|
||||
|
||||
export const isWeekend = (date) => {
|
||||
const day = date.getDay();
|
||||
return day === 0 || day === 6;
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,42 +1,40 @@
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} phoneString au format E.164
|
||||
* @param {*} toFormat L=Country code, X=Number Format="LX XX XX XX XX"
|
||||
* @returns
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @param {*} phoneString au format E.164
|
||||
* @param {*} toFormat L=Country code, X=Number Format="LX XX XX XX XX"
|
||||
* @returns
|
||||
*/
|
||||
export function formatPhoneNumber(phoneString, toFormat = 'LX XX XX XX XX') {
|
||||
if (!phoneString) return;
|
||||
// Vérifier si le numéro est au format international
|
||||
if(!validateE164PhoneNumber(phoneString)){
|
||||
return phoneString;
|
||||
if (!phoneString) return;
|
||||
// Vérifier si le numéro est au format international
|
||||
if (!validateE164PhoneNumber(phoneString)) {
|
||||
return phoneString;
|
||||
}
|
||||
const matches = phoneString.match(/^\+(\d{1,3})(\d{9})$/);
|
||||
if (!matches) return phoneString;
|
||||
|
||||
const [_, countryCode, number] = matches;
|
||||
const prefix = `+${countryCode}`;
|
||||
const digits = number;
|
||||
|
||||
// Initialiser le numéro formaté avec le préfixe
|
||||
let formattedNumber = toFormat.replace('L', prefix);
|
||||
|
||||
let digitIndex = 0;
|
||||
|
||||
// Remplacer les X par les chiffres
|
||||
formattedNumber = formattedNumber.replace(/X/g, (match, offset) => {
|
||||
// Si c'est le dernier groupe de X, mettre tous les chiffres restants
|
||||
if (offset === formattedNumber.lastIndexOf('X') - match.length + 1) {
|
||||
const remainingDigits = digits.substring(digitIndex);
|
||||
digitIndex += remainingDigits.length;
|
||||
return remainingDigits;
|
||||
}
|
||||
const matches = phoneString.match(/^\+(\d{1,3})(\d{9})$/);
|
||||
if (!matches) return phoneString;
|
||||
// Sinon, mettre un seul chiffre
|
||||
return digits[digitIndex++] || '';
|
||||
});
|
||||
|
||||
const [_, countryCode, number] = matches;
|
||||
const prefix = `+${countryCode}`;
|
||||
const digits = number;
|
||||
|
||||
// Initialiser le numéro formaté avec le préfixe
|
||||
let formattedNumber = toFormat.replace('L', prefix);
|
||||
|
||||
let digitIndex = 0;
|
||||
|
||||
|
||||
// Remplacer les X par les chiffres
|
||||
formattedNumber = formattedNumber.replace(/X/g, (match, offset) => {
|
||||
// Si c'est le dernier groupe de X, mettre tous les chiffres restants
|
||||
if (offset === formattedNumber.lastIndexOf('X') - match.length + 1) {
|
||||
const remainingDigits = digits.substring(digitIndex);
|
||||
digitIndex += remainingDigits.length;
|
||||
return remainingDigits;
|
||||
}
|
||||
// Sinon, mettre un seul chiffre
|
||||
return digits[digitIndex++] || '';
|
||||
});
|
||||
|
||||
return formattedNumber;
|
||||
return formattedNumber;
|
||||
}
|
||||
|
||||
// Fonction pour valider un numéro de téléphone au format E.164
|
||||
@ -44,6 +42,6 @@ export function formatPhoneNumber(phoneString, toFormat = 'LX XX XX XX XX') {
|
||||
// qui commence par un signe '+' suivi du code pays et du numéro de téléphone
|
||||
// Par exemple : +33123456789 pour un numéro français
|
||||
export function validateE164PhoneNumber(phoneNumber) {
|
||||
const regEx = /^\+[1-9]\d{9,14}$/;
|
||||
return regEx.test(phoneNumber);
|
||||
};
|
||||
const regEx = /^\+[1-9]\d{9,14}$/;
|
||||
return regEx.test(phoneNumber);
|
||||
}
|
||||
|
||||
@ -1,42 +1,40 @@
|
||||
import { RIGHTS } from '@/utils/rights';
|
||||
export const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
|
||||
|
||||
//URL-Back-End
|
||||
|
||||
// GESTION DocuSeal
|
||||
export const BE_DOCUSEAL_GET_JWT = `${BASE_URL}/DocuSeal/generateToken`
|
||||
export const BE_DOCUSEAL_CLONE_TEMPLATE = `${BASE_URL}/DocuSeal/cloneTemplate`
|
||||
export const BE_DOCUSEAL_REMOVE_TEMPLATE = `${BASE_URL}/DocuSeal/removeTemplate`
|
||||
export const BE_DOCUSEAL_DOWNLOAD_TEMPLATE = `${BASE_URL}/DocuSeal/downloadTemplate`
|
||||
export const BE_DOCUSEAL_GET_JWT = `${BASE_URL}/DocuSeal/generateToken`;
|
||||
export const BE_DOCUSEAL_CLONE_TEMPLATE = `${BASE_URL}/DocuSeal/cloneTemplate`;
|
||||
export const BE_DOCUSEAL_REMOVE_TEMPLATE = `${BASE_URL}/DocuSeal/removeTemplate`;
|
||||
export const BE_DOCUSEAL_DOWNLOAD_TEMPLATE = `${BASE_URL}/DocuSeal/downloadTemplate`;
|
||||
|
||||
// GESTION LOGIN
|
||||
export const BE_AUTH_NEW_PASSWORD_URL = `${BASE_URL}/Auth/newPassword`
|
||||
export const BE_AUTH_REGISTER_URL = `${BASE_URL}/Auth/subscribe`
|
||||
export const BE_AUTH_RESET_PASSWORD_URL = `${BASE_URL}/Auth/resetPassword`
|
||||
export const BE_AUTH_LOGIN_URL = `${BASE_URL}/Auth/login`
|
||||
export const BE_AUTH_REFRESH_JWT_URL = `${BASE_URL}/Auth/refreshJWT`
|
||||
export const BE_AUTH_LOGOUT_URL = `${BASE_URL}/Auth/logout`
|
||||
export const BE_AUTH_PROFILES_URL = `${BASE_URL}/Auth/profiles`
|
||||
export const BE_AUTH_PROFILES_ROLES_URL = `${BASE_URL}/Auth/profileRoles`
|
||||
export const BE_AUTH_CSRF_URL = `${BASE_URL}/Auth/csrf`
|
||||
export const BE_AUTH_INFO_SESSION = `${BASE_URL}/Auth/infoSession`
|
||||
export const BE_AUTH_NEW_PASSWORD_URL = `${BASE_URL}/Auth/newPassword`;
|
||||
export const BE_AUTH_REGISTER_URL = `${BASE_URL}/Auth/subscribe`;
|
||||
export const BE_AUTH_RESET_PASSWORD_URL = `${BASE_URL}/Auth/resetPassword`;
|
||||
export const BE_AUTH_LOGIN_URL = `${BASE_URL}/Auth/login`;
|
||||
export const BE_AUTH_REFRESH_JWT_URL = `${BASE_URL}/Auth/refreshJWT`;
|
||||
export const BE_AUTH_LOGOUT_URL = `${BASE_URL}/Auth/logout`;
|
||||
export const BE_AUTH_PROFILES_URL = `${BASE_URL}/Auth/profiles`;
|
||||
export const BE_AUTH_PROFILES_ROLES_URL = `${BASE_URL}/Auth/profileRoles`;
|
||||
export const BE_AUTH_CSRF_URL = `${BASE_URL}/Auth/csrf`;
|
||||
export const BE_AUTH_INFO_SESSION = `${BASE_URL}/Auth/infoSession`;
|
||||
|
||||
// GESTION INSCRIPTION
|
||||
export const BE_SUBSCRIPTION_STUDENTS_URL = `${BASE_URL}/Subscriptions/students` // Récupère la liste des élèves inscrits ou en cours d'inscriptions
|
||||
export const BE_SUBSCRIPTION_CHILDRENS_URL = `${BASE_URL}/Subscriptions/children` // Récupère la liste des élèves d'un profil
|
||||
export const BE_SUBSCRIPTION_REGISTERFORMS_URL = `${BASE_URL}/Subscriptions/registerForms`
|
||||
export const BE_SUBSCRIPTION_REGISTRATION_TEMPLATE_MASTER_URL = `${BASE_URL}/Subscriptions/registrationTemplateMasters`
|
||||
export const BE_SUBSCRIPTION_REGISTRATION_TEMPLATES_URL = `${BASE_URL}/Subscriptions/registrationTemplates`
|
||||
export const BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL = `${BASE_URL}/Subscriptions/registrationFileGroups`
|
||||
export const BE_SUBSCRIPTION_LAST_GUARDIAN_ID_URL = `${BASE_URL}/Subscriptions/lastGuardianId`
|
||||
|
||||
export const BE_SUBSCRIPTION_STUDENTS_URL = `${BASE_URL}/Subscriptions/students`; // Récupère la liste des élèves inscrits ou en cours d'inscriptions
|
||||
export const BE_SUBSCRIPTION_CHILDRENS_URL = `${BASE_URL}/Subscriptions/children`; // Récupère la liste des élèves d'un profil
|
||||
export const BE_SUBSCRIPTION_REGISTERFORMS_URL = `${BASE_URL}/Subscriptions/registerForms`;
|
||||
export const BE_SUBSCRIPTION_REGISTRATION_TEMPLATE_MASTER_URL = `${BASE_URL}/Subscriptions/registrationTemplateMasters`;
|
||||
export const BE_SUBSCRIPTION_REGISTRATION_TEMPLATES_URL = `${BASE_URL}/Subscriptions/registrationTemplates`;
|
||||
export const BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL = `${BASE_URL}/Subscriptions/registrationFileGroups`;
|
||||
export const BE_SUBSCRIPTION_LAST_GUARDIAN_ID_URL = `${BASE_URL}/Subscriptions/lastGuardianId`;
|
||||
|
||||
//GESTION ECOLE
|
||||
export const BE_SCHOOL_SPECIALITIES_URL = `${BASE_URL}/School/specialities`
|
||||
export const BE_SCHOOL_SCHOOLCLASSES_URL = `${BASE_URL}/School/schoolClasses`
|
||||
export const BE_SCHOOL_TEACHERS_URL = `${BASE_URL}/School/teachers`
|
||||
export const BE_SCHOOL_PLANNINGS_URL = `${BASE_URL}/School/plannings`
|
||||
export const BE_SCHOOL_SPECIALITIES_URL = `${BASE_URL}/School/specialities`;
|
||||
export const BE_SCHOOL_SCHOOLCLASSES_URL = `${BASE_URL}/School/schoolClasses`;
|
||||
export const BE_SCHOOL_TEACHERS_URL = `${BASE_URL}/School/teachers`;
|
||||
export const BE_SCHOOL_PLANNINGS_URL = `${BASE_URL}/School/plannings`;
|
||||
export const BE_SCHOOL_FEES_URL = `${BASE_URL}/School/fees`;
|
||||
export const BE_SCHOOL_DISCOUNTS_URL = `${BASE_URL}/School/discounts`;
|
||||
export const BE_SCHOOL_PAYMENT_PLANS_URL = `${BASE_URL}/School/paymentPlans`;
|
||||
@ -45,83 +43,80 @@ export const BE_SCHOOL_PAYMENT_MODES_URL = `${BASE_URL}/School/paymentModes`;
|
||||
// ESTABLISHMENT
|
||||
export const BE_SCHOOL_ESTABLISHMENT_URL = `${BASE_URL}/Establishment/establishments`;
|
||||
|
||||
|
||||
// GESTION PLANNING
|
||||
export const BE_PLANNING_PLANNINGS_URL = `${BASE_URL}/Planning/plannings`
|
||||
export const BE_PLANNING_EVENTS_URL = `${BASE_URL}/Planning/events`
|
||||
|
||||
export const BE_PLANNING_PLANNINGS_URL = `${BASE_URL}/Planning/plannings`;
|
||||
export const BE_PLANNING_EVENTS_URL = `${BASE_URL}/Planning/events`;
|
||||
|
||||
// FIXME : En attendant la gestion des sessions
|
||||
export const ESTABLISHMENT_ID = 1;
|
||||
|
||||
// GESTION MESSAGERIE
|
||||
export const BE_GESTIONMESSAGERIE_MESSAGES_URL = `${BASE_URL}/GestionMessagerie/messages`
|
||||
export const BE_GESTIONMESSAGERIE_MESSAGERIE_URL = `${BASE_URL}/GestionMessagerie/messagerie`
|
||||
export const BE_GESTIONMESSAGERIE_MESSAGES_URL = `${BASE_URL}/GestionMessagerie/messages`;
|
||||
export const BE_GESTIONMESSAGERIE_MESSAGERIE_URL = `${BASE_URL}/GestionMessagerie/messagerie`;
|
||||
|
||||
// URL FRONT-END
|
||||
export const FE_HOME_URL = `/`
|
||||
export const FE_HOME_URL = `/`;
|
||||
|
||||
// USERS
|
||||
export const FE_USERS_LOGIN_URL = `/users/login`
|
||||
export const FE_USERS_SUBSCRIBE_URL = `/users/subscribe`
|
||||
export const FE_USERS_RESET_PASSWORD_URL = `/users/password/reset`
|
||||
export const FE_USERS_NEW_PASSWORD_URL = `/users/password/new`
|
||||
export const FE_USERS_LOGIN_URL = `/users/login`;
|
||||
export const FE_USERS_SUBSCRIBE_URL = `/users/subscribe`;
|
||||
export const FE_USERS_RESET_PASSWORD_URL = `/users/password/reset`;
|
||||
export const FE_USERS_NEW_PASSWORD_URL = `/users/password/new`;
|
||||
|
||||
// ADMIN
|
||||
export const FE_ADMIN_HOME_URL = `/admin`
|
||||
export const FE_ADMIN_HOME_URL = `/admin`;
|
||||
|
||||
// ADMIN/SUBSCRIPTIONS URL
|
||||
export const FE_ADMIN_SUBSCRIPTIONS_URL = `/admin/subscriptions`
|
||||
export const FE_ADMIN_SUBSCRIPTIONS_EDIT_URL = `/admin/subscriptions/editInscription`
|
||||
export const FE_ADMIN_SUBSCRIPTIONS_VALIDATE_URL = `/admin/subscriptions/validateSubscription`
|
||||
export const FE_ADMIN_SUBSCRIPTIONS_URL = `/admin/subscriptions`;
|
||||
export const FE_ADMIN_SUBSCRIPTIONS_EDIT_URL = `/admin/subscriptions/editInscription`;
|
||||
export const FE_ADMIN_SUBSCRIPTIONS_VALIDATE_URL = `/admin/subscriptions/validateSubscription`;
|
||||
|
||||
//ADMIN/CLASSES URL
|
||||
export const FE_ADMIN_CLASSES_URL = `/admin/classes`
|
||||
export const FE_ADMIN_CLASSES_URL = `/admin/classes`;
|
||||
|
||||
//ADMIN/STRUCTURE URL
|
||||
export const FE_ADMIN_STRUCTURE_URL = `/admin/structure`
|
||||
export const FE_ADMIN_STRUCTURE_URL = `/admin/structure`;
|
||||
|
||||
//ADMIN/DIRECTORY URL
|
||||
export const FE_ADMIN_DIRECTORY_URL = `/admin/directory`
|
||||
export const FE_ADMIN_DIRECTORY_URL = `/admin/directory`;
|
||||
|
||||
//ADMIN/GRADES URL
|
||||
export const FE_ADMIN_GRADES_URL = `/admin/grades`
|
||||
export const FE_ADMIN_GRADES_URL = `/admin/grades`;
|
||||
|
||||
//ADMIN/TEACHERS URL
|
||||
export const FE_ADMIN_TEACHERS_URL = `/admin/teachers`
|
||||
export const FE_ADMIN_TEACHERS_URL = `/admin/teachers`;
|
||||
|
||||
//ADMIN/PLANNING URL
|
||||
export const FE_ADMIN_PLANNING_URL = `/admin/planning`
|
||||
export const FE_ADMIN_PLANNING_URL = `/admin/planning`;
|
||||
|
||||
//ADMIN/SETTINGS URL
|
||||
export const FE_ADMIN_SETTINGS_URL = `/admin/settings`
|
||||
export const FE_ADMIN_SETTINGS_URL = `/admin/settings`;
|
||||
|
||||
// PARENT HOME
|
||||
export const FE_PARENTS_HOME_URL = `/parents`
|
||||
export const FE_PARENTS_MESSAGERIE_URL = `/parents/messagerie`
|
||||
export const FE_PARENTS_SETTINGS_URL = `/parents/settings`
|
||||
export const FE_PARENTS_EDIT_INSCRIPTION_URL = `/parents/editInscription`
|
||||
export const FE_PARENTS_HOME_URL = `/parents`;
|
||||
export const FE_PARENTS_MESSAGERIE_URL = `/parents/messagerie`;
|
||||
export const FE_PARENTS_SETTINGS_URL = `/parents/settings`;
|
||||
export const FE_PARENTS_EDIT_INSCRIPTION_URL = `/parents/editInscription`;
|
||||
|
||||
// API DOCUSEAL
|
||||
export const FE_API_DOCUSEAL_GENERATE_TOKEN = `/api/docuseal/generateToken`
|
||||
export const FE_API_DOCUSEAL_CLONE_URL = `/api/docuseal/cloneTemplate`
|
||||
export const FE_API_DOCUSEAL_DOWNLOAD_URL = `/api/docuseal/downloadTemplate`
|
||||
|
||||
export const FE_API_DOCUSEAL_GENERATE_TOKEN = `/api/docuseal/generateToken`;
|
||||
export const FE_API_DOCUSEAL_CLONE_URL = `/api/docuseal/cloneTemplate`;
|
||||
export const FE_API_DOCUSEAL_DOWNLOAD_URL = `/api/docuseal/downloadTemplate`;
|
||||
|
||||
/**
|
||||
* Fonction pour obtenir l'URL de redirection en fonction du rôle
|
||||
* @param {RIGHTS} role
|
||||
* @returns {string|null} L'URL de redirection ou null si le rôle n'est pas géré
|
||||
*/
|
||||
export function getRedirectUrlFromRole(role) {
|
||||
switch (role) {
|
||||
case RIGHTS.ADMIN:
|
||||
return FE_ADMIN_SUBSCRIPTIONS_URL;
|
||||
case RIGHTS.TEACHER:
|
||||
return FE_ADMIN_SUBSCRIPTIONS_URL;
|
||||
case RIGHTS.PARENT:
|
||||
return FE_PARENTS_HOME_URL;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
export function getRedirectUrlFromRole(role) {
|
||||
switch (role) {
|
||||
case RIGHTS.ADMIN:
|
||||
return FE_ADMIN_SUBSCRIPTIONS_URL;
|
||||
case RIGHTS.TEACHER:
|
||||
return FE_ADMIN_SUBSCRIPTIONS_URL;
|
||||
case RIGHTS.PARENT:
|
||||
return FE_PARENTS_HOME_URL;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ export const WEEKDAYS = [
|
||||
{ id: 4, name: 'Jeudi' },
|
||||
{ id: 5, name: 'Vendredi' },
|
||||
{ id: 6, name: 'Samedi' },
|
||||
{ id: 7, name: 'Dimanche' }
|
||||
{ id: 7, name: 'Dimanche' },
|
||||
];
|
||||
|
||||
export const DEFAULT_EVENT = {
|
||||
@ -18,13 +18,13 @@ export const DEFAULT_EVENT = {
|
||||
color: '#10b981',
|
||||
recurrence: 'none',
|
||||
selectedDays: [],
|
||||
recurrenceEnd: ''
|
||||
recurrenceEnd: '',
|
||||
};
|
||||
|
||||
export const VIEW_TYPES = {
|
||||
WEEK: 'week',
|
||||
MONTH: 'month',
|
||||
YEAR: 'year'
|
||||
YEAR: 'year',
|
||||
};
|
||||
|
||||
export const TIME_SLOTS = Array.from({ length: 24 }, (_, i) => i);
|
||||
export const TIME_SLOTS = Array.from({ length: 24 }, (_, i) => i);
|
||||
|
||||
@ -13,8 +13,10 @@ export const calculateEventPosition = (event, overlappingEvents) => {
|
||||
const endHour = end.getHours() + end.getMinutes() / 60;
|
||||
const duration = endHour - startHour;
|
||||
|
||||
const sortedEvents = overlappingEvents.sort((a, b) => new Date(a.start) - new Date(b.start));
|
||||
const index = sortedEvents.findIndex(e => e.id === event.id);
|
||||
const sortedEvents = overlappingEvents.sort(
|
||||
(a, b) => new Date(a.start) - new Date(b.start)
|
||||
);
|
||||
const index = sortedEvents.findIndex((e) => e.id === event.id);
|
||||
|
||||
return {
|
||||
top: `${startHour * 5}rem`,
|
||||
@ -32,13 +34,13 @@ export const calculateEventPosition = (event, overlappingEvents) => {
|
||||
* @returns {Array<Object>} Liste des événements qui se chevauchent
|
||||
*/
|
||||
export const getOverlappingEvents = (event, dayEvents) => {
|
||||
return dayEvents.filter(otherEvent => {
|
||||
return dayEvents.filter((otherEvent) => {
|
||||
if (event.id === otherEvent.id) return false;
|
||||
const eventStart = new Date(event.start);
|
||||
const eventEnd = new Date(event.end);
|
||||
const otherStart = new Date(otherEvent.start);
|
||||
const otherEnd = new Date(otherEvent.end);
|
||||
return (eventStart < otherEnd && eventEnd > otherStart);
|
||||
return eventStart < otherEnd && eventEnd > otherStart;
|
||||
});
|
||||
};
|
||||
|
||||
@ -49,7 +51,7 @@ export const getOverlappingEvents = (event, dayEvents) => {
|
||||
* @returns {Array<Object>} Liste des événements pour la date donnée
|
||||
*/
|
||||
export const getEventsForDate = (date, events = []) => {
|
||||
return events.filter(event => {
|
||||
return events.filter((event) => {
|
||||
const eventDate = new Date(event.start);
|
||||
return (
|
||||
eventDate.getDate() === date.getDate() &&
|
||||
@ -66,7 +68,7 @@ export const getEventsForDate = (date, events = []) => {
|
||||
* @returns {number} Nombre d'événements dans le mois
|
||||
*/
|
||||
export const getMonthEventCount = (month, events = []) => {
|
||||
return events.filter(event => {
|
||||
return events.filter((event) => {
|
||||
const eventDate = new Date(event.start);
|
||||
return (
|
||||
eventDate.getMonth() === month.getMonth() &&
|
||||
@ -85,7 +87,7 @@ export const getWeekEvents = (day, events) => {
|
||||
const start = startOfDay(day);
|
||||
const end = endOfDay(day);
|
||||
|
||||
return events?.filter(event => {
|
||||
return events?.filter((event) => {
|
||||
const eventStart = new Date(event.start);
|
||||
const eventEnd = new Date(event.end);
|
||||
|
||||
@ -93,9 +95,11 @@ export const getWeekEvents = (day, events) => {
|
||||
// - il commence pendant la journée
|
||||
// - il finit pendant la journée
|
||||
// - il englobe toute la journée
|
||||
return (eventStart >= start && eventStart <= end) || // commence dans la journée
|
||||
(eventEnd >= start && eventEnd <= end) || // finit dans la journée
|
||||
(eventStart <= start && eventEnd >= end); // englobe la journée
|
||||
return (
|
||||
(eventStart >= start && eventStart <= end) || // commence dans la journée
|
||||
(eventEnd >= start && eventEnd <= end) || // finit dans la journée
|
||||
(eventStart <= start && eventEnd >= end)
|
||||
); // englobe la journée
|
||||
});
|
||||
};
|
||||
|
||||
@ -106,5 +110,5 @@ export const getWeekEvents = (day, events) => {
|
||||
* @returns {Array<Object>} Liste des événements filtrés
|
||||
*/
|
||||
export const filterEventsByVisibleSchedules = (events, hiddenSchedules) => {
|
||||
return events.filter(event => !hiddenSchedules.includes(event.planning));
|
||||
return events.filter((event) => !hiddenSchedules.includes(event.planning));
|
||||
};
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
let csrfToken = '';
|
||||
|
||||
export const setCsrfToken = (token) => {
|
||||
csrfToken = token;
|
||||
csrfToken = token;
|
||||
};
|
||||
|
||||
export const getCsrfToken = () => {
|
||||
return csrfToken;
|
||||
};
|
||||
return csrfToken;
|
||||
};
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
export function getGravatarUrl(email, size = 32) {
|
||||
if(email === undefined || typeof email !== 'string') {
|
||||
return 'https://www.gravatar.com/avatar/';
|
||||
}
|
||||
else {
|
||||
const hash = crypto.createHash('md5').update(email.toLowerCase().trim()).digest('hex');
|
||||
return `https://www.gravatar.com/avatar/${hash}?s=${size}&d=identicon`;
|
||||
}
|
||||
if (email === undefined || typeof email !== 'string') {
|
||||
return 'https://www.gravatar.com/avatar/';
|
||||
} else {
|
||||
const hash = crypto
|
||||
.createHash('md5')
|
||||
.update(email.toLowerCase().trim())
|
||||
.digest('hex');
|
||||
return `https://www.gravatar.com/avatar/${hash}?s=${size}&d=identicon`;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,10 +12,10 @@ export async function getAvailableNamespaces(locale) {
|
||||
const messagesPath = path.join(process.cwd(), 'messages', locale);
|
||||
const files = await fs.readdir(messagesPath);
|
||||
return files
|
||||
.filter(file => file.endsWith('.json'))
|
||||
.map(file => file.replace('.json', ''));
|
||||
.filter((file) => file.endsWith('.json'))
|
||||
.map((file) => file.replace('.json', ''));
|
||||
} catch (error) {
|
||||
console.warn(`Impossible de lire les namespaces pour ${locale}:`, error);
|
||||
return ['common']; // Namespace par défaut
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,39 +1,38 @@
|
||||
|
||||
const getCallerInfo = () => {
|
||||
const getCallerInfo = () => {
|
||||
const stackLine = new Error().stack?.split('\n')[3].trim();
|
||||
// Regex pour extraire le fichier, la ligne et la colonne
|
||||
const match = stackLine.match(/\(?([^)]+):(\d+):(\d+)\)?$/);
|
||||
|
||||
let callerInfo = '(unknown)';
|
||||
if (match) {
|
||||
const [ , filePath, line, column ] = match;
|
||||
const [, filePath, line, column] = match;
|
||||
const fileName = filePath.split('/').pop(); // Garde juste le nom du fichier
|
||||
callerInfo = `[${fileName}:${line}]`;
|
||||
}
|
||||
return callerInfo;
|
||||
}
|
||||
};
|
||||
|
||||
const logger = {
|
||||
debug: (...args) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.log.apply(console, ['[DEBUG]',`${getCallerInfo()}`, ...args])
|
||||
console.log.apply(console, ['[DEBUG]', `${getCallerInfo()}`, ...args]);
|
||||
}
|
||||
},
|
||||
error: (...args) => {
|
||||
// Les erreurs sont toujours loguées
|
||||
|
||||
console.error.apply(console,['[ERROR]',`${getCallerInfo()}`,...args]);
|
||||
console.error.apply(console, ['[ERROR]', `${getCallerInfo()}`, ...args]);
|
||||
},
|
||||
warn: (...args) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.warn.apply(console, ['[WARN]',`${getCallerInfo()}`, ...args]);
|
||||
console.warn.apply(console, ['[WARN]', `${getCallerInfo()}`, ...args]);
|
||||
}
|
||||
},
|
||||
info: (...args) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.info.apply(console, ['[INFO]',`${getCallerInfo()}`, ...args]);
|
||||
console.info.apply(console, ['[INFO]', `${getCallerInfo()}`, ...args]);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default logger;
|
||||
export default logger;
|
||||
|
||||
@ -1,18 +1,17 @@
|
||||
export const RIGHTS = {
|
||||
TEACHER: 0,
|
||||
ADMIN: 1,
|
||||
PARENT: 2
|
||||
}
|
||||
PARENT: 2,
|
||||
};
|
||||
|
||||
export function getRightStr(right){
|
||||
if (right === RIGHTS.ADMIN){
|
||||
return "ADMINISTRATEUR";
|
||||
}
|
||||
else if (right === RIGHTS.TEACHER){
|
||||
return "PROFESSEUR";
|
||||
}else if (right === RIGHTS.PARENT){
|
||||
return "PARENT";
|
||||
}else{
|
||||
return "NON DEFINI";
|
||||
}
|
||||
}
|
||||
export function getRightStr(right) {
|
||||
if (right === RIGHTS.ADMIN) {
|
||||
return 'ADMINISTRATEUR';
|
||||
} else if (right === RIGHTS.TEACHER) {
|
||||
return 'PROFESSEUR';
|
||||
} else if (right === RIGHTS.PARENT) {
|
||||
return 'PARENT';
|
||||
} else {
|
||||
return 'NON DEFINI';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user