@antscorp/antsomi-ui 1.3.6-beta.231 → 1.3.6-beta.232

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.
@@ -17,7 +17,7 @@ export const AuthenticateResult = props => {
17
17
  backLogin();
18
18
  }
19
19
  };
20
- return (_jsx(WidgetLayout, { header: null, isShowLogo: false, title: _jsx("div", { style: { marginBottom: 100 } }), gapContent: 100, content: _jsx(Flex, { vertical: true, gap: 50, style: { marginTop: 20 }, children: _jsxs(Flex, { vertical: true, gap: 20, align: "center", children: [_jsx("img", { src: authenSuccessImg, alt: "" }), _jsx(Title, { isMobile: isMobile, children: "Authenticated!" }), _jsxs(Text, { isMobile: isMobile, children: ["Sign in in as ", get(loginData, 'personal.email')] })] }) }), footer: _jsx(Flex, { justify: "center", children: _jsx(Button, { type: "text", onClick: handleBack, style: {
20
+ return (_jsx(WidgetLayout, { header: null, isShowLogo: false, title: _jsx("div", { style: { marginBottom: 100 } }), gapContent: 100, content: _jsx(Flex, { vertical: true, gap: 50, style: { marginTop: 20 }, children: _jsxs(Flex, { vertical: true, gap: 20, align: "center", children: [_jsx("img", { src: authenSuccessImg, alt: "" }), _jsx(Title, { isMobile: isMobile, children: "Authenticated!" }), _jsxs(Text, { isMobile: isMobile, children: ["Sign in in as ", get(loginData, 'personal.full_name')] })] }) }), footer: _jsx(Flex, { justify: "center", children: _jsx(Button, { type: "text", onClick: handleBack, style: {
21
21
  fontSize: isMobile ? '16px' : '14px',
22
22
  }, children: "Sign in with a different account" }) }) }));
23
23
  };
@@ -1 +1 @@
1
- export const maskEmail = (email) => email.replace(/(.)[^@]*(.@.).*(.)/, '$1****$2*******$3');
1
+ export const maskEmail = (email) => email.replace(/(.)[^@]*(.@.).*(.)/, '$1****$2*******$3.');
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useCallback, useState } from 'react';
3
3
  import { Button, Flex, Typography } from 'antd';
4
- import { get } from 'lodash';
4
+ import { get, isEmpty } from 'lodash';
5
5
  import { useImmer } from 'use-immer';
6
6
  import { isMobile } from 'react-device-detect';
7
7
  import { useCountdown } from '@antscorp/antsomi-ui/es/hooks';
@@ -22,7 +22,6 @@ const initialState = {
22
22
  isTrust: false,
23
23
  codeError: true,
24
24
  isLoading: false,
25
- count: 0,
26
25
  isShowResend: true,
27
26
  isDisableResend: false,
28
27
  };
@@ -91,10 +90,13 @@ export const LoginWithEmail = ({ loginData, domainLogin, codeKey = 'code', token
91
90
  }, [setState]);
92
91
  const signIn = useCallback(() => {
93
92
  errorRef.current = true;
94
- setState(draft => {
95
- draft.count += 1;
96
- });
97
- if (!token || state.codeError) {
93
+ if (!token) {
94
+ return;
95
+ }
96
+ if (isEmpty(state.code)) {
97
+ setState(draft => {
98
+ draft.codeError = true;
99
+ });
98
100
  return;
99
101
  }
100
102
  const verificationParams = {
@@ -113,13 +115,13 @@ export const LoginWithEmail = ({ loginData, domainLogin, codeKey = 'code', token
113
115
  });
114
116
  }, [
115
117
  token,
116
- state.codeError,
117
118
  state.code,
118
119
  codeKey,
119
120
  onChangeLoading,
120
121
  domainLogin,
121
122
  handleAuthenticationSuccess,
122
123
  setState,
124
+ networkId,
123
125
  ]);
124
126
  const handleBack = useCallback(() => {
125
127
  backLogin?.();
@@ -140,17 +142,20 @@ export const LoginWithEmail = ({ loginData, domainLogin, codeKey = 'code', token
140
142
  });
141
143
  errorRef.current = true;
142
144
  }, [setState]);
143
- // Validate code on change
144
- useEffect(() => {
145
- setState(draft => {
146
- draft.codeError = !state.code?.trim();
147
- });
148
- }, [state.code, setState]);
149
- const renderErrorMessages = () => errorMessageCode && (_jsx(TextAntsomiUI, { type: "danger", children: LOGIN_ERROR_TYPES[errorMessageCode].message }));
145
+ const renderErrorMessages = () => {
146
+ let errMsg = null;
147
+ if (state.codeError && isEmpty(state.code)) {
148
+ errMsg = _jsx(TextAntsomiUI, { type: "danger", children: "Invalid code, please try again." });
149
+ }
150
+ if (errorMessageCode) {
151
+ errMsg = (_jsx(TextAntsomiUI, { type: "danger", children: LOGIN_ERROR_TYPES[errorMessageCode].message }));
152
+ }
153
+ return errMsg;
154
+ };
150
155
  const renderResendSection = () => {
151
156
  const maskedEmail = maskEmail(userEmail);
152
157
  const baseText = `Please enter the 6-digit code send to ${maskedEmail}. Haven't received it? `;
153
- return (_jsx(Flex, { gap: 5, align: "center", children: _jsxs(Text, { isMobile: isMobile, color: "#595959", children: [baseText, state.isShowResend ? (_jsx(Text, { color: state.isDisableResend ? '#a2a2a2' : '#005eb8', onClick: state.isDisableResend ? undefined : onResendCode, isMobile: isMobile, style: { cursor: 'pointer' }, children: "Resend code" })) : (`You can resend the code in ${seconds} seconds`)] }) }));
158
+ return (_jsx(Flex, { gap: 5, align: "center", children: _jsxs(Text, { isMobile: isMobile, color: "#595959", children: [baseText, state.isShowResend ? (_jsx(Text, { color: state.isDisableResend ? '#a2a2a2' : '#005eb8', onClick: state.isDisableResend ? undefined : onResendCode, isMobile: isMobile, style: { cursor: state.isDisableResend ? 'not-allowed' : 'pointer' }, children: "Resend." })) : (`You can resend the code in ${seconds}s.`)] }) }));
154
159
  };
155
160
  const renderCodeInput = () => (_jsxs(Flex, { vertical: true, gap: 10, children: [_jsx(StyleInput, { isMobile: isMobile, maxLength: CODE_LENGTH, placeholder: "Input your code", value: state.code, onChange: handleCodeChange, status: errorRef.current && state.codeError ? 'error' : undefined }), renderErrorMessages()] }));
156
161
  const renderActionButtons = () => (_jsxs(Flex, { vertical: true, gap: isMobile ? 30 : 15, children: [_jsx(StyleButton, { isMobile: isMobile, type: "primary", onClick: signIn, loading: state.isLoading, children: "Verify" }), _jsx(StyleButton, { isMobile: isMobile, onClick: handleBack, type: "text", children: "Back to login" })] }));
@@ -1 +1,2 @@
1
1
  export * from './BasicLogin';
2
+ export * from './components';
@@ -1 +1,2 @@
1
1
  export * from './BasicLogin';
2
+ export * from './components';
@@ -1 +1 @@
1
- export const maskEmail = (email) => email.replace(/(.)[^@]*(.@.).*(.)/, '$1****$2*******$3');
1
+ export const maskEmail = (email) => email.replace(/(.)[^@]*(.@.).*(.)/, '$1****$2*******$3.');
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React, { useEffect, useRef, useCallback } from 'react';
3
3
  import { Button, Checkbox, Flex, Typography } from 'antd';
4
- import { get } from 'lodash';
4
+ import { get, isEmpty } from 'lodash';
5
5
  import { useImmer } from 'use-immer';
6
6
  import { useCookies } from 'react-cookie';
7
7
  import { isMobile } from 'react-device-detect';
@@ -24,7 +24,7 @@ const { Text: TextAntsomiUI } = Typography;
24
24
  const initialState = {
25
25
  code: '',
26
26
  isTrust: false,
27
- codeError: true,
27
+ codeError: false,
28
28
  isLoading: false,
29
29
  countResend: 0,
30
30
  isShowResend: true,
@@ -88,7 +88,7 @@ export const LoginWithEmail = ({ loginData, domainLogin, codeKey = 'code', token
88
88
  }
89
89
  onLoginFail?.();
90
90
  }
91
- }, [state.isTrust, onLoginSuccess, onLoginFail, handleTrustDevice, setState]);
91
+ }, [onLoginSuccess, onLoginFail, handleTrustDevice, setState]);
92
92
  const makeAuthenticationRequest = useCallback((verificationParams, trustKey) => {
93
93
  const url = `${domainLogin}api/account/authenticate`;
94
94
  const request = new XMLHttpRequest();
@@ -110,7 +110,13 @@ export const LoginWithEmail = ({ loginData, domainLogin, codeKey = 'code', token
110
110
  }, [domainLogin, setState, handleAuthenticationSuccess]);
111
111
  const signIn = useCallback(() => {
112
112
  errorRef.current = true;
113
- if (!token || state.codeError) {
113
+ if (!token) {
114
+ return;
115
+ }
116
+ if (isEmpty(state.code)) {
117
+ setState(draft => {
118
+ draft.codeError = true;
119
+ });
114
120
  return;
115
121
  }
116
122
  const trustKey = state.isTrust ? generateGuid() : null;
@@ -124,15 +130,7 @@ export const LoginWithEmail = ({ loginData, domainLogin, codeKey = 'code', token
124
130
  draft.isLoading = true;
125
131
  });
126
132
  makeAuthenticationRequest(verificationParams, trustKey);
127
- }, [
128
- token,
129
- state.codeError,
130
- state.code,
131
- state.isTrust,
132
- codeKey,
133
- setState,
134
- makeAuthenticationRequest,
135
- ]);
133
+ }, [token, state.code, state.isTrust, codeKey, setState, makeAuthenticationRequest]);
136
134
  const handleBack = useCallback(() => {
137
135
  backLogin?.();
138
136
  }, [backLogin]);
@@ -158,17 +156,20 @@ export const LoginWithEmail = ({ loginData, domainLogin, codeKey = 'code', token
158
156
  draft.isTrust = e.target.checked;
159
157
  });
160
158
  }, [setState]);
161
- // Validate code on change
162
- useEffect(() => {
163
- setState(draft => {
164
- draft.codeError = !state.code || !state.code.trim();
165
- });
166
- }, [state.code, setState]);
167
- const renderErrorMessages = () => errorMessageCode && (_jsx(TextAntsomiUI, { type: "danger", children: LOGIN_ERROR_TYPES[errorMessageCode].message }));
159
+ const renderErrorMessages = () => {
160
+ let errMsg = null;
161
+ if (state.codeError && isEmpty(state.code)) {
162
+ errMsg = _jsx(TextAntsomiUI, { type: "danger", children: "Invalid code, please try again." });
163
+ }
164
+ if (errorMessageCode) {
165
+ errMsg = (_jsx(TextAntsomiUI, { type: "danger", children: LOGIN_ERROR_TYPES[errorMessageCode].message }));
166
+ }
167
+ return errMsg;
168
+ };
168
169
  const renderResendSection = () => {
169
170
  const maskedEmail = maskEmail(userEmail);
170
171
  const baseText = `Please enter the 6-digit code send to ${maskedEmail}. Haven't received it? `;
171
- return (_jsx(Flex, { gap: 5, align: "center", children: _jsxs(Text, { isMobile: isMobile, color: "#595959", children: [baseText, state.isShowResend ? (_jsx(Text, { color: state.isDisableResend ? '#a2a2a2' : '#005eb8', onClick: state.isDisableResend ? undefined : onResendCode, isMobile: isMobile, style: { cursor: 'pointer' }, children: "Resend code" })) : (`You can resend the code in ${seconds} seconds`)] }) }));
172
+ return (_jsx(Flex, { gap: 5, align: "center", children: _jsxs(Text, { isMobile: isMobile, color: "#595959", children: [baseText, state.isShowResend ? (_jsx(Text, { color: state.isDisableResend ? '#a2a2a2' : '#005eb8', onClick: state.isDisableResend ? undefined : onResendCode, isMobile: isMobile, style: { cursor: state.isDisableResend ? 'not-allowed' : 'pointer' }, children: "Resend." })) : (`You can resend the code in ${seconds}s.`)] }) }));
172
173
  };
173
174
  return (_jsx(WidgetLayout, { header: _jsx(Avatar, { image: userAvatar, name: userFullName, email: userEmail }), isShowLogo: false, title: _jsx(Title, { isMobile: isMobile, style: { marginTop: 20 }, children: "Identity Verification" }), gapContent: 30, content: _jsxs(Flex, { vertical: true, gap: 50, style: { marginTop: 20 }, children: [_jsxs(Flex, { vertical: true, gap: 20, align: "center", children: [_jsx("img", { src: loginStep2Image, alt: "Identity Verification" }), _jsx(Text, { isMobile: isMobile, color: "#595959", children: "For added security, we need to verify your identity." })] }), _jsxs(Flex, { vertical: true, gap: isMobile ? 10 : 13, children: [renderResendSection(), _jsxs(Flex, { vertical: true, gap: isMobile ? 20 : 11, children: [_jsxs(Flex, { vertical: true, gap: 10, children: [_jsx(StyleInput, { isMobile: isMobile, maxLength: CODE_LENGTH, placeholder: "Input your code", value: state.code, onChange: handleCodeChange, status: errorRef.current && state.codeError ? 'error' : undefined }), renderErrorMessages()] }), _jsx(Checkbox, { checked: state.isTrust, onChange: handleTrustChange, children: _jsx(TextInfo, { isMobile: isMobile, children: "Remember this browser for future logins" }) })] })] })] }), footer: _jsxs(Flex, { vertical: true, gap: 115, children: [_jsxs(Flex, { vertical: true, gap: isMobile ? 30 : 15, children: [_jsx(StyleButton, { isMobile: isMobile, type: "primary", onClick: signIn, loading: state.isLoading, children: "Verify" }), _jsx(StyleButton, { isMobile: isMobile, onClick: handleBack, type: "text", children: "Back to login" })] }), _jsx(Flex, { justify: "center", children: _jsx(Button, { type: "text", onClick: handleBack, style: {
174
175
  fontSize: isMobile ? '16px' : '14px',
@@ -35,18 +35,18 @@ export const LOGIN_ERROR_TYPES = {
35
35
  },
36
36
  SEND_LIMIT_REACHED: {
37
37
  type: 'SEND_LIMIT_REACHED',
38
- message: 'Requested too many times. Please try again tomorrow.',
38
+ message: 'Requested too many times. Please try again.',
39
39
  },
40
40
  TOO_MANY_ATTEMPTS: {
41
41
  type: 'TOO_MANY_ATTEMPTS',
42
- message: 'Too many incorrect codes. Please try again in a few minutes.',
42
+ message: 'Too many incorrect codes. Try again in a few minutes.',
43
43
  },
44
44
  INVALID_CODE: {
45
45
  type: 'INVALID_CODE',
46
- message: 'Invalid verification code',
46
+ message: 'Invalid code, please try again.',
47
47
  },
48
48
  RESEND_TOO_SOON: {
49
49
  type: 'RESEND_TOO_SOON',
50
- message: 'Too many resends. Please try again in a few minutes.',
50
+ message: 'Too many requests. Please contact Antsomi Support.',
51
51
  },
52
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.6-beta.231",
3
+ "version": "1.3.6-beta.232",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",