@movalib/movalib-commons 1.59.9 → 1.59.10

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/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export { default as MovaCopyright } from './src/MovaCopyright';
22
22
  export { default as MovaVehicleTireField } from './src/MovaVehicleTireField';
23
23
  export { default as ConfirmationDialog } from './src/ConfirmationDialog';
24
24
  export { default as GenderSelector } from './src/GenderSelector';
25
+ export { default as ActivateAccount } from './src/components/singup/ActivateAccount';
25
26
  export { QrCodePLVContainer } from './src/components/QrCodePLVContainer/QrCodePLVContainer';
26
27
  export { PLVComponent, PrintSize } from './src/components/QrCodePLVContainer/PLVComponent';
27
28
  export { default as Subscription } from './src/models/Subscription';
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.readCookie = exports.CategoryPrestation = exports.VehicleTire = exports.Event = exports.Schedule = exports.VehicleGarage = exports.Garage = exports.Document = exports.Vehicle = exports.Address = exports.Role = exports.User = exports.Customer = exports.Logger = exports.Operation = exports.Prestation = exports.Product = exports.Supplier = exports.Employee = exports.Absence = exports.Subscription = exports.PrintSize = exports.PLVComponent = exports.QrCodePLVContainer = exports.GenderSelector = exports.ConfirmationDialog = exports.MovaVehicleTireField = exports.MovaCopyright = exports.MovaSignUp = exports.MovaLogin = exports.MovaSnackbar = exports.TestButton = exports.oldRegexPlate = exports.regexPlate = exports.VehiclePlateField = exports.QRCode = exports.MovaDialog = exports.Loader = exports.MovaDigitalPassport = exports.VehicleFullCard = exports.ScheduleFields = exports.AddressFields = exports.AccountValidation = exports.GaragePLV = exports.IbanInput = exports.DialogForgotPassword = exports.UserService = exports.GarageService = exports.AuthenticationService = exports.VehicleService = void 0;
8
- exports.openDialogPrint = exports.APIMethod = exports.SubscriptionType = exports.SubscriptionState = exports.CountryCode = exports.PrestationState = exports.PrestationType = exports.RegistrationState = exports.SubscriptionPaymentInterval = exports.VehiclePlateType = exports.SlotAlgorithm = exports.OrderState = exports.OrderPreference = exports.ProductType = exports.PartsApplicationType = exports.DateFormatTypes = exports.Gender = exports.DocumentState = exports.DigitalPassportIndex = exports.DocumentType = exports.EventType = exports.EventState = exports.DayOfWeek = exports.MovaAppType = exports.RoleType = exports.CustomerType = exports.API_BASE_URL = exports.request = exports.getLongFormattedDateTime = exports.formatDateByCountryCode = exports.validateEmail = exports.validateText = exports.validatePhoneNumber = exports.getApplicationsShortLabels = exports.isSafariOniOS = exports.getDayOfWeekLabel = exports.findScheduleByDayOfWeek = exports.getFormattedIntervals = exports.getFormattedSchedule = exports.formatPhoneNumber = exports.flexLeftRow = exports.capitalizeFirstLetter = exports.getApplicationShortLabel = exports.isEmpty = exports.formatFrenchVehiclePlate = exports.formatVehicleTire = exports.validateField = exports.deleteCookie = void 0;
7
+ exports.CategoryPrestation = exports.VehicleTire = exports.Event = exports.Schedule = exports.VehicleGarage = exports.Garage = exports.Document = exports.Vehicle = exports.Address = exports.Role = exports.User = exports.Customer = exports.Logger = exports.Operation = exports.Prestation = exports.Product = exports.Supplier = exports.Employee = exports.Absence = exports.Subscription = exports.PrintSize = exports.PLVComponent = exports.QrCodePLVContainer = exports.ActivateAccount = exports.GenderSelector = exports.ConfirmationDialog = exports.MovaVehicleTireField = exports.MovaCopyright = exports.MovaSignUp = exports.MovaLogin = exports.MovaSnackbar = exports.TestButton = exports.oldRegexPlate = exports.regexPlate = exports.VehiclePlateField = exports.QRCode = exports.MovaDialog = exports.Loader = exports.MovaDigitalPassport = exports.VehicleFullCard = exports.ScheduleFields = exports.AddressFields = exports.AccountValidation = exports.GaragePLV = exports.IbanInput = exports.DialogForgotPassword = exports.UserService = exports.GarageService = exports.AuthenticationService = exports.VehicleService = void 0;
8
+ exports.openDialogPrint = exports.APIMethod = exports.SubscriptionType = exports.SubscriptionState = exports.CountryCode = exports.PrestationState = exports.PrestationType = exports.RegistrationState = exports.SubscriptionPaymentInterval = exports.VehiclePlateType = exports.SlotAlgorithm = exports.OrderState = exports.OrderPreference = exports.ProductType = exports.PartsApplicationType = exports.DateFormatTypes = exports.Gender = exports.DocumentState = exports.DigitalPassportIndex = exports.DocumentType = exports.EventType = exports.EventState = exports.DayOfWeek = exports.MovaAppType = exports.RoleType = exports.CustomerType = exports.API_BASE_URL = exports.request = exports.getLongFormattedDateTime = exports.formatDateByCountryCode = exports.validateEmail = exports.validateText = exports.validatePhoneNumber = exports.getApplicationsShortLabels = exports.isSafariOniOS = exports.getDayOfWeekLabel = exports.findScheduleByDayOfWeek = exports.getFormattedIntervals = exports.getFormattedSchedule = exports.formatPhoneNumber = exports.flexLeftRow = exports.capitalizeFirstLetter = exports.getApplicationShortLabel = exports.isEmpty = exports.formatFrenchVehiclePlate = exports.formatVehicleTire = exports.validateField = exports.deleteCookie = exports.readCookie = void 0;
9
9
  // Export des services
10
10
  var VehicleService_1 = require("./src/services/VehicleService");
11
11
  Object.defineProperty(exports, "VehicleService", { enumerable: true, get: function () { return __importDefault(VehicleService_1).default; } });
@@ -58,6 +58,8 @@ var ConfirmationDialog_1 = require("./src/ConfirmationDialog");
58
58
  Object.defineProperty(exports, "ConfirmationDialog", { enumerable: true, get: function () { return __importDefault(ConfirmationDialog_1).default; } });
59
59
  var GenderSelector_1 = require("./src/GenderSelector");
60
60
  Object.defineProperty(exports, "GenderSelector", { enumerable: true, get: function () { return __importDefault(GenderSelector_1).default; } });
61
+ var ActivateAccount_1 = require("./src/components/singup/ActivateAccount");
62
+ Object.defineProperty(exports, "ActivateAccount", { enumerable: true, get: function () { return __importDefault(ActivateAccount_1).default; } });
61
63
  var QrCodePLVContainer_1 = require("./src/components/QrCodePLVContainer/QrCodePLVContainer");
62
64
  Object.defineProperty(exports, "QrCodePLVContainer", { enumerable: true, get: function () { return QrCodePLVContainer_1.QrCodePLVContainer; } });
63
65
  var PLVComponent_1 = require("./src/components/QrCodePLVContainer/PLVComponent");
