namirasoft-account-react 1.4.170 → 1.4.171
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/pages/NSAVerificationPage.d.ts +0 -1
- package/dist/pages/NSAVerificationPage.js +7 -14
- package/dist/pages/NSAVerificationPage.js.map +1 -1
- package/package.json +1 -1
- package/src/pages/NSAVerificationPage.tsx +12 -19
- package/dist/components/NSABoxOTP.d.ts +0 -8
- package/dist/components/NSABoxOTP.js +0 -32
- package/dist/components/NSABoxOTP.js.map +0 -1
- package/dist/components/NSABoxOTP.module.css +0 -11
- package/src/components/NSABoxOTP.module.css +0 -11
- package/src/components/NSABoxOTP.tsx +0 -64
|
@@ -11,7 +11,6 @@ export interface INSAVerificationPageProps extends IBaseComponentProps, INSRoute
|
|
|
11
11
|
children?: ReactNode;
|
|
12
12
|
}
|
|
13
13
|
export interface NSAVerificationPageState {
|
|
14
|
-
code: string;
|
|
15
14
|
isSendCode: boolean;
|
|
16
15
|
}
|
|
17
16
|
export declare function NSAVerificationPage(props: INSAVerificationPageProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -9,29 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
11
|
import Styles from './NSAVerificationPage.module.css';
|
|
12
|
-
import {
|
|
13
|
-
import { useEffect, useState } from "react";
|
|
12
|
+
import { NSBoxString } from 'namirasoft-site-react';
|
|
13
|
+
import { useEffect, useRef, useState } from "react";
|
|
14
14
|
import { NSSection, NSSpace, NSSpaceSizeType, NSButtonBlue } from 'namirasoft-site-react';
|
|
15
15
|
export function NSAVerificationPage(props) {
|
|
16
16
|
var _a, _b, _c;
|
|
17
|
+
let NSBoxString_Ref = useRef(null);
|
|
17
18
|
let code = (_a = props.url.getQuery("code")) !== null && _a !== void 0 ? _a : "";
|
|
18
19
|
useEffect(() => {
|
|
19
20
|
if (code)
|
|
20
21
|
onVerify();
|
|
21
22
|
}, [code]);
|
|
22
23
|
const [state, setState] = useState({
|
|
23
|
-
code,
|
|
24
24
|
isSendCode: code.length > 0
|
|
25
25
|
});
|
|
26
|
-
function onChanged(event, index) {
|
|
27
|
-
const newValue = event.target.value;
|
|
28
|
-
setState(prevState => (Object.assign(Object.assign({}, prevState), { code: state.code + newValue })));
|
|
29
|
-
if (/^\d?$/.test(event.target.value)) {
|
|
30
|
-
const updatedValues = [...state.code];
|
|
31
|
-
updatedValues[index] = newValue;
|
|
32
|
-
setState(prevState => (Object.assign(Object.assign({}, prevState), { code: updatedValues.join("") })));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
26
|
function onRequest() {
|
|
36
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
28
|
try {
|
|
@@ -46,8 +37,10 @@ export function NSAVerificationPage(props) {
|
|
|
46
37
|
}
|
|
47
38
|
function onVerify() {
|
|
48
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _a, _b;
|
|
49
41
|
try {
|
|
50
|
-
|
|
42
|
+
let code = (_b = (_a = NSBoxString_Ref.current) === null || _a === void 0 ? void 0 : _a.getValue()) !== null && _b !== void 0 ? _b : "";
|
|
43
|
+
yield props.onVerify(code);
|
|
51
44
|
props.notifier.onSuccess("Verification has been successfully done.");
|
|
52
45
|
props.onFinished();
|
|
53
46
|
}
|
|
@@ -59,7 +52,7 @@ export function NSAVerificationPage(props) {
|
|
|
59
52
|
return (_jsx(_Fragment, { children: _jsxs(NSSection, { children: [_jsxs("div", { className: `${Styles.nsa_verification_container} ${(_c = (_b = props.classList) === null || _b === void 0 ? void 0 : _b.join(" ")) !== null && _c !== void 0 ? _c : ""}`, style: props.style, children: [_jsx("img", { src: "https://static.namirasoft.com/image/concept/verification/purple.png", alt: 'verification vector', className: Styles.nsa_verification_vector }), _jsxs("div", { className: 'm-0', children: [_jsxs("p", { className: 'm-2', children: ["Type: ", props.contact_type] }), ((state.isSendCode || !props.children) && props.getContactValue(false)) &&
|
|
60
53
|
_jsxs("p", { className: 'm-2', children: [props.contact_value_name, ": ", props.getContactValue(false)] }), props.children &&
|
|
61
54
|
_jsx("div", { style: { display: state.isSendCode ? "none" : undefined }, children: props.children })] }), state.isSendCode ?
|
|
62
|
-
_jsxs(_Fragment, { children: [_jsx("p", { children: "Please enter the code you received" }), _jsx(
|
|
55
|
+
_jsxs(_Fragment, { children: [_jsx("p", { children: "Please enter the code you received" }), _jsx(NSBoxString, { ref: NSBoxString_Ref, title: 'Verification Code', hideHeader: true, required: true })] }) :
|
|
63
56
|
_jsx(_Fragment, { children: _jsx(NSButtonBlue, { onClick: onRequest, title: 'Send Code' }) })] }), _jsx(NSSpace, { size: NSSpaceSizeType.NORMAL }), state.isSendCode &&
|
|
64
57
|
_jsxs(_Fragment, { children: [_jsx(NSButtonBlue, { title: "Verify", onClick: () => onVerify() }), _jsx(NSSpace, { size: NSSpaceSizeType.SMALL }), _jsx("button", { onClick: () => {
|
|
65
58
|
setState(prevState => (Object.assign(Object.assign({}, prevState), { isSendCode: false })));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NSAVerificationPage.js","sourceRoot":"","sources":["../../src/pages/NSAVerificationPage.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,MAAM,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"NSAVerificationPage.js","sourceRoot":"","sources":["../../src/pages/NSAVerificationPage.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,MAAM,MAAM,kCAAkC,CAAC;AACtD,OAAO,EAAuC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzF,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;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AC,UAAU;oBAChB,8BACC,KAAC,YAAY,IAAC,KAAK,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,GAAI,EAC1D,KAAC,OAAO,IAAC,IAAI,EAAE,eAAe,CAAC,KAAK,GAAY,EAChD,iBAAQ,OAAO,EAAE,GAAG,EAAE;oCAErB,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,iCAAM,SAAS,KAAE,UAAU,EAAE,KAAK,IAAG,CAAC,CAAA;gCAC7D,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,iBAAiB,4BAAsB,IAC1D,IAEO,GACV,CACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Styles from './NSAVerificationPage.module.css';
|
|
2
|
-
import { IBaseComponentProps, INSRouterProps } from 'namirasoft-site-react';
|
|
3
|
-
import {
|
|
4
|
-
import React, { ReactNode, useEffect, useState } from "react";
|
|
2
|
+
import { IBaseComponentProps, INSRouterProps, NSBoxString } from 'namirasoft-site-react';
|
|
3
|
+
import { ReactNode, useEffect, useRef, useState } from "react";
|
|
5
4
|
import { NSSection, NSSpace, NSSpaceSizeType, NSButtonBlue } from 'namirasoft-site-react';
|
|
6
5
|
import { INSARouterProps } from '../INSARouterProps';
|
|
7
6
|
|
|
@@ -18,12 +17,13 @@ export interface INSAVerificationPageProps extends IBaseComponentProps, INSRoute
|
|
|
18
17
|
|
|
19
18
|
export interface NSAVerificationPageState
|
|
20
19
|
{
|
|
21
|
-
code: string;
|
|
22
20
|
isSendCode: boolean;
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
export function NSAVerificationPage(props: INSAVerificationPageProps)
|
|
26
24
|
{
|
|
25
|
+
let NSBoxString_Ref = useRef<NSBoxString>(null);
|
|
26
|
+
|
|
27
27
|
let code = props.url.getQuery("code") ?? "";
|
|
28
28
|
useEffect(() =>
|
|
29
29
|
{
|
|
@@ -33,22 +33,9 @@ export function NSAVerificationPage(props: INSAVerificationPageProps)
|
|
|
33
33
|
}, [code]);
|
|
34
34
|
|
|
35
35
|
const [state, setState] = useState<NSAVerificationPageState>({
|
|
36
|
-
code,
|
|
37
36
|
isSendCode: code.length > 0
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
function onChanged(event: React.ChangeEvent<HTMLInputElement>, index: number): void
|
|
41
|
-
{
|
|
42
|
-
const newValue = event.target.value;
|
|
43
|
-
setState(prevState => ({ ...prevState, code: state.code + newValue }));
|
|
44
|
-
if (/^\d?$/.test(event.target.value))
|
|
45
|
-
{
|
|
46
|
-
const updatedValues = [...state.code];
|
|
47
|
-
updatedValues[index] = newValue;
|
|
48
|
-
setState(prevState => ({ ...prevState, code: updatedValues.join("") }))
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
39
|
async function onRequest()
|
|
53
40
|
{
|
|
54
41
|
try
|
|
@@ -66,7 +53,8 @@ export function NSAVerificationPage(props: INSAVerificationPageProps)
|
|
|
66
53
|
{
|
|
67
54
|
try
|
|
68
55
|
{
|
|
69
|
-
|
|
56
|
+
let code = NSBoxString_Ref.current?.getValue() ?? "";
|
|
57
|
+
await props.onVerify(code);
|
|
70
58
|
props.notifier.onSuccess("Verification has been successfully done.");
|
|
71
59
|
props.onFinished();
|
|
72
60
|
} catch (error)
|
|
@@ -104,7 +92,12 @@ export function NSAVerificationPage(props: INSAVerificationPageProps)
|
|
|
104
92
|
state.isSendCode ?
|
|
105
93
|
<>
|
|
106
94
|
<p>Please enter the code you received</p>
|
|
107
|
-
<
|
|
95
|
+
<NSBoxString
|
|
96
|
+
ref={NSBoxString_Ref}
|
|
97
|
+
title='Verification Code'
|
|
98
|
+
hideHeader={true}
|
|
99
|
+
required={true}
|
|
100
|
+
/>
|
|
108
101
|
</> :
|
|
109
102
|
<>
|
|
110
103
|
<NSButtonBlue onClick={onRequest} title='Send Code' />
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { IBaseComponentProps } from 'namirasoft-site-react';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export interface INSABoxOTPProps extends IBaseComponentProps {
|
|
4
|
-
placeholder?: string;
|
|
5
|
-
defaultValue?: string;
|
|
6
|
-
onChanged?: (e: React.ChangeEvent<HTMLInputElement>, index: number) => void;
|
|
7
|
-
}
|
|
8
|
-
export declare function NSABoxOTP(props: INSABoxOTPProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import Styles from './NSABoxOTP.module.css';
|
|
3
|
-
import { useState, useRef } from 'react';
|
|
4
|
-
export function NSABoxOTP(props) {
|
|
5
|
-
var _a, _b;
|
|
6
|
-
let [state, setState] = useState("");
|
|
7
|
-
const [values, setValues] = useState(Array(6).fill(''));
|
|
8
|
-
const inputsRef = useRef([]);
|
|
9
|
-
const handleChange = (index) => (event) => {
|
|
10
|
-
var _a;
|
|
11
|
-
const newValue = event.target.value;
|
|
12
|
-
setState(state + newValue);
|
|
13
|
-
if (/^\d?$/.test(newValue)) {
|
|
14
|
-
const updatedValues = [...values];
|
|
15
|
-
updatedValues[index] = newValue;
|
|
16
|
-
setValues(updatedValues);
|
|
17
|
-
if (newValue && index < 5) {
|
|
18
|
-
(_a = inputsRef.current[index + 1]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (props.onChanged)
|
|
22
|
-
props.onChanged(event, index);
|
|
23
|
-
};
|
|
24
|
-
const handleKeyDown = (index) => (event) => {
|
|
25
|
-
var _a;
|
|
26
|
-
if (event.key === 'Backspace' && !values[index] && index > 0) {
|
|
27
|
-
(_a = inputsRef.current[index - 1]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
return (_jsx("div", { id: props.id, className: `${Styles.nsa_input_parent} ${(_b = (_a = props.classList) === null || _a === void 0 ? void 0 : _a.join(" ")) !== null && _b !== void 0 ? _b : ""}`, style: Object.assign(Object.assign({}, props.style), { display: 'flex', gap: '10px' }), children: values.map((value, index) => (_jsx("input", { ref: el => inputsRef.current[index] = el, type: "text", value: value, onChange: handleChange(index), onKeyDown: handleKeyDown(index), maxLength: 1, style: { width: '30px', textAlign: 'center' }, className: Styles.nsa_otp_input }, `NSABoxOTP_ubput_key_${index}`))) }));
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=NSABoxOTP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NSABoxOTP.js","sourceRoot":"","sources":["../../src/components/NSABoxOTP.tsx"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAE5C,OAAc,EAAE,QAAQ,EAAe,MAAM,EAAE,MAAM,OAAO,CAAC;AAS7D,MAAM,UAAU,SAAS,CAAC,KAAsB;;IAE5C,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IAErC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAW,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAClE,MAAM,SAAS,GAAG,MAAM,CAA8B,EAAE,CAAC,CAAC;IAE1D,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,KAAoC,EAAE,EAAE;;QAE7E,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QACpC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAA;QAC1B,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAC1B,CAAC;YACG,MAAM,aAAa,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;YAClC,aAAa,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;YAChC,SAAS,CAAC,aAAa,CAAC,CAAC;YACzB,I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E,QAAQ,EAAE,EAC7C,SAAS,EAAE,MAAM,CAAC,aAAa,IAR1B,uBAAuB,KAAK,EAAE,CASrC,CACL,CAAC,GAEH,CACV,CAAC;AACN,CAAC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import Styles from './NSABoxOTP.module.css';
|
|
2
|
-
import { IBaseComponentProps } from 'namirasoft-site-react';
|
|
3
|
-
import React, { useState, ChangeEvent, useRef } from 'react';
|
|
4
|
-
|
|
5
|
-
export interface INSABoxOTPProps extends IBaseComponentProps
|
|
6
|
-
{
|
|
7
|
-
placeholder?: string;
|
|
8
|
-
defaultValue?: string;
|
|
9
|
-
onChanged?: (e: React.ChangeEvent<HTMLInputElement>, index: number) => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function NSABoxOTP(props: INSABoxOTPProps)
|
|
13
|
-
{
|
|
14
|
-
let [state, setState] = useState("");
|
|
15
|
-
|
|
16
|
-
const [values, setValues] = useState<string[]>(Array(6).fill(''));
|
|
17
|
-
const inputsRef = useRef<(HTMLInputElement | null)[]>([]);
|
|
18
|
-
|
|
19
|
-
const handleChange = (index: number) => (event: ChangeEvent<HTMLInputElement>) =>
|
|
20
|
-
{
|
|
21
|
-
const newValue = event.target.value;
|
|
22
|
-
setState(state + newValue)
|
|
23
|
-
if (/^\d?$/.test(newValue))
|
|
24
|
-
{
|
|
25
|
-
const updatedValues = [...values];
|
|
26
|
-
updatedValues[index] = newValue;
|
|
27
|
-
setValues(updatedValues);
|
|
28
|
-
if (newValue && index < 5)
|
|
29
|
-
{
|
|
30
|
-
inputsRef.current[index + 1]?.focus();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (props.onChanged)
|
|
34
|
-
props.onChanged(event, index);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const handleKeyDown = (index: number) => (event: React.KeyboardEvent<HTMLInputElement>) =>
|
|
38
|
-
{
|
|
39
|
-
if (event.key === 'Backspace' && !values[index] && index > 0)
|
|
40
|
-
{
|
|
41
|
-
inputsRef.current[index - 1]?.focus();
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<div id={props.id} className={`${Styles.nsa_input_parent} ${props.classList?.join(" ") ?? ""}`} style={{ ...props.style, display: 'flex', gap: '10px' }}>
|
|
47
|
-
{
|
|
48
|
-
values.map((value, index) => (
|
|
49
|
-
<input
|
|
50
|
-
key={`NSABoxOTP_ubput_key_${index}`}
|
|
51
|
-
ref={el => inputsRef.current[index] = el}
|
|
52
|
-
type="text"
|
|
53
|
-
value={value}
|
|
54
|
-
onChange={handleChange(index)}
|
|
55
|
-
onKeyDown={handleKeyDown(index)}
|
|
56
|
-
maxLength={1}
|
|
57
|
-
style={{ width: '30px', textAlign: 'center' }}
|
|
58
|
-
className={Styles.nsa_otp_input}
|
|
59
|
-
/>
|
|
60
|
-
))
|
|
61
|
-
}
|
|
62
|
-
</div >
|
|
63
|
-
);
|
|
64
|
-
}
|