@movalib/movalib-commons 1.0.67 → 1.0.68
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.
- package/.env.development +6 -0
- package/.env.production +4 -0
- package/devIndex.tsx +119 -10
- package/dist/devIndex.js +101 -8
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/src/MovaLogin.js +2 -2
- package/dist/src/MovaSignUp.js +1 -1
- package/dist/src/QRCode.d.ts +1 -0
- package/dist/src/QRCode.js +13 -12
- package/dist/src/ScheduleFields.d.ts +24 -0
- package/dist/src/ScheduleFields.js +202 -0
- package/dist/src/helpers/ApiHelper.d.ts +20 -0
- package/dist/src/helpers/ApiHelper.js +74 -0
- package/dist/src/helpers/CookieUtils.d.ts +6 -0
- package/dist/src/helpers/CookieUtils.js +28 -0
- package/dist/src/helpers/Enums.d.ts +8 -1
- package/dist/src/helpers/Enums.js +10 -2
- package/dist/src/helpers/Tools.d.ts +6 -2
- package/dist/src/helpers/Tools.js +20 -7
- package/dist/src/services/AuthenticationService.d.ts +6 -0
- package/dist/src/services/AuthenticationService.js +106 -0
- package/dist/src/services/GarageService.d.ts +5 -0
- package/dist/src/services/GarageService.js +16 -0
- package/dist/src/services/UserService.d.ts +10 -0
- package/dist/src/services/UserService.js +76 -0
- package/index.ts +3 -1
- package/package.json +9 -8
- package/src/MovaLogin.tsx +2 -2
- package/src/MovaSignUp.tsx +1 -1
- package/src/QRCode.css +4 -0
- package/src/QRCode.tsx +12 -13
- package/src/ScheduleFields.tsx +301 -0
- package/src/helpers/ApiHelper.ts +95 -0
- package/src/helpers/CookieUtils.ts +23 -0
- package/src/helpers/Enums.ts +8 -1
- package/src/helpers/Tools.ts +20 -2
- package/src/services/AuthenticationService.ts +68 -0
- package/src/services/GarageService.ts +14 -0
- package/src/services/UserService.ts +25 -0
- package/tsconfig.json +1 -1
- package/webpack.config.js +9 -0
package/src/helpers/Tools.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
import Cookies from "js-cookie";
|
|
1
2
|
import VehicleTire from "../models/VehicleTire";
|
|
2
3
|
import { MovaFormField } from "./Types";
|
|
4
|
+
import { CSSProperties } from "react";
|
|
5
|
+
|
|
6
|
+
export const flexEnd:CSSProperties = {
|
|
7
|
+
display: 'flex',
|
|
8
|
+
justifyContent: 'end',
|
|
9
|
+
alignItems: 'center'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const flexCenter:CSSProperties = {
|
|
13
|
+
display: 'flex',
|
|
14
|
+
justifyContent: 'center',
|
|
15
|
+
alignItems: 'center'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const isEmpty = (data: Object): boolean => {
|
|
19
|
+
return Object.keys(data).length === 0;
|
|
20
|
+
}
|
|
3
21
|
|
|
4
22
|
export const formatFrenchVehiclePlate = (input: string | undefined): string => {
|
|
5
23
|
if(input){
|
|
@@ -20,7 +38,7 @@ export const formatFrenchVehiclePlate = (input: string | undefined): string => {
|
|
|
20
38
|
return "";
|
|
21
39
|
};
|
|
22
40
|
|
|
23
|
-
export
|
|
41
|
+
export const formatVehicleTire = (vehicleTire: VehicleTire) => {
|
|
24
42
|
if(vehicleTire){
|
|
25
43
|
let concatened = `${vehicleTire.width}${vehicleTire.height}${vehicleTire.diameter}${vehicleTire.speedIndex}`;
|
|
26
44
|
return formatVehicleTireStr(concatened);
|
|
@@ -28,7 +46,7 @@ export function formatVehicleTire(vehicleTire: VehicleTire){
|
|
|
28
46
|
return '';
|
|
29
47
|
}
|
|
30
48
|
|
|
31
|
-
export
|
|
49
|
+
export const formatVehicleTireStr = (input: string) => {
|
|
32
50
|
|
|
33
51
|
let formatted = input.toUpperCase().replace(/[^0-9A-QS-Za-qs-z]/g, '').slice(0, 10);
|
|
34
52
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
|
|
2
|
+
import { COOKIE_GARAGE_TOKEN, COOKIE_INDIVIDUAL_TOKEN, createCookie } from "../helpers/CookieUtils";
|
|
3
|
+
import { APIMethod, MovaAppType } from "../helpers/Enums";
|
|
4
|
+
import Logger from "../helpers/Logger";
|
|
5
|
+
import User from "../models/User";
|
|
6
|
+
import UserService from "./UserService";
|
|
7
|
+
|
|
8
|
+
export default class AuthenticationService {
|
|
9
|
+
|
|
10
|
+
static async login(appType: MovaAppType, email: string, password: string): Promise<APIResponse<User>> {
|
|
11
|
+
try {
|
|
12
|
+
|
|
13
|
+
// Contextualisation selon l'application demandeuse
|
|
14
|
+
let url = '';
|
|
15
|
+
let tokenCookie = '';
|
|
16
|
+
|
|
17
|
+
Logger.info(API_BASE_URL);
|
|
18
|
+
|
|
19
|
+
switch(appType){
|
|
20
|
+
case MovaAppType.GARAGE:
|
|
21
|
+
url = `${API_BASE_URL}/garage/login`;
|
|
22
|
+
tokenCookie = COOKIE_GARAGE_TOKEN;
|
|
23
|
+
break;
|
|
24
|
+
case MovaAppType.INDIVIDUAL:
|
|
25
|
+
url = `${API_BASE_URL}/login`;
|
|
26
|
+
tokenCookie = COOKIE_INDIVIDUAL_TOKEN;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let tokenResponse = await request({
|
|
31
|
+
url: url,
|
|
32
|
+
method: APIMethod.POST,
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
email : email,
|
|
35
|
+
password: password
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if(tokenResponse.success){
|
|
40
|
+
|
|
41
|
+
Logger.info(tokenResponse);
|
|
42
|
+
|
|
43
|
+
createCookie(tokenCookie, tokenResponse.data.accessToken);
|
|
44
|
+
|
|
45
|
+
// Si le login est un succès, on renvoie les infos de l'utilisateur connecté
|
|
46
|
+
let userResponse = await UserService.getCurrentUser();
|
|
47
|
+
|
|
48
|
+
if(!userResponse || !userResponse.success) {
|
|
49
|
+
const errorMsg = 'Erreur au chargement de votre profil';
|
|
50
|
+
Logger.error(errorMsg);
|
|
51
|
+
return { success: false, error: errorMsg };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { success: true, data: userResponse.data };
|
|
55
|
+
|
|
56
|
+
} else {
|
|
57
|
+
|
|
58
|
+
return tokenResponse;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} catch (error: unknown) {
|
|
62
|
+
Logger.error('Error occurred during login:', error);
|
|
63
|
+
let errorMessage = error instanceof Error ? error.message : 'Erreur inconnue';
|
|
64
|
+
|
|
65
|
+
return { success: false, error: errorMessage };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
|
|
2
|
+
import { APIMethod } from "../helpers/Enums";
|
|
3
|
+
import Garage from "../models/Garage";
|
|
4
|
+
|
|
5
|
+
export default class GarageService {
|
|
6
|
+
|
|
7
|
+
static getAdministratedGarages(): Promise<APIResponse<Garage[]>> {
|
|
8
|
+
return request({
|
|
9
|
+
url: `${API_BASE_URL}/user/garages`,
|
|
10
|
+
method: APIMethod.GET,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
|
|
2
|
+
import { APIMethod } from "../helpers/Enums";
|
|
3
|
+
import Logger from "../helpers/Logger";
|
|
4
|
+
import User from "../models/User";
|
|
5
|
+
|
|
6
|
+
export default class UserService {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param email
|
|
10
|
+
* @param password
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
static async getCurrentUser(): Promise<APIResponse<User>> {
|
|
14
|
+
try {
|
|
15
|
+
return await request({
|
|
16
|
+
url: `${API_BASE_URL}/user/me`,
|
|
17
|
+
method: APIMethod.GET
|
|
18
|
+
});
|
|
19
|
+
} catch (error) {
|
|
20
|
+
Logger.error('Error occurred during getting user:', error);
|
|
21
|
+
return Promise.reject(error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
37
37
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
38
38
|
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
39
|
-
//
|
|
39
|
+
//"types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
40
40
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
41
41
|
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
42
42
|
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
package/webpack.config.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const webpack = require('webpack');
|
|
3
4
|
|
|
4
5
|
module.exports = {
|
|
5
6
|
mode: 'development', // ou 'production' ou 'none'
|
|
6
7
|
module: {
|
|
7
8
|
rules: [
|
|
9
|
+
{
|
|
10
|
+
test: /\.css$/i,
|
|
11
|
+
use: ['style-loader', 'css-loader'],
|
|
12
|
+
},
|
|
8
13
|
{
|
|
9
14
|
test: /\.tsx?$/,
|
|
10
15
|
use: 'ts-loader',
|
|
@@ -31,5 +36,9 @@ module.exports = {
|
|
|
31
36
|
new HtmlWebpackPlugin({
|
|
32
37
|
template: path.resolve(__dirname, 'public', 'index.html'), // Chemin vers votre fichier HTML de base
|
|
33
38
|
}),
|
|
39
|
+
new webpack.DefinePlugin({
|
|
40
|
+
'REACT_APP_API_URL': JSON.stringify(process.env.REACT_APP_API_URL),
|
|
41
|
+
'REACT_APP_MOVALIB_APP_URL': JSON.stringify(process.env.REACT_APP_MOVALIB_APP_URL)
|
|
42
|
+
}),
|
|
34
43
|
],
|
|
35
44
|
};
|