@@ -54,6 +54,7 @@ var AccountValidation = function (_a) {
54
54
  var _j = (0, react_1.useState)(false), showPassword = _j[0], setShowPassword = _j[1];
55
55
  var _k = (0, react_1.useState)(false), openPhoneNumberInput = _k[0], setOpenPhoneNumberInput = _k[1];
56
56
  var isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
57
+ var _l = (0, react_1.useState)(false), loadingBtn = _l[0], setLoadingBtn = _l[1];
57
58
  (0, react_1.useEffect)(function () {
58
59
  var params = location !== undefined ? new URLSearchParams(location.search) : undefined;
59
60
  if (params !== undefined) {
@@ -92,6 +93,7 @@ var AccountValidation = function (_a) {
92
93
  }, [location]);
93
94
  var resetUserPassword = function (req) {
94
95
  if (req) {
96
+ setLoadingBtn(true);
95
97
  UserService_1.default.reestPassword(req)
96
98
  .then(function (response) {
97
99
  var _a, _b;
@@ -111,23 +113,26 @@ var AccountValidation = function (_a) {
111
113
  if (onSubmit) {
112
114
  onSubmit(false, error);
113
115
  }
116
+ }).finally(function () {
117
+ setLoadingBtn(false);
114
118
  });
115
119
  }
116
120
  };
117
121
  var activateUserAccount = function (req) {
118
122
  if (req) {
123
+ setLoadingBtn(true);
119
124
  UserService_1.default.validateAccount(req)
120
125
  .then(function (response) {
121
- var _a, _b;
126
+ var _a;
122
127
  Logger_1.default.info(response);
123
128
  if (response.success) {
124
129
  if (onSubmit) {
125
- onSubmit(response.success, (_a = response.data) !== null && _a !== void 0 ? _a : '');
130
+ onSubmit(response.success, 'Le compte a été activé avec succès.');
126
131
  }
127
132
  }
128
133
  else {
129
134
  if (onSubmit) {
130
- onSubmit(response.success, (_b = response.error) !== null && _b !== void 0 ? _b : '');
135
+ onSubmit(response.success, (_a = response.error) !== null && _a !== void 0 ? _a : '');
131
136
  }
132
137
  }
133
138
  }).catch(function (error) {
@@ -135,6 +140,8 @@ var AccountValidation = function (_a) {
135
140
  if (onSubmit) {
136
141
  onSubmit(false, error);
137
142
  }
143
+ }).finally(function () {
144
+ setLoadingBtn(false);
138
145
  });
139
146
  }
140
147
  };
@@ -255,7 +262,7 @@ var AccountValidation = function (_a) {
255
262
  return ((0, jsx_runtime_1.jsxs)("div", { children: [(emptyPwd || smsValidation || resetPassword || true) &&
256
263
  (0, jsx_runtime_1.jsx)(MovaDialog_1.default, __assign({ leafImageColor: 'pink', titleStyle: getTitleStyle(), fullScreen: isMobile, open: emptyPwd || smsValidation || resetPassword || true, closable: false, onClose: function () {
257
264
  throw new Error('Function not implemented.');
258
- }, actions: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, __assign({ type: "submit", onClick: handleValidateAccount, fullWidth: true, variant: "contained", sx: { mt: 4, mb: 0 } }, { children: resetPassword ? (0, jsx_runtime_1.jsx)("span", { children: "R\u00E9initialiser mon mot de passe" }) : (0, jsx_runtime_1.jsx)("span", { children: "Activer mon compte" }) })) }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: {
265
+ }, actions: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, __assign({ loading: loadingBtn, type: "submit", onClick: handleValidateAccount, fullWidth: true, variant: "contained", sx: { mt: 4, mb: 0 } }, { children: resetPassword ? (0, jsx_runtime_1.jsx)("span", { children: "R\u00E9initialiser mon mot de passe" }) : (0, jsx_runtime_1.jsx)("span", { children: "Activer mon compte" }) })) }, { children: (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: {
259
266
  display: 'flex',
260
267
  flexDirection: 'column',
261
268
  alignItems: 'center',
@@ -2,6 +2,7 @@ import { FunctionComponent, ReactNode } from "react";
2
2
  import { AlertColor } from "@mui/material";
3
3
  import { MovaUserSignUpForm } from "./helpers/Types";
4
4
  import { MovaAppType } from "./helpers/Enums";
5
+ import User from "./models/User";
5
6
  /**
6
7
  * Propriétés du composant
7
8
  * movaAppType : type d'application Movalib au sein de laquelle le composant est injectée
@@ -24,6 +25,7 @@ interface MovaSignUpProps {
24
25
  showLoginButton?: boolean;
25
26
  disableGutters?: boolean;
26
27
  usePhoneNumber?: boolean;
28
+ userToEdit?: User;
27
29
  }
28
30
  /**
29
31
  * Formulaire de création d'un compte Movalib (Garage / Utilisateur)
@@ -69,6 +69,7 @@ var InputAdornment_1 = __importDefault(require("@mui/material/InputAdornment"));
69
69
  var Visibility_1 = __importDefault(require("@mui/icons-material/Visibility"));
70
70
  var VisibilityOff_1 = __importDefault(require("@mui/icons-material/VisibilityOff"));
71
71
  var Info_1 = __importDefault(require("@mui/icons-material/Info"));
72
+ var UserService_1 = __importDefault(require("./services/UserService"));
72
73
  // ATTENTION : s'assurer de la présence des documents suivants à la racine du composant porteur (dossier 'public')
73
74
  var CGUPath = "/Movalib_CGU.pdf";
74
75
  // Permet de centrer le contenu de l'application
@@ -77,29 +78,31 @@ var styles = {
77
78
  justifyContent: 'center',
78
79
  alignItems: 'center'
79
80
  };
80
- var initialUserFormState = {
81
- firstname: { value: '', isValid: true },
82
- lastname: { value: '', isValid: true },
83
- email: { value: '', isValid: true },
84
- phoneNumber: { value: '', isValid: true },
85
- password: { value: '', isValid: true },
86
- gender: { value: '', isValid: true },
87
- birthDate: { value: null, isValid: true },
88
- acceptsTerms: { value: false, isValid: true },
89
- };
90
81
  /**
91
82
  * Formulaire de création d'un compte Movalib (Garage / Utilisateur)
92
83
  * ATTENTION : le lien de consultation des CGU doit pointer vers "/terms-and-conditions"
93
84
  */
94
85
  var MovaSignUp = function (_a) {
95
- var loading = _a.loading, movaAppType = _a.movaAppType, onSubmit = _a.onSubmit, _b = _a.darkMode, darkMode = _b === void 0 ? false : _b, alertMessage = _a.alertMessage, alertSeverity = _a.alertSeverity, headerText = _a.headerText, _c = _a.showHeaderLogo, showHeaderLogo = _c === void 0 ? true : _c, _d = _a.showLeafs, showLeafs = _d === void 0 ? true : _d, _e = _a.showCopyright, showCopyright = _e === void 0 ? true : _e, _f = _a.showLoginButton, showLoginButton = _f === void 0 ? true : _f, _g = _a.disableGutters, disableGutters = _g === void 0 ? false : _g, _h = _a.usePhoneNumber, usePhoneNumber = _h === void 0 ? true : _h;
96
- var _j = (0, react_1.useState)(initialUserFormState), userForm = _j[0], setUserForm = _j[1];
86
+ var _b, _c, _d, _e;
87
+ var loading = _a.loading, movaAppType = _a.movaAppType, onSubmit = _a.onSubmit, _f = _a.darkMode, darkMode = _f === void 0 ? false : _f, alertMessage = _a.alertMessage, alertSeverity = _a.alertSeverity, headerText = _a.headerText, _g = _a.showHeaderLogo, showHeaderLogo = _g === void 0 ? true : _g, _h = _a.showLeafs, showLeafs = _h === void 0 ? true : _h, _j = _a.showCopyright, showCopyright = _j === void 0 ? true : _j, _k = _a.showLoginButton, showLoginButton = _k === void 0 ? true : _k, _l = _a.disableGutters, disableGutters = _l === void 0 ? false : _l, _m = _a.usePhoneNumber, usePhoneNumber = _m === void 0 ? true : _m, _o = _a.userToEdit, userToEdit = _o === void 0 ? null : _o;
88
+ var _p = (0, react_1.useState)({
89
+ firstname: { value: (_b = userToEdit === null || userToEdit === void 0 ? void 0 : userToEdit.firstname) !== null && _b !== void 0 ? _b : '', isValid: true },
90
+ lastname: { value: (_c = userToEdit === null || userToEdit === void 0 ? void 0 : userToEdit.lastname) !== null && _c !== void 0 ? _c : '', isValid: true },
91
+ email: { value: (_d = userToEdit === null || userToEdit === void 0 ? void 0 : userToEdit.email) !== null && _d !== void 0 ? _d : '', isValid: true },
92
+ phoneNumber: { value: (_e = userToEdit === null || userToEdit === void 0 ? void 0 : userToEdit.phoneNumber) !== null && _e !== void 0 ? _e : '', isValid: true },
93
+ password: { value: '', isValid: true },
94
+ gender: { value: '', isValid: true },
95
+ birthDate: { value: null, isValid: true },
96
+ acceptsTerms: { value: false, isValid: true },
97
+ }), userForm = _p[0], setUserForm = _p[1];
97
98
  var history = (0, react_router_dom_1.useHistory)();
98
- var _k = (0, react_1.useState)(""), message = _k[0], setMessage = _k[1];
99
+ var _q = (0, react_1.useState)(""), message = _q[0], setMessage = _q[1];
99
100
  var theme = (0, material_1.useTheme)();
100
- var _l = (0, react_1.useState)(false), showPassword = _l[0], setShowPassword = _l[1];
101
- var _m = (0, react_1.useState)(false), openEmailInfo = _m[0], setOpenEmailInfo = _m[1];
102
- var _o = (0, react_1.useState)(false), openPhoneNumberInfo = _o[0], setOpenPhoneNumberInfo = _o[1];
101
+ var _r = (0, react_1.useState)(false), showPassword = _r[0], setShowPassword = _r[1];
102
+ var _s = (0, react_1.useState)(false), openEmailInfo = _s[0], setOpenEmailInfo = _s[1];
103
+ var _t = (0, react_1.useState)(false), openPhoneNumberInfo = _t[0], setOpenPhoneNumberInfo = _t[1];
104
+ var _u = (0, react_1.useState)(false), userExist = _u[0], setUserExist = _u[1];
105
+ var _v = (0, react_1.useState)(false), userIsAlreadyActive = _v[0], setUserIsAlreadyActive = _v[1];
103
106
  var handleDateChange = function (name, date) {
104
107
  var _a;
105
108
  if (name && date) {
@@ -121,6 +124,28 @@ var MovaSignUp = function (_a) {
121
124
  if (fieldValue.length > 10) {
122
125
  fieldValue = fieldValue.substring(0, 10);
123
126
  }
127
+ if (fieldValue.length === 10) {
128
+ UserService_1.default.existsByPhoneNumber(fieldValue).then(function (response) {
129
+ if (response && response.data) {
130
+ if (response.data.isActive === false) {
131
+ setUserExist(true);
132
+ setUserIsAlreadyActive(false);
133
+ }
134
+ else if (response.data.isActive === true) {
135
+ setUserIsAlreadyActive(true);
136
+ setUserExist(false);
137
+ }
138
+ else {
139
+ setUserExist(false);
140
+ setUserIsAlreadyActive(false);
141
+ }
142
+ }
143
+ });
144
+ }
145
+ else {
146
+ setUserExist(false);
147
+ setUserIsAlreadyActive(false);
148
+ }
124
149
  }
125
150
  // Capitalisation automatique du prénom
126
151
  if (fieldName == "firstname") {
@@ -229,9 +254,9 @@ var MovaSignUp = function (_a) {
229
254
  '& .MuiOutlinedInput-notchedOutline': {
230
255
  borderColor: darkMode ? 'white' : 'default', // Couleur de la bordure
231
256
  }
232
- } }), usePhoneNumber && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { type: "tel", margin: "normal", required: true, fullWidth: true, id: "phoneNumber", label: "N\u00B0 de t\u00E9l\u00E9phone", name: "phoneNumber", autoComplete: "tel", onChange: function (e) { return handleInputChange(e); }, value: userForm.phoneNumber.value, error: Boolean(userForm.phoneNumber.error), helperText: userForm.phoneNumber.error, InputProps: {
233
- endAdornment: ((0, jsx_runtime_1.jsx)(InputAdornment_1.default, __assign({ position: "end" }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ edge: "end", onClick: function () { return setOpenPhoneNumberInfo(!openPhoneNumberInfo); } }, { children: (0, jsx_runtime_1.jsx)(Info_1.default, {}) })) }))),
234
- } }), openPhoneNumberInfo && (0, jsx_runtime_1.jsx)(material_1.Alert, __assign({ severity: "info", variant: 'standard' }, { children: "Entrez le num\u00E9ro de t\u00E9l\u00E9phone que vous avez utilis\u00E9 pour r\u00E9server, afin de suivre facilement vos rendez-vous." }))] }), (0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", required: true, fullWidth: true, id: "email", label: "Adresse email", name: "email", autoComplete: "email", onChange: function (e) { return handleInputChange(e); }, value: userForm.email.value, error: !userForm.email.isValid, helperText: userForm.email.error, sx: {
257
+ } }), usePhoneNumber && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { type: "tel", margin: "normal", required: true, fullWidth: true, id: "phoneNumber", label: "N\u00B0 de t\u00E9l\u00E9phone", name: "phoneNumber", autoComplete: "tel", disabled: userToEdit && userToEdit.phoneNumber ? true : false, onChange: function (e) { return handleInputChange(e); }, value: userForm.phoneNumber.value, error: Boolean(userForm.phoneNumber.error), helperText: userForm.phoneNumber.error, InputProps: {
258
+ endAdornment: ((0, jsx_runtime_1.jsx)(InputAdornment_1.default, __assign({ position: "end" }, { children: !userExist && (0, jsx_runtime_1.jsx)(material_1.IconButton, __assign({ edge: "end", onClick: function () { return setOpenPhoneNumberInfo(!openPhoneNumberInfo); } }, { children: (0, jsx_runtime_1.jsx)(Info_1.default, {}) })) }))),
259
+ } }), openPhoneNumberInfo && !userExist && (0, jsx_runtime_1.jsx)(material_1.Alert, __assign({ severity: "info", variant: 'standard' }, { children: "Entrez le num\u00E9ro de t\u00E9l\u00E9phone que vous avez utilis\u00E9 pour r\u00E9server, afin de suivre facilement vos rendez-vous." })), userExist && (0, jsx_runtime_1.jsx)(material_1.Alert, __assign({ severity: "success", variant: 'standard' }, { children: "Rendez-vous trouv\u00E9(s) pour ce num\u00E9ro ! Vous pourrez le(s) consulter apr\u00E8s avoir cr\u00E9\u00E9 votre compte." })), userIsAlreadyActive && (0, jsx_runtime_1.jsx)(material_1.Alert, __assign({ severity: "error", sx: { marginTop: '5px' }, variant: 'standard' }, { children: "Il semble qu\u2019un compte existe d\u00E9j\u00E0 avec ce num\u00E9ro. Connectez-vous ou utilisez \"Mot de passe oubli\u00E9\" pour y acc\u00E9der facilement." }))] }), (0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", required: true, fullWidth: true, id: "email", label: "Adresse email", name: "email", autoComplete: "email", disabled: userToEdit && userToEdit.email ? true : false, onChange: function (e) { return handleInputChange(e); }, value: userForm.email.value, error: !userForm.email.isValid, helperText: userForm.email.error, sx: {
235
260
  '& .MuiOutlinedInput-notchedOutline': {
236
261
  borderColor: darkMode ? 'white' : 'default', // Couleur de la bordure
237
262
  }
@@ -0,0 +1,10 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { MovaAppType } from '../../helpers/Enums';
3
+ interface ActivateAccountProps {
4
+ movaAppType: MovaAppType;
5
+ smsValidation: boolean;
6
+ onSubmit: (success: boolean, message: string) => void;
7
+ onResendSecurityCode?: (success: boolean, message: string) => void;
8
+ }
9
+ declare const ActivateAccount: FunctionComponent<ActivateAccountProps>;
10
+ export default ActivateAccount;
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var jsx_runtime_1 = require("react/jsx-runtime");
18
+ var react_1 = require("react");
19
+ var react_router_dom_1 = require("react-router-dom");
20
+ var UserService_1 = __importDefault(require("../../services/UserService"));
21
+ var material_1 = require("@mui/material");
22
+ var Logger_1 = __importDefault(require("../../helpers/Logger"));
23
+ var Enums_1 = require("../../helpers/Enums");
24
+ var Tools_1 = require("../../helpers/Tools");
25
+ var MovaSignUp_1 = __importDefault(require("../../MovaSignUp"));
26
+ var Validator_1 = require("../../helpers/Validator");
27
+ var ActivateAccount = function (_a) {
28
+ var movaAppType = _a.movaAppType, smsValidation = _a.smsValidation, onSubmit = _a.onSubmit, onResendSecurityCode = _a.onResendSecurityCode;
29
+ var code = (0, react_router_dom_1.useParams)().code;
30
+ var location = (0, react_router_dom_1.useLocation)();
31
+ var theme = (0, material_1.useTheme)();
32
+ var _b = (0, react_1.useState)(""), alertMessage = _b[0], setAlertMessage = _b[1];
33
+ // La sévérité est initialiée à "error" par défaut
34
+ var _c = (0, react_1.useState)('error'), alertSeverity = _c[0], setAlertSeverity = _c[1];
35
+ var _d = (0, react_1.useState)(false), loading = _d[0], setLoading = _d[1];
36
+ var _e = (0, react_1.useState)(null), currentUser = _e[0], setCurrentUser = _e[1];
37
+ var _f = (0, react_1.useState)(false), expiredCode = _f[0], setExpiredCode = _f[1];
38
+ var _g = (0, react_1.useState)(false), unknowCode = _g[0], setUnknowCode = _g[1];
39
+ var _h = (0, react_1.useState)({ phoneNumber: { value: '', isValid: true } }), validationForm = _h[0], setValidationForm = _h[1];
40
+ var history = (0, react_router_dom_1.useHistory)();
41
+ // ajout d'un load pour le chargement de la page
42
+ var getUserByTokenOrCode = function () {
43
+ setExpiredCode(false);
44
+ setUnknowCode(false);
45
+ var params = location !== undefined ? new URLSearchParams(location.search) : undefined;
46
+ var req = {
47
+ token: !smsValidation ? params === null || params === void 0 ? void 0 : params.get('token') : null,
48
+ securityCode: smsValidation ? code : null,
49
+ demoGarage: Boolean(params === null || params === void 0 ? void 0 : params.get('demoGarage'))
50
+ };
51
+ UserService_1.default.validateAccount(req).then(function (response) {
52
+ if (response.success) {
53
+ setCurrentUser(response.data);
54
+ }
55
+ else {
56
+ var data = response.data;
57
+ if (data === null || data === void 0 ? void 0 : data.expiredCode) {
58
+ setExpiredCode(true);
59
+ }
60
+ if (data === null || data === void 0 ? void 0 : data.unknownCode) {
61
+ setUnknowCode(true);
62
+ }
63
+ }
64
+ });
65
+ };
66
+ (0, react_1.useEffect)(function () {
67
+ getUserByTokenOrCode();
68
+ }, []);
69
+ var updateActivateUseronSubmit = function (form) {
70
+ // appelle api pour mettre a jour l'utilisateur + auto activate en fonction du movaAPPType
71
+ if (movaAppType === Enums_1.MovaAppType.INDIVIDUAL && currentUser) {
72
+ setLoading(true);
73
+ try {
74
+ // On prépare la query
75
+ var query = {
76
+ code: code,
77
+ email: form.email.value,
78
+ password: form.password.value,
79
+ firstname: form.firstname.value,
80
+ lastname: form.lastname.value,
81
+ };
82
+ UserService_1.default.editUser(query, currentUser.id)
83
+ .then(function (response) {
84
+ var _a, _b;
85
+ //success or Error this is parent component responsability
86
+ Logger_1.default.info(response);
87
+ if (response.success) {
88
+ onSubmit(response.success, (_a = response.data) !== null && _a !== void 0 ? _a : 'Le compte a été mis à jour et activé avec succès');
89
+ history.push('/login');
90
+ }
91
+ else {
92
+ onSubmit(response.success, (_b = response.error) !== null && _b !== void 0 ? _b : 'Erreur lors de la mise à jour du compte');
93
+ }
94
+ }).catch(function (error) {
95
+ onSubmit(false, 'Erreur lors de la mise à jour du compte');
96
+ Logger_1.default.error(error);
97
+ setAlertMessage(error);
98
+ });
99
+ }
100
+ catch (error) {
101
+ console.error('Error occurred during submission:', error);
102
+ }
103
+ finally {
104
+ setLoading(false);
105
+ }
106
+ }
107
+ };
108
+ var controlPhoneNumber = function () {
109
+ var _a, _b, _c, _d, _e;
110
+ var newForm = validationForm;
111
+ var newField;
112
+ newForm.phoneNumber = (0, Tools_1.validateField)(validationForm.phoneNumber, function (value) { return !!value; }, 'Champ obligatoire');
113
+ // Validator 'phoneNumber'
114
+ if ((_a = newForm.phoneNumber) === null || _a === void 0 ? void 0 : _a.value) {
115
+ if (((_b = newForm.phoneNumber) === null || _b === void 0 ? void 0 : _b.value.length) < 10) {
116
+ newField = { value: (_c = validationForm.phoneNumber) === null || _c === void 0 ? void 0 : _c.value, error: "Le n° de téléphone est invalide." };
117
+ }
118
+ else {
119
+ newField = { value: (_d = validationForm.phoneNumber) === null || _d === void 0 ? void 0 : _d.value, error: '' };
120
+ }
121
+ newForm = __assign(__assign({}, newForm), { phoneNumber: newField });
122
+ }
123
+ setValidationForm(newForm);
124
+ return !Boolean((_e = newForm.phoneNumber) === null || _e === void 0 ? void 0 : _e.error);
125
+ };
126
+ var handleInputChange = function (e) {
127
+ var _a;
128
+ if (e) {
129
+ var fieldName = e.target.name;
130
+ var fieldValue = e.target.value;
131
+ var newField = (_a = {}, _a[fieldName] = { value: fieldValue, isValid: true }, _a);
132
+ if (fieldName == "phoneNumber") {
133
+ if (!(0, Validator_1.validatePhoneNumber)(fieldValue))
134
+ return;
135
+ }
136
+ setValidationForm(__assign(__assign({}, validationForm), newField));
137
+ }
138
+ };
139
+ var resendCode = function () {
140
+ var _a;
141
+ if (controlPhoneNumber() && onResendSecurityCode) {
142
+ var req = {
143
+ phoneNumber: (_a = validationForm.phoneNumber) === null || _a === void 0 ? void 0 : _a.value
144
+ };
145
+ UserService_1.default.resendActivationAccount(req)
146
+ .then(function (response) {
147
+ var _a, _b;
148
+ Logger_1.default.info(response);
149
+ if (response.success) {
150
+ onResendSecurityCode(response.success, (_a = response.data) !== null && _a !== void 0 ? _a : '');
151
+ }
152
+ else {
153
+ onResendSecurityCode(response.success, (_b = response.error) !== null && _b !== void 0 ? _b : '');
154
+ }
155
+ history.push('/login');
156
+ }).catch(function (error) {
157
+ Logger_1.default.error(error);
158
+ if (onSubmit) {
159
+ onSubmit(false, error);
160
+ }
161
+ });
162
+ }
163
+ };
164
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [currentUser !== null && (0, jsx_runtime_1.jsx)(MovaSignUp_1.default, { movaAppType: movaAppType, onSubmit: updateActivateUseronSubmit, alertMessage: alertMessage, alertSeverity: alertSeverity, userToEdit: currentUser, loading: loading }), expiredCode && ((0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: { width: '99vw', height: '99vh', display: 'flex' } }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: {
165
+ display: 'block',
166
+ margin: 'auto',
167
+ textAlign: 'center',
168
+ padding: 3,
169
+ borderRadius: 2,
170
+ boxShadow: 3,
171
+ maxWidth: 400,
172
+ backgroundColor: 'white',
173
+ } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "h6", color: "error", gutterBottom: true }, { children: "Code de validation expir\u00E9" })), (0, jsx_runtime_1.jsxs)(material_1.Typography, { children: [(0, jsx_runtime_1.jsx)("b", { children: "Indiquez nous votre num\u00E9ro de t\u00E9l\u00E9phone." }), (0, jsx_runtime_1.jsx)("br", {}), "Nous allons renvoyer un SMS d'activation de compte"] }), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 6 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", fullWidth: true, required: true, id: "phoneNumber", label: "N\u00B0 de t\u00E9l\u00E9phone", name: "phoneNumber", autoComplete: "tel", onChange: function (e) { return handleInputChange(e); }, value: validationForm.phoneNumber.value, error: Boolean(validationForm.phoneNumber.error), helperText: validationForm.phoneNumber.error }) })), (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ onClick: resendCode, sx: { cursor: 'pointer', textAlign: 'center', width: '100%', mt: 1 } }, { children: "Renvoyer le code" }))] })) }))), unknowCode && ((0, jsx_runtime_1.jsx)(material_1.Box, __assign({ sx: { width: '99vw', height: '99vh', display: 'flex' } }, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: {
174
+ display: 'flex',
175
+ flexDirection: 'column',
176
+ alignItems: 'center',
177
+ justifyContent: 'center',
178
+ height: '100%',
179
+ width: '100%',
180
+ margin: 'auto',
181
+ textAlign: 'center',
182
+ padding: 3,
183
+ borderRadius: 2,
184
+ boxShadow: 3,
185
+ backgroundColor: 'white',
186
+ } }, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: "h6", color: "error", gutterBottom: true }, { children: "Code de validation invalide" })), (0, jsx_runtime_1.jsxs)(material_1.Typography, __assign({ variant: "body1", color: "textSecondary", gutterBottom: true }, { children: ["Le code de validation fourni ne correspond \u00E0 aucun utilisateur (ou votre compte a d\u00E9j\u00E0 \u00E9t\u00E9 activ\u00E9). ", (0, jsx_runtime_1.jsx)("br", {}), "Essayez de vous connecter avec votre num\u00E9ro de t\u00E9l\u00E9phone.", (0, jsx_runtime_1.jsx)("br", {}), "Si le probl\u00E8me persiste, veuillez nous contacter \u00E0", ' ', (0, jsx_runtime_1.jsx)("b", { children: "support@movalib.com" }), "."] })), (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ variant: "contained", color: "primary", onClick: function (e) { return history.push('/login'); }, sx: { marginTop: 2 } }, { children: "Retour \u00E0 la connexion" }))] })) })))] }));
187
+ };
188
+ exports.default = ActivateAccount;
@@ -25,19 +25,19 @@ function handleResponse(response) {
25
25
  var errorMsg = void 0;
26
26
  switch (response.status) {
27
27
  case 403:
28
- errorMsg = 'Accès non autorisé (403)';
28
+ errorMsg = 'Accès non autorisé';
29
29
  break;
30
30
  case 404:
31
- errorMsg = 'La ressource demandée est introuvable (404)';
31
+ errorMsg = (typeof data === 'string') ? data : 'La ressource demandée est introuvable';
32
32
  break;
33
33
  case 500:
34
- errorMsg = 'Une erreur interne du serveur est survenue (500)';
34
+ errorMsg = 'Une erreur interne du serveur est survenue';
35
35
  break;
36
36
  default:
37
- errorMsg = (typeof data === 'string') ? data : "Une erreur est survenue (".concat(response.status, ")");
37
+ errorMsg = (typeof data === 'string') ? data : "Une erreur est survenue";
38
38
  break;
39
39
  }
40
- return { success: false, error: errorMsg };
40
+ return { success: false, error: errorMsg, data: data };
41
41
  }
