@redneckz/wildless-cms-uni-blocks 0.14.911 → 0.14.913

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 (213) hide show
  1. package/bundle/api/LeadServiceAPI.d.ts +12 -3
  2. package/bundle/bundle.umd.js +716 -684
  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/ExchangeRateTile/ExchangeCurrencyCalculator.js +2 -2
  26. package/dist/components/ExchangeRateTile/ExchangeCurrencyCalculator.js.map +1 -1
  27. package/dist/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  28. package/dist/retail/api/checkCode.d.ts +1 -9
  29. package/dist/retail/api/checkCode.js +1 -22
  30. package/dist/retail/api/checkCode.js.map +1 -1
  31. package/dist/retail/api/sendCode.d.ts +1 -1
  32. package/dist/retail/api/sendCode.js +2 -8
  33. package/dist/retail/api/sendCode.js.map +1 -1
  34. package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  35. package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +5 -24
  36. package/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
  37. package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  38. package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +7 -10
  39. package/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
  40. package/dist/retail/utils/mockLocalStorage.js +2 -2
  41. package/dist/retail/utils/mockLocalStorage.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/ExchangeRateTile/ExchangeCurrencyCalculator.js +2 -2
  62. package/lib/components/ExchangeRateTile/ExchangeCurrencyCalculator.js.map +1 -1
  63. package/lib/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  64. package/lib/retail/api/checkCode.d.ts +1 -9
  65. package/lib/retail/api/checkCode.js +1 -22
  66. package/lib/retail/api/checkCode.js.map +1 -1
  67. package/lib/retail/api/sendCode.d.ts +1 -1
  68. package/lib/retail/api/sendCode.js +1 -7
  69. package/lib/retail/api/sendCode.js.map +1 -1
  70. package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  71. package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +5 -24
  72. package/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
  73. package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  74. package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +5 -8
  75. package/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
  76. package/lib/retail/utils/mockLocalStorage.js +2 -2
  77. package/lib/retail/utils/mockLocalStorage.js.map +1 -1
  78. package/lib/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  79. package/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  80. package/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js +15 -0
  81. package/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js.map +1 -0
  82. package/lib/utils/getTimer.d.ts +2 -0
  83. package/lib/utils/getTimer.js +3 -0
  84. package/lib/utils/getTimer.js.map +1 -0
  85. package/mobile/bundle/api/LeadServiceAPI.d.ts +12 -3
  86. package/mobile/bundle/bundle.umd.js +716 -684
  87. package/mobile/bundle/bundle.umd.min.js +1 -1
  88. package/mobile/bundle/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  89. package/mobile/bundle/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  90. package/mobile/bundle/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  91. package/mobile/bundle/retail/api/checkCode.d.ts +1 -9
  92. package/mobile/bundle/retail/api/sendCode.d.ts +1 -1
  93. package/mobile/bundle/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  94. package/mobile/bundle/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  95. package/mobile/bundle/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  96. package/mobile/bundle/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  97. package/mobile/bundle/utils/getTimer.d.ts +2 -0
  98. package/mobile/dist/api/LeadServiceAPI.d.ts +12 -3
  99. package/mobile/dist/api/LeadServiceAPI.js +0 -3
  100. package/mobile/dist/api/LeadServiceAPI.js.map +1 -1
  101. package/mobile/dist/components/ApplicationForm/ApplicationForm.js +1 -3
  102. package/mobile/dist/components/ApplicationForm/ApplicationForm.js.map +1 -1
  103. package/mobile/dist/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  104. package/mobile/dist/components/ApplicationForm/VerifyPhoneDialog.js +37 -0
  105. package/mobile/dist/components/ApplicationForm/VerifyPhoneDialog.js.map +1 -0
  106. package/mobile/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  107. package/mobile/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.js +50 -0
  108. package/mobile/dist/components/ApplicationForm/useVerifyPhoneDialogSubmit.js.map +1 -0
  109. package/mobile/dist/components/ExchangeRateTile/ExchangeCurrencyCalculator.js +2 -2
  110. package/mobile/dist/components/ExchangeRateTile/ExchangeCurrencyCalculator.js.map +1 -1
  111. package/mobile/dist/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  112. package/mobile/dist/retail/api/checkCode.d.ts +1 -9
  113. package/mobile/dist/retail/api/checkCode.js +1 -22
  114. package/mobile/dist/retail/api/checkCode.js.map +1 -1
  115. package/mobile/dist/retail/api/sendCode.d.ts +1 -1
  116. package/mobile/dist/retail/api/sendCode.js +2 -8
  117. package/mobile/dist/retail/api/sendCode.js.map +1 -1
  118. package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  119. package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +5 -24
  120. package/mobile/dist/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
  121. package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  122. package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +7 -10
  123. package/mobile/dist/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
  124. package/mobile/dist/retail/utils/mockLocalStorage.js +2 -2
  125. package/mobile/dist/retail/utils/mockLocalStorage.js.map +1 -1
  126. package/mobile/dist/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  127. package/mobile/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  128. package/mobile/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js +17 -0
  129. package/mobile/dist/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js.map +1 -0
  130. package/mobile/dist/utils/getTimer.d.ts +2 -0
  131. package/mobile/dist/utils/getTimer.js +6 -0
  132. package/mobile/dist/utils/getTimer.js.map +1 -0
  133. package/mobile/lib/api/LeadServiceAPI.d.ts +12 -3
  134. package/mobile/lib/api/LeadServiceAPI.js +0 -3
  135. package/mobile/lib/api/LeadServiceAPI.js.map +1 -1
  136. package/mobile/lib/common.css +1 -1
  137. package/mobile/lib/components/ApplicationForm/ApplicationForm.js +1 -3
  138. package/mobile/lib/components/ApplicationForm/ApplicationForm.js.map +1 -1
  139. package/mobile/lib/components/ApplicationForm/VerifyPhoneDialog.d.ts +10 -0
  140. package/mobile/lib/components/ApplicationForm/VerifyPhoneDialog.js +35 -0
  141. package/mobile/lib/components/ApplicationForm/VerifyPhoneDialog.js.map +1 -0
  142. package/mobile/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.d.ts +18 -0
  143. package/mobile/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.js +47 -0
  144. package/mobile/lib/components/ApplicationForm/useVerifyPhoneDialogSubmit.js.map +1 -0
  145. package/mobile/lib/components/ExchangeRateTile/ExchangeCurrencyCalculator.js +2 -2
  146. package/mobile/lib/components/ExchangeRateTile/ExchangeCurrencyCalculator.js.map +1 -1
  147. package/mobile/lib/components/TariffsTable/TariffsTableCell.d.ts +1 -1
  148. package/mobile/lib/retail/api/checkCode.d.ts +1 -9
  149. package/mobile/lib/retail/api/checkCode.js +1 -22
  150. package/mobile/lib/retail/api/checkCode.js.map +1 -1
  151. package/mobile/lib/retail/api/sendCode.d.ts +1 -1
  152. package/mobile/lib/retail/api/sendCode.js +1 -7
  153. package/mobile/lib/retail/api/sendCode.js.map +1 -1
  154. package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.d.ts +0 -4
  155. package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js +5 -24
  156. package/mobile/lib/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.js.map +1 -1
  157. package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.d.ts +1 -6
  158. package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js +5 -8
  159. package/mobile/lib/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.js.map +1 -1
  160. package/mobile/lib/retail/utils/mockLocalStorage.js +2 -2
  161. package/mobile/lib/retail/utils/mockLocalStorage.js.map +1 -1
  162. package/mobile/lib/ui-kit/ResponseTypeDialog/ResponseTypeDialog.d.ts +1 -1
  163. package/mobile/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.d.ts +16 -0
  164. package/mobile/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js +15 -0
  165. package/mobile/lib/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.js.map +1 -0
  166. package/mobile/lib/utils/getTimer.d.ts +2 -0
  167. package/mobile/lib/utils/getTimer.js +3 -0
  168. package/mobile/lib/utils/getTimer.js.map +1 -0
  169. package/mobile/src/api/LeadServiceAPI.ts +13 -7
  170. package/mobile/src/components/ApplicationForm/ApplicationForm.tsx +1 -3
  171. package/mobile/src/components/ApplicationForm/VerifyPhoneDialog.tsx +73 -0
  172. package/mobile/src/components/ApplicationForm/useVerifyPhoneDialogSubmit.tsx +63 -0
  173. package/mobile/src/components/ExchangeRateTile/ExchangeCurrencyCalculator.tsx +2 -2
  174. package/mobile/src/components/TariffsTable/TariffsTableCell.tsx +1 -1
  175. package/mobile/src/retail/api/checkCode.ts +2 -47
  176. package/mobile/src/retail/api/sendCode.ts +1 -9
  177. package/mobile/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +23 -82
  178. package/mobile/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +7 -21
  179. package/mobile/src/retail/utils/mockLocalStorage.ts +9 -15
  180. package/mobile/src/ui-kit/ResponseTypeDialog/ResponseTypeDialog.tsx +1 -1
  181. package/mobile/src/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.tsx +80 -0
  182. package/mobile/src/utils/getTimer.ts +4 -0
  183. package/package.json +1 -1
  184. package/src/api/LeadServiceAPI.ts +13 -7
  185. package/src/components/ApplicationForm/ApplicationForm.tsx +1 -3
  186. package/src/components/ApplicationForm/VerifyPhoneDialog.tsx +73 -0
  187. package/src/components/ApplicationForm/useVerifyPhoneDialogSubmit.tsx +63 -0
  188. package/src/components/ExchangeRateTile/ExchangeCurrencyCalculator.tsx +2 -2
  189. package/src/components/TariffsTable/TariffsTableCell.tsx +1 -1
  190. package/src/retail/api/checkCode.ts +2 -47
  191. package/src/retail/api/sendCode.ts +1 -9
  192. package/src/retail/components/VerifyPhoneDialog/VerifyPhoneDialog.tsx +23 -82
  193. package/src/retail/components/VerifyPhoneDialog/useVerifyPhoneDialogSubmit.tsx +7 -21
  194. package/src/retail/utils/mockLocalStorage.ts +9 -15
  195. package/src/ui-kit/ResponseTypeDialog/ResponseTypeDialog.tsx +1 -1
  196. package/src/ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout.tsx +80 -0
  197. package/src/utils/getTimer.ts +4 -0
  198. package/bundle/model/onClose.d.ts +0 -3
  199. package/dist/model/onClose.d.ts +0 -3
  200. package/dist/model/onClose.js +0 -2
  201. package/dist/model/onClose.js.map +0 -1
  202. package/lib/model/onClose.d.ts +0 -3
  203. package/lib/model/onClose.js +0 -2
  204. package/lib/model/onClose.js.map +0 -1
  205. package/mobile/bundle/model/onClose.d.ts +0 -3
  206. package/mobile/dist/model/onClose.d.ts +0 -3
  207. package/mobile/dist/model/onClose.js +0 -2
  208. package/mobile/dist/model/onClose.js.map +0 -1
  209. package/mobile/lib/model/onClose.d.ts +0 -3
  210. package/mobile/lib/model/onClose.js +0 -2
  211. package/mobile/lib/model/onClose.js.map +0 -1
  212. package/mobile/src/model/onClose.ts +0 -3
  213. package/src/model/onClose.ts +0 -3
