@redneckz/wildless-cms-uni-blocks 0.14.912 → 0.14.914

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.
Files changed (223) hide show
  1. package/bundle/api/LeadServiceAPI.d.ts +12 -3
  2. package/bundle/bundle.umd.js +715 -683
  3. package/bundle/bundle.umd.min.js +1 -1
  4. package/bundle/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  5. package/bundle/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  6. package/bundle/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  7. package/bundle/retail/api/checkCode.d.ts +1 -9
  8. package/bundle/retail/api/sendCode.d.ts +1 -1
  9. package/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  10. package/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  11. package/bundle/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  12. package/bundle/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  13. package/bundle/utils/getTimer.d.ts +2 -0
  14. package/dist/api/LeadServiceAPI.d.ts +12 -3
  15. package/dist/api/LeadServiceAPI.js +0 -3
  16. package/dist/api/LeadServiceAPI.js.map +1 -1
  17. package/dist/components/ApplicationForm/ApplicationForm.js +1 -3
  18. package/dist/components/ApplicationForm/ApplicationForm.js.map +1 -1
  19. package/dist/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  20. package/dist/components/ApplicationForm/VerifyPhoneDialog.js +37 -0
  21. package/dist/components/ApplicationForm/VerifyPhoneDialog.js.map +1 -0
  22. package/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  23. package/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.js +50 -0
  24. package/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.js.map +1 -0
  25. package/dist/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  26. package/dist/retail/api/checkCode.d.ts +1 -9
  27. package/dist/retail/api/checkCode.js +1 -22
  28. package/dist/retail/api/checkCode.js.map +1 -1
  29. package/dist/retail/api/sendCode.d.ts +1 -1
  30. package/dist/retail/api/sendCode.js +2 -8
  31. package/dist/retail/api/sendCode.js.map +1 -1
  32. package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  33. package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +5 -24
  34. package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
  35. package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  36. package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +7 -10
  37. package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
  38. package/dist/retail/utils/mockLocalStorage.js +2 -2
  39. package/dist/retail/utils/mockLocalStorage.js.map +1 -1
  40. package/dist/ui-kit/BaseTile/BaseTile.js +1 -1
  41. package/dist/ui-kit/BaseTile/BaseTile.js.map +1 -1
  42. package/dist/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  43. package/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  44. package/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js +17 -0
  45. package/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js.map +1 -0
  46. package/dist/utils/getTimer.d.ts +2 -0
  47. package/dist/utils/getTimer.js +6 -0
  48. package/dist/utils/getTimer.js.map +1 -0
  49. package/lib/api/LeadServiceAPI.d.ts +12 -3
  50. package/lib/api/LeadServiceAPI.js +0 -3
  51. package/lib/api/LeadServiceAPI.js.map +1 -1
  52. package/lib/common.css +1 -1
  53. package/lib/components/ApplicationForm/ApplicationForm.js +1 -3
  54. package/lib/components/ApplicationForm/ApplicationForm.js.map +1 -1
  55. package/lib/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  56. package/lib/components/ApplicationForm/VerifyPhoneDialog.js +35 -0
  57. package/lib/components/ApplicationForm/VerifyPhoneDialog.js.map +1 -0
  58. package/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  59. package/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.js +47 -0
  60. package/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.js.map +1 -0
  61. package/lib/components/Carousel/Carousel.fixture.d.ts +1 -0
  62. package/lib/components/CarouselRecommendationCard/CarouselRecommendationCard.fixture.d.ts +1 -1
  63. package/lib/components/CarouselTariffsCard/CarouselTariffsCard.fixture.d.ts +2 -0
  64. package/lib/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  65. package/lib/retail/api/checkCode.d.ts +1 -9
  66. package/lib/retail/api/checkCode.js +1 -22
  67. package/lib/retail/api/checkCode.js.map +1 -1
  68. package/lib/retail/api/sendCode.d.ts +1 -1
  69. package/lib/retail/api/sendCode.js +1 -7
  70. package/lib/retail/api/sendCode.js.map +1 -1
  71. package/lib/retail/components/DraftDialog/utils.d.ts +3 -3
  72. package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  73. package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +5 -24
  74. package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
  75. package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  76. package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +5 -8
  77. package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
  78. package/lib/retail/utils/mockLocalStorage.js +2 -2
  79. package/lib/retail/utils/mockLocalStorage.js.map +1 -1
  80. package/lib/ui-kit/BaseTile/BaseTile.js +1 -1
  81. package/lib/ui-kit/BaseTile/BaseTile.js.map +1 -1
  82. package/lib/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  83. package/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  84. package/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js +15 -0
  85. package/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js.map +1 -0
  86. package/lib/utils/getTimer.d.ts +2 -0
  87. package/lib/utils/getTimer.js +3 -0
  88. package/lib/utils/getTimer.js.map +1 -0
  89. package/mobile/bundle/api/LeadServiceAPI.d.ts +12 -3
  90. package/mobile/bundle/bundle.umd.js +715 -683
  91. package/mobile/bundle/bundle.umd.min.js +1 -1
  92. package/mobile/bundle/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  93. package/mobile/bundle/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  94. package/mobile/bundle/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  95. package/mobile/bundle/retail/api/checkCode.d.ts +1 -9
  96. package/mobile/bundle/retail/api/sendCode.d.ts +1 -1
  97. package/mobile/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  98. package/mobile/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  99. package/mobile/bundle/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  100. package/mobile/bundle/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  101. package/mobile/bundle/utils/getTimer.d.ts +2 -0
  102. package/mobile/dist/api/LeadServiceAPI.d.ts +12 -3
  103. package/mobile/dist/api/LeadServiceAPI.js +0 -3
  104. package/mobile/dist/api/LeadServiceAPI.js.map +1 -1
  105. package/mobile/dist/components/ApplicationForm/ApplicationForm.js +1 -3
  106. package/mobile/dist/components/ApplicationForm/ApplicationForm.js.map +1 -1
  107. package/mobile/dist/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  108. package/mobile/dist/components/ApplicationForm/VerifyPhoneDialog.js +37 -0
  109. package/mobile/dist/components/ApplicationForm/VerifyPhoneDialog.js.map +1 -0
  110. package/mobile/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  111. package/mobile/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.js +50 -0
  112. package/mobile/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.js.map +1 -0
  113. package/mobile/dist/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  114. package/mobile/dist/retail/api/checkCode.d.ts +1 -9
  115. package/mobile/dist/retail/api/checkCode.js +1 -22
  116. package/mobile/dist/retail/api/checkCode.js.map +1 -1
  117. package/mobile/dist/retail/api/sendCode.d.ts +1 -1
  118. package/mobile/dist/retail/api/sendCode.js +2 -8
  119. package/mobile/dist/retail/api/sendCode.js.map +1 -1
  120. package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  121. package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +5 -24
  122. package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
  123. package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  124. package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +7 -10
  125. package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
  126. package/mobile/dist/retail/utils/mockLocalStorage.js +2 -2
  127. package/mobile/dist/retail/utils/mockLocalStorage.js.map +1 -1
  128. package/mobile/dist/ui-kit/BaseTile/BaseTile.js +1 -1
  129. package/mobile/dist/ui-kit/BaseTile/BaseTile.js.map +1 -1
  130. package/mobile/dist/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  131. package/mobile/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  132. package/mobile/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js +17 -0
  133. package/mobile/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js.map +1 -0
  134. package/mobile/dist/utils/getTimer.d.ts +2 -0
  135. package/mobile/dist/utils/getTimer.js +6 -0
  136. package/mobile/dist/utils/getTimer.js.map +1 -0
  137. package/mobile/lib/api/LeadServiceAPI.d.ts +12 -3
  138. package/mobile/lib/api/LeadServiceAPI.js +0 -3
  139. package/mobile/lib/api/LeadServiceAPI.js.map +1 -1
  140. package/mobile/lib/common.css +1 -1
  141. package/mobile/lib/components/ApplicationForm/ApplicationForm.js +1 -3
  142. package/mobile/lib/components/ApplicationForm/ApplicationForm.js.map +1 -1
  143. package/mobile/lib/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  144. package/mobile/lib/components/ApplicationForm/VerifyPhoneDialog.js +35 -0
  145. package/mobile/lib/components/ApplicationForm/VerifyPhoneDialog.js.map +1 -0
  146. package/mobile/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  147. package/mobile/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.js +47 -0
  148. package/mobile/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.js.map +1 -0
  149. package/mobile/lib/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  150. package/mobile/lib/retail/api/checkCode.d.ts +1 -9
  151. package/mobile/lib/retail/api/checkCode.js +1 -22
  152. package/mobile/lib/retail/api/checkCode.js.map +1 -1
  153. package/mobile/lib/retail/api/sendCode.d.ts +1 -1
  154. package/mobile/lib/retail/api/sendCode.js +1 -7
  155. package/mobile/lib/retail/api/sendCode.js.map +1 -1
  156. package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  157. package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +5 -24
  158. package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
  159. package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  160. package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +5 -8
  161. package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
  162. package/mobile/lib/retail/utils/mockLocalStorage.js +2 -2
  163. package/mobile/lib/retail/utils/mockLocalStorage.js.map +1 -1
  164. package/mobile/lib/ui-kit/BaseTile/BaseTile.js +1 -1
  165. package/mobile/lib/ui-kit/BaseTile/BaseTile.js.map +1 -1
  166. package/mobile/lib/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  167. package/mobile/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  168. package/mobile/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js +15 -0
  169. package/mobile/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js.map +1 -0
  170. package/mobile/lib/utils/getTimer.d.ts +2 -0
  171. package/mobile/lib/utils/getTimer.js +3 -0
  172. package/mobile/lib/utils/getTimer.js.map +1 -0
  173. package/mobile/src/api/LeadServiceAPI.ts +13 -7
  174. package/mobile/src/components/ApplicationForm/ApplicationForm.tsx +1 -3
  175. package/mobile/src/components/ApplicationForm/VerifyPhoneDialog.tsx +73 -0
  176. package/mobile/src/components/ApplicationForm/useVerifyPhoneDialogSubmit.tsx +63 -0
  177. package/mobile/src/components/TariffsTable/TariffsTableCell.tsx +1 -1
  178. package/mobile/src/retail/api/checkCode.ts +2 -47
  179. package/mobile/src/retail/api/sendCode.ts +1 -9
  180. package/mobile/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +23 -82
  181. package/mobile/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +7 -21
  182. package/mobile/src/retail/utils/mockLocalStorage.ts +9 -15
  183. package/mobile/src/ui-kit/BaseTile/BaseTile.tsx +1 -1
  184. package/mobile/src/ui-kit/ResponseTypeDialog/ResponseTypeDialog.tsx +1 -1
  185. package/mobile/src/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.tsx +80 -0
  186. package/mobile/src/utils/getTimer.ts +4 -0
  187. package/package.json +1 -1
  188. package/src/api/LeadServiceAPI.ts +13 -7
  189. package/src/components/ApplicationForm/ApplicationForm.tsx +1 -3
  190. package/src/components/ApplicationForm/VerifyPhoneDialog.tsx +73 -0
  191. package/src/components/ApplicationForm/useVerifyPhoneDialogSubmit.tsx +63 -0
  192. package/src/components/Carousel/Carousel.fixture.mobile.tsx +16 -16
  193. package/src/components/Carousel/Carousel.fixture.tsx +42 -20
  194. package/src/components/CarouselRecommendationCard/CarouselRecommendationCard.fixture.mobile.tsx +19 -19
  195. package/src/components/CarouselRecommendationCard/CarouselRecommendationCard.fixture.tsx +44 -23
  196. package/src/components/CarouselTariffsCard/CarouselTariffsCard.fixture.tsx +12 -12
  197. package/src/components/TariffsTable/TariffsTableCell.tsx +1 -1
  198. package/src/icons/IconName.ts +4 -4
  199. package/src/retail/api/checkCode.ts +2 -47
  200. package/src/retail/api/sendCode.ts +1 -9
  201. package/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +23 -82
  202. package/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +7 -21
  203. package/src/retail/utils/mockLocalStorage.ts +9 -15
  204. package/src/ui-kit/BaseTile/BaseTile.tsx +1 -1
  205. package/src/ui-kit/ResponseTypeDialog/ResponseTypeDialog.tsx +1 -1
  206. package/src/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.tsx +80 -0
  207. package/src/utils/getTimer.ts +4 -0
  208. package/bundle/model/onClose.d.ts +0 -3
  209. package/dist/model/onClose.d.ts +0 -3
  210. package/dist/model/onClose.js +0 -2
  211. package/dist/model/onClose.js.map +0 -1
  212. package/lib/model/onClose.d.ts +0 -3
  213. package/lib/model/onClose.js +0 -2
  214. package/lib/model/onClose.js.map +0 -1
  215. package/mobile/bundle/model/onClose.d.ts +0 -3
  216. package/mobile/dist/model/onClose.d.ts +0 -3
  217. package/mobile/dist/model/onClose.js +0 -2
  218. package/mobile/dist/model/onClose.js.map +0 -1
  219. package/mobile/lib/model/onClose.d.ts +0 -3
  220. package/mobile/lib/model/onClose.js +0 -2
  221. package/mobile/lib/model/onClose.js.map +0 -1
  222. package/mobile/src/model/onClose.ts +0 -3
  223. package/src/model/onClose.ts +0 -3
