@redneckz/wildless-cms-uni-blocks 0.14.926 → 0.14.927
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 +50 -34
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/ApplicationLeadForm/useApplicationLeadApi.d.ts +2 -2
- package/bundle/retail/api/checkCode.d.ts +1 -2
- package/bundle/retail/api/sendCode.d.ts +1 -1
- package/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +1 -0
- package/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +3 -2
- package/bundle/retail/utils/saveToken.d.ts +2 -0
- package/dist/components/ApplicationLeadForm/ApplicationLeadForm.js +10 -2
- package/dist/components/ApplicationLeadForm/ApplicationLeadForm.js.map +1 -1
- package/dist/components/ApplicationLeadForm/useApplicationLeadApi.d.ts +2 -2
- package/dist/components/ApplicationLeadForm/useApplicationLeadApi.js +9 -5
- package/dist/components/ApplicationLeadForm/useApplicationLeadApi.js.map +1 -1
- package/dist/retail/api/checkCode.d.ts +1 -2
- package/dist/retail/api/checkCode.js +2 -9
- package/dist/retail/api/checkCode.js.map +1 -1
- package/dist/retail/api/esiaRequestProfile.js +2 -2
- package/dist/retail/api/esiaRequestProfile.js.map +1 -1
- package/dist/retail/api/sendCode.d.ts +1 -1
- package/dist/retail/api/sendCode.js +1 -3
- package/dist/retail/api/sendCode.js.map +1 -1
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +1 -0
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +8 -4
- package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +3 -2
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +18 -14
- package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/dist/retail/utils/mockLocalStorage.js +4 -1
- package/dist/retail/utils/mockLocalStorage.js.map +1 -1
- package/dist/retail/utils/saveToken.d.ts +2 -0
- package/dist/retail/utils/saveToken.js +8 -0
- package/dist/retail/utils/saveToken.js.map +1 -0
- package/lib/components/ApplicationLeadForm/ApplicationLeadForm.js +10 -2
- package/lib/components/ApplicationLeadForm/ApplicationLeadForm.js.map +1 -1
- package/lib/components/ApplicationLeadForm/useApplicationLeadApi.d.ts +2 -2
- package/lib/components/ApplicationLeadForm/useApplicationLeadApi.js +10 -6
- package/lib/components/ApplicationLeadForm/useApplicationLeadApi.js.map +1 -1
- package/lib/retail/api/checkCode.d.ts +1 -2
- package/lib/retail/api/checkCode.js +2 -8
- package/lib/retail/api/checkCode.js.map +1 -1
- package/lib/retail/api/esiaRequestProfile.js +1 -1
- package/lib/retail/api/esiaRequestProfile.js.map +1 -1
- package/lib/retail/api/sendCode.d.ts +1 -1
- package/lib/retail/api/sendCode.js +1 -3
- package/lib/retail/api/sendCode.js.map +1 -1
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +1 -0
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +8 -4
- package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +3 -2
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +18 -14
- package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/lib/retail/utils/mockLocalStorage.js +4 -1
- package/lib/retail/utils/mockLocalStorage.js.map +1 -1
- package/lib/retail/utils/saveToken.d.ts +2 -0
- package/lib/retail/utils/saveToken.js +5 -0
- package/lib/retail/utils/saveToken.js.map +1 -0
- package/mobile/bundle/bundle.umd.js +50 -34
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/ApplicationLeadForm/useApplicationLeadApi.d.ts +2 -2
- package/mobile/bundle/retail/api/checkCode.d.ts +1 -2
- package/mobile/bundle/retail/api/sendCode.d.ts +1 -1
- package/mobile/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +1 -0
- package/mobile/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +3 -2
- package/mobile/bundle/retail/utils/saveToken.d.ts +2 -0
- package/mobile/dist/components/ApplicationLeadForm/ApplicationLeadForm.js +10 -2
- package/mobile/dist/components/ApplicationLeadForm/ApplicationLeadForm.js.map +1 -1
- package/mobile/dist/components/ApplicationLeadForm/useApplicationLeadApi.d.ts +2 -2
- package/mobile/dist/components/ApplicationLeadForm/useApplicationLeadApi.js +9 -5
- package/mobile/dist/components/ApplicationLeadForm/useApplicationLeadApi.js.map +1 -1
- package/mobile/dist/retail/api/checkCode.d.ts +1 -2
- package/mobile/dist/retail/api/checkCode.js +2 -9
- package/mobile/dist/retail/api/checkCode.js.map +1 -1
- package/mobile/dist/retail/api/esiaRequestProfile.js +2 -2
- package/mobile/dist/retail/api/esiaRequestProfile.js.map +1 -1
- package/mobile/dist/retail/api/sendCode.d.ts +1 -1
- package/mobile/dist/retail/api/sendCode.js +1 -3
- package/mobile/dist/retail/api/sendCode.js.map +1 -1
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +1 -0
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +8 -4
- package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +3 -2
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +18 -14
- package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/mobile/dist/retail/utils/mockLocalStorage.js +4 -1
- package/mobile/dist/retail/utils/mockLocalStorage.js.map +1 -1
- package/mobile/dist/retail/utils/saveToken.d.ts +2 -0
- package/mobile/dist/retail/utils/saveToken.js +8 -0
- package/mobile/dist/retail/utils/saveToken.js.map +1 -0
- package/mobile/lib/components/ApplicationLeadForm/ApplicationLeadForm.js +10 -2
- package/mobile/lib/components/ApplicationLeadForm/ApplicationLeadForm.js.map +1 -1
- package/mobile/lib/components/ApplicationLeadForm/useApplicationLeadApi.d.ts +2 -2
- package/mobile/lib/components/ApplicationLeadForm/useApplicationLeadApi.js +10 -6
- package/mobile/lib/components/ApplicationLeadForm/useApplicationLeadApi.js.map +1 -1
- package/mobile/lib/retail/api/checkCode.d.ts +1 -2
- package/mobile/lib/retail/api/checkCode.js +2 -8
- package/mobile/lib/retail/api/checkCode.js.map +1 -1
- package/mobile/lib/retail/api/esiaRequestProfile.js +1 -1
- package/mobile/lib/retail/api/esiaRequestProfile.js.map +1 -1
- package/mobile/lib/retail/api/sendCode.d.ts +1 -1
- package/mobile/lib/retail/api/sendCode.js +1 -3
- package/mobile/lib/retail/api/sendCode.js.map +1 -1
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +1 -0
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +8 -4
- package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +3 -2
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +18 -14
- package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
- package/mobile/lib/retail/utils/mockLocalStorage.js +4 -1
- package/mobile/lib/retail/utils/mockLocalStorage.js.map +1 -1
- package/mobile/lib/retail/utils/saveToken.d.ts +2 -0
- package/mobile/lib/retail/utils/saveToken.js +5 -0
- package/mobile/lib/retail/utils/saveToken.js.map +1 -0
- package/mobile/src/components/ApplicationLeadForm/ApplicationLeadForm.tsx +10 -2
- package/mobile/src/components/ApplicationLeadForm/useApplicationLeadApi.tsx +11 -5
- package/mobile/src/retail/api/checkCode.ts +2 -9
- package/mobile/src/retail/api/esiaRequestProfile.ts +2 -1
- package/mobile/src/retail/api/sendCode.ts +1 -4
- package/mobile/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +15 -4
- package/mobile/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +22 -15
- package/mobile/src/retail/utils/mockLocalStorage.ts +6 -2
- package/mobile/src/retail/utils/saveToken.ts +6 -0
- package/package.json +1 -1
- package/src/components/ApplicationLeadForm/ApplicationLeadForm.tsx +10 -2
- package/src/components/ApplicationLeadForm/useApplicationLeadApi.tsx +11 -5
- package/src/retail/api/checkCode.ts +2 -9
- package/src/retail/api/esiaRequestProfile.ts +2 -1
- package/src/retail/api/sendCode.ts +1 -4
- package/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +15 -4
- package/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +22 -15
- package/src/retail/utils/mockLocalStorage.ts +6 -2
- package/src/retail/utils/saveToken.ts +6 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { checkCode } from '../api/checkCode';
|
|
1
|
+
import { checkCode, type CheckCodeResponse } from '../api/checkCode';
|
|
2
2
|
import { createDraftTask } from '../api/createDraftTask';
|
|
3
3
|
import { createUserProfile } from '../api/createUserProfile';
|
|
4
4
|
import { sendCode } from '../api/sendCode';
|
|
5
|
+
import { saveToken } from './saveToken';
|
|
5
6
|
|
|
6
7
|
const PHONE = '+11111111111';
|
|
7
8
|
const PROGRAM_ID = '13';
|
|
@@ -18,11 +19,14 @@ export const mockLocalStorage = async () => {
|
|
|
18
19
|
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
await checkCode({
|
|
22
|
+
const response = await checkCode({
|
|
22
23
|
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
23
24
|
smsText: '1234',
|
|
24
25
|
});
|
|
25
26
|
|
|
27
|
+
const data = (await response.json()) as CheckCodeResponse;
|
|
28
|
+
saveToken(data);
|
|
29
|
+
|
|
26
30
|
const task = {
|
|
27
31
|
taskId: globalThis.localStorage.getItem('taskId'),
|
|
28
32
|
participantId: globalThis.localStorage.getItem('participantId'),
|
package/package.json
CHANGED
|
@@ -45,6 +45,7 @@ export const ApplicationLeadForm = JSX<ApplicationLeadFormProps>(
|
|
|
45
45
|
...rest
|
|
46
46
|
}) => {
|
|
47
47
|
const [esiaStatus, setEsiaStatus] = useState<EsiaStatuses>();
|
|
48
|
+
const [ok, setOK] = useState<boolean | undefined>();
|
|
48
49
|
const [attemptsWithoutConsents, setAttemptsWithoutConsents] = useState(0);
|
|
49
50
|
const leadForm = useRef<HTMLFormElement | null>(null);
|
|
50
51
|
const applicationFormData = useMemo(() => getApplicationFormData(productType), [productType]);
|
|
@@ -56,6 +57,9 @@ export const ApplicationLeadForm = JSX<ApplicationLeadFormProps>(
|
|
|
56
57
|
() => getFormValidator(inputs, extendedValidatorObj),
|
|
57
58
|
[inputs, extendedValidatorObj],
|
|
58
59
|
);
|
|
60
|
+
const changeSubmitFormStatus = (status?: boolean) => {
|
|
61
|
+
setOK(status);
|
|
62
|
+
};
|
|
59
63
|
|
|
60
64
|
const initialFormState = useInitApplicationLead({
|
|
61
65
|
inputs,
|
|
@@ -64,11 +68,12 @@ export const ApplicationLeadForm = JSX<ApplicationLeadFormProps>(
|
|
|
64
68
|
setEsiaStatus,
|
|
65
69
|
esiaAuthSuccess: esiaStatus === EsiaStatuses.Success,
|
|
66
70
|
});
|
|
67
|
-
const { isSending,
|
|
71
|
+
const { isSending, handleSubmit } = useApplicationLeadApi({
|
|
68
72
|
programId,
|
|
69
73
|
nextStepLink,
|
|
70
74
|
productType,
|
|
71
75
|
data,
|
|
76
|
+
changeSubmitFormStatus,
|
|
72
77
|
});
|
|
73
78
|
|
|
74
79
|
const [, { field, onSubmit, reset }] = useForm(initialFormState, {
|
|
@@ -90,7 +95,10 @@ export const ApplicationLeadForm = JSX<ApplicationLeadFormProps>(
|
|
|
90
95
|
const responseTypeDialog = useDialog(ResponseTypeDialog);
|
|
91
96
|
useEffect(() => {
|
|
92
97
|
if (ok !== undefined) {
|
|
93
|
-
responseTypeDialog.open({
|
|
98
|
+
responseTypeDialog.open({
|
|
99
|
+
ok,
|
|
100
|
+
onClose: () => changeSubmitFormStatus(undefined),
|
|
101
|
+
});
|
|
94
102
|
}
|
|
95
103
|
}, [ok]);
|
|
96
104
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
|
-
import { useCallback
|
|
2
|
+
import { useCallback } from '@redneckz/uni-jsx/lib/hooks';
|
|
3
3
|
import { useBool } from '@redneckz/uni-jsx/lib/hooks/useBool';
|
|
4
4
|
import { useSessionStore } from '@redneckz/uni-jsx/lib/Store/useSessionStore';
|
|
5
5
|
import { locationNavigator } from '../../external/locationNavigator';
|
|
@@ -32,6 +32,7 @@ interface ApplicationLeadApiProps extends AspectsProps {
|
|
|
32
32
|
programId: string;
|
|
33
33
|
nextStepLink: string;
|
|
34
34
|
productType: ProductType;
|
|
35
|
+
changeSubmitFormStatus: (status?: boolean) => void;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -40,9 +41,9 @@ export const useApplicationLeadApi = ({
|
|
|
40
41
|
nextStepLink,
|
|
41
42
|
productType,
|
|
42
43
|
data,
|
|
44
|
+
changeSubmitFormStatus,
|
|
43
45
|
}: ApplicationLeadApiProps) => {
|
|
44
46
|
const [isSending, { setTrue: startSending, setFalse: endSending }] = useBool(false);
|
|
45
|
-
const [ok, setOK] = useState<boolean | undefined>();
|
|
46
47
|
const saveUserData = useSaveUserData();
|
|
47
48
|
const sessionStore = useSessionStore<ApplicationLeadStore>();
|
|
48
49
|
const leadFormStore = useLeadFormStore();
|
|
@@ -57,6 +58,10 @@ export const useApplicationLeadApi = ({
|
|
|
57
58
|
const consentBkiDialog = useConsentBkiDialog(goToNextStep);
|
|
58
59
|
const verifyPhoneDialog = useDialog(VerifyPhoneDialog);
|
|
59
60
|
const draftDialog = useDraftDialog();
|
|
61
|
+
const handleFailSendForm = () => {
|
|
62
|
+
verifyPhoneDialog.close();
|
|
63
|
+
changeSubmitFormStatus(false);
|
|
64
|
+
};
|
|
60
65
|
|
|
61
66
|
const handleSubmit = useCallback(async (formData: LeadFormState) => {
|
|
62
67
|
try {
|
|
@@ -109,7 +114,7 @@ export const useApplicationLeadApi = ({
|
|
|
109
114
|
await sendCurrentTask();
|
|
110
115
|
}
|
|
111
116
|
} catch {
|
|
112
|
-
|
|
117
|
+
handleFailSendForm();
|
|
113
118
|
}
|
|
114
119
|
};
|
|
115
120
|
|
|
@@ -119,15 +124,16 @@ export const useApplicationLeadApi = ({
|
|
|
119
124
|
phone: transformedFormData.phone as string,
|
|
120
125
|
consents: acceptedConsents,
|
|
121
126
|
onSuccess: handleSuccessVerify,
|
|
127
|
+
onFail: handleFailSendForm,
|
|
122
128
|
});
|
|
123
129
|
} catch {
|
|
124
|
-
|
|
130
|
+
handleFailSendForm();
|
|
125
131
|
} finally {
|
|
126
132
|
endSending();
|
|
127
133
|
}
|
|
128
134
|
}, []);
|
|
129
135
|
|
|
130
|
-
return { isSending,
|
|
136
|
+
return { isSending, handleSubmit };
|
|
131
137
|
};
|
|
132
138
|
|
|
133
139
|
const getAcceptedConsents = (formData: LeadFormState, productType: ProductType): string[] => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { doRequest } from './doRequest';
|
|
2
2
|
|
|
3
3
|
export type CheckCodeBody = {
|
|
4
4
|
smsText: string;
|
|
@@ -14,11 +14,4 @@ export type CheckCodeResponse = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const checkCode = async (body: CheckCodeBody) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export const saveToken = (data: CheckCodeResponse | null) => {
|
|
20
|
-
if (data?.access_token && data?.refresh_token) {
|
|
21
|
-
globalThis.sessionStorage.setItem('accessToken', data.access_token);
|
|
22
|
-
globalThis.sessionStorage.setItem('refreshToken', data.refresh_token);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
17
|
+
await doRequest('/sms/checkCode', 'POST', body);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { saveToken
|
|
1
|
+
import { saveToken } from '../utils/saveToken';
|
|
2
|
+
import { type CheckCodeResponse } from './checkCode';
|
|
2
3
|
import { fetchRetailJSON } from './doRequest';
|
|
3
4
|
import { updateRefreshToken } from './updateRefreshToken';
|
|
4
5
|
|
|
@@ -7,7 +7,4 @@ export type SendCodeBody = {
|
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export const sendCode = (body: SendCodeBody) =>
|
|
11
|
-
doRequest('/sms/sendCode', 'POST', body)
|
|
12
|
-
.then((res) => res.text())
|
|
13
|
-
.then((text) => text === 'OK');
|
|
10
|
+
export const sendCode = (body: SendCodeBody) => doRequest('/sms/sendCode', 'POST', body);
|
|
@@ -23,10 +23,18 @@ export interface VerifyPhoneDialogProps extends OnCloseProps {
|
|
|
23
23
|
withDescription?: boolean;
|
|
24
24
|
consents?: string[];
|
|
25
25
|
onSuccess?: (smsCode?: string) => void;
|
|
26
|
+
onFail?: () => void;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
29
|
-
({
|
|
30
|
+
({
|
|
31
|
+
phone,
|
|
32
|
+
withDescription = true,
|
|
33
|
+
consents,
|
|
34
|
+
onSuccess = noop,
|
|
35
|
+
onClose = noop,
|
|
36
|
+
onFail = noop,
|
|
37
|
+
}) => {
|
|
30
38
|
const [values, setValues] = useState<string[]>(Array(CODE_LENGTH).fill('') as string[]);
|
|
31
39
|
const sessionStore = useSessionStore<SmsCodeStore>();
|
|
32
40
|
|
|
@@ -42,6 +50,7 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
42
50
|
} = useVerifyPhoneDialogSubmit({
|
|
43
51
|
values,
|
|
44
52
|
onSuccess,
|
|
53
|
+
onFail,
|
|
45
54
|
});
|
|
46
55
|
|
|
47
56
|
const captchaDialog = useDialog(CaptchaDialog);
|
|
@@ -54,7 +63,7 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
54
63
|
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
55
64
|
});
|
|
56
65
|
|
|
57
|
-
if (response) {
|
|
66
|
+
if (response.ok) {
|
|
58
67
|
setTimeNextReq(TIME_TO_RESEND);
|
|
59
68
|
restartTimer(TIME_TO_RESEND);
|
|
60
69
|
setErrorText('');
|
|
@@ -62,10 +71,12 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
|
|
|
62
71
|
sendTime: Date.now(),
|
|
63
72
|
attempts: 0,
|
|
64
73
|
};
|
|
65
|
-
} else {
|
|
74
|
+
} else if (response.status === 429) {
|
|
66
75
|
captchaDialog.open({ phoneNumber, sendCode: handleSendCode });
|
|
76
|
+
} else {
|
|
77
|
+
onFail();
|
|
67
78
|
}
|
|
68
|
-
}, [phoneNumber, restartTimer
|
|
79
|
+
}, [phoneNumber, restartTimer]);
|
|
69
80
|
|
|
70
81
|
useEffect(() => {
|
|
71
82
|
if (!sessionStore.smsCode?.sendTime) {
|
|
@@ -2,13 +2,15 @@ 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
4
|
import { getTimer } from '../../../utils/getTimer';
|
|
5
|
-
import { checkCode } from '../../api/checkCode';
|
|
5
|
+
import { checkCode, type CheckCodeResponse } from '../../api/checkCode';
|
|
6
|
+
import { saveToken } from '../../utils/saveToken';
|
|
6
7
|
|
|
7
8
|
export const TIME_TO_RESEND = 180;
|
|
8
9
|
|
|
9
10
|
type useVerifyPhoneDialogSubmitProps = {
|
|
10
11
|
values: string[];
|
|
11
|
-
onSuccess
|
|
12
|
+
onSuccess: (smsCode?: string) => void;
|
|
13
|
+
onFail: () => void;
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
export interface SmsCodeStore {
|
|
@@ -21,6 +23,7 @@ export interface SmsCodeStore {
|
|
|
21
23
|
export const useVerifyPhoneDialogSubmit = ({
|
|
22
24
|
values,
|
|
23
25
|
onSuccess,
|
|
26
|
+
onFail,
|
|
24
27
|
}: useVerifyPhoneDialogSubmitProps) => {
|
|
25
28
|
const sessionStore = useSessionStore<SmsCodeStore>();
|
|
26
29
|
const attempts = sessionStore.smsCode?.attempts || 0;
|
|
@@ -36,25 +39,29 @@ export const useVerifyPhoneDialogSubmit = ({
|
|
|
36
39
|
const isSubmitButtonDisabled = attempts > 2 || isTimeExpired || !values.every(Boolean);
|
|
37
40
|
|
|
38
41
|
const handleSubmit = useCallback(async () => {
|
|
39
|
-
|
|
40
|
-
sessionStore.smsCode
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
sessionStore.smsCode = {
|
|
43
|
+
...sessionStore.smsCode,
|
|
44
|
+
attempts: attempts + 1,
|
|
45
|
+
};
|
|
46
|
+
startLoading();
|
|
47
|
+
const response = await checkCode({
|
|
48
|
+
smsText: values.join(''),
|
|
49
|
+
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (response.ok) {
|
|
53
|
+
const data = (await response.json()) as CheckCodeResponse;
|
|
54
|
+
saveToken(data);
|
|
49
55
|
setTimeNextReq(0);
|
|
50
56
|
resetError();
|
|
51
57
|
sessionStore.smsCode = null;
|
|
52
58
|
onSuccess?.(values.join(''));
|
|
53
|
-
}
|
|
59
|
+
} else if (response.status === 403) {
|
|
54
60
|
setErrorText(attempts > 1 ? 'Исчерпан лимит ввода смс-кода' : 'Неверный код');
|
|
55
|
-
}
|
|
56
|
-
|
|
61
|
+
} else {
|
|
62
|
+
onFail();
|
|
57
63
|
}
|
|
64
|
+
endLoading();
|
|
58
65
|
}, [values, attempts]);
|
|
59
66
|
|
|
60
67
|
useEffect(() => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { checkCode } from '../api/checkCode';
|
|
1
|
+
import { checkCode, type CheckCodeResponse } from '../api/checkCode';
|
|
2
2
|
import { createDraftTask } from '../api/createDraftTask';
|
|
3
3
|
import { createUserProfile } from '../api/createUserProfile';
|
|
4
4
|
import { sendCode } from '../api/sendCode';
|
|
5
|
+
import { saveToken } from './saveToken';
|
|
5
6
|
|
|
6
7
|
const PHONE = '+11111111111';
|
|
7
8
|
const PROGRAM_ID = '13';
|
|
@@ -18,11 +19,14 @@ export const mockLocalStorage = async () => {
|
|
|
18
19
|
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
19
20
|
});
|
|
20
21
|
|
|
21
|
-
await checkCode({
|
|
22
|
+
const response = await checkCode({
|
|
22
23
|
smsCodesSetName: { key: 'AUTHENTICATION' },
|
|
23
24
|
smsText: '1234',
|
|
24
25
|
});
|
|
25
26
|
|
|
27
|
+
const data = (await response.json()) as CheckCodeResponse;
|
|
28
|
+
saveToken(data);
|
|
29
|
+
|
|
26
30
|
const task = {
|
|
27
31
|
taskId: globalThis.localStorage.getItem('taskId'),
|
|
28
32
|
participantId: globalThis.localStorage.getItem('participantId'),
|