@@ -0,0 +1,73 @@
1
+ import { JSX } from '@redneckz/uni-jsx';
2
+ import { useCallback, useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { LeadServiceAPI, type LeadRequest } from '../../api/LeadServiceAPI';
4
+ import type { OnCloseProps } from '../../model/OnCloseProps';
5
+ import { useCountDownTimer } from '../../ui-kit/TimerCircle/useCountDownTimer';
6
+ import { VerifyPhoneDialogLayout } from '../../ui-kit/VerifyPhoneDialogLayout/VerfiyPhoneDialogLayout';
7
+ import { formatPhone } from '../../utils/formatPhone';
8
+ import { noop } from '../../utils/noop';
9
+ import { useVerifyPhoneDialogSubmit } from './useVerifyPhoneDialogSubmit';
10
+ const API = LeadServiceAPI();
11
+
12
+ const CODE_LENGTH = 4;
13
+ export const TIME_TO_RESEND = 180;
14
+
15
+ export interface VerifyPhoneDialogProps extends OnCloseProps {
16
+ phone: string;
17
+ onSuccess?: (smsCode?: string) => void;
18
+ formatData?: LeadRequest;
19
+ reqId?: string;
20
+ }
21
+
22
+ export const VerifyPhoneDialog = JSX<VerifyPhoneDialogProps>(
23
+ ({ phone, onSuccess = noop, onClose = noop, formatData = {}, reqId }) => {
24
+ const [values, setValues] = useState<string[]>(Array(CODE_LENGTH).fill('') as string[]);
25
+ const [requestId, setRequestId] = useState(reqId);
26
+
27
+ const {
28
+ handleSubmit,
29
+ hasError,
30
+ errorText,
31
+ isLoading,
32
+ timeNextReq,
33
+ isSubmitButtonDisabled,
34
+ setTimeNextReq,
35
+ setErrorText,
36
+ } = useVerifyPhoneDialogSubmit({
37
+ values,
38
+ onSuccess,
39
+ formatData,
40
+ reqId: requestId ?? '',
41
+ });
42
+
43
+ const phoneNumber = formatPhone(phone);
44
+ const restartTimer = useCountDownTimer({ seconds: timeNextReq, onTick: setTimeNextReq });
45
+
46
+ const handleSendCode = useCallback(async () => {
47
+ const response = await API.sendCode({ phone: phoneNumber });
48
+
49
+ if (response) {
50
+ setTimeNextReq(TIME_TO_RESEND);
51
+ restartTimer(TIME_TO_RESEND);
52
+ setErrorText('');
53
+ setRequestId(String(response));
54
+ }
55
+ }, [phoneNumber, restartTimer, onClose]);
56
+
57
+ return (
58
+ <VerifyPhoneDialogLayout
59
+ isSubmitButtonDisabled={isSubmitButtonDisabled}
60
+ onSubmit={handleSubmit}
61
+ onSendCode={handleSendCode}
62
+ timeNextReq={timeNextReq}
63
+ values={values}
64
+ onChange={setValues}
65
+ phone={phone}
66
+ isLoading={isLoading}
67
+ errorText={errorText}
68
+ hasError={hasError}
69
+ onClose={onClose}
70
+ />
71
+ );
72
+ },
73
+ );
@@ -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
+ };
@@ -131,7 +131,7 @@ const handleInputSell =
131
131
  (value: string, currencyFrom: Currency, currencyTo: Currency) => {
132
132
  setCalcState({ inputSell: formatValue(value), selectBuy: currencyTo });
133
133
  const rate =
134
- currencyRatesSell.find((_) => _.currency?.currency === currencyTo)?.buyExchangeRate ||
134
+ currencyRatesSell.find((_) => _.currency?.currency === currencyTo)?.saleExchangeRate ||
135
135
  currencyRatesSell.find((_) => _.currency?.currency === currencyFrom)?.buyExchangeRate;
136
136
  if (rate) {
137
137
  setCalcState({
@@ -145,7 +145,7 @@ const handleInputBuy =
145
145
  (value: string, currencyTo: Currency, currencyFrom: Currency) => {
146
146
  setCalcState({ inputBuy: formatValue(value), selectSell: currencyFrom });
147
147
  const rate =
148
- currencyRatesBuy.find((_) => _.currency?.currency === currencyFrom)?.saleExchangeRate ||
148
+ currencyRatesBuy.find((_) => _.currency?.currency === currencyFrom)?.buyExchangeRate ||
149
149
  currencyRatesBuy.find((_) => _.currency?.currency === currencyTo)?.saleExchangeRate;
150
150
  if (rate) {
151
151
  setCalcState({
@@ -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'),
@@ -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);
@@ -1,3 +0,0 @@
1
- export interface OnCloseProps {
2
- onClose?: () => void;
3
- }
@@ -1,3 +0,0 @@
1
- export interface OnCloseProps {
2
- onClose?: () => void;
3
- }
@@ -1,2 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- //# sourceMappingURL=onClose.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"onClose.js","sourceRoot":"","sources":["../../src/model/onClose.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- export interface OnCloseProps {
2
- onClose?: () => void;
3
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=onClose.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"onClose.js","sourceRoot":"","sources":["../../src/model/onClose.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- export interface OnCloseProps {
2
- onClose?: () => void;
3
- }
@@ -1,3 +0,0 @@
1
- export interface OnCloseProps {
2
- onClose?: () => void;
3
- }
@@ -1,2 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- //# sourceMappingURL=onClose.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"onClose.js","sourceRoot":"","sources":["../../src/model/onClose.ts"],"names":[],"mappings":""}