@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.
Files changed (107) hide show
  1. package/bundle/EventBus/defaultEventBus.d.ts +2 -2
  2. package/bundle/bundle.umd.js +18 -8
  3. package/bundle/bundle.umd.min.js +1 -1
  4. package/bundle/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
  5. package/bundle/hooks/useLocation.d.ts +2 -7
  6. package/bundle/hooks/useRegions.d.ts +1 -0
  7. package/bundle/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
  8. package/bundle/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
  9. package/dist/EventBus/defaultEventBus.d.ts +2 -2
  10. package/dist/components/Calculator/CreditCalculatorForm.js +12 -0
  11. package/dist/components/Calculator/CreditCalculatorForm.js.map +1 -1
  12. package/dist/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
  13. package/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
  14. package/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  15. package/dist/hooks/useLocation.d.ts +2 -7
  16. package/dist/hooks/useLocation.js.map +1 -1
  17. package/dist/hooks/useRegions.d.ts +1 -0
  18. package/dist/hooks/useRegions.js.map +1 -1
  19. package/dist/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
  20. package/dist/ui-kit/LinkWrapper/LinkWrapper.js +2 -2
  21. package/dist/ui-kit/LinkWrapper/LinkWrapper.js.map +1 -1
  22. package/dist/ui-kit/LocationDialog/LocationDialog.js +4 -3
  23. package/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  24. package/dist/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
  25. package/dist/ui-kit/LocationDialog/renderRegion.js +4 -3
  26. package/dist/ui-kit/LocationDialog/renderRegion.js.map +1 -1
  27. package/lib/EventBus/defaultEventBus.d.ts +2 -2
  28. package/lib/components/Calculator/CreditCalculatorForm.js +12 -0
  29. package/lib/components/Calculator/CreditCalculatorForm.js.map +1 -1
  30. package/lib/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
  31. package/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
  32. package/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  33. package/lib/hooks/useLocation.d.ts +2 -7
  34. package/lib/hooks/useLocation.js.map +1 -1
  35. package/lib/hooks/useRegions.d.ts +1 -0
  36. package/lib/hooks/useRegions.js.map +1 -1
  37. package/lib/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
  38. package/lib/ui-kit/LinkWrapper/LinkWrapper.js +2 -2
  39. package/lib/ui-kit/LinkWrapper/LinkWrapper.js.map +1 -1
  40. package/lib/ui-kit/LocationDialog/LocationDialog.js +4 -3
  41. package/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  42. package/lib/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
  43. package/lib/ui-kit/LocationDialog/renderRegion.js +4 -3
  44. package/lib/ui-kit/LocationDialog/renderRegion.js.map +1 -1
  45. package/mobile/bundle/EventBus/defaultEventBus.d.ts +2 -2
  46. package/mobile/bundle/bundle.umd.js +18 -8
  47. package/mobile/bundle/bundle.umd.min.js +1 -1
  48. package/mobile/bundle/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
  49. package/mobile/bundle/hooks/useLocation.d.ts +2 -7
  50. package/mobile/bundle/hooks/useRegions.d.ts +1 -0
  51. package/mobile/bundle/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
  52. package/mobile/bundle/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
  53. package/mobile/dist/EventBus/defaultEventBus.d.ts +2 -2
  54. package/mobile/dist/components/Calculator/CreditCalculatorForm.js +12 -0
  55. package/mobile/dist/components/Calculator/CreditCalculatorForm.js.map +1 -1
  56. package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
  57. package/mobile/dist/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
  58. package/mobile/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  59. package/mobile/dist/hooks/useLocation.d.ts +2 -7
  60. package/mobile/dist/hooks/useLocation.js.map +1 -1
  61. package/mobile/dist/hooks/useRegions.d.ts +1 -0
  62. package/mobile/dist/hooks/useRegions.js.map +1 -1
  63. package/mobile/dist/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
  64. package/mobile/dist/ui-kit/LinkWrapper/LinkWrapper.js +2 -2
  65. package/mobile/dist/ui-kit/LinkWrapper/LinkWrapper.js.map +1 -1
  66. package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js +4 -3
  67. package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  68. package/mobile/dist/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
  69. package/mobile/dist/ui-kit/LocationDialog/renderRegion.js +4 -3
  70. package/mobile/dist/ui-kit/LocationDialog/renderRegion.js.map +1 -1
  71. package/mobile/lib/EventBus/defaultEventBus.d.ts +2 -2
  72. package/mobile/lib/components/Calculator/CreditCalculatorForm.js +12 -0
  73. package/mobile/lib/components/Calculator/CreditCalculatorForm.js.map +1 -1
  74. package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.d.ts +2 -2
  75. package/mobile/lib/components/ExchangeRateTile/useFetchExchangeRateData.js.map +1 -1
  76. package/mobile/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
  77. package/mobile/lib/hooks/useLocation.d.ts +2 -7
  78. package/mobile/lib/hooks/useLocation.js.map +1 -1
  79. package/mobile/lib/hooks/useRegions.d.ts +1 -0
  80. package/mobile/lib/hooks/useRegions.js.map +1 -1
  81. package/mobile/lib/ui-kit/LinkWrapper/LinkWrapper.d.ts +1 -0
  82. package/mobile/lib/ui-kit/LinkWrapper/LinkWrapper.js +2 -2
  83. package/mobile/lib/ui-kit/LinkWrapper/LinkWrapper.js.map +1 -1
  84. package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js +4 -3
  85. package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
  86. package/mobile/lib/ui-kit/LocationDialog/renderRegion.d.ts +1 -1
  87. package/mobile/lib/ui-kit/LocationDialog/renderRegion.js +4 -3
  88. package/mobile/lib/ui-kit/LocationDialog/renderRegion.js.map +1 -1
  89. package/mobile/src/EventBus/defaultEventBus.ts +2 -2
  90. package/mobile/src/components/Calculator/CreditCalculatorForm.tsx +23 -0
  91. package/mobile/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +2 -2
  92. package/mobile/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +3 -2
  93. package/mobile/src/hooks/useLocation.ts +6 -13
  94. package/mobile/src/hooks/useRegions.ts +1 -0
  95. package/mobile/src/ui-kit/LinkWrapper/LinkWrapper.tsx +3 -2
  96. package/mobile/src/ui-kit/LocationDialog/LocationDialog.tsx +9 -8
  97. package/mobile/src/ui-kit/LocationDialog/renderRegion.tsx +16 -15
  98. package/package.json +1 -1
  99. package/src/EventBus/defaultEventBus.ts +2 -2
  100. package/src/components/Calculator/CreditCalculatorForm.tsx +23 -0
  101. package/src/components/ExchangeRateTile/useFetchExchangeRateData.ts +2 -2
  102. package/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +3 -2
  103. package/src/hooks/useLocation.ts +6 -13
  104. package/src/hooks/useRegions.ts +1 -0
  105. package/src/ui-kit/LinkWrapper/LinkWrapper.tsx +3 -2
  106. package/src/ui-kit/LocationDialog/LocationDialog.tsx +9 -8
  107. 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 RegionData } from '../../hooks/useLocation';
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: RegionData) {
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, type RegionData } from '../../hooks/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: RegionData, onClick?: () => void) => (
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 = 'Москва'): [RegionData, (_: RegionData) => void] {
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((_: RegionData) => {
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<RegionData>,
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 = (): RegionData | null => {
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 = (_: RegionData) => {
48
+ const storeLocation = (_: Region) => {
56
49
  try {
57
50
  globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
58
51
  } catch (ex) {
@@ -7,6 +7,7 @@ export interface Region {
7
7
  id?: number;
8
8
  code?: string;
9
9
  name?: string;
10
+ slug?: string;
10
11
  }
11
12
 
12
13
  export function useRegions(): Region[] {
@@ -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, basePath: '/' });
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
- <Text size="text-l" font="font-light">
56
- Сейчас выбран:&nbsp;
57
- </Text>
58
- <LinkButton href={href} onClick={() => selectCurrentLocation(currentLocation)}>
59
- <Text color="text-primary-main">{currentLocation.name}</Text>
60
- </LinkButton>
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
- <div key={region.id} className="mb-xs sm:mb-2xs">
7
- <button
8
- className="cursor-pointer hover:text-primary-hover"
9
- onClick={() => {
10
- onChangeLocation && onChangeLocation(region);
11
- }}
12
- type="button"
13
- >
14
- <Text size="text-l" font="font-light">
15
- {region.name || ''}
16
- </Text>
17
- </button>
18
- </div>
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@redneckz/wildless-cms-uni-blocks",
3
- "version": "0.14.231",
3
+ "version": "0.14.233",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "ЦК",
@@ -1,11 +1,11 @@
1
1
  import { type TabActivationEvent } from '../components/Tabs/TabActivationEvent';
2
- import { type RegionData } from '../hooks/useLocation';
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: RegionData;
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 RegionData } from '../../hooks/useLocation';
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: RegionData) {
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, type RegionData } from '../../hooks/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: RegionData, onClick?: () => void) => (
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 = 'Москва'): [RegionData, (_: RegionData) => void] {
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((_: RegionData) => {
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<RegionData>,
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 = (): RegionData | null => {
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 = (_: RegionData) => {
48
+ const storeLocation = (_: Region) => {
56
49
  try {
57
50
  globalThis.localStorage?.setItem(LOCATION_STORAGE_KEY, JSON.stringify(_));
58
51
  } catch (ex) {
@@ -7,6 +7,7 @@ export interface Region {
7
7
  id?: number;
8
8
  code?: string;
9
9
  name?: string;
10
+ slug?: string;
10
11
  }
11
12
 
12
13
  export function useRegions(): Region[] {
@@ -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, basePath: '/' });
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
- <Text size="text-l" font="font-light">
56
- Сейчас выбран:&nbsp;
57
- </Text>
58
- <LinkButton href={href} onClick={() => selectCurrentLocation(currentLocation)}>
59
- <Text color="text-primary-main">{currentLocation.name}</Text>
60
- </LinkButton>
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
- <div key={region.id} className="mb-xs sm:mb-2xs">
7
- <button
8
- className="cursor-pointer hover:text-primary-hover"
9
- onClick={() => {
10
- onChangeLocation && onChangeLocation(region);
11
- }}
12
- type="button"
13
- >
14
- <Text size="text-l" font="font-light">
15
- {region.name || ''}
16
- </Text>
17
- </button>
18
- </div>
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;