@redneckz/wildless-cms-uni-blocks 0.14.652 → 0.14.654

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 (118) hide show
  1. package/bundle/api/RetailAPI/updateRefreshToken.d.ts +1 -0
  2. package/bundle/api/RetailAPI/updateUserTask.d.ts +7 -0
  3. package/bundle/bundle.umd.js +60 -8
  4. package/bundle/bundle.umd.min.js +1 -1
  5. package/bundle/components/ApplicationLeadForm/getInitialFormState.d.ts +3 -0
  6. package/bundle/components/CreditForm/getZeroStepData.d.ts +3 -0
  7. package/bundle/hooks/useInterval.d.ts +1 -0
  8. package/dist/api/RetailAPI/doRequest.js +1 -0
  9. package/dist/api/RetailAPI/doRequest.js.map +1 -1
  10. package/dist/api/RetailAPI/updateRefreshToken.d.ts +1 -0
  11. package/dist/api/RetailAPI/updateRefreshToken.js +31 -0
  12. package/dist/api/RetailAPI/updateRefreshToken.js.map +1 -0
  13. package/dist/api/RetailAPI/updateUserTask.d.ts +7 -0
  14. package/dist/api/RetailAPI/updateUserTask.js.map +1 -1
  15. package/dist/components/ApplicationLeadForm/getInitialFormState.d.ts +3 -0
  16. package/dist/components/ApplicationLeadForm/getInitialFormState.js.map +1 -1
  17. package/dist/components/CreditForm/CreditForm.js +9 -1
  18. package/dist/components/CreditForm/CreditForm.js.map +1 -1
  19. package/dist/components/CreditForm/CreditFormStatusTracker.js +8 -6
  20. package/dist/components/CreditForm/CreditFormStatusTracker.js.map +1 -1
  21. package/dist/components/CreditForm/getCreditFormTaskData.js +3 -0
  22. package/dist/components/CreditForm/getCreditFormTaskData.js.map +1 -1
  23. package/dist/components/CreditForm/getZeroStepData.d.ts +3 -0
  24. package/dist/components/CreditForm/getZeroStepData.js +16 -0
  25. package/dist/components/CreditForm/getZeroStepData.js.map +1 -0
  26. package/dist/hooks/useInterval.d.ts +1 -0
  27. package/dist/hooks/useInterval.js +14 -0
  28. package/dist/hooks/useInterval.js.map +1 -0
  29. package/lib/api/RetailAPI/doRequest.js +1 -0
  30. package/lib/api/RetailAPI/doRequest.js.map +1 -1
  31. package/lib/api/RetailAPI/updateRefreshToken.d.ts +1 -0
  32. package/lib/api/RetailAPI/updateRefreshToken.js +28 -0
  33. package/lib/api/RetailAPI/updateRefreshToken.js.map +1 -0
  34. package/lib/api/RetailAPI/updateUserTask.d.ts +7 -0
  35. package/lib/api/RetailAPI/updateUserTask.js.map +1 -1
  36. package/lib/components/ApplicationLeadForm/getInitialFormState.d.ts +3 -0
  37. package/lib/components/ApplicationLeadForm/getInitialFormState.js.map +1 -1
  38. package/lib/components/CreditForm/CreditForm.js +10 -2
  39. package/lib/components/CreditForm/CreditForm.js.map +1 -1
  40. package/lib/components/CreditForm/CreditFormStatusTracker.js +8 -6
  41. package/lib/components/CreditForm/CreditFormStatusTracker.js.map +1 -1
  42. package/lib/components/CreditForm/getCreditFormTaskData.js +3 -0
  43. package/lib/components/CreditForm/getCreditFormTaskData.js.map +1 -1
  44. package/lib/components/CreditForm/getZeroStepData.d.ts +3 -0
  45. package/lib/components/CreditForm/getZeroStepData.js +13 -0
  46. package/lib/components/CreditForm/getZeroStepData.js.map +1 -0
  47. package/lib/hooks/useInterval.d.ts +1 -0
  48. package/lib/hooks/useInterval.js +11 -0
  49. package/lib/hooks/useInterval.js.map +1 -0
  50. package/mobile/bundle/api/RetailAPI/updateRefreshToken.d.ts +1 -0
  51. package/mobile/bundle/api/RetailAPI/updateUserTask.d.ts +7 -0
  52. package/mobile/bundle/bundle.umd.js +60 -8
  53. package/mobile/bundle/bundle.umd.min.js +1 -1
  54. package/mobile/bundle/components/ApplicationLeadForm/getInitialFormState.d.ts +3 -0
  55. package/mobile/bundle/components/CreditForm/getZeroStepData.d.ts +3 -0
  56. package/mobile/bundle/hooks/useInterval.d.ts +1 -0
  57. package/mobile/dist/api/RetailAPI/doRequest.js +1 -0
  58. package/mobile/dist/api/RetailAPI/doRequest.js.map +1 -1
  59. package/mobile/dist/api/RetailAPI/updateRefreshToken.d.ts +1 -0
  60. package/mobile/dist/api/RetailAPI/updateRefreshToken.js +31 -0
  61. package/mobile/dist/api/RetailAPI/updateRefreshToken.js.map +1 -0
  62. package/mobile/dist/api/RetailAPI/updateUserTask.d.ts +7 -0
  63. package/mobile/dist/api/RetailAPI/updateUserTask.js.map +1 -1
  64. package/mobile/dist/components/ApplicationLeadForm/getInitialFormState.d.ts +3 -0
  65. package/mobile/dist/components/ApplicationLeadForm/getInitialFormState.js.map +1 -1
  66. package/mobile/dist/components/CreditForm/CreditForm.js +9 -1
  67. package/mobile/dist/components/CreditForm/CreditForm.js.map +1 -1
  68. package/mobile/dist/components/CreditForm/CreditFormStatusTracker.js +8 -6
  69. package/mobile/dist/components/CreditForm/CreditFormStatusTracker.js.map +1 -1
  70. package/mobile/dist/components/CreditForm/getCreditFormTaskData.js +3 -0
  71. package/mobile/dist/components/CreditForm/getCreditFormTaskData.js.map +1 -1
  72. package/mobile/dist/components/CreditForm/getZeroStepData.d.ts +3 -0
  73. package/mobile/dist/components/CreditForm/getZeroStepData.js +16 -0
  74. package/mobile/dist/components/CreditForm/getZeroStepData.js.map +1 -0
  75. package/mobile/dist/hooks/useInterval.d.ts +1 -0
  76. package/mobile/dist/hooks/useInterval.js +14 -0
  77. package/mobile/dist/hooks/useInterval.js.map +1 -0
  78. package/mobile/lib/api/RetailAPI/doRequest.js +1 -0
  79. package/mobile/lib/api/RetailAPI/doRequest.js.map +1 -1
  80. package/mobile/lib/api/RetailAPI/updateRefreshToken.d.ts +1 -0
  81. package/mobile/lib/api/RetailAPI/updateRefreshToken.js +28 -0
  82. package/mobile/lib/api/RetailAPI/updateRefreshToken.js.map +1 -0
  83. package/mobile/lib/api/RetailAPI/updateUserTask.d.ts +7 -0
  84. package/mobile/lib/api/RetailAPI/updateUserTask.js.map +1 -1
  85. package/mobile/lib/components/ApplicationLeadForm/getInitialFormState.d.ts +3 -0
  86. package/mobile/lib/components/ApplicationLeadForm/getInitialFormState.js.map +1 -1
  87. package/mobile/lib/components/CreditForm/CreditForm.js +10 -2
  88. package/mobile/lib/components/CreditForm/CreditForm.js.map +1 -1
  89. package/mobile/lib/components/CreditForm/CreditFormStatusTracker.js +8 -6
  90. package/mobile/lib/components/CreditForm/CreditFormStatusTracker.js.map +1 -1
  91. package/mobile/lib/components/CreditForm/getCreditFormTaskData.js +3 -0
  92. package/mobile/lib/components/CreditForm/getCreditFormTaskData.js.map +1 -1
  93. package/mobile/lib/components/CreditForm/getZeroStepData.d.ts +3 -0
  94. package/mobile/lib/components/CreditForm/getZeroStepData.js +13 -0
  95. package/mobile/lib/components/CreditForm/getZeroStepData.js.map +1 -0
  96. package/mobile/lib/hooks/useInterval.d.ts +1 -0
  97. package/mobile/lib/hooks/useInterval.js +11 -0
  98. package/mobile/lib/hooks/useInterval.js.map +1 -0
  99. package/mobile/src/api/RetailAPI/doRequest.ts +1 -0
  100. package/mobile/src/api/RetailAPI/updateRefreshToken.ts +42 -0
  101. package/mobile/src/api/RetailAPI/updateUserTask.ts +8 -0
  102. package/mobile/src/components/ApplicationLeadForm/getInitialFormState.tsx +3 -0
  103. package/mobile/src/components/CreditForm/CreditForm.tsx +11 -2
  104. package/mobile/src/components/CreditForm/CreditFormStatusTracker.tsx +3 -0
  105. package/mobile/src/components/CreditForm/getCreditFormTaskData.ts +3 -0
  106. package/mobile/src/components/CreditForm/getZeroStepData.ts +17 -0
  107. package/mobile/src/hooks/useInterval.ts +14 -0
  108. package/package.json +1 -1
  109. package/src/api/RetailAPI/doRequest.ts +1 -0
  110. package/src/api/RetailAPI/updateRefreshToken.ts +42 -0
  111. package/src/api/RetailAPI/updateUserTask.ts +8 -0
  112. package/src/components/ApplicationLeadForm/getInitialFormState.tsx +3 -0
  113. package/src/components/CreditForm/CreditForm.fixture.tsx +7 -0
  114. package/src/components/CreditForm/CreditForm.tsx +11 -2
  115. package/src/components/CreditForm/CreditFormStatusTracker.tsx +3 -0
  116. package/src/components/CreditForm/getCreditFormTaskData.ts +3 -0
  117. package/src/components/CreditForm/getZeroStepData.ts +17 -0
  118. package/src/hooks/useInterval.ts +14 -0