@@ -0,0 +1,63 @@
1
+ import { useCallback, useState } from '@redneckz/uni-jsx/lib/hooks';
2
+ import { useBool } from '@redneckz/uni-jsx/lib/hooks/useBool';
3
+ import { LeadServiceAPI, type LeadRequest } from '../../api/LeadServiceAPI';
4
+ import { getTimer } from '../../utils/getTimer';
5
+ const API = LeadServiceAPI();
6
+
7
+ type useVerifyPhoneDialogSubmitProps = {
8
+ values: string[];
9
+ formatData: LeadRequest;
10
+ reqId: string;
11
+ onSuccess?: (smsCode?: string) => void;
12
+ };
13
+
14
+ export const useVerifyPhoneDialogSubmit = ({
15
+ values,
16
+ onSuccess,
17
+ formatData,
18
+ reqId,
19
+ }: useVerifyPhoneDialogSubmitProps) => {
20
+ const timer = Math.max(getTimer(Date.now()), 0);
21
+
22
+ const [errorText, setErrorText] = useState('');
23
+ const [isLoading, { setTrue: startLoading, setFalse: endLoading }] = useBool(false);
24
+ const [timeNextReq, setTimeNextReq] = useState(timer);
25
+
26
+ const resetError = useCallback(() => setErrorText(''), []);
27
+
28
+ const isSubmitButtonDisabled = !values.every(Boolean);
29
+
30
+ const handleSubmit = useCallback(async () => {
31
+ try {
32
+ startLoading();
33
+ const response = await API.checkCode({
34
+ code: values.join(''),
35
+ body: formatData,
36
+ reqId,
37
+ });
38
+ if (response?.errorDesc) {
39
+ setErrorText(response?.errorDesc);
40
+
41
+ return;
42
+ }
43
+ setTimeNextReq(0);
44
+ resetError();
45
+ onSuccess?.(values.join(''));
46
+ } catch {
47
+ setErrorText('Неверный код');
48
+ } finally {
49
+ endLoading();
50
+ }
51
+ }, [values]);
52
+
53
+ return {
54
+ handleSubmit,
55
+ hasError: Boolean(errorText),
56
+ errorText,
57
+ isLoading,
58
+ timeNextReq,
59
+ isSubmitButtonDisabled,
60
+ setTimeNextReq,
61
+ setErrorText,
62
+ };
63
+ };
@@ -1,6 +1,6 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
2
  import type { JSONRefObject } from '../../data/JSONRefObject';
