@redneckz/wildless-cms-uni-blocks 0.14.865 → 0.14.866
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/bundle/bundle.umd.js +43 -26
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +7 -2
- package/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -2
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +7 -2
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +19 -10
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -2
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +21 -10
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +7 -2
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +18 -9
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -2
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +21 -10
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +43 -26
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +7 -2
- package/mobile/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -2
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +7 -2
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +19 -10
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -2
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +21 -10
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +7 -2
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +18 -9
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -2
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +21 -10
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/mobile/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +31 -27
- package/mobile/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +22 -10
- package/package.json +1 -1
- package/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +31 -27
- package/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +22 -10
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { JSX } from '@redneckz/uni-jsx';
|
|
3
3
|
import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
4
4
|
|
|
5
|
+
import { useSessionStore } from '@redneckz/uni-jsx/lib/Store/useSessionStore';
|
|
5
6
|
import { Headline } from '../../../components/Headline/Headline';
|
|
6
7
|
import type { OnCloseProps } from '../../../model/OnCloseProps';
|
|
7
8
|
import { Button } from '../../../ui-kit/Button/Button';
|
|
@@ -20,26 +21,27 @@ import { InputCode } from './InputCode';
|
|
|
20
21
|
import { SubmitButton } from './SubmitButton';
|
|
21
22
|
import { useVerifyPhoneDialogSubmit } from './useVerifyPhoneDialogSubmit';
|
|
22
23
|
|
|
24
|
+
export const TIME_TO_RESEND = 180;
|
|
25
|
+
const CODE_LENGTH = 4;
|
|
26
|
+
|
|
23
27
|
export interface VerifyPhoneDialogProps extends OnCloseProps {
|
|
24
28
|
phone: string;
|
|
25
|
-
code?: boolean;
|
|
26
29
|
withDescription?: boolean;
|
|
27
|
-
codeLength?: number;
|
|
28
30
|
consents?: string[];
|
|
29
31
|
onSuccess?: (smsCode?: string) => void;
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
export interface SmsCodeStore {
|
|
35
|
+
smsCode: {
|
|
36
|
+
sendTime?: number;
|
|
37
|
+
attempts?: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
33
|
-
({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
withDescription = true,
|
|
37
|
-
codeLength = 4,
|
|
38
|
-
consents,
|
|
39
|
-
onSuccess = noop,
|
|
40
|
-
onClose = noop,
|
|
41
|
-
}) => {
|
|
42
|
-
const [values, setValues] = useState(Array(codeLength).fill(''));
|
|
42
|
+
({ phone, withDescription = true, consents, onSuccess = noop, onClose = noop }) => {
|
|
43
|
+
const [values, setValues] = useState(Array(CODE_LENGTH).fill(''));
|
|
44
|
+
const sessionStore = useSessionStore<SmsCodeStore>();
|
|
43
45
|
|
|
44
46
|
const {
|
|
45
47
|
handleSubmit,
|
|
@@ -49,8 +51,7 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
49
51
|
timeNextReq,
|
|
50
52
|
isSubmitButtonDisabled,
|
|
51
53
|
setTimeNextReq,
|
|
52
|
-
|
|
53
|
-
setAttempts,
|
|
54
|
+
setErrorText,
|
|
54
55
|
} = useVerifyPhoneDialogSubmit({ values, onSuccess });
|
|
55
56
|
|
|
56
57
|
const captchaDialog = useDialog(CaptchaDialog);
|
|
@@ -66,17 +67,22 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
66
67
|
});
|
|
67
68
|
|
|
68
69
|
if (isSuccessSendCode) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
setTimeNextReq(TIME_TO_RESEND);
|
|
71
|
+
restartTimer(TIME_TO_RESEND);
|
|
72
|
+
setErrorText('');
|
|
73
|
+
sessionStore.smsCode = {
|
|
74
|
+
sendTime: Date.now(),
|
|
75
|
+
attempts: 0,
|
|
76
|
+
};
|
|
73
77
|
} else {
|
|
74
78
|
captchaDialog.open({ phoneNumber, sendCode: handleSendCode });
|
|
75
79
|
}
|
|
76
80
|
}, [phoneNumber, restartTimer, onClose]);
|
|
77
81
|
|
|
78
82
|
useEffect(() => {
|
|
79
|
-
|
|
83
|
+
if (!sessionStore.smsCode?.sendTime) {
|
|
84
|
+
handleSendCode();
|
|
85
|
+
}
|
|
80
86
|
}, []);
|
|
81
87
|
|
|
82
88
|
return (
|
|
@@ -93,14 +99,12 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
93
99
|
isEmbedded={true}
|
|
94
100
|
as="h6"
|
|
95
101
|
/>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/>
|
|
103
|
-
) : null}
|
|
102
|
+
<InputCode
|
|
103
|
+
values={values}
|
|
104
|
+
setValues={setValues}
|
|
105
|
+
errorText={errorText}
|
|
106
|
+
hasError={hasError}
|
|
107
|
+
/>
|
|
104
108
|
{renderText(timeNextReq, handleSendCode)}
|
|
105
109
|
|
|
106
110
|
{withDescription ? (
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { useBool } from '@redneckz/uni-jsx/lib/hooks/useBool';
|
|
3
|
+
import { useSessionStore } from '@redneckz/uni-jsx/lib/Store/useSessionStore';
|
|
3
4
|
import { checkCode } from '../../api/checkCode';
|
|
5
|
+
import { TIME_TO_RESEND, type SmsCodeStore } from './VerifyPhoneDialog';
|
|
4
6
|
|
|
5
7
|
type useVerifyPhoneDialogSubmitProps = {
|
|
6
8
|
values: string[];
|
|
@@ -11,28 +13,33 @@ export const useVerifyPhoneDialogSubmit = ({
|
|
|
11
13
|
values,
|
|
12
14
|
onSuccess,
|
|
13
15
|
}: useVerifyPhoneDialogSubmitProps) => {
|
|
16
|
+
const sessionStore = useSessionStore<SmsCodeStore>();
|
|
17
|
+
const attempts = sessionStore.smsCode?.attempts || 0;
|
|
18
|
+
const timer = Math.max(getTimer(sessionStore.smsCode?.sendTime || Date.now()), 0);
|
|
19
|
+
|
|
14
20
|
const [errorText, setErrorText] = useState('');
|
|
15
21
|
const [isLoading, { setTrue: startLoading, setFalse: endLoading }] = useBool(false);
|
|
16
|
-
const [timeNextReq, setTimeNextReq] = useState(
|
|
17
|
-
const [isTimerStarted, setIsTimerStarted] = useState(false);
|
|
18
|
-
const [attempts, setAttempts] = useState(0);
|
|
22
|
+
const [timeNextReq, setTimeNextReq] = useState(timer);
|
|
19
23
|
|
|
20
24
|
const resetError = useCallback(() => setErrorText(''), []);
|
|
21
25
|
|
|
22
|
-
const isTimeExpired = Boolean(timeNextReq === 0 &&
|
|
26
|
+
const isTimeExpired = Boolean(timeNextReq === 0 && sessionStore.smsCode?.sendTime);
|
|
23
27
|
const isSubmitButtonDisabled = attempts > 2 || isTimeExpired || !values.every(Boolean);
|
|
24
28
|
|
|
25
29
|
const handleSubmit = useCallback(async () => {
|
|
26
30
|
try {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
sessionStore.smsCode = {
|
|
32
|
+
...sessionStore.smsCode,
|
|
33
|
+
attempts: attempts + 1,
|
|
34
|
+
};
|
|
30
35
|
startLoading();
|
|
31
36
|
await checkCode({
|
|
32
37
|
smsText: values.join(''),
|
|
33
38
|
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
34
39
|
});
|
|
40
|
+
setTimeNextReq(0);
|
|
35
41
|
resetError();
|
|
42
|
+
sessionStore.smsCode = null;
|
|
36
43
|
await onSuccess?.(values.join(''));
|
|
37
44
|
} catch {
|
|
38
45
|
setErrorText(attempts > 1 ? 'Исчерпан лимит ввода смс-кода' : 'Неверный код');
|
|
@@ -42,7 +49,11 @@ export const useVerifyPhoneDialogSubmit = ({
|
|
|
42
49
|
}, [values, attempts]);
|
|
43
50
|
|
|
44
51
|
useEffect(() => {
|
|
45
|
-
|
|
52
|
+
if (isTimeExpired) {
|
|
53
|
+
setErrorText('Код просрочен');
|
|
54
|
+
} else if (attempts > 2) {
|
|
55
|
+
setErrorText('Исчерпан лимит ввода смс-кода');
|
|
56
|
+
}
|
|
46
57
|
}, [isTimeExpired]);
|
|
47
58
|
|
|
48
59
|
return {
|
|
@@ -53,7 +64,8 @@ export const useVerifyPhoneDialogSubmit = ({
|
|
|
53
64
|
timeNextReq,
|
|
54
65
|
isSubmitButtonDisabled,
|
|
55
66
|
setTimeNextReq,
|
|
56
|
-
|
|
57
|
-
setAttempts,
|
|
67
|
+
setErrorText,
|
|
58
68
|
};
|
|
59
69
|
};
|
|
70
|
+
|
|
71
|
+
const getTimer = (sendTime: number) => TIME_TO_RESEND - Math.floor((Date.now() - sendTime) / 1000);
|