@movalib/movalib-commons 1.0.59 → 1.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ import { format, utcToZonedTime } from 'date-fns-tz';
2
+ import { fr } from 'date-fns/locale';
3
+ import { DateFormatTypes } from './Enums';
4
+
5
+
6
+ export const formatDateByCountryCode = (date: Date | undefined, countryCode: string, formatType: DateFormatTypes): string => {
7
+
8
+ if(date){
9
+ // Tableau de correspondance entre les codes de pays et les fuseaux horaires
10
+ const countryTimeZones: { [key: string]: string } = {
11
+ 'FR': 'Europe/Paris',
12
+ // Ajoutez d'autres correspondances de codes de pays et de fuseaux horaires ici
13
+ };
14
+
15
+ const timeZone = countryTimeZones[countryCode.toUpperCase()];
16
+
17
+ if (!timeZone) {
18
+ throw new Error('Code de pays non pris en charge');
19
+ }
20
+
21
+ // Convertir la date UTC en date du fuseau horaire local
22
+ const zonedDate = utcToZonedTime(date, timeZone);
23
+
24
+ // Formater la date
25
+ switch(formatType){
26
+
27
+ case DateFormatTypes.SHORT_FORMAT_DATE:
28
+ case DateFormatTypes.LONG_FORMAT_DATETIME:
29
+ return format(zonedDate, formatType, { timeZone, locale: fr });
30
+
31
+ case DateFormatTypes.LONG_FORMAT_DATETIME_LITERAL:
32
+ return getLongFormattedDateTime(zonedDate, timeZone, fr);
33
+ }
34
+
35
+ return format(zonedDate, formatType, { timeZone, locale: fr });
36
+ }
37
+
38
+ return '';
39
+ };
40
+
41
+ export function getLongFormattedDateTime(date: Date | undefined, timeZone: string, locale: Locale){
42
+ if(date){
43
+ const day = capitalizeFirstLetter(format(date, 'eeee', { timeZone, locale: locale }));
44
+ const month = capitalizeFirstLetter(format(date, 'MMMM', { timeZone, locale: locale }));
45
+ const hours = format(date, 'HH', { timeZone, locale: locale });
46
+ const minutes = format(date, 'mm', { timeZone, locale: locale });
47
+ const dayOfMonth = format(date, 'dd', { timeZone, locale });
48
+
49
+ return `${day} ${dayOfMonth} ${month} à ${hours}:${minutes}`;
50
+ }
51
+ return '';
52
+ }
53
+
54
+ export function capitalizeFirstLetter(str: string): string {
55
+ if (str.length === 0) {
56
+ return str;
57
+ }
58
+
59
+ const firstChar = str.charAt(0).toUpperCase();
60
+ const restOfString = str.slice(1);
61
+
62
+ return firstChar + restOfString;
63
+ }
@@ -1,3 +1,10 @@
1
+
2
+ export enum DateFormatTypes {
3
+ SHORT_FORMAT_DATE = 'dd/MM/yyyy',
4
+ LONG_FORMAT_DATETIME = 'dd/MM/yyyy HH:mm:ss',
5
+ LONG_FORMAT_DATETIME_LITERAL = "EEEE dd MMMM yyyy 'à' HH:mm"
6
+ }
7
+
1
8
  export enum Gender {
2
9
  MALE,
3
10
  FEMALE,
@@ -0,0 +1,28 @@
1
+ class Logger {
2
+
3
+ static isEnabled(): boolean {
4
+ return localStorage.getItem('modeDebug') === 'true';
5
+ }
6
+
7
+ static enableLogging() {
8
+ localStorage.setItem('modeDebug', 'true');
9
+ }
10
+
11
+ static disableLogging() {
12
+ localStorage.removeItem('modeDebug');
13
+ }
14
+
15
+ static info(...args: any[]) {
16
+ if (Logger.isEnabled()) {
17
+ console.info('INFO:', ...args);
18
+ }
19
+ }
20
+
21
+ static error(...args: any[]) {
22
+ if (Logger.isEnabled()) {
23
+ console.error('ERROR:', ...args);
24
+ }
25
+ }
26
+ }
27
+
28
+ export default Logger;
@@ -1,6 +1,25 @@
1
1
  import VehicleTire from "../models/VehicleTire";
2
2
  import { MovaFormField } from "./Types";
3
3
 
4
+ export const formatFrenchVehiclePlate = (input: string | undefined): string => {
5
+ if(input){
6
+ // Supprimer tous les caractères non alphanumériques
7
+ let cleanedInput = input.replace(/[^A-Z0-9]/gi, '').toUpperCase();
8
+
9
+ // Ajouter des tirets aux positions appropriées
10
+ if (cleanedInput.length >= 2) {
11
+ cleanedInput = `${cleanedInput.slice(0, 2)}-${cleanedInput.slice(2)}`;
12
+ }
13
+ if (cleanedInput.length >= 6) {
14
+ cleanedInput = `${cleanedInput.slice(0, 6)}-${cleanedInput.slice(6, 8)}`;
15
+ }
16
+
17
+ return cleanedInput;
18
+ }
19
+
20
+ return "";
21
+ };
22
+
4
23
  export function formatVehicleTire(vehicleTire: VehicleTire){
5
24
  if(vehicleTire){
6
25
  let concatened = `${vehicleTire.width}${vehicleTire.height}${vehicleTire.diameter}${vehicleTire.speedIndex}`;
@@ -4,6 +4,7 @@ import Prestation from "./Prestation";
4
4
  import Customer from "./Customer";
5
5
  import Vehicle from "./Vehicle";
6
6
  import { OriginReference } from "../helpers/Types";
7
+ import { channel } from "diagnostics_channel";
7
8
 
8
9
  export default class Event {
9
10
 
@@ -14,8 +15,8 @@ export default class Event {
14
15
  title: string;
15
16
  garageName: string;
16
17
  garageId: number;
17
- startDate?: Date;
18
- endDate?: Date;
18
+ start?: Date;
19
+ end?: Date;
19
20
  state: EventState;
20
21
  prestations?: Prestation[];
21
22
  /**
@@ -41,9 +42,9 @@ export default class Event {
41
42
  */
42
43
  originReferences?: OriginReference[];
43
44
 
44
- constructor({ id, notes, ownerId, type, title, garageName, garageId, state, startDate, endDate, prestations, guestsId, vehicleId, quoteId, originReferences }
45
+ constructor({ id, notes, ownerId, type, title, garageName, garageId, state, start, end, prestations, guestsId, vehicleId, quoteId, originReferences }
45
46
  : { id: string; notes?: string; ownerId: number; type : EventType; title: string; garageName: string; garageId: number;
46
- state: EventState; startDate?: Date; endDate?: Date, prestations?: Prestation[],
47
+ state: EventState; start?: Date; end?: Date, prestations?: Prestation[],
47
48
  guestsId?: string[], vehicleId?: number, quoteId?: number, originReferences?: OriginReference[]})
48
49
  {
49
50
  this.id = id;
@@ -54,8 +55,8 @@ export default class Event {
54
55
  this.garageName = garageName;
55
56
  this.garageId = garageId;
56
57
  this.state = state;
57
- this.startDate = startDate ? new Date(startDate) : undefined;
58
- this.endDate = endDate ? new Date(endDate) : undefined;
58
+ this.start = start ? new Date(start) : undefined;
59
+ this.end = end ? new Date(end) : undefined;
59
60
  this.prestations = prestations;
60
61
  this.guestsId = guestsId;
61
62
  this.vehicleId = vehicleId;
@@ -67,8 +68,11 @@ export default class Event {
67
68
  let list:string = '';
68
69
 
69
70
  if(event.originReferences && event.originReferences.length !== 0){
70
- event.originReferences?.forEach(reference => {
71
- list = `${reference.key} : ${reference.value}`;
71
+ event.originReferences?.forEach((reference, index) => {
72
+ if(index > 0){
73
+ list += " / ";
74
+ }
75
+ list += `${reference.key} : ${reference.value}`;
72
76
  })
73
77
  }
74
78
  return list;