@movalib/movalib-commons 1.0.3 → 1.0.4
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/dist/MovaCopyright.d.ts +2 -0
- package/dist/MovaCopyright.js +17 -0
- package/dist/MovaLogin.d.ts +9 -0
- package/dist/MovaLogin.js +152 -0
- package/dist/MovaSnackbar.d.ts +15 -0
- package/dist/MovaSnackbar.js +34 -0
- package/dist/TestButton.d.ts +6 -0
- package/dist/TestButton.js +6 -0
- package/dist/helpers/Enums.d.ts +14 -0
- package/dist/helpers/Enums.js +15 -0
- package/dist/helpers/Tools.d.ts +1 -0
- package/dist/helpers/Tools.js +1 -0
- package/dist/helpers/Types.d.ts +9 -0
- package/dist/helpers/Types.js +1 -0
- package/dist/helpers/Validator.d.ts +3 -0
- package/dist/helpers/Validator.js +47 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/package.json +1 -1
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Link, Typography } from "@mui/material";
|
|
14
|
+
function MovaCopyright(props) {
|
|
15
|
+
return (_jsxs(Typography, __assign({ variant: "body2", color: "text.secondary", align: "center" }, props, { children: ['Copyright © ', _jsx(Link, __assign({ color: "inherit", href: "https://www.movalib.com" }, { children: "Movalib.com" })), ' ', new Date().getFullYear(), '.'] })));
|
|
16
|
+
}
|
|
17
|
+
export default MovaCopyright;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionComponent } from "react";
|
|
2
|
+
import { MovaLoginForm } from "./helpers/Types";
|
|
3
|
+
import { MovaAppType } from "./helpers/Enums";
|
|
4
|
+
interface MovaLoginProps {
|
|
5
|
+
movaAppType: MovaAppType;
|
|
6
|
+
onSubmit: (form: MovaLoginForm) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const MovaLogin: FunctionComponent<MovaLoginProps>;
|
|
9
|
+
export default MovaLogin;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
49
|
+
import { useState } from "react";
|
|
50
|
+
import { LoadingButton } from '@mui/lab';
|
|
51
|
+
import LogoLarge from './assets/images/logo/logo_large.png';
|
|
52
|
+
import LogoProLarge from './assets/images/logo/logo_pro_large.png';
|
|
53
|
+
import GreenLeafImage from './assets/images/logo/leaf_green_large.png';
|
|
54
|
+
import PinkLeafImage from './assets/images/logo/leaf_pink_large.png';
|
|
55
|
+
import { Alert, Box, Checkbox, Container, CssBaseline, FormControlLabel, Grid, Link, TextField } from "@mui/material";
|
|
56
|
+
import MovaCopyright from "./MovaCopyright";
|
|
57
|
+
import { MovaAppType } from "./helpers/Enums";
|
|
58
|
+
import { validateEmail } from "./helpers/Validator";
|
|
59
|
+
// Permet de centrer le contenu de l'application
|
|
60
|
+
var styles = {
|
|
61
|
+
display: 'flex',
|
|
62
|
+
justifyContent: 'center',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
height: '100vh', // Ajustez la hauteur en fonction de vos besoins
|
|
65
|
+
};
|
|
66
|
+
var initialFormState = {
|
|
67
|
+
email: { value: '', isValid: true },
|
|
68
|
+
password: { value: '', isValid: true },
|
|
69
|
+
};
|
|
70
|
+
var MovaLogin = function (_a) {
|
|
71
|
+
var movaAppType = _a.movaAppType, onSubmit = _a.onSubmit;
|
|
72
|
+
var _b = useState(initialFormState), form = _b[0], setForm = _b[1];
|
|
73
|
+
var _c = useState(""), message = _c[0], setMessage = _c[1];
|
|
74
|
+
var _d = useState(false), loading = _d[0], setLoading = _d[1];
|
|
75
|
+
var handleInputChange = function (e) {
|
|
76
|
+
var _a;
|
|
77
|
+
var fieldName = e.target.name;
|
|
78
|
+
var fieldValue = e.target.value;
|
|
79
|
+
var newField = (_a = {}, _a[fieldName] = { value: fieldValue, isValid: true }, _a);
|
|
80
|
+
setForm(__assign(__assign({}, form), newField));
|
|
81
|
+
};
|
|
82
|
+
var handleSubmit = function (e) { return __awaiter(void 0, void 0, void 0, function () {
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
setLoading(true);
|
|
86
|
+
try {
|
|
87
|
+
if (validateForm() && onSubmit) {
|
|
88
|
+
// Si le formulaire est valide, on appel la function callback transmise en props
|
|
89
|
+
onSubmit(form);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error('Error occurred during submission:', error);
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
setLoading(false);
|
|
97
|
+
}
|
|
98
|
+
return [2 /*return*/];
|
|
99
|
+
});
|
|
100
|
+
}); };
|
|
101
|
+
var validateForm = function () {
|
|
102
|
+
var newForm = form;
|
|
103
|
+
// Validator email
|
|
104
|
+
if (!validateEmail(form.email.value.length)) {
|
|
105
|
+
var errorMsg = 'Adresse email invalide';
|
|
106
|
+
var newField = { value: form.email.value, error: errorMsg, isValid: false };
|
|
107
|
+
newForm = __assign(__assign({}, newForm), { email: newField });
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
var newField = { value: form.email.value, error: '', isValid: true };
|
|
111
|
+
newForm = __assign(__assign({}, newForm), { email: newField });
|
|
112
|
+
}
|
|
113
|
+
// Validator password
|
|
114
|
+
if (form.password.value.length < 8) {
|
|
115
|
+
var errorMsg = 'Votre mot de passe doit faire au moins 8 caractères de long.';
|
|
116
|
+
var newField = { value: form.password.value, error: errorMsg, isValid: false };
|
|
117
|
+
newForm = __assign(__assign({}, newForm), { password: newField });
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
var newField = { value: form.password.value, error: '', isValid: true };
|
|
121
|
+
newForm = __assign(__assign({}, newForm), { password: newField });
|
|
122
|
+
}
|
|
123
|
+
setForm(newForm);
|
|
124
|
+
return newForm.email.isValid && newForm.password.isValid;
|
|
125
|
+
};
|
|
126
|
+
var getMovaLogo = function () {
|
|
127
|
+
return movaAppType === MovaAppType.GARAGE ? LogoProLarge :
|
|
128
|
+
movaAppType === MovaAppType.USER ? LogoLarge :
|
|
129
|
+
movaAppType === MovaAppType.ADMIN ? LogoLarge : LogoLarge;
|
|
130
|
+
};
|
|
131
|
+
return (_jsxs("div", __assign({ style: styles }, { children: [_jsx("img", { src: GreenLeafImage, style: { position: 'fixed',
|
|
132
|
+
float: 'left',
|
|
133
|
+
width: '250px',
|
|
134
|
+
height: '400px',
|
|
135
|
+
top: '-20%',
|
|
136
|
+
left: '3%',
|
|
137
|
+
opacity: '0.3',
|
|
138
|
+
zIndex: -8 }, alt: 'Feuille Verte Movalib' }), _jsxs(Container, __assign({ component: "main", maxWidth: "xs" }, { children: [_jsx(CssBaseline, {}), _jsxs(Box, __assign({ sx: {
|
|
139
|
+
marginTop: 6,
|
|
140
|
+
display: 'flex',
|
|
141
|
+
flexDirection: 'column',
|
|
142
|
+
alignItems: 'center',
|
|
143
|
+
} }, { children: [_jsx("img", { src: getMovaLogo(), style: { width: '80%' } }), _jsx("br", {})] })), _jsxs(Box, __assign({ component: "form", onSubmit: handleSubmit, noValidate: true, sx: { mt: 1 } }, { children: [_jsx(TextField, { margin: "normal", required: true, fullWidth: true, id: "email", label: "Adresse email", name: "email", autoComplete: "email", autoFocus: true, onChange: function (e) { return handleInputChange(e); }, value: form.email.value, error: !form.email.isValid, helperText: form.email.error }), _jsx(TextField, { margin: "normal", required: true, fullWidth: true, name: "password", label: "Mot de passe", type: "password", id: "password", autoComplete: "current-password", onChange: function (e) { return handleInputChange(e); }, value: form.password.value, error: !form.password.isValid, helperText: form.password.error }), _jsx(FormControlLabel, { control: _jsx(Checkbox, { value: "remember", color: "primary" }), label: "Se souvenir de moi" }), _jsx(LoadingButton, __assign({ loading: loading, type: "submit", fullWidth: true, variant: "contained", sx: { mt: 3, mb: 2 } }, { children: _jsx("span", { children: "Se connecter" }) })), message && _jsx(Alert, __assign({ severity: "error", sx: { mb: 2 } }, { children: message })), _jsxs(Grid, __assign({ container: true }, { children: [_jsx(Grid, __assign({ item: true, xs: true }, { children: _jsx(Link, __assign({ href: "#", variant: "body2", color: "text.secondary" }, { children: "Mot de passe oubli\u00E9 ?" })) })), _jsx(Grid, __assign({ item: true }, { children: _jsx(Link, __assign({ href: "#", variant: "body2", color: "text.secondary" }, { children: "Créer un compte" })) }))] }))] })), _jsx(MovaCopyright, { sx: { mt: 8, mb: 4 } })] })), _jsx("img", { src: PinkLeafImage, style: { position: 'fixed',
|
|
144
|
+
float: 'right',
|
|
145
|
+
width: '250px',
|
|
146
|
+
height: '400px',
|
|
147
|
+
bottom: '-20%',
|
|
148
|
+
right: '3%',
|
|
149
|
+
opacity: '0.3',
|
|
150
|
+
zIndex: '-10' }, alt: 'Feuille Rose Movalib' })] })));
|
|
151
|
+
};
|
|
152
|
+
export default MovaLogin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
interface MovaSnackbarProps {
|
|
3
|
+
snackbar: {
|
|
4
|
+
open: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
severity: 'success' | 'info' | 'warning' | 'error' | undefined;
|
|
7
|
+
};
|
|
8
|
+
setSnackbar: (snackbar: {
|
|
9
|
+
open: boolean;
|
|
10
|
+
message: string;
|
|
11
|
+
severity: 'success' | 'info' | 'warning' | 'error' | undefined;
|
|
12
|
+
}) => void;
|
|
13
|
+
}
|
|
14
|
+
declare const MovaSnackbar: FunctionComponent<MovaSnackbarProps>;
|
|
15
|
+
export default MovaSnackbar;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { Snackbar, Alert, IconButton } from '@mui/material';
|
|
14
|
+
import CloseIcon from '@mui/icons-material/CloseRounded';
|
|
15
|
+
var MovaSnackbar = function (_a) {
|
|
16
|
+
var snackbar = _a.snackbar, setSnackbar = _a.setSnackbar;
|
|
17
|
+
/**
|
|
18
|
+
* Gestion de la fermeture de la snackbar. Si la raison de cette fermeture est
|
|
19
|
+
* un clic en dehors de la zone de contenu on intercepte et annule la fermeture 'clickaway'.
|
|
20
|
+
* @param event Evénnement de fermeture
|
|
21
|
+
* @param reason Origine de l'événnement de fermeture
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
var handleClose = function (event, reason) {
|
|
25
|
+
if (reason === 'clickaway')
|
|
26
|
+
return;
|
|
27
|
+
setSnackbar({ open: false, message: '', severity: undefined });
|
|
28
|
+
};
|
|
29
|
+
var handleCloseAlert = function (event) {
|
|
30
|
+
setSnackbar({ open: false, message: '', severity: undefined });
|
|
31
|
+
};
|
|
32
|
+
return (_jsx(Snackbar, __assign({ open: snackbar.open, autoHideDuration: 5000, onClose: handleClose }, { children: _jsx(Alert, __assign({ severity: snackbar.severity, variant: "filled", sx: { width: '100%' }, action: _jsx(_Fragment, { children: _jsx(IconButton, __assign({ size: "small", "aria-label": "close", color: "inherit", onClick: handleCloseAlert }, { children: _jsx(CloseIcon, { fontSize: "small" }) })) }) }, { children: snackbar.message })) })));
|
|
33
|
+
};
|
|
34
|
+
export default MovaSnackbar;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export var MovaAppType;
|
|
2
|
+
(function (MovaAppType) {
|
|
3
|
+
/**
|
|
4
|
+
* Application Garagiste
|
|
5
|
+
*/
|
|
6
|
+
MovaAppType["GARAGE"] = "GARAGE";
|
|
7
|
+
/**
|
|
8
|
+
* Application Utilisateur (automobiliste)
|
|
9
|
+
*/
|
|
10
|
+
MovaAppType["USER"] = "USER";
|
|
11
|
+
/**
|
|
12
|
+
* Application Administrateur (MovaTeam)
|
|
13
|
+
*/
|
|
14
|
+
MovaAppType["ADMIN"] = "ADMIN";
|
|
15
|
+
})(MovaAppType || (MovaAppType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Un email valide
|
|
3
|
+
*/
|
|
4
|
+
var emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
|
|
5
|
+
/**
|
|
6
|
+
* Un mot de passe qui contient au moins une majuscule, une minuscule, un chiffre
|
|
7
|
+
* et un caractère spécial. La longueur du mot de passe doit être d'au moins 8 caractères.
|
|
8
|
+
*/
|
|
9
|
+
var passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
|
|
10
|
+
/**
|
|
11
|
+
* Un numéro de téléphone (10 chiffres)
|
|
12
|
+
*/
|
|
13
|
+
var phoneNumberRegex = /^\d{0,10}$/;
|
|
14
|
+
/**
|
|
15
|
+
* Un code postal (5 chiffres)
|
|
16
|
+
*/
|
|
17
|
+
var postalCodeRegex = /^\d{5}$/;
|
|
18
|
+
/**
|
|
19
|
+
* Une URL valide
|
|
20
|
+
*/
|
|
21
|
+
var urlRegex = /^(ftp|http|https):\/\/[^ "]+$/;
|
|
22
|
+
/**
|
|
23
|
+
* Un nom pouvant contenir des lettres, chiffres d'une taille comprise entre 3 et 20 caractères
|
|
24
|
+
*/
|
|
25
|
+
var userNameRegex = /^[a-z0-9_-]{3,20}$/;
|
|
26
|
+
/**
|
|
27
|
+
* Un texte pouvant contenir des lettres, chiffres et quelques caractères spéciaux
|
|
28
|
+
*/
|
|
29
|
+
var textRegex = /^[a-zA-Z0-9\s.,!?'"()+=-_-éèçà]+$/;
|
|
30
|
+
export function validatePhoneNumber(phoneNumber) {
|
|
31
|
+
if (phoneNumber === null || phoneNumber === undefined) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return phoneNumberRegex.test(phoneNumber);
|
|
35
|
+
}
|
|
36
|
+
export function validateText(text) {
|
|
37
|
+
if (text === null || text === undefined) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return textRegex.test(text);
|
|
41
|
+
}
|
|
42
|
+
export function validateEmail(email) {
|
|
43
|
+
if (email === null || email === undefined) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return emailRegex.test(email);
|
|
47
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as TestButton } from './TestButton';
|
|
2
|
+
export { default as MovaSnackbar } from './MovaSnackbar';
|
|
3
|
+
export { default as MovaLogin } from './MovaLogin';
|
|
4
|
+
export { default as MovaCopyright } from './MovaCopyright';
|
|
5
|
+
export type { MovaFormField } from './helpers/Types';
|
|
6
|
+
export type { MovaLoginForm } from './helpers/Types';
|
package/dist/index.js
ADDED
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
62
62
|
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
63
63
|
// "removeComments": true, /* Disable emitting comments. */
|
|
64
|
-
"noEmit": true, /* Disable emitting files from a compilation. */
|
|
64
|
+
//"noEmit": true, /* Disable emitting files from a compilation. */
|
|
65
65
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
66
66
|
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
67
67
|
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|