@redneckz/wildless-cms-uni-blocks 0.14.231 → 0.14.233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/EventBus/defaultEventBus.d.ts +2 -2
- package/bundle/bundle.umd.js +18 -8
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
- package/bundle/hooks/useLocation.d.ts +2 -7
- package/bundle/hooks/useRegions.d.ts +1 -0
- package/bundle/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
- package/bundle/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
- package/dist/EventBus/defaultEventBus.d.ts +2 -2
- package/dist/components/Calculator/CreditCalculatorForm.js +12 -0
- package/dist/components/Calculator/CreditCalculatorForm.js.map +1 -1
- package/dist/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
- package/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
- package/dist/hooks/useLocation.d.ts +2 -7
- package/dist/hooks/useLocation.js.map +1 -1
- package/dist/hooks/useRegions.d.ts +1 -0
- package/dist/hooks/useRegions.js.map +1 -1
- package/dist/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
- package/dist/ui-kit/LinkWrapper/LinkWrapper.js +2 -2
- package/dist/ui-kit/LinkWrapper/LinkWrapper.js.map +1 -1
- package/dist/ui-kit/LocationDialog/LocationDialog.js +4 -3
- package/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
- package/dist/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
- package/dist/ui-kit/LocationDialog/renderRegion.js +4 -3
- package/dist/ui-kit/LocationDialog/renderRegion.js.map +1 -1
- package/lib/EventBus/defaultEventBus.d.ts +2 -2
- package/lib/components/Calculator/CreditCalculatorForm.js +12 -0
- package/lib/components/Calculator/CreditCalculatorForm.js.map +1 -1
- package/lib/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
- package/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
- package/lib/hooks/useLocation.d.ts +2 -7
- package/lib/hooks/useLocation.js.map +1 -1
- package/lib/hooks/useRegions.d.ts +1 -0
- package/lib/hooks/useRegions.js.map +1 -1
- package/lib/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
- package/lib/ui-kit/LinkWrapper/LinkWrapper.js +2 -2
- package/lib/ui-kit/LinkWrapper/LinkWrapper.js.map +1 -1
- package/lib/ui-kit/LocationDialog/LocationDialog.js +4 -3
- package/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
- package/lib/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
- package/lib/ui-kit/LocationDialog/renderRegion.js +4 -3
- package/lib/ui-kit/LocationDialog/renderRegion.js.map +1 -1
- package/mobile/bundle/EventBus/defaultEventBus.d.ts +2 -2
- package/mobile/bundle/bundle.umd.js +18 -8
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
- package/mobile/bundle/hooks/useLocation.d.ts +2 -7
- package/mobile/bundle/hooks/useRegions.d.ts +1 -0
- package/mobile/bundle/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
- package/mobile/bundle/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
- package/mobile/dist/EventBus/defaultEventBus.d.ts +2 -2
- package/mobile/dist/components/Calculator/CreditCalculatorForm.js +12 -0
- package/mobile/dist/components/Calculator/CreditCalculatorForm.js.map +1 -1
- package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
- package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/mobile/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
- package/mobile/dist/hooks/useLocation.d.ts +2 -7
- package/mobile/dist/hooks/useLocation.js.map +1 -1
- package/mobile/dist/hooks/useRegions.d.ts +1 -0
- package/mobile/dist/hooks/useRegions.js.map +1 -1
- package/mobile/dist/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
- package/mobile/dist/ui-kit/LinkWrapper/LinkWrapper.js +2 -2
- package/mobile/dist/ui-kit/LinkWrapper/LinkWrapper.js.map +1 -1
- package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js +4 -3
- package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
- package/mobile/dist/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
- package/mobile/dist/ui-kit/LocationDialog/renderRegion.js +4 -3
- package/mobile/dist/ui-kit/LocationDialog/renderRegion.js.map +1 -1
- package/mobile/lib/EventBus/defaultEventBus.d.ts +2 -2
- package/mobile/lib/components/Calculator/CreditCalculatorForm.js +12 -0
- package/mobile/lib/components/Calculator/CreditCalculatorForm.js.map +1 -1
- package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
- package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
- package/mobile/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
- package/mobile/lib/hooks/useLocation.d.ts +2 -7
- package/mobile/lib/hooks/useLocation.js.map +1 -1
- package/mobile/lib/hooks/useRegions.d.ts +1 -0
- package/mobile/lib/hooks/useRegions.js.map +1 -1
- package/mobile/lib/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
- package/mobile/lib/ui-kit/LinkWrapper/LinkWrapper.js +2 -2
- package/mobile/lib/ui-kit/LinkWrapper/LinkWrapper.js.map +1 -1
- package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js +4 -3
- package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
- package/mobile/lib/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
- package/mobile/lib/ui-kit/LocationDialog/renderRegion.js +4 -3
- package/mobile/lib/ui-kit/LocationDialog/renderRegion.js.map +1 -1
- package/mobile/src/EventBus/defaultEventBus.ts +2 -2
- package/mobile/src/components/Calculator/CreditCalculatorForm.tsx +23 -0
- package/mobile/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +2 -2
- package/mobile/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +3 -2
- package/mobile/src/hooks/useLocation.ts +6 -13
- package/mobile/src/hooks/useRegions.ts +1 -0
- package/mobile/src/ui-kit/LinkWrapper/LinkWrapper.tsx +3 -2
- package/mobile/src/ui-kit/LocationDialog/LocationDialog.tsx +9 -8
- package/mobile/src/ui-kit/LocationDialog/renderRegion.tsx +16 -15
- package/package.json +1 -1
- package/src/EventBus/defaultEventBus.ts +2 -2
- package/src/components/Calculator/CreditCalculatorForm.tsx +23 -0
- package/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +2 -2
- package/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +3 -2
- package/src/hooks/useLocation.ts +6 -13
- package/src/hooks/useRegions.ts +1 -0
- package/src/ui-kit/LinkWrapper/LinkWrapper.tsx +3 -2
- package/src/ui-kit/LocationDialog/LocationDialog.tsx +9 -8
- package/src/ui-kit/LocationDialog/renderRegion.tsx +16 -15
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/* eslint-disable max-lines, max-lines-per-function */
|
|
2
2
|
import { JSX } from '@redneckz/uni-jsx';
|
|
3
|
+
import { useEffect } from '@redneckz/uni-jsx/lib/hooks';
|
|
3
4
|
import { type JSONRefObject } from '../../data/JSONRefObject';
|
|
4
5
|
import { useForm, type FormFieldRegisterer } from '../../hooks/useForm';
|
|
5
6
|
import { Checkbox } from '../../ui-kit/Checkbox/Checkbox';
|
|
6
7
|
import { renderButtonsSection } from '../../ui-kit/LinkButton/renderButtonsSection';
|
|
8
|
+
import { clamp } from '../../utils/clamp';
|
|
7
9
|
import {
|
|
8
10
|
type CreditCalculatorParamsViewSettings,
|
|
9
11
|
type CreditCalculatorProps,
|
|
@@ -53,6 +55,27 @@ export const CreditCalculatorForm = JSX<CreditCalculatorProp>(
|
|
|
53
55
|
...field('isAnnuity'),
|
|
54
56
|
});
|
|
55
57
|
|
|
58
|
+
const { onChange: setMoneyValue } = field('moneyValue');
|
|
59
|
+
const { onChange: setMonthsValue } = field('monthsValue');
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
setMoneyValue &&
|
|
63
|
+
setMoneyValue(
|
|
64
|
+
clamp(userInputParams.moneyValue, calculatorParams.minSum, calculatorParams.maxSum),
|
|
65
|
+
);
|
|
66
|
+
}, [calculatorParams.minSum, calculatorParams.maxSum]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
setMonthsValue &&
|
|
70
|
+
setMonthsValue(
|
|
71
|
+
clamp(
|
|
72
|
+
userInputParams.monthsValue,
|
|
73
|
+
calculatorParams.minMonths,
|
|
74
|
+
calculatorParams.maxMonths,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
}, [calculatorParams.minMonths, calculatorParams.maxMonths]);
|
|
78
|
+
|
|
56
79
|
return (
|
|
57
80
|
<CalculatorFormLayout
|
|
58
81
|
className={className}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
2
|
import { type ExchangeCurrencyItem } from '../../components/ExchangeRateTile/ExchangeCurrencyCalculator';
|
|
3
|
-
import { type
|
|
3
|
+
import { type Region } from '../../hooks/useRegions';
|
|
4
4
|
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../../utils/fetchJSON';
|
|
5
5
|
|
|
6
6
|
export interface ExchangeData {
|
|
@@ -12,7 +12,7 @@ export interface ExchangeData {
|
|
|
12
12
|
|
|
13
13
|
const EXCHANGE_RATES_URL = '/api/v1/exchangerates';
|
|
14
14
|
|
|
15
|
-
export function useFetchExchangeRateData(currentRegion:
|
|
15
|
+
export function useFetchExchangeRateData(currentRegion: Region) {
|
|
16
16
|
const regionCode = currentRegion?.code || '000';
|
|
17
17
|
|
|
18
18
|
const { data } = useAsyncData(
|
|
@@ -3,7 +3,8 @@ import { useCallback, useEffect, useMemo, useState } from '@redneckz/uni-jsx/lib
|
|
|
3
3
|
import { type RefObject } from 'react';
|
|
4
4
|
import { type SitemapData } from '../../data/SitemapData';
|
|
5
5
|
import { useActiveRoute } from '../../hooks/useActiveRoute';
|
|
6
|
-
import { useLocation
|
|
6
|
+
import { useLocation } from '../../hooks/useLocation';
|
|
7
|
+
import { type Region } from '../../hooks/useRegions';
|
|
7
8
|
import { type LinkProps } from '../../model/LinkProps';
|
|
8
9
|
import { Dialog } from '../../ui-kit/DialogManager/Dialog';
|
|
9
10
|
import { Heading } from '../../ui-kit/Heading/Heading';
|
|
@@ -110,7 +111,7 @@ const renderOfficeLink = (officesLink?: string) =>
|
|
|
110
111
|
</a>
|
|
111
112
|
) : null;
|
|
112
113
|
|
|
113
|
-
const renderLocation = (location:
|
|
114
|
+
const renderLocation = (location: Region, onClick?: () => void) => (
|
|
114
115
|
<div className="flex items-center text-s cursor-pointer" onClick={onClick}>
|
|
115
116
|
<Img
|
|
116
117
|
image={{ icon: 'GeolocationIcon', iconVersion: 'black' }}
|
|
@@ -3,33 +3,26 @@ import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
|
3
3
|
import { defaultEventBus } from '../EventBus/defaultEventBus';
|
|
4
4
|
import { useLatestEvent } from '../EventBus/useLatestEvent';
|
|
5
5
|
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
6
|
+
import { type Region } from './useRegions';
|
|
6
7
|
|
|
7
8
|
const REGION_URL = '/api/v1/region';
|
|
8
|
-
|
|
9
|
-
export interface RegionData {
|
|
10
|
-
id?: number;
|
|
11
|
-
code?: string;
|
|
12
|
-
name?: string;
|
|
13
|
-
slug?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
9
|
const LOCATION_STORAGE_KEY = 'location';
|
|
17
10
|
|
|
18
|
-
export function useLocation(defaultLocation = 'Москва'): [
|
|
11
|
+
export function useLocation(defaultLocation = 'Москва'): [Region, (_: Region) => void] {
|
|
19
12
|
const [currentLocation, fireCurrentLocation] = useLatestEvent(
|
|
20
13
|
defaultEventBus,
|
|
21
14
|
'location',
|
|
22
15
|
restoreLocation() ?? { name: defaultLocation },
|
|
23
16
|
);
|
|
24
17
|
|
|
25
|
-
const selectCurrentLocation = useCallback((_:
|
|
18
|
+
const selectCurrentLocation = useCallback((_: Region) => {
|
|
26
19
|
storeLocation(_);
|
|
27
20
|
fireCurrentLocation(_);
|
|
28
21
|
}, []);
|
|
29
22
|
|
|
30
23
|
const { data } = useAsyncData(
|
|
31
24
|
hasStoredLocation() ? null : REGION_URL,
|
|
32
|
-
fetchJSONUnsafe as FetchJSONUnsafeType<
|
|
25
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<Region>,
|
|
33
26
|
);
|
|
34
27
|
useEffect(() => {
|
|
35
28
|
if (data && !hasStoredLocation()) {
|
|
@@ -42,7 +35,7 @@ export function useLocation(defaultLocation = 'Москва'): [RegionData, (_:
|
|
|
42
35
|
|
|
43
36
|
const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
|
|
44
37
|
|
|
45
|
-
const restoreLocation = ():
|
|
38
|
+
const restoreLocation = (): Region | null => {
|
|
46
39
|
try {
|
|
47
40
|
const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
|
|
48
41
|
|
|
@@ -52,7 +45,7 @@ const restoreLocation = (): RegionData | null => {
|
|
|
52
45
|
}
|
|
53
46
|
};
|
|
54
47
|
|
|
55
|
-
const storeLocation = (_:
|
|
48
|
+
const storeLocation = (_: Region) => {
|
|
56
49
|
try {
|
|
57
50
|
globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
|
|
58
51
|
} catch (ex) {
|
|
@@ -8,12 +8,13 @@ interface LinkWrapperProps {
|
|
|
8
8
|
href?: string;
|
|
9
9
|
target?: Target;
|
|
10
10
|
isRemote?: boolean;
|
|
11
|
+
onClick?: () => void;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export const LinkWrapper = JSX<LinkWrapperProps>(
|
|
14
|
-
({ className = '', href, target, isRemote = false, children }) => {
|
|
15
|
+
({ className = '', href, target, isRemote = false, onClick, children }) => {
|
|
15
16
|
const link = useLink({ isRemote });
|
|
16
|
-
const linkProps = link({ href, target });
|
|
17
|
+
const linkProps = link({ href, target, onClick });
|
|
17
18
|
const Tag = href ? 'a' : 'div';
|
|
18
19
|
|
|
19
20
|
return (
|
|
@@ -4,11 +4,12 @@ import { type ForeignOfficeProps } from '../../data/SitemapData';
|
|
|
4
4
|
import { useLink } from '../../hooks/useLink';
|
|
5
5
|
import { useLocation } from '../../hooks/useLocation';
|
|
6
6
|
import { useRegions, type Region } from '../../hooks/useRegions';
|
|
7
|
-
import { LinkButton } from '../../ui-kit/LinkButton/LinkButton';
|
|
8
7
|
import { groupBy } from '../../utils/groupBy';
|
|
9
8
|
import { jaroWinklerDistance } from '../../utils/jaroWinklerDistance';
|
|
10
9
|
import { Dialog } from '../DialogManager/Dialog';
|
|
11
10
|
import { useDialogManager } from '../DialogManager/useDialogManager';
|
|
11
|
+
import { LinkWrapper } from '../LinkWrapper/LinkWrapper';
|
|
12
|
+
import { Paragraph } from '../Paragraph/Paragraph';
|
|
12
13
|
import { Text } from '../Text/Text';
|
|
13
14
|
import { renderForeignOffices } from './renderForeignOffices';
|
|
14
15
|
import { renderRegion } from './renderRegion';
|
|
@@ -25,7 +26,7 @@ export interface LocationDialogProps {
|
|
|
25
26
|
export const LocationDialog = JSX<LocationDialogProps>(({ foreignOffices, defaultLocation }) => {
|
|
26
27
|
const [currentLocation, selectCurrentLocation] = useLocation(defaultLocation);
|
|
27
28
|
|
|
28
|
-
const link = useLink({ isRemote: true
|
|
29
|
+
const link = useLink({ isRemote: true });
|
|
29
30
|
const { href } = link({ href: `/branches/${currentLocation.slug}` });
|
|
30
31
|
|
|
31
32
|
const [query, setQuery] = useState('');
|
|
@@ -52,12 +53,12 @@ export const LocationDialog = JSX<LocationDialogProps>(({ foreignOffices, defaul
|
|
|
52
53
|
</Text>
|
|
53
54
|
{currentLocation ? (
|
|
54
55
|
<div className="mb-s">
|
|
55
|
-
<
|
|
56
|
-
Сейчас
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</
|
|
56
|
+
<Paragraph size="text-l" color="text-primary-text">
|
|
57
|
+
Сейчас выбран:
|
|
58
|
+
<LinkWrapper isRemote href={href} className="inline mx-2xs text-primary-main">
|
|
59
|
+
{currentLocation.name}
|
|
60
|
+
</LinkWrapper>
|
|
61
|
+
</Paragraph>
|
|
61
62
|
</div>
|
|
62
63
|
) : null}
|
|
63
64
|
<SearchBar onSearch={setQuery} searchTerm={query} />
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { type Region } from '../../hooks/useRegions';
|
|
2
|
+
import { LinkWrapper } from '../LinkWrapper/LinkWrapper';
|
|
2
3
|
import { Text } from '../Text/Text';
|
|
3
4
|
|
|
4
5
|
export const renderRegion = (onChangeLocation?: (region: Region) => void) => (region: Region) =>
|
|
5
|
-
(
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
</
|
|
18
|
-
</
|
|
19
|
-
);
|
|
6
|
+
region.name ? (
|
|
7
|
+
<LinkWrapper
|
|
8
|
+
key={String(region.id)}
|
|
9
|
+
isRemote
|
|
10
|
+
href={`/branches/${region.slug}`}
|
|
11
|
+
className="mb-xs sm:mb-2xs hover:text-primary-hover"
|
|
12
|
+
onClick={() => {
|
|
13
|
+
onChangeLocation && onChangeLocation(region);
|
|
14
|
+
}}
|
|
15
|
+
>
|
|
16
|
+
<Text size="text-l" font="font-light">
|
|
17
|
+
{region.name}
|
|
18
|
+
</Text>
|
|
19
|
+
</LinkWrapper>
|
|
20
|
+
) : null;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type TabActivationEvent } from '../components/Tabs/TabActivationEvent';
|
|
2
|
-
import { type
|
|
2
|
+
import { type Region } from '../hooks/useRegions';
|
|
3
3
|
import { type DialogAction } from '../ui-kit/DialogManager/DialogAction';
|
|
4
4
|
import { type PopupAction } from '../ui-kit/PopupManager/PopupAction';
|
|
5
5
|
import { EventBus } from './EventBus';
|
|
6
6
|
|
|
7
7
|
interface GlobalEventMap {
|
|
8
|
-
location:
|
|
8
|
+
location: Region;
|
|
9
9
|
dialog: DialogAction;
|
|
10
10
|
popup: PopupAction;
|
|
11
11
|
tab: TabActivationEvent;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/* eslint-disable max-lines, max-lines-per-function */
|
|
2
2
|
import { JSX } from '@redneckz/uni-jsx';
|
|
3
|
+
import { useEffect } from '@redneckz/uni-jsx/lib/hooks';
|
|
3
4
|
import { type JSONRefObject } from '../../data/JSONRefObject';
|
|
4
5
|
import { useForm, type FormFieldRegisterer } from '../../hooks/useForm';
|
|
5
6
|
import { Checkbox } from '../../ui-kit/Checkbox/Checkbox';
|
|
6
7
|
import { renderButtonsSection } from '../../ui-kit/LinkButton/renderButtonsSection';
|
|
8
|
+
import { clamp } from '../../utils/clamp';
|
|
7
9
|
import {
|
|
8
10
|
type CreditCalculatorParamsViewSettings,
|
|
9
11
|
type CreditCalculatorProps,
|
|
@@ -53,6 +55,27 @@ export const CreditCalculatorForm = JSX<CreditCalculatorProp>(
|
|
|
53
55
|
...field('isAnnuity'),
|
|
54
56
|
});
|
|
55
57
|
|
|
58
|
+
const { onChange: setMoneyValue } = field('moneyValue');
|
|
59
|
+
const { onChange: setMonthsValue } = field('monthsValue');
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
setMoneyValue &&
|
|
63
|
+
setMoneyValue(
|
|
64
|
+
clamp(userInputParams.moneyValue, calculatorParams.minSum, calculatorParams.maxSum),
|
|
65
|
+
);
|
|
66
|
+
}, [calculatorParams.minSum, calculatorParams.maxSum]);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
setMonthsValue &&
|
|
70
|
+
setMonthsValue(
|
|
71
|
+
clamp(
|
|
72
|
+
userInputParams.monthsValue,
|
|
73
|
+
calculatorParams.minMonths,
|
|
74
|
+
calculatorParams.maxMonths,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
}, [calculatorParams.minMonths, calculatorParams.maxMonths]);
|
|
78
|
+
|
|
56
79
|
return (
|
|
57
80
|
<CalculatorFormLayout
|
|
58
81
|
className={className}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
2
2
|
import { type ExchangeCurrencyItem } from '../../components/ExchangeRateTile/ExchangeCurrencyCalculator';
|
|
3
|
-
import { type
|
|
3
|
+
import { type Region } from '../../hooks/useRegions';
|
|
4
4
|
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../../utils/fetchJSON';
|
|
5
5
|
|
|
6
6
|
export interface ExchangeData {
|
|
@@ -12,7 +12,7 @@ export interface ExchangeData {
|
|
|
12
12
|
|
|
13
13
|
const EXCHANGE_RATES_URL = '/api/v1/exchangerates';
|
|
14
14
|
|
|
15
|
-
export function useFetchExchangeRateData(currentRegion:
|
|
15
|
+
export function useFetchExchangeRateData(currentRegion: Region) {
|
|
16
16
|
const regionCode = currentRegion?.code || '000';
|
|
17
17
|
|
|
18
18
|
const { data } = useAsyncData(
|
|
@@ -3,7 +3,8 @@ import { useCallback, useEffect, useMemo, useState } from '@redneckz/uni-jsx/lib
|
|
|
3
3
|
import { type RefObject } from 'react';
|
|
4
4
|
import { type SitemapData } from '../../data/SitemapData';
|
|
5
5
|
import { useActiveRoute } from '../../hooks/useActiveRoute';
|
|
6
|
-
import { useLocation
|
|
6
|
+
import { useLocation } from '../../hooks/useLocation';
|
|
7
|
+
import { type Region } from '../../hooks/useRegions';
|
|
7
8
|
import { type LinkProps } from '../../model/LinkProps';
|
|
8
9
|
import { Dialog } from '../../ui-kit/DialogManager/Dialog';
|
|
9
10
|
import { Heading } from '../../ui-kit/Heading/Heading';
|
|
@@ -110,7 +111,7 @@ const renderOfficeLink = (officesLink?: string) =>
|
|
|
110
111
|
</a>
|
|
111
112
|
) : null;
|
|
112
113
|
|
|
113
|
-
const renderLocation = (location:
|
|
114
|
+
const renderLocation = (location: Region, onClick?: () => void) => (
|
|
114
115
|
<div className="flex items-center text-s cursor-pointer" onClick={onClick}>
|
|
115
116
|
<Img
|
|
116
117
|
image={{ icon: 'GeolocationIcon', iconVersion: 'black' }}
|
package/src/hooks/useLocation.ts
CHANGED
|
@@ -3,33 +3,26 @@ import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
|
3
3
|
import { defaultEventBus } from '../EventBus/defaultEventBus';
|
|
4
4
|
import { useLatestEvent } from '../EventBus/useLatestEvent';
|
|
5
5
|
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
6
|
+
import { type Region } from './useRegions';
|
|
6
7
|
|
|
7
8
|
const REGION_URL = '/api/v1/region';
|
|
8
|
-
|
|
9
|
-
export interface RegionData {
|
|
10
|
-
id?: number;
|
|
11
|
-
code?: string;
|
|
12
|
-
name?: string;
|
|
13
|
-
slug?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
9
|
const LOCATION_STORAGE_KEY = 'location';
|
|
17
10
|
|
|
18
|
-
export function useLocation(defaultLocation = 'Москва'): [
|
|
11
|
+
export function useLocation(defaultLocation = 'Москва'): [Region, (_: Region) => void] {
|
|
19
12
|
const [currentLocation, fireCurrentLocation] = useLatestEvent(
|
|
20
13
|
defaultEventBus,
|
|
21
14
|
'location',
|
|
22
15
|
restoreLocation() ?? { name: defaultLocation },
|
|
23
16
|
);
|
|
24
17
|
|
|
25
|
-
const selectCurrentLocation = useCallback((_:
|
|
18
|
+
const selectCurrentLocation = useCallback((_: Region) => {
|
|
26
19
|
storeLocation(_);
|
|
27
20
|
fireCurrentLocation(_);
|
|
28
21
|
}, []);
|
|
29
22
|
|
|
30
23
|
const { data } = useAsyncData(
|
|
31
24
|
hasStoredLocation() ? null : REGION_URL,
|
|
32
|
-
fetchJSONUnsafe as FetchJSONUnsafeType<
|
|
25
|
+
fetchJSONUnsafe as FetchJSONUnsafeType<Region>,
|
|
33
26
|
);
|
|
34
27
|
useEffect(() => {
|
|
35
28
|
if (data && !hasStoredLocation()) {
|
|
@@ -42,7 +35,7 @@ export function useLocation(defaultLocation = 'Москва'): [RegionData, (_:
|
|
|
42
35
|
|
|
43
36
|
const hasStoredLocation = () => Boolean(globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY));
|
|
44
37
|
|
|
45
|
-
const restoreLocation = ():
|
|
38
|
+
const restoreLocation = (): Region | null => {
|
|
46
39
|
try {
|
|
47
40
|
const data = globalThis.localStorage?.getItem(LOCATION_STORAGE_KEY);
|
|
48
41
|
|
|
@@ -52,7 +45,7 @@ const restoreLocation = (): RegionData | null => {
|
|
|
52
45
|
}
|
|
53
46
|
};
|
|
54
47
|
|
|
55
|
-
const storeLocation = (_:
|
|
48
|
+
const storeLocation = (_: Region) => {
|
|
56
49
|
try {
|
|
57
50
|
globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
|
|
58
51
|
} catch (ex) {
|
package/src/hooks/useRegions.ts
CHANGED
|
@@ -8,12 +8,13 @@ interface LinkWrapperProps {
|
|
|
8
8
|
href?: string;
|
|
9
9
|
target?: Target;
|
|
10
10
|
isRemote?: boolean;
|
|
11
|
+
onClick?: () => void;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export const LinkWrapper = JSX<LinkWrapperProps>(
|
|
14
|
-
({ className = '', href, target, isRemote = false, children }) => {
|
|
15
|
+
({ className = '', href, target, isRemote = false, onClick, children }) => {
|
|
15
16
|
const link = useLink({ isRemote });
|
|
16
|
-
const linkProps = link({ href, target });
|
|
17
|
+
const linkProps = link({ href, target, onClick });
|
|
17
18
|
const Tag = href ? 'a' : 'div';
|
|
18
19
|
|
|
19
20
|
return (
|
|
@@ -4,11 +4,12 @@ import { type ForeignOfficeProps } from '../../data/SitemapData';
|
|
|
4
4
|
import { useLink } from '../../hooks/useLink';
|
|
5
5
|
import { useLocation } from '../../hooks/useLocation';
|
|
6
6
|
import { useRegions, type Region } from '../../hooks/useRegions';
|
|
7
|
-
import { LinkButton } from '../../ui-kit/LinkButton/LinkButton';
|
|
8
7
|
import { groupBy } from '../../utils/groupBy';
|
|
9
8
|
import { jaroWinklerDistance } from '../../utils/jaroWinklerDistance';
|
|
10
9
|
import { Dialog } from '../DialogManager/Dialog';
|
|
11
10
|
import { useDialogManager } from '../DialogManager/useDialogManager';
|
|
11
|
+
import { LinkWrapper } from '../LinkWrapper/LinkWrapper';
|
|
12
|
+
import { Paragraph } from '../Paragraph/Paragraph';
|
|
12
13
|
import { Text } from '../Text/Text';
|
|
13
14
|
import { renderForeignOffices } from './renderForeignOffices';
|
|
14
15
|
import { renderRegion } from './renderRegion';
|
|
@@ -25,7 +26,7 @@ export interface LocationDialogProps {
|
|
|
25
26
|
export const LocationDialog = JSX<LocationDialogProps>(({ foreignOffices, defaultLocation }) => {
|
|
26
27
|
const [currentLocation, selectCurrentLocation] = useLocation(defaultLocation);
|
|
27
28
|
|
|
28
|
-
const link = useLink({ isRemote: true
|
|
29
|
+
const link = useLink({ isRemote: true });
|
|
29
30
|
const { href } = link({ href: `/branches/${currentLocation.slug}` });
|
|
30
31
|
|
|
31
32
|
const [query, setQuery] = useState('');
|
|
@@ -52,12 +53,12 @@ export const LocationDialog = JSX<LocationDialogProps>(({ foreignOffices, defaul
|
|
|
52
53
|
</Text>
|
|
53
54
|
{currentLocation ? (
|
|
54
55
|
<div className="mb-s">
|
|
55
|
-
<
|
|
56
|
-
Сейчас
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</
|
|
56
|
+
<Paragraph size="text-l" color="text-primary-text">
|
|
57
|
+
Сейчас выбран:
|
|
58
|
+
<LinkWrapper isRemote href={href} className="inline mx-2xs text-primary-main">
|
|
59
|
+
{currentLocation.name}
|
|
60
|
+
</LinkWrapper>
|
|
61
|
+
</Paragraph>
|
|
61
62
|
</div>
|
|
62
63
|
) : null}
|
|
63
64
|
<SearchBar onSearch={setQuery} searchTerm={query} />
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { type Region } from '../../hooks/useRegions';
|
|
2
|
+
import { LinkWrapper } from '../LinkWrapper/LinkWrapper';
|
|
2
3
|
import { Text } from '../Text/Text';
|
|
3
4
|
|
|
4
5
|
export const renderRegion = (onChangeLocation?: (region: Region) => void) => (region: Region) =>
|
|
5
|
-
(
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
</
|
|
18
|
-
</
|
|
19
|
-
);
|
|
6
|
+
region.name ? (
|
|
7
|
+
<LinkWrapper
|
|
8
|
+
key={String(region.id)}
|
|
9
|
+
isRemote
|
|
10
|
+
href={`/branches/${region.slug}`}
|
|
11
|
+
className="mb-xs sm:mb-2xs hover:text-primary-hover"
|
|
12
|
+
onClick={() => {
|
|
13
|
+
onChangeLocation && onChangeLocation(region);
|
|
14
|
+
}}
|
|
15
|
+
>
|
|
16
|
+
<Text size="text-l" font="font-light">
|
|
17
|
+
{region.name}
|
|
18
|
+
</Text>
|
|
19
|
+
</LinkWrapper>
|
|
20
|
+
) : null;
|