@movalib/movalib-commons 1.1.74 → 1.1.76

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/devIndex.tsx CHANGED
@@ -192,7 +192,7 @@ const App = () => {
192
192
  </Box>
193
193
 
194
194
 
195
- {openAccountValidation && <AccountValidation smsValidation={true} movaAppType={MovaAppType.GARAGE}
195
+ {openAccountValidation && <AccountValidation smsValidation={true} resetPassword={false} movaAppType={MovaAppType.GARAGE}
196
196
  onSubmit={function (success: boolean, message: string): void {
197
197
  throw new Error('Function not implemented.');
198
198
  } } onResendSecurityCode={function (success: boolean, message: string): void {
package/dist/devIndex.js CHANGED
@@ -155,7 +155,7 @@ var App = function () {
155
155
  throw new Error('Function not implemented.');
156
156
  } }), (0, jsx_runtime_1.jsx)("br", {}), " ", (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)(IbanInput_1.default, { onIbanChange: function (iban) {
157
157
  throw new Error('Function not implemented.');
158
- } })] }))] })), (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ onClick: function () { return setOpenAccountValidation(!openAccountValidation); } }, { children: "Validation de compte" })) })), openAccountValidation && (0, jsx_runtime_1.jsx)(AccountValidation_1.default, { smsValidation: true, movaAppType: Enums_1.MovaAppType.GARAGE, onSubmit: function (success, message) {
158
+ } })] }))] })), (0, jsx_runtime_1.jsx)(material_1.Box, __assign({ style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ onClick: function () { return setOpenAccountValidation(!openAccountValidation); } }, { children: "Validation de compte" })) })), openAccountValidation && (0, jsx_runtime_1.jsx)(AccountValidation_1.default, { smsValidation: true, resetPassword: false, movaAppType: Enums_1.MovaAppType.GARAGE, onSubmit: function (success, message) {
159
159
  throw new Error('Function not implemented.');
160
160
  }, onResendSecurityCode: function (success, message) {
161
161
  throw new Error('Function not implemented.');
@@ -3,6 +3,7 @@ import { MovaAppType } from './helpers/Enums';
3
3
  interface AccountValidationProps {
4
4
  movaAppType: MovaAppType;
5
5
  smsValidation: boolean;
6
+ resetPassword: boolean;
6
7
  onSubmit: (success: boolean, message: string) => void;
7
8
  onResendSecurityCode?: (success: boolean, message: string) => void;
8
9
  }
@@ -39,7 +39,7 @@ var initialFormState = {
39
39
  };
40
40
  var AccountValidation = function (_a) {
41
41
  var _b, _c, _d, _e;
42
- var movaAppType = _a.movaAppType, smsValidation = _a.smsValidation, onSubmit = _a.onSubmit, onResendSecurityCode = _a.onResendSecurityCode;
42
+ var movaAppType = _a.movaAppType, smsValidation = _a.smsValidation, resetPassword = _a.resetPassword, onSubmit = _a.onSubmit, onResendSecurityCode = _a.onResendSecurityCode;
43
43
  var _f = (0, react_1.useState)(true), loading = _f[0], setLoading = _f[1];
44
44
  var _g = (0, react_1.useState)(initialFormState), validationForm = _g[0], setValidationForm = _g[1];
45
45
  var location = (0, react_router_dom_1.useLocation)();
@@ -55,16 +55,40 @@ var AccountValidation = function (_a) {
55
55
  // Si cette variable est transmise, cela signifie que le compte a été créé sans mot de passe
56
56
  var localEmptyPwd = Boolean(params.get('emptyPwd'));
57
57
  setEmptyPwd(localEmptyPwd);
58
- if (token) {
58
+ if (token && !resetPassword) {
59
59
  if (!localEmptyPwd) {
60
60
  var req = {
61
61
  token: token
62
62
  };
63
- activateAccount(req);
63
+ activateUserAccount(req);
64
64
  }
65
65
  }
66
66
  }, [location]);
67
- var activateAccount = function (req) {
67
+ var resetUserPassword = function (req) {
68
+ if (req) {
69
+ UserService_1.default.reestPassword(req)
70
+ .then(function (response) {
71
+ var _a, _b;
72
+ Logger_1.default.info(response);
73
+ if (response.success) {
74
+ if (onSubmit) {
75
+ onSubmit(response.success, (_a = response.data) !== null && _a !== void 0 ? _a : '');
76
+ }
77
+ }
78
+ else {
79
+ if (onSubmit) {
80
+ onSubmit(response.success, (_b = response.error) !== null && _b !== void 0 ? _b : '');
81
+ }
82
+ }
83
+ }).catch(function (error) {
84
+ Logger_1.default.error(error);
85
+ if (onSubmit) {
86
+ onSubmit(false, error);
87
+ }
88
+ });
89
+ }
90
+ };
91
+ var activateUserAccount = function (req) {
68
92
  if (req) {
69
93
  UserService_1.default.validateAccount(req)
70
94
  .then(function (response) {
@@ -128,7 +152,7 @@ var AccountValidation = function (_a) {
128
152
  password: validationForm.password.value,
129
153
  demoGarage: Boolean(params.get('demoGarage'))
130
154
  };
131
- activateAccount(req);
155
+ resetPassword ? resetUserPassword(req) : activateUserAccount(req);
132
156
  }
133
157
  };
134
158
  var getTitleStyle = function () {
@@ -190,17 +214,17 @@ var AccountValidation = function (_a) {
190
214
  });
191
215
  }
192
216
  };
193
- return ((0, jsx_runtime_1.jsxs)("div", { children: [(emptyPwd || smsValidation) &&
217
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(emptyPwd || smsValidation || resetPassword) &&
194
218
  (0, jsx_runtime_1.jsx)(MovaDialog_1.default, __assign({ leafImageColor: 'pink', titleStyle: getTitleStyle(), fullScreen: isMobile, open: emptyPwd || smsValidation, closable: false, onClose: function () {
195
219
  throw new Error('Function not implemented.');
196
- }, actions: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, __assign({ type: "submit", onClick: handleValidateAccount, fullWidth: true, variant: "contained", sx: { mt: 4, mb: 0 } }, { children: (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: {
220
+ }, 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: {
197
221
  display: 'flex',
198
222
  flexDirection: 'column',
199
223
  alignItems: 'center',
200
224
  } }, { children: [(0, jsx_runtime_1.jsx)("img", { src: getMovaLogo(), style: { width: '50%' } }), (0, jsx_runtime_1.jsx)("br", {})] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ sx: { mt: 2, mb: 3 } }, { children: movaAppType === Enums_1.MovaAppType.INDIVIDUAL ?
201
- "Pour commencer, définis ton mot de passe et active ton compte 😉"
225
+ resetPassword ? "Définis ton nouveau mot de passe" : "Pour commencer, définis ton mot de passe et active ton compte 😉"
202
226
  :
203
- "Pour commencer, définissez votre mot de passe et activez votre compte 😉" })) })), smsValidation && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Code re\u00E7u par SMS", required: true, fullWidth: true, name: "securityCode", variant: "outlined", value: (_b = validationForm.securityCode) === null || _b === void 0 ? void 0 : _b.value, error: !((_c = validationForm.securityCode) === null || _c === void 0 ? void 0 : _c.isValid), helperText: Boolean((_d = validationForm.securityCode) === null || _d === void 0 ? void 0 : _d.error) ? (_e = validationForm.securityCode) === null || _e === void 0 ? void 0 : _e.error : null, onChange: function (e) { return handleInputChange(e); }, inputProps: {
227
+ resetPassword ? "Définissez votre nouveau mot de passe" : "Pour commencer, définissez votre mot de passe et activez votre compte 😉" })) })), smsValidation && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 12 }, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Code re\u00E7u par SMS", required: true, fullWidth: true, name: "securityCode", variant: "outlined", value: (_b = validationForm.securityCode) === null || _b === void 0 ? void 0 : _b.value, error: !((_c = validationForm.securityCode) === null || _c === void 0 ? void 0 : _c.isValid), helperText: Boolean((_d = validationForm.securityCode) === null || _d === void 0 ? void 0 : _d.error) ? (_e = validationForm.securityCode) === null || _e === void 0 ? void 0 : _e.error : null, onChange: function (e) { return handleInputChange(e); }, inputProps: {
204
228
  maxLength: 6,
205
229
  inputMode: 'numeric',
206
230
  pattern: '[0-9]*' // Permet seulement la saisie de chiffres
@@ -8,7 +8,7 @@ export type APIResponse<T> = {
8
8
  export type APIRequest = {
9
9
  url: string;
10
10
  method: APIMethod;
11
- appType: MovaAppType;
11
+ appType?: MovaAppType;
12
12
  body?: string | FormData;
13
13
  };
14
14
  /**
@@ -2,5 +2,6 @@ import { APIResponse } from "../helpers/ApiHelper";
2
2
  import { MovaAppType } from "../helpers/Enums";
3
3
  import User from "../models/User";
4
4
  export default class AuthenticationService {
5
+ static forgotPassword(req: any): Promise<APIResponse<string>>;
5
6
  static login(appType: MovaAppType, email: string, password: string): Promise<APIResponse<User>>;
6
7
  }
@@ -47,6 +47,17 @@ var UserService_1 = __importDefault(require("./UserService"));
47
47
  var AuthenticationService = /** @class */ (function () {
48
48
  function AuthenticationService() {
49
49
  }
50
+ AuthenticationService.forgotPassword = function (req) {
51
+ return __awaiter(this, void 0, void 0, function () {
52
+ return __generator(this, function (_a) {
53
+ return [2 /*return*/, (0, ApiHelper_1.request)({
54
+ url: "".concat(ApiHelper_1.API_BASE_URL, "/forgot-password"),
55
+ method: Enums_1.APIMethod.POST,
56
+ body: JSON.stringify(req)
57
+ })];
58
+ });
59
+ });
60
+ };
50
61
  AuthenticationService.login = function (appType, email, password) {
51
62
  return __awaiter(this, void 0, void 0, function () {
52
63
  var url, tokenCookie, tokenResponse, userResponse, errorMsg, error_1, errorMessage;
@@ -3,6 +3,7 @@ import { MovaAppType } from "../helpers/Enums";
3
3
  import Garage from "../models/Garage";
4
4
  import User from "../models/User";
5
5
  export default class UserService {
6
+ static reestPassword(req: any): Promise<APIResponse<string>>;
6
7
  static resendSecurityCode(req: any): Promise<APIResponse<string>>;
7
8
  static getSalesGarages(salesId: string): Promise<APIResponse<Garage[]>>;
8
9
  static validateAccount(req: any): Promise<APIResponse<string>>;
@@ -45,6 +45,14 @@ var Logger_1 = __importDefault(require("../helpers/Logger"));
45
45
  var UserService = /** @class */ (function () {
46
46
  function UserService() {
47
47
  }
48
+ UserService.reestPassword = function (req) {
49
+ return (0, ApiHelper_1.request)({
50
+ url: "".concat(ApiHelper_1.API_BASE_URL, "/user/reset-password"),
51
+ method: Enums_1.APIMethod.POST,
52
+ appType: Enums_1.MovaAppType.INDIVIDUAL,
53
+ body: JSON.stringify(req)
54
+ });
55
+ };
48
56
  UserService.resendSecurityCode = function (req) {
49
57
  return (0, ApiHelper_1.request)({
50
58
  url: "".concat(ApiHelper_1.API_BASE_URL, "/user/resend-security-code"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.1.74",
3
+ "version": "1.1.76",
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",
@@ -11,7 +11,6 @@ import { MovaAppType } from './helpers/Enums';
11
11
  import { MovaFormField, MovaValidationForm } from './helpers/Types';
12
12
  import { validateField } from './helpers/Tools';
13
13
  import MovaDialog from './MovaDialog';
14
-
15
14
  import LogoLarge from './assets/images/logo/logo_large.png';
16
15
  import LogoProLarge from './assets/images/logo/logo_pro_large.png';
17
16
  import ConfirmationDialog from './ConfirmationDialog';
@@ -27,11 +26,12 @@ const initialFormState = {
27
26
  interface AccountValidationProps {
28
27
  movaAppType: MovaAppType,
29
28
  smsValidation: boolean,
29
+ resetPassword: boolean,
30
30
  onSubmit: (success:boolean, message:string) => void,
31
31
  onResendSecurityCode?: (success:boolean, message:string) => void,
32
32
  }
33
33
 
34
- const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppType, smsValidation, onSubmit, onResendSecurityCode }) => {
34
+ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppType, smsValidation, resetPassword, onSubmit, onResendSecurityCode }) => {
35
35
 
36
36
  const [loading, setLoading] = useState(true);
37
37
  const [validationForm, setValidationForm] = useState<MovaValidationForm>(initialFormState);
@@ -52,7 +52,7 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
52
52
  let localEmptyPwd = Boolean(params.get('emptyPwd'));
53
53
  setEmptyPwd(localEmptyPwd);
54
54
 
55
- if (token) {
55
+ if (token && !resetPassword) {
56
56
 
57
57
  if(!localEmptyPwd){
58
58
 
@@ -60,13 +60,40 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
60
60
  token: token
61
61
  }
62
62
 
63
- activateAccount(req);
63
+ activateUserAccount(req);
64
64
  }
65
65
  }
66
66
 
67
67
  }, [location]);
68
68
 
69
- const activateAccount = (req: any) => {
69
+ const resetUserPassword = (req: any) => {
70
+ if(req){
71
+
72
+ UserService.reestPassword(req)
73
+ .then(response => {
74
+
75
+ Logger.info(response);
76
+
77
+ if(response.success){
78
+ if(onSubmit){
79
+ onSubmit(response.success, response.data ?? '');
80
+ }
81
+ }else{
82
+ if(onSubmit){
83
+ onSubmit(response.success, response.error ?? '');
84
+ }
85
+ }
86
+
87
+ }).catch(error => {
88
+ Logger.error(error);
89
+ if(onSubmit){
90
+ onSubmit(false, error);
91
+ }
92
+ });
93
+ }
94
+ }
95
+
96
+ const activateUserAccount = (req: any) => {
70
97
  if(req){
71
98
 
72
99
  UserService.validateAccount(req)
@@ -148,7 +175,7 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
148
175
  demoGarage: Boolean(params.get('demoGarage'))
149
176
  }
150
177
 
151
- activateAccount(req);
178
+ resetPassword ? resetUserPassword(req) : activateUserAccount(req);
152
179
  }
153
180
  }
154
181
 
@@ -225,7 +252,7 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
225
252
 
226
253
  return (
227
254
  <div>
228
- {(emptyPwd || smsValidation) &&
255
+ {(emptyPwd || smsValidation || resetPassword) &&
229
256
  <MovaDialog
230
257
  leafImageColor='pink'
231
258
  titleStyle={getTitleStyle()}
@@ -242,7 +269,7 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
242
269
  fullWidth
243
270
  variant="contained"
244
271
  sx={{ mt: 4, mb: 0 }}>
245
- <span>Activer mon compte</span>
272
+ {resetPassword ? <span>Réinitialiser mon mot de passe</span> : <span>Activer mon compte</span>}
246
273
  </LoadingButton>
247
274
  }>
248
275
  <Grid container>
@@ -261,9 +288,9 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
261
288
  <Grid item xs={12}>
262
289
  <Typography sx={{ mt: 2, mb: 3 }}>
263
290
  {movaAppType === MovaAppType.INDIVIDUAL ?
264
- "Pour commencer, définis ton mot de passe et active ton compte 😉"
291
+ resetPassword ? "Définis ton nouveau mot de passe" : "Pour commencer, définis ton mot de passe et active ton compte 😉"
265
292
  :
266
- "Pour commencer, définissez votre mot de passe et activez votre compte 😉"
293
+ resetPassword ? "Définissez votre nouveau mot de passe" : "Pour commencer, définissez votre mot de passe et activez votre compte 😉"
267
294
  }
268
295
  </Typography>
269
296
  </Grid>
@@ -14,7 +14,7 @@ export type APIResponse<T> = {
14
14
  export type APIRequest = {
15
15
  url: string,
16
16
  method: APIMethod,
17
- appType: MovaAppType,
17
+ appType?: MovaAppType,
18
18
  body?: string | FormData
19
19
  }
20
20
 
@@ -7,6 +7,14 @@ import UserService from "./UserService";
7
7
 
8
8
  export default class AuthenticationService {
9
9
 
10
+ static async forgotPassword(req: any): Promise<APIResponse<string>> {
11
+ return request({
12
+ url: `${API_BASE_URL}/forgot-password`,
13
+ method: APIMethod.POST,
14
+ body: JSON.stringify(req)
15
+ });
16
+ }
17
+
10
18
  static async login(appType: MovaAppType, email: string, password: string): Promise<APIResponse<User>> {
11
19
  try {
12
20
 
@@ -6,6 +6,15 @@ import User from "../models/User";
6
6
 
7
7
  export default class UserService {
8
8
 
9
+ static reestPassword(req: any): Promise<APIResponse<string>> {
10
+ return request({
11
+ url: `${API_BASE_URL}/user/reset-password`,
12
+ method: APIMethod.POST,
13
+ appType: MovaAppType.INDIVIDUAL,
14
+ body: JSON.stringify(req)
15
+ });
16
+ }
17
+
9
18
  static resendSecurityCode(req: any): Promise<APIResponse<string>> {
10
19
  return request({
11
20
  url: `${API_BASE_URL}/user/resend-security-code`,