42
42
  return { success: true, data: data };
43
43
  });
@@ -7,8 +7,13 @@ export default class UserService {
7
7
  static existsByPhoneNumber(phoneNumber: string): Promise<APIResponse<User>>;
8
8
  static reestPassword(req: any): Promise<APIResponse<string>>;
9
9
  static resendSecurityCode(req: any): Promise<APIResponse<string>>;
10
+ static resendActivationAccount(req: any): Promise<APIResponse<string>>;
10
11
  static getSalesGarages(salesId: string): Promise<APIResponse<Garage[]>>;
11
- static validateAccount(req: any): Promise<APIResponse<string>>;
12
+ static validateAccount(req: any): Promise<APIResponse<User | {
13
+ expiredCode?: boolean;
14
+ unknowCode?: boolean;
15
+ }>>;
16
+ static editUser(req: any, userId: string): Promise<APIResponse<string>>;
12
17
  /**
13
18
  * @param email
14
19
  * @param password
@@ -73,6 +73,14 @@ var UserService = /** @class */ (function () {
73
73
  body: JSON.stringify(req)
74
74
  });
75
75
  };
76
+ UserService.resendActivationAccount = function (req) {
77
+ return (0, ApiHelper_1.request)({
78
+ url: "".concat(ApiHelper_1.API_BASE_URL, "/user/resend-activation-link"),
79
+ method: Enums_1.APIMethod.POST,
80
+ appType: Enums_1.MovaAppType.INDIVIDUAL,
81
+ body: JSON.stringify(req)
82
+ });
83
+ };
76
84
  UserService.getSalesGarages = function (salesId) {
77
85
  return (0, ApiHelper_1.request)({
78
86
  url: "".concat(ApiHelper_1.API_BASE_URL, "/sales/").concat(salesId, "/garages"),
@@ -88,6 +96,14 @@ var UserService = /** @class */ (function () {
88
96
  body: JSON.stringify(req)
89
97
  });
90
98
  };
99
+ UserService.editUser = function (req, userId) {
100
+ return (0, ApiHelper_1.request)({
101
+ url: "".concat(ApiHelper_1.API_BASE_URL, "/user/").concat(userId, "/complete"),
102
+ method: Enums_1.APIMethod.PATCH,
103
+ appType: Enums_1.MovaAppType.INDIVIDUAL,
104
+ body: JSON.stringify(req)
105
+ });
106
+ };
91
107
  /**
92
108
  * @param email
93
109
  * @param password
package/index.ts CHANGED
@@ -28,6 +28,7 @@ export { default as MovaCopyright } from './src/MovaCopyright';
28
28
  export { default as MovaVehicleTireField } from './src/MovaVehicleTireField';
29
29
  export { default as ConfirmationDialog } from './src/ConfirmationDialog';
30
30
  export { default as GenderSelector } from './src/GenderSelector';
31
+ export { default as ActivateAccount } from './src/components/singup/ActivateAccount';
31
32
  export { QrCodePLVContainer } from './src/components/QrCodePLVContainer/QrCodePLVContainer';
32
33
  export { PLVComponent, PrintSize } from './src/components/QrCodePLVContainer/PLVComponent';
33
34
  // Export des classes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.59.9",
3
+ "version": "1.59.10",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -48,6 +48,7 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
48
48
  const [showPassword, setShowPassword] = useState(false);
49
49
  const [openPhoneNumberInput, setOpenPhoneNumberInput] = useState<boolean>(false);
50
50
  const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
51
+ const [loadingBtn, setLoadingBtn] = useState<boolean>(false);
51
52
 
52
53
  useEffect(() => {
53
54
 
@@ -99,6 +100,7 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
99
100
 
100
101
  const resetUserPassword = (req: any) => {
101
102
  if(req){
103
+ setLoadingBtn(true);
102
104
 
103
105
  UserService.reestPassword(req)
104
106
  .then(response => {
@@ -120,13 +122,15 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
120
122
  if(onSubmit){
121
123
  onSubmit(false, error);
122
124
  }
125
+ }).finally(() => {
126
+ setLoadingBtn(false);
123
127
  });
124
128
  }
125
129
  }
126
130
 
127
131
  const activateUserAccount = (req: any) => {
128
132
  if(req){
129
-
133
+ setLoadingBtn(true);
130
134
  UserService.validateAccount(req)
131
135
  .then(response => {
132
136
 
@@ -134,7 +138,7 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
134
138
 
135
139
  if(response.success){
136
140
  if(onSubmit){
137
- onSubmit(response.success, response.data ?? '');
141
+ onSubmit(response.success, 'Le compte a été activé avec succès.');
138
142
  }
139
143
  }else{
140
144
  if(onSubmit){
@@ -147,6 +151,8 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
147
151
  if(onSubmit){
148
152
  onSubmit(false, error);
149
153
  }
154
+ }).finally(() => {
155
+ setLoadingBtn(false);
150
156
  });
151
157
  }
152
158
  }
@@ -311,6 +317,7 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
311
317
  }}
312
318
  actions={
313
319
  <LoadingButton
320
+ loading={loadingBtn}
314
321
  type="submit"
315
322
  onClick={handleValidateAccount}
316
323
  fullWidth
@@ -22,6 +22,8 @@ import VisibilityOff from '@mui/icons-material/VisibilityOff';
22
22
  import InfoIcon from '@mui/icons-material/Info';
23
23
  import isValid from 'date-fns/isValid';
24
24
  import Logger from "./helpers/Logger";
25
+ import User from "./models/User";
26
+ import UserService from "./services/UserService";
25
27
 
26
28
  // ATTENTION : s'assurer de la présence des documents suivants à la racine du composant porteur (dossier 'public')
27
29
  const CGUPath:string = "/Movalib_CGU.pdf";
@@ -33,17 +35,6 @@ const styles: CSSProperties = {
33
35
  alignItems: 'center'
34
36
  };
35
37
 
36
- const initialUserFormState = {
37
- firstname: { value: '', isValid: true },
38
- lastname: { value: '', isValid: true },
39
- email: { value: '', isValid: true },
40
- phoneNumber: { value: '', isValid: true },
41
- password: { value: '', isValid: true },
42
- gender: { value: '', isValid: true },
43
- birthDate: { value: null, isValid: true },
44
- acceptsTerms: { value: false, isValid: true },
45
- };
46
-
47
38
  /**
48
39
  * Propriétés du composant
49
40
  * movaAppType : type d'application Movalib au sein de laquelle le composant est injectée
@@ -66,6 +57,7 @@ interface MovaSignUpProps {
66
57
  showLoginButton?: boolean,
67
58
  disableGutters?: boolean,
68
59
  usePhoneNumber?: boolean
60
+ userToEdit?: User,
69
61
  }
70
62
 
71
63
  /**
@@ -73,16 +65,28 @@ interface MovaSignUpProps {
73
65
  * ATTENTION : le lien de consultation des CGU doit pointer vers "/terms-and-conditions"
74
66
  */
75
67
  const MovaSignUp: FunctionComponent<MovaSignUpProps> = ({ loading, movaAppType, onSubmit, darkMode = false, alertMessage, alertSeverity, headerText,
76
- showHeaderLogo = true, showLeafs= true, showCopyright = true, showLoginButton = true, disableGutters = false, usePhoneNumber = true}) => {
77
-
78
- const [userForm, setUserForm] = useState<MovaUserSignUpForm>(initialUserFormState);
68
+ showHeaderLogo = true, showLeafs= true, showCopyright = true, showLoginButton = true, disableGutters = false, usePhoneNumber = true, userToEdit = null}) => {
69
+
70
+ const [userForm, setUserForm] = useState<MovaUserSignUpForm>(
71
+ {
72
+ firstname: { value: userToEdit?.firstname ?? '', isValid: true },
73
+ lastname: { value: userToEdit?.lastname ?? '', isValid: true },
74
+ email: { value: userToEdit?.email ?? '', isValid: true },
75
+ phoneNumber: { value: userToEdit?.phoneNumber ?? '', isValid: true },
76
+ password: { value: '', isValid: true },
77
+ gender: { value: '', isValid: true },
78
+ birthDate: { value: null, isValid: true },
79
+ acceptsTerms: { value: false, isValid: true },
80
+ }
81
+ );
79
82
  const history = useHistory();
80
83
  const [message, setMessage] = useState<string>("");
81
84
  const theme = useTheme();
82
85
  const [showPassword, setShowPassword] = useState(false);
83
86
  const [openEmailInfo, setOpenEmailInfo] = useState(false);
84
87
  const [openPhoneNumberInfo, setOpenPhoneNumberInfo] = useState(false);
85
-
88
+ const [userExist, setUserExist] = useState<boolean>(false);
89
+ const [userIsAlreadyActive, setUserIsAlreadyActive] = useState<boolean>(false);
86
90
  const handleDateChange = (name: string, date: Date | null) => {
87
91
 
88
92
  if(name && date){
@@ -106,6 +110,25 @@ const MovaSignUp: FunctionComponent<MovaSignUpProps> = ({ loading, movaAppType,
106
110
  if (fieldValue.length > 10) {
107
111
  fieldValue = fieldValue.substring(0, 10);
108
112
  }
113
+ if (fieldValue.length === 10){
114
+ UserService.existsByPhoneNumber(fieldValue).then((response) => {
115
+ if(response && response.data){
116
+ if(response.data.isActive === false){
117
+ setUserExist(true);
118
+ setUserIsAlreadyActive(false);
119
+ } else if (response.data.isActive === true){
120
+ setUserIsAlreadyActive(true);
121
+ setUserExist(false);
122
+ } else {
123
+ setUserExist(false);
124
+ setUserIsAlreadyActive(false);
125
+ }
126
+ }
127
+ })
128
+ } else {
129
+ setUserExist(false);
130
+ setUserIsAlreadyActive(false);
131
+ }
109
132
  }
110
133
 
111
134
  // Capitalisation automatique du prénom
@@ -285,24 +308,28 @@ const MovaSignUp: FunctionComponent<MovaSignUpProps> = ({ loading, movaAppType,
285
308
  id="phoneNumber"
286
309
  label="N° de téléphone"
287
310
  name="phoneNumber"
288
- autoComplete="tel"
311
+ autoComplete="tel"
312
+ disabled={userToEdit && userToEdit.phoneNumber ? true : false}
289
313
  onChange={e => handleInputChange(e)}
290
314
  value={userForm.phoneNumber.value}
291
315
  error={Boolean(userForm.phoneNumber.error)}
292
316
  helperText={userForm.phoneNumber.error}
293
317
  InputProps={{
294
318
  endAdornment: (
295
- <InputAdornment position="end">
296
- <IconButton
319
+ <InputAdornment position="end">
320
+ {!userExist && <IconButton
297
321
  edge="end"
298
322
  onClick={() => setOpenPhoneNumberInfo(!openPhoneNumberInfo)}
299
323
  ><InfoIcon />
300
- </IconButton>
324
+ </IconButton>}
301
325
  </InputAdornment>
302
326
  ),
303
327
  }}
304
328
  />
305
- {openPhoneNumberInfo && <Alert severity="info" variant='standard'>Entrez le numéro de téléphone que vous avez utilisé pour réserver, afin de suivre facilement vos rendez-vous.</Alert>}
329
+ {openPhoneNumberInfo && !userExist && <Alert severity="info" variant='standard'>Entrez le numéro de téléphone que vous avez utilisé pour réserver, afin de suivre facilement vos rendez-vous.</Alert>}
330
+ {userExist && <Alert severity="success" variant='standard'>Rendez-vous trouvé(s) pour ce numéro ! Vous pourrez le(s) consulter après avoir créé votre compte.</Alert>}
331
+ {userIsAlreadyActive && <Alert severity="error" sx={{marginTop: '5px'}} variant='standard'>Il semble qu’un compte existe déjà avec ce numéro. Connectez-vous ou utilisez "Mot de passe oublié" pour y accéder facilement.</Alert>}
332
+
306
333
  </>
307
334
  }
308
335
  <TextField
@@ -313,6 +340,7 @@ const MovaSignUp: FunctionComponent<MovaSignUpProps> = ({ loading, movaAppType,
313
340
  label="Adresse email"
314
341
  name="email"
315
342
  autoComplete="email"
343
+ disabled={userToEdit && userToEdit.email ? true : false}
316
344
  onChange={e => handleInputChange(e)}
317
345
  value={userForm.email.value}
318
346
  error={!userForm.email.isValid}
@@ -0,0 +1,273 @@
1
+ import { CSSProperties, FunctionComponent, useEffect, useState } from 'react';
2
+ import { useHistory, useLocation, useParams } from 'react-router-dom';
3
+ import UserService from '../../services/UserService';
4
+ import { AlertColor, Box, Button, Checkbox, CircularProgress, FormControl, FormControlLabel, FormHelperText, Grid, IconButton, Link, SelectChangeEvent, TextField, Typography, colors, darken, useMediaQuery, useTheme } from '@mui/material';
5
+ import Logger from '../../helpers/Logger';
6
+ import { MovaAppType } from '../../helpers/Enums';
7
+ import { MovaFormField, MovaUserSignUpForm, MovaValidationForm } from '../../helpers/Types';
8
+ import { flexStart, validateField } from '../../helpers/Tools';
9
+ import User from '../../models/User';
10
+ import { set } from 'date-fns';
11
+ import MovaSignUp from '../../MovaSignUp';
12
+ import { validatePhoneNumber } from '../../helpers/Validator';
13
+
14
+ interface RouteParams {
15
+ code: string; // Définissez ici les paramètres de route attendus
16
+ }
17
+ interface ActivateAccountProps {
18
+ movaAppType: MovaAppType,
19
+ smsValidation: boolean,
20
+ onSubmit: (success: boolean, message: string) => void,
21
+ onResendSecurityCode?: (success: boolean, message: string) => void,
22
+ }
23
+
24
+
25
+ const ActivateAccount: FunctionComponent<ActivateAccountProps> = ({ movaAppType, smsValidation, onSubmit, onResendSecurityCode }) => {
26
+ const { code } = useParams<RouteParams>();
27
+ const location = useLocation();
28
+ const theme = useTheme();
29
+ const [alertMessage, setAlertMessage] = useState<string>("");
30
+ // La sévérité est initialiée à "error" par défaut
31
+ const [alertSeverity, setAlertSeverity] = useState<AlertColor>('error');
32
+ const [loading, setLoading] = useState(false);
33
+ const [currentUser, setCurrentUser] = useState<User | null>(null);
34
+ const [expiredCode, setExpiredCode] = useState(false);
35
+ const [unknowCode, setUnknowCode] = useState(false);
36
+ const [validationForm, setValidationForm] = useState<any>({ phoneNumber: { value: '', isValid: true } });
37
+
38
+ const history = useHistory();
39
+ // ajout d'un load pour le chargement de la page
40
+ const getUserByTokenOrCode = () => {
41
+ setExpiredCode(false);
42
+ setUnknowCode(false);
43
+ const params = location !== undefined ? new URLSearchParams(location.search) : undefined;
44
+ let req = {
45
+ token: !smsValidation ? params?.get('token') : null,
46
+ securityCode: smsValidation ? code : null,
47
+ demoGarage: Boolean(params?.get('demoGarage'))
48
+ }
49
+ UserService.validateAccount(req).then(response => {
50
+ if (response.success) {
51
+ setCurrentUser(response.data as User);
52
+ } else {
53
+ const data = response.data as { expiredCode?: boolean, unknownCode?: boolean };
54
+ if (data?.expiredCode) {
55
+ setExpiredCode(true);
56
+ }
57
+ if (data?.unknownCode) {
58
+ setUnknowCode(true);
59
+ }
60
+ }
61
+ })
62
+ };
63
+
64
+ useEffect(() => {
65
+ getUserByTokenOrCode();
66
+ }, []);
67
+
68
+ const updateActivateUseronSubmit = (form: MovaUserSignUpForm) => {
69
+ // appelle api pour mettre a jour l'utilisateur + auto activate en fonction du movaAPPType
70
+ if (movaAppType === MovaAppType.INDIVIDUAL && currentUser) {
71
+ setLoading(true);
72
+ try {
73
+
74
+ // On prépare la query
75
+ let query = {
76
+ code: code,
77
+ email: form.email.value,
78
+ password: form.password.value,
79
+ firstname: form.firstname.value,
80
+ lastname: form.lastname.value,
81
+ }
82
+
83
+ UserService.editUser(query, currentUser.id)
84
+ .then(response => {
85
+ //success or Error this is parent component responsability
86
+ Logger.info(response);
87
+ if (response.success) {
88
+ onSubmit(response.success, response.data ?? 'Le compte a été mis à jour et activé avec succès');
89
+ history.push('/login');
90
+ } else {
91
+ onSubmit(response.success, response.error ?? 'Erreur lors de la mise à jour du compte');
92
+ }
93
+
94
+ }).catch(error => {
95
+ onSubmit(false, 'Erreur lors de la mise à jour du compte');
96
+ Logger.error(error);
97
+ setAlertMessage(error);
98
+ });
99
+
100
+ } catch (error) {
101
+ console.error('Error occurred during submission:', error);
102
+ } finally {
103
+ setLoading(false);
104
+ }
105
+ }
106
+
107
+
108
+ }
109
+ const controlPhoneNumber = (): boolean => {
110
+
111
+ let newForm: MovaValidationForm = validationForm;
112
+ let newField: MovaFormField;
113
+
114
+ newForm.phoneNumber = validateField(validationForm.phoneNumber, value => !!value, 'Champ obligatoire');
115
+
116
+ // Validator 'phoneNumber'
117
+ if (newForm.phoneNumber?.value) {
118
+ if (newForm.phoneNumber?.value.length < 10) {
119
+ newField = { value: validationForm.phoneNumber?.value, error: "Le n° de téléphone est invalide." };
120
+ } else {
121
+ newField = { value: validationForm.phoneNumber?.value, error: '' };
122
+ }
123
+ newForm = { ...newForm, ...{ phoneNumber: newField } };
124
+ }
125
+
126
+ setValidationForm(newForm);
127
+
128
+ return !Boolean(newForm.phoneNumber?.error);
129
+ }
130
+
131
+
132
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | null): void => {
133
+ if (e) {
134
+ const fieldName: string = e.target.name;
135
+ const fieldValue: string = e.target.value;
136
+ const newField: MovaFormField = { [fieldName]: { value: fieldValue, isValid: true } };
137
+
138
+ if (fieldName == "phoneNumber") {
139
+ if (!validatePhoneNumber(fieldValue))
140
+ return;
141
+ }
142
+
143
+ setValidationForm({ ...validationForm, ...newField });
144
+ }
145
+ }
146
+
147
+ const resendCode = () => {
148
+
149
+ if (controlPhoneNumber() && onResendSecurityCode) {
150
+
151
+ let req = {
152
+ phoneNumber: validationForm.phoneNumber?.value
153
+ }
154
+
155
+ UserService.resendActivationAccount(req)
156
+ .then(response => {
157
+
158
+ Logger.info(response);
159
+
160
+ if (response.success) {
161
+ onResendSecurityCode(response.success, response.data ?? '');
162
+ } else {
163
+ onResendSecurityCode(response.success, response.error ?? '');
164
+ }
165
+ history.push('/login');
166
+
167
+ }).catch(error => {
168
+ Logger.error(error);
169
+ if (onSubmit) {
170
+ onSubmit(false, error);
171
+ }
172
+ });
173
+ }
174
+ }
175
+
176
+ return (
177
+ <>
178
+ {currentUser !== null && <MovaSignUp
179
+ movaAppType={movaAppType}
180
+ onSubmit={updateActivateUseronSubmit}
181
+ alertMessage={alertMessage}
182
+ alertSeverity={alertSeverity}
183
+ userToEdit={currentUser}
184
+ loading={loading} />}
185
+ {expiredCode && (
186
+ <Box sx={{ width: '99vw', height: '99vh', display: 'flex' }}>
187
+ <Box
188
+ sx={{
189
+ display: 'block',
190
+ margin: 'auto',
191
+ textAlign: 'center',
192
+ padding: 3,
193
+ borderRadius: 2,
194
+ boxShadow: 3,
195
+ maxWidth: 400,
196
+ backgroundColor: 'white',
197
+ }}
198
+ >
199
+ <Typography variant="h6" color="error" gutterBottom>
200
+ Code de validation expiré
201
+ </Typography>
202
+ <Typography><b>Indiquez nous votre numéro de téléphone.</b><br />Nous allons renvoyer un SMS d'activation de compte</Typography>
203
+ <Grid item xs={6}>
204
+ <TextField
205
+ margin="normal"
206
+ fullWidth
207
+ required
208
+ id="phoneNumber"
209
+ label="N° de téléphone"
210
+ name="phoneNumber"
211
+ autoComplete="tel"
212
+ onChange={e => handleInputChange(e)}
213
+ value={validationForm.phoneNumber.value}
214
+ error={Boolean(validationForm.phoneNumber.error)}
215
+ helperText={validationForm.phoneNumber.error}
216
+ />
217
+ </Grid>
218
+ <Button
219
+ onClick={resendCode}
220
+ sx={{ cursor: 'pointer', textAlign: 'center', width: '100%', mt: 1 }}
221
+ >
222
+ Renvoyer le code
223
+ </Button>
224
+ </Box>
225
+ </Box>
226
+ )}
227
+ {unknowCode && (
228
+ <Box sx={{ width: '99vw', height: '99vh', display: 'flex' }}>
229
+ <Box
230
+ sx={{
231
+ display: 'flex',
232
+ flexDirection: 'column',
233
+ alignItems: 'center',
234
+ justifyContent: 'center',
235
+ height: '100%',
236
+ width: '100%',
237
+ margin: 'auto',
238
+ textAlign: 'center',
239
+ padding: 3,
240
+ borderRadius: 2,
241
+ boxShadow: 3,
242
+ backgroundColor: 'white',
243
+ }}
244
+ >
245
+ <Typography variant="h6" color="error" gutterBottom>
246
+ Code de validation invalide
247
+ </Typography>
248
+ <Typography variant="body1" color="textSecondary" gutterBottom>
249
+ Le code de validation fourni ne correspond à aucun utilisateur (ou votre compte a déjà été activé). <br />
250
+ Essayez de vous connecter avec votre numéro de téléphone.
251
+ <br />
252
+ Si le problème persiste, veuillez nous contacter à{' '}
253
+ <b>support@movalib.com</b>.
254
+ </Typography>
255
+ <Button
256
+ variant="contained"
257
+ color="primary"
258
+ onClick={(e) => history.push('/login')}
259
+ sx={{ marginTop: 2 }}
260
+ >
261
+ Retour à la connexion
262
+ </Button>
263
+ </Box>
264
+ </Box>
265
+ )}
266
+
267
+ </>
268
+ );
269
+ };
270
+
271
+ export default ActivateAccount;
272
+
273
+
@@ -55,16 +55,16 @@ function handleResponse(response: Response): Promise<APIResponse<any>> {
55
55
 
56
56
  switch(response.status){
57
57
  case 403:
58
- errorMsg = 'Accès non autorisé (403)'; break;
58
+ errorMsg = 'Accès non autorisé'; break;
59
59
  case 404:
60
- errorMsg = 'La ressource demandée est introuvable (404)'; break;
60
+ errorMsg = (typeof data === 'string') ? data : 'La ressource demandée est introuvable'; break;
61
61
  case 500:
62
- errorMsg = 'Une erreur interne du serveur est survenue (500)'; break;
62
+ errorMsg = 'Une erreur interne du serveur est survenue'; break;
63
63
  default:
64
- errorMsg = (typeof data === 'string') ? data : `Une erreur est survenue (${response.status})`; break;
64
+ errorMsg = (typeof data === 'string') ? data : `Une erreur est survenue`; break;
65
65
  }
66
66
 
67
- return { success: false, error: errorMsg };
67
+ return { success: false, error: errorMsg, data: data };
68
68
  }
69
69
 
70
70
  return { success: true, data };
@@ -38,6 +38,15 @@ export default class UserService {
38
38
  });
39
39
  }
40
40
 
41
+ static resendActivationAccount(req: any): Promise<APIResponse<string>> {
42
+ return request({
43
+ url: `${API_BASE_URL}/user/resend-activation-link`,
44
+ method: APIMethod.POST,
45
+ appType: MovaAppType.INDIVIDUAL,
46
+ body: JSON.stringify(req)
47
+ });
48
+ }
49
+
41
50
  static getSalesGarages(salesId: string,): Promise<APIResponse<Garage[]>> {
42
51
  return request({
43
52
  url: `${API_BASE_URL}/sales/${salesId}/garages`,
@@ -46,7 +55,7 @@ export default class UserService {
46
55
  });
47
56
  }
48
57
 
49
- static validateAccount(req: any): Promise<APIResponse<string>> {
58
+ static validateAccount(req: any): Promise<APIResponse<User | {expiredCode?:boolean, unknowCode?: boolean}>> {
50
59
  return request({
51
60
  url: `${API_BASE_URL}/user/validate-account`,
52
61
  method: APIMethod.POST,
@@ -55,6 +64,15 @@ export default class UserService {
55
64
  });
56
65
  }
57
66
 
67
+ static editUser(req: any, userId: string): Promise<APIResponse<string>> {
68
+ return request({
69
+ url: `${API_BASE_URL}/user/${userId}/complete`,
70
+ method: APIMethod.PATCH,
71
+ appType: MovaAppType.INDIVIDUAL,
72
+ body: JSON.stringify(req)
73
+ });
74
+ }
75
+
58
76
  /**
59
77
  * @param email
60
78
  * @param password