3
- import { type OnCloseProps } from '../../model/onClose';
3
+ import { type OnCloseProps } from '../../model/OnCloseProps';
4
4
  import { TableInnerButton } from '../../ui-kit/InnerTable/InnerTableButton';
5
5
  import {
6
6
  type TableFetchData,
@@ -1,14 +1,10 @@
1
- import { LeadServiceAPI, type LeadRequest } from '../../api/LeadServiceAPI';
2
1
  import { fetchRetailJSON } from './doRequest';
3
- const API = LeadServiceAPI();
4
2
 
5
3
  export type CheckCodeBody = {
6
4
  smsText: string;
7
5
  smsCodesSetName: {
8
6
  key: 'AUTHENTICATION' | 'SEND_TASK';
9
7
  };
10
- reqId?: string;
11
- body?: LeadRequest;
12
8
  };
13
9
 
14
10
  export type CheckCodeResponse = {
@@ -17,32 +13,8 @@ export type CheckCodeResponse = {
17
13
  refresh_token: string;
18
14
  };
19
15
 
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
- };
16
+ export const checkCode = async (body: CheckCodeBody) =>
17
+ fetchRetailJSON<CheckCodeResponse>('/sms/checkCode', 'POST', body).then(saveToken);
46
18
 
47
19
  export const saveToken = (data: CheckCodeResponse | null) => {
48
20
  if (data?.access_token && data?.refresh_token) {
@@ -50,20 +22,3 @@ export const saveToken = (data: CheckCodeResponse | null) => {
50
22
  globalThis.sessionStorage.setItem('refreshToken', data.refresh_token);
51
23
  }
52
24
  };
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,6 +1,4 @@
1
- import { LeadServiceAPI } from '../../api/LeadServiceAPI';
2
1
  import { doRequest } from './doRequest';
3
- const API = LeadServiceAPI();
4
2
 
5
3
  export type SendCodeBody = {
6
4
  phoneNumber: string;
@@ -9,13 +7,7 @@ export type SendCodeBody = {
9
7
  };
10
8
  };
11
9
 
12
- export const sendCode = (body: SendCodeBody, isRetail: boolean) => {
13
- return isRetail ? fetchRetail(body) : fetchMain(body);
14
- };
15
-
16
- const fetchRetail = (body: SendCodeBody) =>
10
+ export const sendCode = (body: SendCodeBody) =>
17
11
  doRequest('/sms/sendCode', 'POST', body)
18
12
  .then((res) => res.text())
19
13
  .then((text) => text === 'OK');
20
-
21
- const fetchMain = (body: SendCodeBody) => API.sendCode({ phone: body.phoneNumber });
@@ -1,23 +1,15 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
2
  import { useCallback, useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
3
3
  import { useSessionStore } from '@redneckz/uni-jsx/lib/Store/useSessionStore';
4
- import { type LeadRequest } from '../../../api/LeadServiceAPI';
5
- import { Headline } from '../../../components/Headline/Headline';
6
4
  import type { OnCloseProps } from '../../../model/OnCloseProps';
7
- import { Button } from '../../../ui-kit/Button/Button';
8
- import { ButtonTitle } from '../../../ui-kit/Button/ButtonTitle';
9
- import { Dialog } from '../../../ui-kit/DialogManager/Dialog';
10
5
  import { useDialog } from '../../../ui-kit/DialogManager/useDialog';
11
- import { Loader } from '../../../ui-kit/Loader/Loader';
12
6
  import { RichText } from '../../../ui-kit/RichText/RichText';
13
- import { Timer } from '../../../ui-kit/TimerCircle/Timer';
14
7
  import { useCountDownTimer } from '../../../ui-kit/TimerCircle/useCountDownTimer';
8
+ import { VerifyPhoneDialogLayout } from '../../../ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout';
15
9
  import { formatPhone } from '../../../utils/formatPhone';
16
10
  import { noop } from '../../../utils/noop';
17
11
  import { sendCode } from '../../api/sendCode';
18
12
  import { CaptchaDialog } from '../CaptchaDialog/CaptchaDialog';
19
- import { InputCode } from './InputCode';
20
- import { SubmitButton } from './SubmitButton';
21
13
  import {
22
14
  TIME_TO_RESEND,
23
15
  useVerifyPhoneDialogSubmit,
@@ -31,26 +23,12 @@ export interface VerifyPhoneDialogProps extends OnCloseProps {
31
23
  withDescription?: boolean;
32
24
  consents?: string[];
33
25
  onSuccess?: (smsCode?: string) => void;
34
- formatData?: LeadRequest;
35
- reqId?: string;
36
- isRetail?: boolean;
37
26
  }
38
27
 
39
28
  export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
40
- // eslint-disable-next-line max-lines-per-function
41
- ({
42
- phone,
43
- withDescription = true,
44
- consents,
45
- onSuccess = noop,
46
- onClose = noop,
47
- formatData,
48
- reqId,
49
- isRetail = true,
50
- }) => {
51
- const [values, setValues] = useState(Array(CODE_LENGTH).fill(''));
29
+ ({ phone, withDescription = true, consents, onSuccess = noop, onClose = noop }) => {
30
+ const [values, setValues] = useState<string[]>(Array(CODE_LENGTH).fill('') as string[]);
52
31
  const sessionStore = useSessionStore<SmsCodeStore>();
53
- const [requestId, setRequestId] = useState(reqId);
54
32
 
55
33
  const {
56
34
  handleSubmit,
@@ -64,9 +42,6 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
64
42
  } = useVerifyPhoneDialogSubmit({
65
43
  values,
66
44
  onSuccess,
67
- formatData,
68
- reqId: requestId,
69
- isRetail,
70
45
  });
71
46
 
72
47
  const captchaDialog = useDialog(CaptchaDialog);
@@ -74,13 +49,10 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
74
49
  const restartTimer = useCountDownTimer({ seconds: timeNextReq, onTick: setTimeNextReq });
75
50
 
76
51
  const handleSendCode = useCallback(async () => {
77
- const response = await sendCode(
78
- {
79
- phoneNumber,
80
- smsCodesSetName: { key: 'AUTHENTICATION' },
81
- },
82
- isRetail,
83
- );
52
+ const response = await sendCode({
53
+ phoneNumber,
54
+ smsCodesSetName: { key: 'AUTHENTICATION' },
55
+ });
84
56
 
85
57
  if (response) {
86
58
  setTimeNextReq(TIME_TO_RESEND);
@@ -90,52 +62,37 @@ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
90
62
  sendTime: Date.now(),
91
63
  attempts: 0,
92
64
  };
93
-
94
- if (!isRetail) {
95
- setRequestId(String(response));
96
- }
97
65
  } else {
98
66
  captchaDialog.open({ phoneNumber, sendCode: handleSendCode });
99
67
  }
100
68
  }, [phoneNumber, restartTimer, onClose]);
101
69
 
102
70
  useEffect(() => {
103
- if (!sessionStore.smsCode?.sendTime && isRetail) {
71
+ if (!sessionStore.smsCode?.sendTime) {
104
72
  handleSendCode();
105
73
  }
106
74
  }, []);
107
75
 
108
76
  return (
109
- <Dialog maxWidth="lg" onClose={onClose}>
110
- <div className="flex flex-col gap-xl items-center rounded-md">
111
- {renderHeadline(phone)}
112
- <InputCode
113
- values={values}
114
- setValues={setValues}
115
- errorText={errorText}
116
- hasError={hasError}
117
- />
118
- {renderText(timeNextReq, handleSendCode)}
119
- {renderDescription(consents, withDescription)}
120
- {renderNextButton(isSubmitButtonDisabled, handleSubmit)}
121
- {isLoading ? <Loader blur={false} /> : null}
122
- </div>
123
- </Dialog>
77
+ <VerifyPhoneDialogLayout
78
+ isSubmitButtonDisabled={isSubmitButtonDisabled}
79
+ onSubmit={handleSubmit}
80
+ onSendCode={handleSendCode}
81
+ timeNextReq={timeNextReq}
82
+ values={values}
83
+ onChange={setValues}
84
+ phone={phone}
85
+ isLoading={isLoading}
86
+ errorText={errorText}
87
+ hasError={hasError}
88
+ onClose={onClose}
89
+ >
90
+ {renderDescription(consents, withDescription)}
91
+ </VerifyPhoneDialogLayout>
124
92
  );
125
93
  },
126
94
  );
127
95
 
128
- const renderHeadline = (phone: string) => (
129
- <Headline
130
- className="w-full"
131
- title="Подтвердите номер телефона"
132
- description={`Мы отправили код на ${phone}`}
133
- headlineVersion="XS"
134
- isEmbedded={true}
135
- as="h6"
136
- />
137
- );
138
-
139
96
  const renderDescription = (consents?: string[], isRender = false) =>
140
97
  isRender ? (
141
98
  <RichText itemSize="list-s">
@@ -147,19 +104,3 @@ const renderDescription = (consents?: string[], isRender = false) =>
147
104
  </ul>
148
105
  </RichText>
149
106
  ) : null;
150
-
151
- const renderNextButton = (disabled: boolean, onClick: () => void) => (
152
- <SubmitButton text="Далее" disabled={disabled} onClick={onClick} />
153
- );
154
-
155
- const renderText = (timeNextReq: number, handleSendCode: () => void) =>
156
- timeNextReq ? (
157
- <div className="flex flex-row text-l font-light text-base">
158
- Получить новый код можно через
159
- <Timer className="pl-2xs" seconds={timeNextReq} />
160
- </div>
161
- ) : (
162
- <Button embedded onClick={handleSendCode}>
163
- <ButtonTitle>Получить новый код</ButtonTitle>
164
- </Button>
165
- );
@@ -1,18 +1,14 @@
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
+ import { getTimer } from '../../../utils/getTimer';
5
5
  import { checkCode } from '../../api/checkCode';
6
6
 
7
7
  export const TIME_TO_RESEND = 180;
8
- export const TIME_TO_MAIN_EXPIRE = 600;
9
8
 
10
9
  type useVerifyPhoneDialogSubmitProps = {
11
10
  values: string[];
12
11
  onSuccess?: (smsCode?: string) => void;
13
- formatData?: LeadRequest;
14
- reqId?: string;
15
- isRetail?: boolean;
16
12
  };
17
13
 
18
14
  export interface SmsCodeStore {
@@ -25,9 +21,6 @@ export interface SmsCodeStore {
25
21
  export const useVerifyPhoneDialogSubmit = ({
26
22
  values,
27
23
  onSuccess,
28
- formatData,
29
- reqId,
30
- isRetail = true,
31
24
  }: useVerifyPhoneDialogSubmitProps) => {
32
25
  const sessionStore = useSessionStore<SmsCodeStore>();
33
26
  const attempts = sessionStore.smsCode?.attempts || 0;
@@ -49,19 +42,14 @@ export const useVerifyPhoneDialogSubmit = ({
49
42
  attempts: attempts + 1,
50
43
  };
51
44
  startLoading();
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
- );
45
+ await checkCode({
46
+ smsText: values.join(''),
47
+ smsCodesSetName: { key: 'AUTHENTICATION' },
48
+ });
61
49
  setTimeNextReq(0);
62
50
  resetError();
63
51
  sessionStore.smsCode = null;
64
- await onSuccess?.(values.join(''));
52
+ onSuccess?.(values.join(''));
65
53
  } catch {
66
54
  setErrorText(attempts > 1 ? 'Исчерпан лимит ввода смс-кода' : 'Неверный код');
67
55
  } finally {
@@ -70,7 +58,7 @@ export const useVerifyPhoneDialogSubmit = ({
70
58
  }, [values, attempts]);
71
59
 
72
60
  useEffect(() => {
73
- if (isTimeExpired && isRetail) {
61
+ if (isTimeExpired) {
74
62
  setErrorText('Код просрочен');
75
63
  } else if (attempts > 2) {
76
64
  setErrorText('Исчерпан лимит ввода смс-кода');
@@ -88,5 +76,3 @@ export const useVerifyPhoneDialogSubmit = ({
88
76
  setErrorText,
89
77
  };
90
78
  };
91
-
92
- const getTimer = (sendTime: number) => TIME_TO_RESEND - Math.floor((Date.now() - sendTime) / 1000);
@@ -13,21 +13,15 @@ export const mockLocalStorage = async () => {
13
13
  globalThis.localStorage.getItem('profileId') ??
14
14
  (await createUserProfile({ profile: { phone: PHONE } }));
15
15
 
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
- );
16
+ await sendCode({
17
+ phoneNumber: PHONE,
18
+ smsCodesSetName: { key: 'AUTHENTICATION' },
19
+ });
20
+
21
+ await checkCode({
22
+ smsCodesSetName: { key: 'AUTHENTICATION' },
23
+ smsText: '1234',
24
+ });
31
25
 
32
26
  const task = {
33
27
  taskId: globalThis.localStorage.getItem('taskId'),
@@ -94,7 +94,7 @@ export const BaseTile = JSX<BaseTileProps>(
94
94
 
95
95
  const renderMiddleContent = (insetTitle: VNode, children: VNode) =>
96
96
  insetTitle || children ? (
97
- <div className="grow space-y-lg w-fit">
97
+ <div className="space-y-lg">
98
98
  {insetTitle}
99
99
  {children}
100
100
  </div>
@@ -1,6 +1,6 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
2
  import { Headline } from '../../components/Headline/Headline';
3
- import { type OnCloseProps } from '../../model/onClose';
3
+ import { type OnCloseProps } from '../../model/OnCloseProps';
4
4
  import { Button } from '../Button/Button';
5
5
  import { Dialog } from '../DialogManager/Dialog';
6
6
  import { Img } from '../Img/Img';
@@ -0,0 +1,80 @@
1
+ import { JSX } from '@redneckz/uni-jsx';
2
+ import { Headline } from '../../components/Headline/Headline';
3
+ import { type OnCloseProps } from '../../model/OnCloseProps';
4
+ import { type VNode } from '../../model/VNode';
5
+ import { InputCode } from '../../retail/components/VerifyPhoneDialog/InputCode';
6
+ import { SubmitButton } from '../../retail/components/VerifyPhoneDialog/SubmitButton';
7
+ import { Button } from '../Button/Button';
8
+ import { ButtonTitle } from '../Button/ButtonTitle';
9
+ import { Dialog } from '../DialogManager/Dialog';
10
+ import { Loader } from '../Loader/Loader';
11
+ import { Timer } from '../TimerCircle/Timer';
12
+
13
+ export interface VerifyPhoneDialogProps extends OnCloseProps {
14
+ isSubmitButtonDisabled: boolean;
15
+ onSubmit: () => Promise<void>;
16
+ onSendCode: () => Promise<void>;
17
+ timeNextReq: number;
18
+ values: string[];
19
+ onChange: (values: string[]) => void;
20
+ phone: string;
21
+ children?: VNode;
22
+ isLoading?: boolean;
23
+ errorText?: string;
24
+ hasError?: boolean;
25
+ }
26
+
27
+ export const VerifyPhoneDialogLayout = JSX<VerifyPhoneDialogProps>(
28
+ ({
29
+ children,
30
+ isLoading,
31
+ isSubmitButtonDisabled,
32
+ timeNextReq,
33
+ onSubmit,
34
+ onSendCode,
35
+ values,
36
+ onChange,
37
+ errorText,
38
+ hasError,
39
+ phone,
40
+ onClose,
41
+ }) => (
42
+ <Dialog maxWidth="lg" onClose={onClose}>
43
+ <div className="flex flex-col gap-xl items-center rounded-md">
44
+ {renderHeadline(phone)}
45
+ <InputCode values={values} setValues={onChange} errorText={errorText} hasError={hasError} />
46
+ {renderText(timeNextReq, onSendCode)}
47
+ {children}
48
+ {renderNextButton(isSubmitButtonDisabled, onSubmit)}
49
+ {isLoading ? <Loader blur={false} /> : null}
50
+ </div>
51
+ </Dialog>
52
+ ),
53
+ );
54
+
55
+ const renderHeadline = (phone: string) => (
56
+ <Headline
57
+ className="w-full"
58
+ title="Подтвердите номер телефона"
59
+ description={`Мы отправили код на ${phone}`}
60
+ headlineVersion="XS"
61
+ isEmbedded={true}
62
+ as="h6"
63
+ />
64
+ );
65
+
66
+ const renderNextButton = (disabled: boolean, onClick: () => void) => (
67
+ <SubmitButton text="Далее" disabled={disabled} onClick={onClick} />
68
+ );
69
+
70
+ const renderText = (timeNextReq: number, handleSendCode: () => void) =>
71
+ timeNextReq ? (
72
+ <div className="flex flex-row text-l font-light text-base gap-2xs">
73
+ <span> Получить новый код можно через</span>
74
+ <Timer seconds={timeNextReq} />
75
+ </div>
76
+ ) : (
77
+ <Button embedded onClick={handleSendCode}>
78
+ <ButtonTitle>Получить новый код</ButtonTitle>
79
+ </Button>
80
+ );
@@ -0,0 +1,4 @@
1
+ export const TIME_TO_RESEND = 180;
2
+
3
+ export const getTimer = (sendTime: number) =>
4
+ TIME_TO_RESEND - Math.floor((Date.now() - sendTime) / 1000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redneckz/wildless-cms-uni-blocks",
3
- "version": "0.14.912",
3
+ "version": "0.14.914",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "ЦК",
@@ -1,6 +1,5 @@
1
1
  import { type JSONRecord, type JSONScalar } from '@redneckz/json-op';
2
2
  import { type Router } from '../external/useRouter';
3
- import { type MainBody } from '../retail/api/checkCode';
4
3
  import { API_BASE_URI } from './apiBaseUrl';
5
4
  import { getPhoneBody, getSubmitBody } from './getSubmitBody';
6
5
 
@@ -18,7 +17,18 @@ export type LeadRequest = Record<string, JSONRecord | JSONScalar | null> & {
18
17
  partnerName?: string;
19
18
  };
20
19
 
21
- export type CheckCodeProps = MainBody;
20
+ export type CheckCodeProps = {
21
+ reqId: string;
22
+ code: string;
23
+ body: LeadRequest;
24
+ };
25
+
26
+ type CheckCodeResponse = {
27
+ errorCode?: string;
28
+ errorDesc?: string;
29
+ reqId?: string;
30
+ status?: string;
31
+ } | null;
22
32
 
23
33
  type VerifiedLeadRequest = {
24
34
  requestId: string;
@@ -73,7 +83,7 @@ export function LeadServiceAPI() {
73
83
  }
74
84
  }
75
85
 
76
- async function checkCode({ reqId, code, body }: CheckCodeProps) {
86
+ async function checkCode({ reqId, code, body }: CheckCodeProps): Promise<CheckCodeResponse> {
77
87
  const submitBody = {
78
88
  requestId: reqId,
79
89
  confimationCode: code,
@@ -83,10 +93,6 @@ export function LeadServiceAPI() {
83
93
  try {
84
94
  const response = await LeadServiceFetch(`${API_BASE_URI}/confirmCorporateLead`, submitBody);
85
95
 
86
- if (!response?.ok) {
87
- return null;
88
- }
89
-
90
96
  return await response.json();
91
97
  } catch (e) {
92
98
  return null;
@@ -6,7 +6,6 @@ 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';
10
9
  import { ApplicationFormLayout } from '../../ui-kit/ApplicationFormLayout/ApplicationFormLayout';
11
10
  import { useDialog } from '../../ui-kit/DialogManager/useDialog';
12
11
  import { getConsentDataProcessing } from '../../ui-kit/FormField/getConsentDataProcessing';
@@ -28,6 +27,7 @@ import { getFormatData } from './getFormatData';
28
27
  import { getInitialFormState, type FormState } from './getInitialFormState';
29
28
  import { renderAgreementSubmit } from './renderAgreementSubmit';
30
29
  import { renderContacts } from './renderContacts';
30
+ import { VerifyPhoneDialog } from './VerifyPhoneDialog';
31
31
 
32
32
  export interface ApplicationFormProps extends ApplicationFormContent, UniBlockProps {}
33
33
 
@@ -84,10 +84,8 @@ export const ApplicationForm = UniBlock<ApplicationFormProps>(
84
84
 
85
85
  verifyPhoneDialog.open({
86
86
  phone,
87
- withDescription: false,
88
87
  formatData,
89
88
  reqId: String(response),
90
- isRetail: false,
91
89
  onSuccess: () => {
92
90
  verifyPhoneDialog.close();
93
91
  responseTypeDialog.open({ ok: true, typeForm });