@@ -36,6 +36,11 @@ type ParticipantIncome = {
36
36
  value: number;
37
37
  };
38
38
 
39
+ export type PaymentType = {
40
+ key: 'ANNUITY' | 'DIFFERENTIAL';
41
+ value: string;
42
+ };
43
+
39
44
  export type Participant = {
40
45
  birthDate?: string;
41
46
  id: number;
@@ -100,6 +105,9 @@ export type Participant = {
100
105
  paymentSystemTypeCd?: string;
101
106
  classCard?: Option;
102
107
  codeWord?: string;
108
+ loanAmount?: number;
109
+ creditPeriod?: number;
110
+ paymentTypeCd?: PaymentType;
103
111
  };
104
112
 
105
113
  export type UpdateUserTaskBody = {
@@ -130,6 +130,9 @@ export interface FormState extends FormConsents {
130
130
  cardCategory?: { key: ''; text: '' };
131
131
  codeWord?: string;
132
132
  esiaAccountTypeCd?: Option;
133
+ moneyValue?: number;
134
+ monthsValue?: number;
135
+ isAnnuity?: boolean;
133
136
  }
134
137
 
135
138
  const initialFormState = {
@@ -1,5 +1,6 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useCallback, useMemo, useState } from '@redneckz/uni-jsx/lib/hooks';
2
+ import { useCallback, useEffect, useMemo, useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { updateRefreshToken } from '../../api/RetailAPI/updateRefreshToken';
3
4
  import { type SectionsProps } from '../../model/InputSectionsType';
4
5
  import { BlockWrapper } from '../../ui-kit/BlockWrapper';
5
6
  import { type UniBlockProps } from '../../UniBlock/UniBlockProps';
@@ -27,6 +28,8 @@ const WIZARD_TITLES = [
27
28
  export const CreditForm = JSX<CreditFormWizardProps>(({ className, ...rest }) => {
28
29
  const [step, setStep] = useState(0);
29
30
 
31
+ useEffect(updateRefreshToken, []);
32
+
30
33
  const handleNextStep = useCallback(() => {
31
34
  setStep((_) => Math.min(_ + 1, WIZARD_STEPS));
32
35
  }, []);
@@ -61,9 +64,15 @@ export const CreditForm = JSX<CreditFormWizardProps>(({ className, ...rest }) =>
61
64
  finishForm={setIsFormFinished}
62
65
  renderStep={
63
66
  isStartStep
64
- ? ({ registerSubmit }) => (
67
+ ? ({ registerSubmit, field }) => (
65
68
  <CalculatorCredit
66
69
  {...{
70
+ // TODO: Remove "as never"
71
+ defaultParams: {
72
+ sum: field('moneyValue' as never).value,
73
+ period: field('monthsValue' as never).value,
74
+ isAnnuity: field('isAnnuity' as never).value,
75
+ },
67
76
  title: 'Калькулятор кредита',
68
77
  footnote:
69
78
  'Расчёт является предварительным. Точные условия будут предоставлены в отделении Банка.',
@@ -23,6 +23,7 @@ export const CreditFormStatusTracker = JSX(() => {
23
23
  }
24
24
 
25
25
  const trackStatus = () =>
26
+ taskId &&
26
27
  getTaskStatus({ taskId }).then((res) => {
27
28
  if (res.statusCd && res.statusCd !== STATUS_TYPE.process) {
28
29
  clearInterval(pullingInterval);
@@ -31,6 +32,8 @@ export const CreditFormStatusTracker = JSX(() => {
31
32
  });
32
33
 
33
34
  const pullingInterval = setInterval(trackStatus, 30000);
35
+
36
+ return () => clearInterval(pullingInterval);
34
37
  }, []);
35
38
 
36
39
  return renderStatus(status);
@@ -4,6 +4,7 @@ import { getFirstStepData } from './getFirstStepData';
4
4
  import { getFourthStepData } from './getFourthStepData';
5
5
  import { getSecondStepData } from './getSecondStepData';
6
6
  import { getThirdStepData } from './getThirdStepData';
7
+ import { getZeroStepData } from './getZeroStepData';
7
8
 
8
9
  type getCreditFormTaskDataProps = {
9
10
  participantId: number;
@@ -48,6 +49,8 @@ export const getCreditFormTaskData = ({
48
49
 
49
50
  const getCurrentStepData = (step: number, formData: FormState): Partial<Participant> => {
50
51
  switch (step) {
52
+ case 0:
53
+ return getZeroStepData(formData);
51
54
  case 1:
52
55
  return getFirstStepData(formData);
53
56
  case 2:
@@ -0,0 +1,17 @@
1
+ import { type Participant, type PaymentType } from '../../api/RetailAPI/updateUserTask';
2
+ import { type FormState } from '../ApplicationLeadForm/getInitialFormState';
3
+
4
+ const PAYMENT_TYPE_DATA: Record<string, PaymentType> = {
5
+ annuity: { key: 'ANNUITY', value: 'Аннуитетный' },
6
+ differential: { key: 'DIFFERENTIAL', value: 'Дифференцированный ' },
7
+ };
8
+
9
+ export const getZeroStepData = (formData: FormState): Partial<Participant> => {
10
+ const { moneyValue, monthsValue, isAnnuity } = formData;
11
+
12
+ return {
13
+ loanAmount: moneyValue,
14
+ creditPeriod: monthsValue,
15
+ paymentTypeCd: PAYMENT_TYPE_DATA[isAnnuity ? 'annuity' : 'differential'],
16
+ };
17
+ };
@@ -0,0 +1,14 @@
1
+ import { useCallback, useEffect, useRef } from '@redneckz/uni-jsx/lib/hooks';
2
+
3
+ export const useInterval = (handler: (stop: () => void) => void, period: number) => {
4
+ const timer = useRef<any | null>(null);
5
+ const clearTimer = useCallback(() => timer.current && clearInterval(timer.current as number), []);
6
+
7
+ useEffect(() => {
8
+ timer.current = setInterval(() => handler(clearTimer), period);
9
+
10
+ return clearTimer;
11
+ }, [handler, period]);
12
+
13
+ return clearTimer;
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redneckz/wildless-cms-uni-blocks",
3
- "version": "0.14.652",
3
+ "version": "0.14.654",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "ЦК",
@@ -15,6 +15,7 @@ export async function doRequest<R>(
15
15
  body: body ? JSON.stringify(body) : null,
16
16
  });
17
17
 
18
+ // TODO: add error handling
18
19
  return isJSON(response) ? response.json() : response;
19
20
  }
20
21
 
@@ -0,0 +1,42 @@
1
+ import { doRequest } from './doRequest';
2
+
3
+ interface UpdateRefreshTokenBody {
4
+ refresh_token: string;
5
+ access_token: string;
6
+ }
7
+
8
+ const PORTAL_NATURAL_URL = '/';
9
+
10
+ const UPDATING_INTERVAL = 60000 * 4;
11
+
12
+ export const updateRefreshToken = () => {
13
+ const refreshToken = globalThis.sessionStorage?.getItem('refreshToken');
14
+ const accessToken = globalThis.sessionStorage?.getItem('accessToken');
15
+ const taskId = globalThis.localStorage.getItem('taskId');
16
+
17
+ if (!accessToken || !refreshToken || !taskId) {
18
+ globalThis.location.href = PORTAL_NATURAL_URL;
19
+
20
+ return () => null;
21
+ }
22
+
23
+ const timer = setInterval(async () => {
24
+ const res = await doRequest<UpdateRefreshTokenBody | Response>('/auth/refresh', 'POST', {
25
+ // eslint-disable-next-line camelcase
26
+ refresh_token: refreshToken,
27
+ // eslint-disable-next-line camelcase
28
+ access_token: accessToken,
29
+ });
30
+
31
+ if (res instanceof Response) {
32
+ globalThis.location.href = PORTAL_NATURAL_URL;
33
+
34
+ return;
35
+ }
36
+
37
+ sessionStorage.setItem('refreshToken', res.refresh_token);
38
+ sessionStorage.setItem('accessToken', res.access_token);
39
+ }, UPDATING_INTERVAL);
40
+
41
+ return () => clearInterval(timer);
42
+ };
@@ -36,6 +36,11 @@ type ParticipantIncome = {
36
36
  value: number;
37
37
  };
38
38
 
39
+ export type PaymentType = {
40
+ key: 'ANNUITY' | 'DIFFERENTIAL';
41
+ value: string;
42
+ };
43
+
39
44
  export type Participant = {
40
45
  birthDate?: string;
41
46
  id: number;
@@ -100,6 +105,9 @@ export type Participant = {
100
105
  paymentSystemTypeCd?: string;
101
106
  classCard?: Option;
102
107
  codeWord?: string;
108
+ loanAmount?: number;
109
+ creditPeriod?: number;
110
+ paymentTypeCd?: PaymentType;
103
111
  };
104
112
 
105
113
  export type UpdateUserTaskBody = {
@@ -130,6 +130,9 @@ export interface FormState extends FormConsents {
130
130
  cardCategory?: { key: ''; text: '' };
131
131
  codeWord?: string;
132
132
  esiaAccountTypeCd?: Option;
133
+ moneyValue?: number;
134
+ monthsValue?: number;
135
+ isAnnuity?: boolean;
133
136
  }
134
137
 
135
138
  const initialFormState = {
@@ -3,6 +3,13 @@ import { DialogManager } from '../../ui-kit/DialogManager/DialogManager';
3
3
  import { PopupManager } from '../../ui-kit/PopupManager/PopupManager';
4
4
  import { CreditForm } from './CreditForm';
5
5
 
6
+ const MOCK_TOKEN = 'mockKEY';
7
+ const MOCK_TASK_ID = '111111';
8
+
9
+ globalThis.sessionStorage?.setItem('refreshToken', MOCK_TOKEN);
10
+ globalThis.sessionStorage?.setItem('accessToken', MOCK_TOKEN);
11
+ globalThis.localStorage.setItem('taskId', MOCK_TASK_ID);
12
+
6
13
  export default {
7
14
  default: (
8
15
  <div>
@@ -1,5 +1,6 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useCallback, useMemo, useState } from '@redneckz/uni-jsx/lib/hooks';
2
+ import { useCallback, useEffect, useMemo, useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { updateRefreshToken } from '../../api/RetailAPI/updateRefreshToken';
3
4
  import { type SectionsProps } from '../../model/InputSectionsType';
4
5
  import { BlockWrapper } from '../../ui-kit/BlockWrapper';
5
6
  import { type UniBlockProps } from '../../UniBlock/UniBlockProps';
@@ -27,6 +28,8 @@ const WIZARD_TITLES = [
27
28
  export const CreditForm = JSX<CreditFormWizardProps>(({ className, ...rest }) => {
28
29
  const [step, setStep] = useState(0);
29
30
 
31
+ useEffect(updateRefreshToken, []);
32
+
30
33
  const handleNextStep = useCallback(() => {
31
34
  setStep((_) => Math.min(_ + 1, WIZARD_STEPS));
32
35
  }, []);
@@ -61,9 +64,15 @@ export const CreditForm = JSX<CreditFormWizardProps>(({ className, ...rest }) =>
61
64
  finishForm={setIsFormFinished}
62
65
  renderStep={
63
66
  isStartStep
64
- ? ({ registerSubmit }) => (
67
+ ? ({ registerSubmit, field }) => (
65
68
  <CalculatorCredit
66
69
  {...{
70
+ // TODO: Remove "as never"
71
+ defaultParams: {
72
+ sum: field('moneyValue' as never).value,
73
+ period: field('monthsValue' as never).value,
74
+ isAnnuity: field('isAnnuity' as never).value,
75
+ },
67
76
  title: 'Калькулятор кредита',
68
77
  footnote:
69
78
  'Расчёт является предварительным. Точные условия будут предоставлены в отделении Банка.',
@@ -23,6 +23,7 @@ export const CreditFormStatusTracker = JSX(() => {
23
23
  }
24
24
 
25
25
  const trackStatus = () =>
26
+ taskId &&
26
27
  getTaskStatus({ taskId }).then((res) => {
27
28
  if (res.statusCd && res.statusCd !== STATUS_TYPE.process) {
28
29
  clearInterval(pullingInterval);
@@ -31,6 +32,8 @@ export const CreditFormStatusTracker = JSX(() => {
31
32
  });
32
33
 
33
34
  const pullingInterval = setInterval(trackStatus, 30000);
35
+
36
+ return () => clearInterval(pullingInterval);
34
37
  }, []);
35
38
 
36
39
  return renderStatus(status);
@@ -4,6 +4,7 @@ import { getFirstStepData } from './getFirstStepData';
4
4
  import { getFourthStepData } from './getFourthStepData';
5
5
  import { getSecondStepData } from './getSecondStepData';
6
6
  import { getThirdStepData } from './getThirdStepData';
7
+ import { getZeroStepData } from './getZeroStepData';
7
8
 
8
9
  type getCreditFormTaskDataProps = {
9
10
  participantId: number;
@@ -48,6 +49,8 @@ export const getCreditFormTaskData = ({
48
49
 
49
50
  const getCurrentStepData = (step: number, formData: FormState): Partial<Participant> => {
50
51
  switch (step) {
52
+ case 0:
53
+ return getZeroStepData(formData);
51
54
  case 1:
52
55
  return getFirstStepData(formData);
53
56
  case 2:
@@ -0,0 +1,17 @@
1
+ import { type Participant, type PaymentType } from '../../api/RetailAPI/updateUserTask';
2
+ import { type FormState } from '../ApplicationLeadForm/getInitialFormState';
3
+
4
+ const PAYMENT_TYPE_DATA: Record<string, PaymentType> = {
5
+ annuity: { key: 'ANNUITY', value: 'Аннуитетный' },
6
+ differential: { key: 'DIFFERENTIAL', value: 'Дифференцированный ' },
7
+ };
8
+
9
+ export const getZeroStepData = (formData: FormState): Partial<Participant> => {
10
+ const { moneyValue, monthsValue, isAnnuity } = formData;
11
+
12
+ return {
13
+ loanAmount: moneyValue,
14
+ creditPeriod: monthsValue,
15
+ paymentTypeCd: PAYMENT_TYPE_DATA[isAnnuity ? 'annuity' : 'differential'],
16
+ };
17
+ };
@@ -0,0 +1,14 @@
1
+ import { useCallback, useEffect, useRef } from '@redneckz/uni-jsx/lib/hooks';
2
+
3
+ export const useInterval = (handler: (stop: () => void) => void, period: number) => {
4
+ const timer = useRef<any | null>(null);
5
+ const clearTimer = useCallback(() => timer.current && clearInterval(timer.current as number), []);
6
+
7
+ useEffect(() => {
8
+ timer.current = setInterval(() => handler(clearTimer), period);
9
+
10
+ return clearTimer;
11
+ }, [handler, period]);
12
+
13
+ return clearTimer;
14
+ };