@redneckz/wildless-cms-uni-blocks 0.14.888 → 0.14.889
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/api/LeadServiceAPI.d.ts +8 -0
- package/bundle/api/getSubmitBody.d.ts +494 -0
- package/bundle/bundle.umd.js +663 -561
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/ApplicationForm/ApplicationFormContent.d.ts +1 -1
- package/bundle/retail/api/checkCode.d.ts +9 -1
- package/bundle/retail/api/sendCode.d.ts +1 -1
- package/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +4 -0
- package/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +6 -1
- package/dist/api/LeadServiceAPI.d.ts +8 -0
- package/dist/api/LeadServiceAPI.js +41 -49
- package/dist/api/LeadServiceAPI.js.map +1 -1
- package/dist/api/getSubmitBody.d.ts +494 -0
- package/dist/api/getSubmitBody.js +59 -0
- package/dist/api/getSubmitBody.js.map +1 -0
- package/dist/components/ApplicationForm/ApplicationForm.js +30 -5
- package/dist/components/ApplicationForm/ApplicationForm.js.map +1 -1
- package/dist/components/ApplicationForm/ApplicationFormContent.d.ts +1 -1
- package/dist/retail/api/checkCode.d.ts +9 -1
- package/dist/retail/api/checkCode.js +22 -1
- package/dist/retail/api/checkCode.js.map +1 -1
- package/dist/retail/api/sendCode.d.ts +1 -1
- package/dist/retail/api/sendCode.js +8 -2
- package/dist/retail/api/sendCode.js.map +1 -1
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +4 -0
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +10 -4
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +6 -1
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +7 -4
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/dist/retail/utils/mockLocalStorage.js +2 -2
- package/dist/retail/utils/mockLocalStorage.js.map +1 -1
- package/lib/api/LeadServiceAPI.d.ts +8 -0
- package/lib/api/LeadServiceAPI.js +41 -49
- package/lib/api/LeadServiceAPI.js.map +1 -1
- package/lib/api/getSubmitBody.d.ts +494 -0
- package/lib/api/getSubmitBody.js +54 -0
- package/lib/api/getSubmitBody.js.map +1 -0
- package/lib/components/ApplicationForm/ApplicationForm.fixture.d.ts +1 -0
- package/lib/components/ApplicationForm/ApplicationForm.js +30 -5
- package/lib/components/ApplicationForm/ApplicationForm.js.map +1 -1
- package/lib/components/ApplicationForm/ApplicationFormContent.d.ts +1 -1
- package/lib/retail/api/checkCode.d.ts +9 -1
- package/lib/retail/api/checkCode.js +22 -1
- package/lib/retail/api/checkCode.js.map +1 -1
- package/lib/retail/api/sendCode.d.ts +1 -1
- package/lib/retail/api/sendCode.js +7 -1
- package/lib/retail/api/sendCode.js.map +1 -1
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +4 -0
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +10 -4
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +6 -1
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +6 -3
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/lib/retail/utils/mockLocalStorage.js +2 -2
- package/lib/retail/utils/mockLocalStorage.js.map +1 -1
- package/mobile/bundle/api/LeadServiceAPI.d.ts +8 -0
- package/mobile/bundle/api/getSubmitBody.d.ts +494 -0
- package/mobile/bundle/bundle.umd.js +663 -561
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/ApplicationForm/ApplicationFormContent.d.ts +1 -1
- package/mobile/bundle/retail/api/checkCode.d.ts +9 -1
- package/mobile/bundle/retail/api/sendCode.d.ts +1 -1
- package/mobile/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +4 -0
- package/mobile/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +6 -1
- package/mobile/dist/api/LeadServiceAPI.d.ts +8 -0
- package/mobile/dist/api/LeadServiceAPI.js +41 -49
- package/mobile/dist/api/LeadServiceAPI.js.map +1 -1
- package/mobile/dist/api/getSubmitBody.d.ts +494 -0
- package/mobile/dist/api/getSubmitBody.js +59 -0
- package/mobile/dist/api/getSubmitBody.js.map +1 -0
- package/mobile/dist/components/ApplicationForm/ApplicationForm.js +30 -5
- package/mobile/dist/components/ApplicationForm/ApplicationForm.js.map +1 -1
- package/mobile/dist/components/ApplicationForm/ApplicationFormContent.d.ts +1 -1
- package/mobile/dist/retail/api/checkCode.d.ts +9 -1
- package/mobile/dist/retail/api/checkCode.js +22 -1
- package/mobile/dist/retail/api/checkCode.js.map +1 -1
- package/mobile/dist/retail/api/sendCode.d.ts +1 -1
- package/mobile/dist/retail/api/sendCode.js +8 -2
- package/mobile/dist/retail/api/sendCode.js.map +1 -1
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +4 -0
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +10 -4
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +6 -1
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +7 -4
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/mobile/dist/retail/utils/mockLocalStorage.js +2 -2
- package/mobile/dist/retail/utils/mockLocalStorage.js.map +1 -1
- package/mobile/lib/api/LeadServiceAPI.d.ts +8 -0
- package/mobile/lib/api/LeadServiceAPI.js +41 -49
- package/mobile/lib/api/LeadServiceAPI.js.map +1 -1
- package/mobile/lib/api/getSubmitBody.d.ts +494 -0
- package/mobile/lib/api/getSubmitBody.js +54 -0
- package/mobile/lib/api/getSubmitBody.js.map +1 -0
- package/mobile/lib/components/ApplicationForm/ApplicationForm.js +30 -5
- package/mobile/lib/components/ApplicationForm/ApplicationForm.js.map +1 -1
- package/mobile/lib/components/ApplicationForm/ApplicationFormContent.d.ts +1 -1
- package/mobile/lib/retail/api/checkCode.d.ts +9 -1
- package/mobile/lib/retail/api/checkCode.js +22 -1
- package/mobile/lib/retail/api/checkCode.js.map +1 -1
- package/mobile/lib/retail/api/sendCode.d.ts +1 -1
- package/mobile/lib/retail/api/sendCode.js +7 -1
- package/mobile/lib/retail/api/sendCode.js.map +1 -1
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +4 -0
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +10 -4
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +6 -1
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +6 -3
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/mobile/lib/retail/utils/mockLocalStorage.js +2 -2
- package/mobile/lib/retail/utils/mockLocalStorage.js.map +1 -1
- package/mobile/src/api/LeadServiceAPI.ts +64 -82
- package/mobile/src/api/getSubmitBody.ts +94 -0
- package/mobile/src/components/ApplicationForm/ApplicationForm.example.json +2 -2
- package/mobile/src/components/ApplicationForm/ApplicationForm.tsx +33 -4
- package/mobile/src/components/ApplicationForm/ApplicationFormContent.ts +1 -1
- package/mobile/src/retail/api/checkCode.ts +47 -2
- package/mobile/src/retail/api/sendCode.ts +9 -1
- package/mobile/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +29 -8
- package/mobile/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +18 -5
- package/mobile/src/retail/utils/mockLocalStorage.ts +15 -9
- package/package.json +1 -1
- package/src/api/LeadServiceAPI.ts +64 -82
- package/src/api/getSubmitBody.ts +94 -0
- package/src/components/ApplicationForm/ApplicationForm.example.json +2 -2
- package/src/components/ApplicationForm/ApplicationForm.fixture.mobile.tsx +2 -2
- package/src/components/ApplicationForm/ApplicationForm.fixture.tsx +24 -2
- package/src/components/ApplicationForm/ApplicationForm.tsx +33 -4
- package/src/components/ApplicationForm/ApplicationFormContent.ts +1 -1
- package/src/retail/api/checkCode.ts +47 -2
- package/src/retail/api/sendCode.ts +9 -1
- package/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +29 -8
- package/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +18 -5
- package/src/retail/utils/mockLocalStorage.ts +15 -9
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { LeadServiceAPI, type LeadRequest } from '../../api/LeadServiceAPI';
|
|
1
2
|
import { fetchRetailJSON } from './doRequest';
|
|
3
|
+
const API = LeadServiceAPI();
|
|
2
4
|
|
|
3
5
|
export type CheckCodeBody = {
|
|
4
6
|
smsText: string;
|
|
5
7
|
smsCodesSetName: {
|
|
6
8
|
key: 'AUTHENTICATION' | 'SEND_TASK';
|
|
7
9
|
};
|
|
10
|
+
reqId?: string;
|
|
11
|
+
body?: LeadRequest;
|
|
8
12
|
};
|
|
9
13
|
|
|
10
14
|
export type CheckCodeResponse = {
|
|
@@ -13,8 +17,32 @@ export type CheckCodeResponse = {
|
|
|
13
17
|
refresh_token: string;
|
|
14
18
|
};
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
type RetailBody = {
|
|
21
|
+
smsText: string;
|
|
22
|
+
smsCodesSetName: {
|
|
23
|
+
key: 'AUTHENTICATION' | 'SEND_TASK';
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type MainBody = {
|
|
28
|
+
code: string;
|
|
29
|
+
reqId: string;
|
|
30
|
+
body: LeadRequest;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type TransformedBody = RetailBody | MainBody;
|
|
34
|
+
|
|
35
|
+
export const checkCode = async (body: CheckCodeBody, isRetail: boolean) => {
|
|
36
|
+
const transformedBody = transformBody(body, isRetail);
|
|
37
|
+
|
|
38
|
+
return isRetail
|
|
39
|
+
? fetchRetailJSON<CheckCodeResponse>('/sms/checkCode', 'POST', transformedBody).then(saveToken)
|
|
40
|
+
: fetchMain(transformedBody as MainBody).then((res) => {
|
|
41
|
+
if (res === null) {
|
|
42
|
+
throw new Error('Неверный код');
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
18
46
|
|
|
19
47
|
export const saveToken = (data: CheckCodeResponse | null) => {
|
|
20
48
|
if (data?.access_token && data?.refresh_token) {
|
|
@@ -22,3 +50,20 @@ export const saveToken = (data: CheckCodeResponse | null) => {
|
|
|
22
50
|
globalThis.sessionStorage.setItem('refreshToken', data.refresh_token);
|
|
23
51
|
}
|
|
24
52
|
};
|
|
53
|
+
|
|
54
|
+
const fetchMain = (body: MainBody) => API.checkCode(body);
|
|
55
|
+
|
|
56
|
+
const transformBody = (
|
|
57
|
+
{ smsText, smsCodesSetName, body, reqId }: CheckCodeBody,
|
|
58
|
+
isRetail: boolean,
|
|
59
|
+
): TransformedBody => {
|
|
60
|
+
if (isRetail) {
|
|
61
|
+
return { smsText, smsCodesSetName };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!reqId || !body) {
|
|
65
|
+
throw new Error('Произошла ошибка, попробуйте позднее');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { code: smsText, reqId, body };
|
|
69
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { LeadServiceAPI } from '../../api/LeadServiceAPI';
|
|
1
2
|
import { doRequest } from './doRequest';
|
|
3
|
+
const API = LeadServiceAPI();
|
|
2
4
|
|
|
3
5
|
export type SendCodeBody = {
|
|
4
6
|
phoneNumber: string;
|
|
@@ -7,7 +9,13 @@ export type SendCodeBody = {
|
|
|
7
9
|
};
|
|
8
10
|
};
|
|
9
11
|
|
|
10
|
-
export const sendCode = (body: SendCodeBody) =>
|
|
12
|
+
export const sendCode = (body: SendCodeBody, isRetail: boolean) => {
|
|
13
|
+
return isRetail ? fetchRetail(body) : fetchMain(body);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const fetchRetail = (body: SendCodeBody) =>
|
|
11
17
|
doRequest('/sms/sendCode', 'POST', body)
|
|
12
18
|
.then((res) => res.text())
|
|
13
19
|
.then((text) => text === 'OK');
|
|
20
|
+
|
|
21
|
+
const fetchMain = (body: SendCodeBody) => API.sendCode({ phone: body.phoneNumber });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable max-lines-per-function */
|
|
2
2
|
import { JSX } from '@redneckz/uni-jsx';
|
|
3
3
|
import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
4
|
-
|
|
5
4
|
import { useSessionStore } from '@redneckz/uni-jsx/lib/Store/useSessionStore';
|
|
5
|
+
import { type LeadRequest } from '../../../api/LeadServiceAPI';
|
|
6
6
|
import { Headline } from '../../../components/Headline/Headline';
|
|
7
7
|
import type { OnCloseProps } from '../../../model/OnCloseProps';
|
|
8
8
|
import { Button } from '../../../ui-kit/Button/Button';
|
|
@@ -32,10 +32,22 @@ export interface VerifyPhoneDialogProps extends OnCloseProps {
|
|
|
32
32
|
withDescription?: boolean;
|
|
33
33
|
consents?: string[];
|
|
34
34
|
onSuccess?: (smsCode?: string) => void;
|
|
35
|
+
formatData?: LeadRequest;
|
|
36
|
+
reqId?: string;
|
|
37
|
+
isRetail?: boolean;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
38
|
-
({
|
|
41
|
+
({
|
|
42
|
+
phone,
|
|
43
|
+
withDescription = true,
|
|
44
|
+
consents,
|
|
45
|
+
onSuccess = noop,
|
|
46
|
+
onClose = noop,
|
|
47
|
+
formatData,
|
|
48
|
+
reqId,
|
|
49
|
+
isRetail = true,
|
|
50
|
+
}) => {
|
|
39
51
|
const [values, setValues] = useState(Array(CODE_LENGTH).fill(''));
|
|
40
52
|
const sessionStore = useSessionStore<SmsCodeStore>();
|
|
41
53
|
|
|
@@ -48,7 +60,13 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
48
60
|
isSubmitButtonDisabled,
|
|
49
61
|
setTimeNextReq,
|
|
50
62
|
setErrorText,
|
|
51
|
-
} = useVerifyPhoneDialogSubmit({
|
|
63
|
+
} = useVerifyPhoneDialogSubmit({
|
|
64
|
+
values,
|
|
65
|
+
onSuccess,
|
|
66
|
+
formatData,
|
|
67
|
+
reqId,
|
|
68
|
+
isRetail,
|
|
69
|
+
});
|
|
52
70
|
|
|
53
71
|
const captchaDialog = useDialog(CaptchaDialog);
|
|
54
72
|
|
|
@@ -57,10 +75,13 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
57
75
|
const restartTimer = useCountDownTimer({ seconds: timeNextReq, onTick: setTimeNextReq });
|
|
58
76
|
|
|
59
77
|
const handleSendCode = useCallback(async () => {
|
|
60
|
-
const isSuccessSendCode = await sendCode(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
const isSuccessSendCode = await sendCode(
|
|
79
|
+
{
|
|
80
|
+
phoneNumber,
|
|
81
|
+
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
82
|
+
},
|
|
83
|
+
isRetail,
|
|
84
|
+
);
|
|
64
85
|
|
|
65
86
|
if (isSuccessSendCode) {
|
|
66
87
|
setTimeNextReq(TIME_TO_RESEND);
|
|
@@ -76,7 +97,7 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
76
97
|
}, [phoneNumber, restartTimer, onClose]);
|
|
77
98
|
|
|
78
99
|
useEffect(() => {
|
|
79
|
-
if (!sessionStore.smsCode?.sendTime) {
|
|
100
|
+
if (!sessionStore.smsCode?.sendTime && isRetail) {
|
|
80
101
|
handleSendCode();
|
|
81
102
|
}
|
|
82
103
|
}, []);
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { useBool } from '@redneckz/uni-jsx/lib/hooks/useBool';
|
|
3
3
|
import { useSessionStore } from '@redneckz/uni-jsx/lib/Store/useSessionStore';
|
|
4
|
+
import { type LeadRequest } from '../../../api/LeadServiceAPI';
|
|
4
5
|
import { checkCode } from '../../api/checkCode';
|
|
5
6
|
|
|
6
7
|
export const TIME_TO_RESEND = 180;
|
|
8
|
+
export const TIME_TO_MAIN_EXPIRE = 600;
|
|
7
9
|
|
|
8
10
|
type useVerifyPhoneDialogSubmitProps = {
|
|
9
11
|
values: string[];
|
|
10
12
|
onSuccess?: (smsCode?: string) => void;
|
|
13
|
+
formatData?: LeadRequest;
|
|
14
|
+
reqId?: string;
|
|
15
|
+
isRetail?: boolean;
|
|
11
16
|
};
|
|
12
17
|
|
|
13
18
|
export interface SmsCodeStore {
|
|
@@ -20,6 +25,9 @@ export interface SmsCodeStore {
|
|
|
20
25
|
export const useVerifyPhoneDialogSubmit = ({
|
|
21
26
|
values,
|
|
22
27
|
onSuccess,
|
|
28
|
+
formatData,
|
|
29
|
+
reqId,
|
|
30
|
+
isRetail = true,
|
|
23
31
|
}: useVerifyPhoneDialogSubmitProps) => {
|
|
24
32
|
const sessionStore = useSessionStore<SmsCodeStore>();
|
|
25
33
|
const attempts = sessionStore.smsCode?.attempts || 0;
|
|
@@ -41,10 +49,15 @@ export const useVerifyPhoneDialogSubmit = ({
|
|
|
41
49
|
attempts: attempts + 1,
|
|
42
50
|
};
|
|
43
51
|
startLoading();
|
|
44
|
-
await checkCode(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
await checkCode(
|
|
53
|
+
{
|
|
54
|
+
smsText: values.join(''),
|
|
55
|
+
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
56
|
+
body: isRetail ? undefined : formatData,
|
|
57
|
+
reqId: isRetail ? undefined : reqId,
|
|
58
|
+
},
|
|
59
|
+
isRetail,
|
|
60
|
+
);
|
|
48
61
|
setTimeNextReq(0);
|
|
49
62
|
resetError();
|
|
50
63
|
sessionStore.smsCode = null;
|
|
@@ -57,7 +70,7 @@ export const useVerifyPhoneDialogSubmit = ({
|
|
|
57
70
|
}, [values, attempts]);
|
|
58
71
|
|
|
59
72
|
useEffect(() => {
|
|
60
|
-
if (isTimeExpired) {
|
|
73
|
+
if (isTimeExpired && isRetail) {
|
|
61
74
|
setErrorText('Код просрочен');
|
|
62
75
|
} else if (attempts > 2) {
|
|
63
76
|
setErrorText('Исчерпан лимит ввода смс-кода');
|
|
@@ -13,15 +13,21 @@ export const mockLocalStorage = async () => {
|
|
|
13
13
|
globalThis.localStorage.getItem('profileId') ??
|
|
14
14
|
(await createUserProfile({ profile: { phone: PHONE } }));
|
|
15
15
|
|
|
16
|
-
await sendCode(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
await sendCode(
|
|
17
|
+
{
|
|
18
|
+
phoneNumber: PHONE,
|
|
19
|
+
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
20
|
+
},
|
|
21
|
+
true,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
await checkCode(
|
|
25
|
+
{
|
|
26
|
+
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
27
|
+
smsText: '1234',
|
|
28
|
+
},
|
|
29
|
+
true,
|
|
30
|
+
);
|
|
25
31
|
|
|
26
32
|
const task = {
|
|
27
33
|
taskId: globalThis.localStorage.getItem('taskId'),
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type JSONRecord, type JSONScalar } from '@redneckz/json-op';
|
|
2
2
|
import { type Router } from '../external/useRouter';
|
|
3
|
-
import {
|
|
4
|
-
import { formatPhone } from '../utils/formatPhone';
|
|
3
|
+
import { type MainBody } from '../retail/api/checkCode';
|
|
5
4
|
import { API_BASE_URI } from './apiBaseUrl';
|
|
5
|
+
import { getPhoneBody, getSubmitBody } from './getSubmitBody';
|
|
6
6
|
|
|
7
7
|
export type LeadRequest = Record<string, JSONRecord | JSONScalar | null> & {
|
|
8
8
|
typeForm?: string;
|
|
@@ -17,63 +17,30 @@ export type LeadRequest = Record<string, JSONRecord | JSONScalar | null> & {
|
|
|
17
17
|
companyNameByInn?: string;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
export type CheckCodeProps = MainBody;
|
|
21
|
+
|
|
22
|
+
type VerifiedLeadRequest = {
|
|
23
|
+
requestId: string;
|
|
24
|
+
confirmationCode: string;
|
|
25
|
+
leadRequest: LeadRequest;
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
type PhoneOnly = {
|
|
29
|
+
phone?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type SubmitBody = PhoneOnly | LeadRequest | CheckCodeProps | VerifiedLeadRequest;
|
|
33
|
+
|
|
27
34
|
export function LeadServiceAPI() {
|
|
28
35
|
async function send(body: LeadRequest, router: Router, isIndividualType = false) {
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
region,
|
|
32
|
-
phone = '',
|
|
33
|
-
email,
|
|
34
|
-
birthday,
|
|
35
|
-
desiredMeetingDate,
|
|
36
|
-
inn,
|
|
37
|
-
innDadata,
|
|
38
|
-
fullRegion,
|
|
39
|
-
addressBranch,
|
|
40
|
-
secondaryPhone = '',
|
|
41
|
-
bankEmpolee,
|
|
42
|
-
applicationDate,
|
|
43
|
-
serviceDirection,
|
|
44
|
-
partnerSymbolCode,
|
|
45
|
-
companyNameByInn,
|
|
46
|
-
...staticBody
|
|
47
|
-
} = body;
|
|
36
|
+
const { serviceDirection } = body;
|
|
37
|
+
|
|
48
38
|
const isNaturalPerson = isIndividualType && serviceDirection !== 'Юридическое лицо / ИП';
|
|
49
39
|
const url = `${API_BASE_URI}${isNaturalPerson ? '/lead' : '/sendcorporatelead'}`;
|
|
50
|
-
const submitBody =
|
|
51
|
-
typeForm,
|
|
52
|
-
...getRegion(region, isNaturalPerson),
|
|
53
|
-
...getEmail(email, isNaturalPerson),
|
|
54
|
-
...getPhone(phone),
|
|
55
|
-
...getFormatDate(desiredMeetingDate as string, 'desiredMeetingDate'),
|
|
56
|
-
...(isNaturalPerson ? getFormatDate(birthday as string) : { inn }),
|
|
57
|
-
...(typeForm === 'FEEDBACK'
|
|
58
|
-
? {}
|
|
59
|
-
: {
|
|
60
|
-
addressBranch,
|
|
61
|
-
bankEmpolee,
|
|
62
|
-
applicationDate,
|
|
63
|
-
...getSecondaryPhone(secondaryPhone as string),
|
|
64
|
-
}),
|
|
65
|
-
...addPageSlug(typeForm, router),
|
|
66
|
-
...formatPFForm(typeForm, { innDadata, fullRegion, partnerSymbolCode, companyNameByInn }),
|
|
67
|
-
...staticBody,
|
|
68
|
-
};
|
|
40
|
+
const submitBody = getSubmitBody(body, isNaturalPerson, router);
|
|
69
41
|
|
|
70
42
|
try {
|
|
71
|
-
const response = await
|
|
72
|
-
method: 'POST',
|
|
73
|
-
headers: { 'Content-Type': 'application/json' },
|
|
74
|
-
mode: 'cors',
|
|
75
|
-
body: JSON.stringify(submitBody),
|
|
76
|
-
});
|
|
43
|
+
const response = await LeadServiceFetch(url, submitBody);
|
|
77
44
|
|
|
78
45
|
if (!response?.ok) {
|
|
79
46
|
return null;
|
|
@@ -85,42 +52,57 @@ export function LeadServiceAPI() {
|
|
|
85
52
|
}
|
|
86
53
|
}
|
|
87
54
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
91
|
-
}
|
|
55
|
+
async function sendCode({ phone }: PhoneOnly) {
|
|
56
|
+
const submitBody = getPhoneBody(phone);
|
|
92
57
|
|
|
93
|
-
|
|
58
|
+
try {
|
|
59
|
+
const response = LeadServiceFetch(`${API_BASE_URI}/initCorporateLead`, submitBody).then(
|
|
60
|
+
async (res) => {
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
throw new Error(`Ошибка HTTP: ${res.status}`);
|
|
63
|
+
}
|
|
94
64
|
|
|
95
|
-
|
|
96
|
-
|
|
65
|
+
return await res.text();
|
|
66
|
+
},
|
|
67
|
+
);
|
|
97
68
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
69
|
+
return await response;
|
|
70
|
+
} catch (e) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
101
74
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
75
|
+
async function checkCode({ reqId, code, body }: CheckCodeProps) {
|
|
76
|
+
const submitBody = {
|
|
77
|
+
requestId: reqId,
|
|
78
|
+
confimationCode: code,
|
|
79
|
+
leadRequest: getSubmitBody(body, false),
|
|
80
|
+
};
|
|
105
81
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
? {}
|
|
109
|
-
: { secondaryPhoneNumber: formatPhone(secondaryPhone) };
|
|
82
|
+
try {
|
|
83
|
+
const response = await LeadServiceFetch(`${API_BASE_URI}/confirmCorporateLead`, submitBody);
|
|
110
84
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
? {
|
|
114
|
-
inn: data?.innDadata,
|
|
115
|
-
region: data?.fullRegion,
|
|
116
|
-
partnerComments: data?.partnerSymbolCode,
|
|
117
|
-
fullname: data?.companyNameByInn,
|
|
85
|
+
if (!response?.ok) {
|
|
86
|
+
return null;
|
|
118
87
|
}
|
|
119
|
-
: {};
|
|
120
88
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
89
|
+
return await response.json();
|
|
90
|
+
} catch (e) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
send,
|
|
97
|
+
sendCode,
|
|
98
|
+
checkCode,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const LeadServiceFetch = (url: string, submitBody: SubmitBody) =>
|
|
103
|
+
fetch(url, {
|
|
104
|
+
method: 'POST',
|
|
105
|
+
headers: { 'Content-Type': 'application/json' },
|
|
106
|
+
mode: 'cors',
|
|
107
|
+
body: JSON.stringify(submitBody),
|
|
108
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { JSONRecord, JSONScalar } from '@redneckz/json-op';
|
|
2
|
+
import type { Router } from '../external/useRouter';
|
|
3
|
+
import { formatDate } from '../utils/formatDate';
|
|
4
|
+
import { formatPhone } from '../utils/formatPhone';
|
|
5
|
+
import { type LeadRequest } from './LeadServiceAPI';
|
|
6
|
+
|
|
7
|
+
type PFFormData = {
|
|
8
|
+
innDadata?: string;
|
|
9
|
+
fullRegion?: string;
|
|
10
|
+
partnerSymbolCode?: string;
|
|
11
|
+
companyNameByInn?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const getSubmitBody = (body: LeadRequest, isNaturalPerson: boolean, router?: Router) => {
|
|
15
|
+
const {
|
|
16
|
+
typeForm,
|
|
17
|
+
region,
|
|
18
|
+
phone = '',
|
|
19
|
+
email,
|
|
20
|
+
birthday,
|
|
21
|
+
desiredMeetingDate,
|
|
22
|
+
inn,
|
|
23
|
+
innDadata,
|
|
24
|
+
fullRegion,
|
|
25
|
+
addressBranch,
|
|
26
|
+
secondaryPhone = '',
|
|
27
|
+
bankEmpolee,
|
|
28
|
+
applicationDate,
|
|
29
|
+
partnerSymbolCode,
|
|
30
|
+
companyNameByInn,
|
|
31
|
+
...staticBody
|
|
32
|
+
} = body;
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
typeForm,
|
|
36
|
+
...getRegion(region, isNaturalPerson),
|
|
37
|
+
...getEmail(email, isNaturalPerson),
|
|
38
|
+
...getPhone(phone),
|
|
39
|
+
...getFormatDate(desiredMeetingDate as string, 'desiredMeetingDate'),
|
|
40
|
+
...(isNaturalPerson ? getFormatDate(birthday as string) : { inn }),
|
|
41
|
+
...(typeForm === 'FEEDBACK'
|
|
42
|
+
? {}
|
|
43
|
+
: {
|
|
44
|
+
addressBranch,
|
|
45
|
+
bankEmpolee,
|
|
46
|
+
applicationDate,
|
|
47
|
+
...getSecondaryPhone(secondaryPhone as string),
|
|
48
|
+
}),
|
|
49
|
+
...addPageSlug(typeForm, router),
|
|
50
|
+
...formatPFForm(typeForm, { innDadata, fullRegion, partnerSymbolCode, companyNameByInn }),
|
|
51
|
+
...staticBody,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const getPhoneBody = (phone?: string) => {
|
|
56
|
+
return {
|
|
57
|
+
...getPhone(phone),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const getPhone = (phone?: string) => (phone ? { phone: formatPhone(phone) } : {});
|
|
62
|
+
|
|
63
|
+
const getFormatDate = (date?: string, key = 'birthday') =>
|
|
64
|
+
date ? { [key]: formatDate(date) } : {};
|
|
65
|
+
|
|
66
|
+
const getRegion = (region: JSONRecord | JSONScalar | null, isNaturalPerson = true) => ({
|
|
67
|
+
[isNaturalPerson ? 'regionBranch' : 'region']: region,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const getEmail = (email?: string, isNaturalPerson = true) => ({
|
|
71
|
+
[isNaturalPerson ? 'email' : 'mail']: email,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const getSecondaryPhone = (secondaryPhone = '') =>
|
|
75
|
+
!secondaryPhone || secondaryPhone === '+7 ('
|
|
76
|
+
? {}
|
|
77
|
+
: { secondaryPhoneNumber: formatPhone(secondaryPhone) };
|
|
78
|
+
|
|
79
|
+
const formatPFForm = (typeForm?: string, data?: PFFormData) =>
|
|
80
|
+
typeForm === 'PF'
|
|
81
|
+
? {
|
|
82
|
+
inn: data?.innDadata,
|
|
83
|
+
region: data?.fullRegion,
|
|
84
|
+
partnerComments: data?.partnerSymbolCode,
|
|
85
|
+
fullname: data?.companyNameByInn,
|
|
86
|
+
}
|
|
87
|
+
: {};
|
|
88
|
+
|
|
89
|
+
const addPageSlug = (typeForm?: string, router?: Router) =>
|
|
90
|
+
typeForm === 'UNIVERSAL'
|
|
91
|
+
? {
|
|
92
|
+
typeForm: router?.pathname?.split('/')?.at(-1) || '/',
|
|
93
|
+
}
|
|
94
|
+
: {};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"padding": "",
|
|
8
8
|
"title": "Заполните онлайн-заявку на эквайринг",
|
|
9
9
|
"typeForm": "ACQR",
|
|
10
|
-
"endpoint": "
|
|
10
|
+
"endpoint": "initcorporatelead",
|
|
11
11
|
"sections": [
|
|
12
12
|
{
|
|
13
13
|
"title": "Вид эквайринга и регион",
|
|
@@ -533,7 +533,7 @@
|
|
|
533
533
|
"padding": "",
|
|
534
534
|
"title": "Форма заявка",
|
|
535
535
|
"typeForm": "DPST",
|
|
536
|
-
"endpoint": "
|
|
536
|
+
"endpoint": "initcorporatelead",
|
|
537
537
|
"sections": [
|
|
538
538
|
{
|
|
539
539
|
"inputs": [
|
|
@@ -59,7 +59,7 @@ export default {
|
|
|
59
59
|
className="col-span-12"
|
|
60
60
|
title="Заполните онлайн-заявку на эквайринг"
|
|
61
61
|
typeForm="ACQR"
|
|
62
|
-
endpoint="
|
|
62
|
+
endpoint="initcorporatelead"
|
|
63
63
|
sections={[
|
|
64
64
|
{
|
|
65
65
|
title: 'Вид эквайринга и регион',
|
|
@@ -359,7 +359,7 @@ export default {
|
|
|
359
359
|
className="col-span-12"
|
|
360
360
|
title="Форма заявка депозит"
|
|
361
361
|
typeForm="DPST"
|
|
362
|
-
endpoint="
|
|
362
|
+
endpoint="initcorporatelead"
|
|
363
363
|
sections={[
|
|
364
364
|
{
|
|
365
365
|
title: 'Оставьте заявку и мы ответим на любые вопросы по депозитам',
|
|
@@ -59,7 +59,7 @@ export default {
|
|
|
59
59
|
className="col-span-12"
|
|
60
60
|
title="Заполните онлайн-заявку на эквайринг"
|
|
61
61
|
typeForm="ACQR"
|
|
62
|
-
endpoint="
|
|
62
|
+
endpoint="initcorporatelead"
|
|
63
63
|
sections={[
|
|
64
64
|
{
|
|
65
65
|
title: 'Вид эквайринга и регион',
|
|
@@ -355,7 +355,7 @@ export default {
|
|
|
355
355
|
className="col-span-12"
|
|
356
356
|
title="Форма заявка депозит"
|
|
357
357
|
typeForm="DPST"
|
|
358
|
-
endpoint="
|
|
358
|
+
endpoint="initcorporatelead"
|
|
359
359
|
sections={[
|
|
360
360
|
{
|
|
361
361
|
title: 'Оставьте заявку и мы ответим на любые вопросы по депозитам',
|
|
@@ -892,6 +892,28 @@ export default {
|
|
|
892
892
|
<DialogManager />
|
|
893
893
|
</div>
|
|
894
894
|
),
|
|
895
|
+
withSms: (
|
|
896
|
+
<div className="container grid grid-cols-12">
|
|
897
|
+
<ApplicationForm
|
|
898
|
+
className="col-span-12"
|
|
899
|
+
title="Онлайн-заявка от партнера"
|
|
900
|
+
typeForm="PF"
|
|
901
|
+
endpoint="initcorporatelead"
|
|
902
|
+
sections={[
|
|
903
|
+
{
|
|
904
|
+
inputs: [
|
|
905
|
+
{ name: 'name', required: true },
|
|
906
|
+
{ name: 'phone', required: true },
|
|
907
|
+
],
|
|
908
|
+
},
|
|
909
|
+
]}
|
|
910
|
+
button={button}
|
|
911
|
+
link={linkCorp}
|
|
912
|
+
/>
|
|
913
|
+
<PopupManager />
|
|
914
|
+
<DialogManager />
|
|
915
|
+
</div>
|
|
916
|
+
),
|
|
895
917
|
rkoApk: (
|
|
896
918
|
<div className="container grid grid-cols-12">
|
|
897
919
|
<ApplicationForm
|
|
@@ -6,6 +6,7 @@ import { useAspects } from '../../hooks/useAspects/useAspects';
|
|
|
6
6
|
import { useForm, type FormFieldRegisterer } from '../../hooks/useForm/useForm';
|
|
7
7
|
import { type FormTypeFieldDef } from '../../model/FormTypeFieldDef';
|
|
8
8
|
import { type SectionsProps } from '../../model/InputSectionsType';
|
|
9
|
+
import { VerifyPhoneDialog } from '../../retail/components/VerifyPhoneDialog/VerifyPhoneDialog';
|
|
9
10
|
import { ApplicationFormLayout } from '../../ui-kit/ApplicationFormLayout/ApplicationFormLayout';
|
|
10
11
|
import { useDialog } from '../../ui-kit/DialogManager/useDialog';
|
|
11
12
|
import { getConsentDataProcessing } from '../../ui-kit/FormField/getConsentDataProcessing';
|
|
@@ -38,6 +39,7 @@ type renderSectionsType = {
|
|
|
38
39
|
const API = LeadServiceAPI();
|
|
39
40
|
|
|
40
41
|
export const ApplicationForm = UniBlock<ApplicationFormProps>(
|
|
42
|
+
// eslint-disable-next-line max-lines-per-function
|
|
41
43
|
({
|
|
42
44
|
className,
|
|
43
45
|
title,
|
|
@@ -66,14 +68,41 @@ export const ApplicationForm = UniBlock<ApplicationFormProps>(
|
|
|
66
68
|
const responseTypeDialog = useDialog(ResponseTypeDialog);
|
|
67
69
|
const aspects = useAspects();
|
|
68
70
|
|
|
71
|
+
const verifyPhoneDialog = useDialog(VerifyPhoneDialog);
|
|
72
|
+
|
|
69
73
|
const handleSubmit = useCallback(
|
|
70
74
|
async (formData: FormState, ev: PreventableEventWithTarget) => {
|
|
71
75
|
const formatData = getFormatData({ ...formData, ...additionalParams });
|
|
72
|
-
const ok = Boolean(await API.send(formatData, router, endpoint === 'lead'));
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
if (endpoint === 'initcorporatelead') {
|
|
78
|
+
const { phone } = formatData;
|
|
79
|
+
|
|
80
|
+
const response = await API.sendCode({ phone: String(phone) });
|
|
81
|
+
|
|
82
|
+
if (!response) {
|
|
83
|
+
responseTypeDialog.open({ ok: Boolean(response), typeForm });
|
|
84
|
+
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
verifyPhoneDialog.open({
|
|
89
|
+
phone,
|
|
90
|
+
withDescription: false,
|
|
91
|
+
formatData,
|
|
92
|
+
reqId: String(response),
|
|
93
|
+
isRetail: false,
|
|
94
|
+
onSuccess: () => {
|
|
95
|
+
verifyPhoneDialog.close();
|
|
96
|
+
responseTypeDialog.open({ ok: true, typeForm });
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
const ok = Boolean(await API.send(formatData, router, endpoint === 'lead'));
|
|
101
|
+
|
|
102
|
+
responseTypeDialog.open({ ok, typeForm });
|
|
103
|
+
if (ok) {
|
|
104
|
+
handleAspects({ aspectsAttributes: data, aspects, ev });
|
|
105
|
+
}
|
|
77
106
|
}
|
|
78
107
|
},
|
|
79
108
|
[typeForm],
|