@movalib/movalib-commons 1.1.4 → 1.1.5

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.
@@ -2,8 +2,7 @@ import { FunctionComponent } from 'react';
2
2
  import { MovaAppType } from './helpers/Enums';
3
3
  interface AccountValidationProps {
4
4
  movaAppType: MovaAppType;
5
- onSuccess: () => void;
6
- onError: () => void;
5
+ onSubmit: (success: boolean, message: string) => void;
7
6
  }
8
7
  declare const AccountValidation: FunctionComponent<AccountValidationProps>;
9
8
  export default AccountValidation;
@@ -32,7 +32,7 @@ var initialFormState = {
32
32
  confirmation: { value: '', isValid: true },
33
33
  };
34
34
  var AccountValidation = function (_a) {
35
- var movaAppType = _a.movaAppType, onSuccess = _a.onSuccess, onError = _a.onError;
35
+ var movaAppType = _a.movaAppType, onSubmit = _a.onSubmit;
36
36
  var _b = (0, react_1.useState)(true), loading = _b[0], setLoading = _b[1];
37
37
  var _c = (0, react_1.useState)(initialFormState), passwordForm = _c[0], setPasswordForm = _c[1];
38
38
  var location = (0, react_router_dom_1.useLocation)();
@@ -58,18 +58,24 @@ var AccountValidation = function (_a) {
58
58
  }, [location]);
59
59
  var activateAccount = function (req) {
60
60
  if (req) {
61
- Logger_1.default.info(req);
62
61
  UserService_1.default.validateAccount(req)
63
62
  .then(function (response) {
64
- // Affichage notification utilisateur
63
+ var _a, _b;
65
64
  Logger_1.default.info(response);
66
- if (onSuccess) {
67
- onSuccess();
65
+ if (response.success) {
66
+ if (onSubmit) {
67
+ onSubmit(response.success, (_a = response.data) !== null && _a !== void 0 ? _a : '');
68
+ }
69
+ }
70
+ else {
71
+ if (onSubmit) {
72
+ onSubmit(response.success, (_b = response.error) !== null && _b !== void 0 ? _b : '');
73
+ }
68
74
  }
69
75
  }).catch(function (error) {
70
76
  Logger_1.default.error(error);
71
- if (onError) {
72
- onError();
77
+ if (onSubmit) {
78
+ onSubmit(false, error);
73
79
  }
74
80
  });
75
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
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",
@@ -19,11 +19,10 @@ const initialFormState = {
19
19
 
20
20
  interface AccountValidationProps {
21
21
  movaAppType: MovaAppType,
22
- onSuccess: () => void,
23
- onError: () => void,
22
+ onSubmit: (success:boolean, message:string) => void,
24
23
  }
25
24
 
26
- const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppType, onSuccess, onError }) => {
25
+ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppType, onSubmit }) => {
27
26
 
28
27
  const [loading, setLoading] = useState(true);
29
28
  const [passwordForm, setPasswordForm] = useState<MovaPasswordForm>(initialFormState);
@@ -60,21 +59,25 @@ const AccountValidation: FunctionComponent<AccountValidationProps> = ({ movaAppT
60
59
  const activateAccount = (req: any) => {
61
60
  if(req){
62
61
 
63
- Logger.info(req);
64
-
65
62
  UserService.validateAccount(req)
66
63
  .then(response => {
67
64
 
68
- // Affichage notification utilisateur
69
65
  Logger.info(response);
70
- if(onSuccess){
71
- onSuccess();
66
+
67
+ if(response.success){
68
+ if(onSubmit){
69
+ onSubmit(response.success, response.data ?? '');
70
+ }
71
+ }else{
72
+ if(onSubmit){
73
+ onSubmit(response.success, response.error ?? '');
74
+ }
72
75
  }
73
76
 
74
77
  }).catch(error => {
75
78
  Logger.error(error);
76
- if(onError){
77
- onError();
79
+ if(onSubmit){
80
+ onSubmit(false, error);
78
81
  }
79
82
  });
80
83
  }