@redneckz/wildless-cms-uni-blocks 0.14.674 → 0.14.676
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/EventBus.d.ts +1 -8
- package/bundle/EventBus/defaultEventBus.d.ts +0 -9
- package/bundle/bundle.umd.js +406 -136
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/hooks/useLocation.d.ts +4 -1
- package/bundle/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
- package/dist/EventBus/EventBus.d.ts +1 -8
- package/dist/EventBus/EventBus.js +2 -28
- package/dist/EventBus/EventBus.js.map +1 -1
- package/dist/EventBus/defaultEventBus.d.ts +0 -9
- package/dist/EventBus/defaultEventBus.js.map +1 -1
- package/dist/components/CarouselTariffsCard/CarouselTariffsCard.js +1 -1
- package/dist/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
- package/dist/components/ContentPage/ContentPage.js +2 -0
- package/dist/components/ContentPage/ContentPage.js.map +1 -1
- package/dist/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
- package/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
- package/dist/components/Header/HeaderSecondaryMenu.js +1 -1
- package/dist/components/Header/HeaderSecondaryMenu.js.map +1 -1
- package/dist/components/OfficesAtmsMap/AtmsMap.js +1 -1
- package/dist/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
- package/dist/components/OfficesAtmsMap/OfficesMap.js +1 -1
- package/dist/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
- package/dist/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
- package/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
- package/dist/hooks/useLocation.d.ts +4 -1
- package/dist/hooks/useLocation.js +16 -34
- package/dist/hooks/useLocation.js.map +1 -1
- package/dist/hooks/useRegions.js +3 -1
- package/dist/hooks/useRegions.js.map +1 -1
- package/dist/ui-kit/DialogManager/useDialogsList.js +3 -0
- package/dist/ui-kit/DialogManager/useDialogsList.js.map +1 -1
- package/dist/ui-kit/FormField/Fields/AddressFactField.js +1 -1
- package/dist/ui-kit/FormField/Fields/AddressFactField.js.map +1 -1
- package/dist/ui-kit/FormField/validators.js +3 -2
- package/dist/ui-kit/FormField/validators.js.map +1 -1
- package/dist/ui-kit/Input/InputControl.js +4 -1
- package/dist/ui-kit/Input/InputControl.js.map +1 -1
- package/dist/ui-kit/LocationDialog/LocationDialog.js +11 -14
- package/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
- package/dist/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
- package/dist/ui-kit/LocationDialog/SelectedLocation.js +15 -0
- package/dist/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
- package/dist/ui-kit/PopupManager/PopupManager.js +3 -0
- package/dist/ui-kit/PopupManager/PopupManager.js.map +1 -1
- package/lib/EventBus/EventBus.d.ts +1 -8
- package/lib/EventBus/EventBus.js +1 -27
- package/lib/EventBus/EventBus.js.map +1 -1
- package/lib/EventBus/defaultEventBus.d.ts +0 -9
- package/lib/EventBus/defaultEventBus.js.map +1 -1
- package/lib/components/CarouselTariffsCard/CarouselTariffsCard.js +1 -1
- package/lib/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
- package/lib/components/ContentPage/ContentPage.js +2 -0
- package/lib/components/ContentPage/ContentPage.js.map +1 -1
- package/lib/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
- package/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
- package/lib/components/Header/HeaderSecondaryMenu.js +1 -1
- package/lib/components/Header/HeaderSecondaryMenu.js.map +1 -1
- package/lib/components/OfficesAtmsMap/AtmsMap.js +1 -1
- package/lib/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
- package/lib/components/OfficesAtmsMap/OfficesMap.js +1 -1
- package/lib/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
- package/lib/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
- package/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
- package/lib/hooks/useLocation.d.ts +4 -1
- package/lib/hooks/useLocation.js +15 -34
- package/lib/hooks/useLocation.js.map +1 -1
- package/lib/hooks/useRegions.js +3 -1
- package/lib/hooks/useRegions.js.map +1 -1
- package/lib/ui-kit/DialogManager/useDialogsList.js +3 -0
- package/lib/ui-kit/DialogManager/useDialogsList.js.map +1 -1
- package/lib/ui-kit/FormField/Fields/AddressFactField.js +1 -1
- package/lib/ui-kit/FormField/Fields/AddressFactField.js.map +1 -1
- package/lib/ui-kit/FormField/validators.js +3 -2
- package/lib/ui-kit/FormField/validators.js.map +1 -1
- package/lib/ui-kit/Input/InputControl.js +4 -1
- package/lib/ui-kit/Input/InputControl.js.map +1 -1
- package/lib/ui-kit/LocationDialog/LocationDialog.js +13 -16
- package/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
- package/lib/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
- package/lib/ui-kit/LocationDialog/SelectedLocation.js +13 -0
- package/lib/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
- package/lib/ui-kit/PopupManager/PopupManager.js +3 -0
- package/lib/ui-kit/PopupManager/PopupManager.js.map +1 -1
- package/mobile/bundle/EventBus/EventBus.d.ts +1 -8
- package/mobile/bundle/EventBus/defaultEventBus.d.ts +0 -9
- package/mobile/bundle/bundle.umd.js +406 -136
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/hooks/useLocation.d.ts +4 -1
- package/mobile/bundle/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
- package/mobile/dist/EventBus/EventBus.d.ts +1 -8
- package/mobile/dist/EventBus/EventBus.js +2 -28
- package/mobile/dist/EventBus/EventBus.js.map +1 -1
- package/mobile/dist/EventBus/defaultEventBus.d.ts +0 -9
- package/mobile/dist/EventBus/defaultEventBus.js.map +1 -1
- package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCard.js +1 -1
- package/mobile/dist/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
- package/mobile/dist/components/ContentPage/ContentPage.js +2 -0
- package/mobile/dist/components/ContentPage/ContentPage.js.map +1 -1
- package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
- package/mobile/dist/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
- package/mobile/dist/components/Header/HeaderSecondaryMenu.js +1 -1
- package/mobile/dist/components/Header/HeaderSecondaryMenu.js.map +1 -1
- package/mobile/dist/components/OfficesAtmsMap/AtmsMap.js +1 -1
- package/mobile/dist/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
- package/mobile/dist/components/OfficesAtmsMap/OfficesMap.js +1 -1
- package/mobile/dist/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
- package/mobile/dist/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
- package/mobile/dist/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
- package/mobile/dist/hooks/useLocation.d.ts +4 -1
- package/mobile/dist/hooks/useLocation.js +16 -34
- package/mobile/dist/hooks/useLocation.js.map +1 -1
- package/mobile/dist/hooks/useRegions.js +3 -1
- package/mobile/dist/hooks/useRegions.js.map +1 -1
- package/mobile/dist/ui-kit/DialogManager/useDialogsList.js +3 -0
- package/mobile/dist/ui-kit/DialogManager/useDialogsList.js.map +1 -1
- package/mobile/dist/ui-kit/FormField/Fields/AddressFactField.js +1 -1
- package/mobile/dist/ui-kit/FormField/Fields/AddressFactField.js.map +1 -1
- package/mobile/dist/ui-kit/FormField/validators.js +3 -2
- package/mobile/dist/ui-kit/FormField/validators.js.map +1 -1
- package/mobile/dist/ui-kit/Input/InputControl.js +4 -1
- package/mobile/dist/ui-kit/Input/InputControl.js.map +1 -1
- package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js +11 -14
- package/mobile/dist/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
- package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
- package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.js +15 -0
- package/mobile/dist/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
- package/mobile/dist/ui-kit/PopupManager/PopupManager.js +3 -0
- package/mobile/dist/ui-kit/PopupManager/PopupManager.js.map +1 -1
- package/mobile/lib/EventBus/EventBus.d.ts +1 -8
- package/mobile/lib/EventBus/EventBus.js +1 -27
- package/mobile/lib/EventBus/EventBus.js.map +1 -1
- package/mobile/lib/EventBus/defaultEventBus.d.ts +0 -9
- package/mobile/lib/EventBus/defaultEventBus.js.map +1 -1
- package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCard.js +1 -1
- package/mobile/lib/components/CarouselTariffsCard/CarouselTariffsCard.js.map +1 -1
- package/mobile/lib/components/ContentPage/ContentPage.js +2 -0
- package/mobile/lib/components/ContentPage/ContentPage.js.map +1 -1
- package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js +1 -1
- package/mobile/lib/components/ExchangeRateTile/ExchangeRateTile.js.map +1 -1
- package/mobile/lib/components/Header/HeaderSecondaryMenu.js +1 -1
- package/mobile/lib/components/Header/HeaderSecondaryMenu.js.map +1 -1
- package/mobile/lib/components/OfficesAtmsMap/AtmsMap.js +1 -1
- package/mobile/lib/components/OfficesAtmsMap/AtmsMap.js.map +1 -1
- package/mobile/lib/components/OfficesAtmsMap/OfficesMap.js +1 -1
- package/mobile/lib/components/OfficesAtmsMap/OfficesMap.js.map +1 -1
- package/mobile/lib/components/StickyBottomMenu/BurgerMenuDialog.js +1 -1
- package/mobile/lib/components/StickyBottomMenu/BurgerMenuDialog.js.map +1 -1
- package/mobile/lib/hooks/useLocation.d.ts +4 -1
- package/mobile/lib/hooks/useLocation.js +15 -34
- package/mobile/lib/hooks/useLocation.js.map +1 -1
- package/mobile/lib/hooks/useRegions.js +3 -1
- package/mobile/lib/hooks/useRegions.js.map +1 -1
- package/mobile/lib/ui-kit/DialogManager/useDialogsList.js +3 -0
- package/mobile/lib/ui-kit/DialogManager/useDialogsList.js.map +1 -1
- package/mobile/lib/ui-kit/FormField/Fields/AddressFactField.js +1 -1
- package/mobile/lib/ui-kit/FormField/Fields/AddressFactField.js.map +1 -1
- package/mobile/lib/ui-kit/FormField/validators.js +3 -2
- package/mobile/lib/ui-kit/FormField/validators.js.map +1 -1
- package/mobile/lib/ui-kit/Input/InputControl.js +4 -1
- package/mobile/lib/ui-kit/Input/InputControl.js.map +1 -1
- package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js +13 -16
- package/mobile/lib/ui-kit/LocationDialog/LocationDialog.js.map +1 -1
- package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.d.ts +5 -0
- package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.js +13 -0
- package/mobile/lib/ui-kit/LocationDialog/SelectedLocation.js.map +1 -0
- package/mobile/lib/ui-kit/PopupManager/PopupManager.js +3 -0
- package/mobile/lib/ui-kit/PopupManager/PopupManager.js.map +1 -1
- package/mobile/src/EventBus/EventBus.ts +1 -36
- package/mobile/src/EventBus/defaultEventBus.ts +0 -10
- package/mobile/src/components/CarouselTariffsCard/CarouselTariffsCard.tsx +1 -1
- package/mobile/src/components/ContentPage/ContentPage.tsx +2 -0
- package/mobile/src/components/ExchangeRateTile/ExchangeRateTile.tsx +1 -1
- package/mobile/src/components/Header/HeaderSecondaryMenu.tsx +1 -1
- package/mobile/src/components/OfficesAtmsMap/AtmsMap.tsx +1 -1
- package/mobile/src/components/OfficesAtmsMap/OfficesMap.tsx +1 -1
- package/mobile/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +1 -1
- package/mobile/src/hooks/useLocation.ts +25 -47
- package/mobile/src/hooks/useRegions.ts +4 -1
- package/mobile/src/ui-kit/DialogManager/useDialogsList.ts +3 -0
- package/mobile/src/ui-kit/FormField/Fields/AddressFactField.tsx +1 -1
- package/mobile/src/ui-kit/FormField/validators.ts +4 -3
- package/mobile/src/ui-kit/Input/InputControl.tsx +5 -2
- package/mobile/src/ui-kit/LocationDialog/LocationDialog.tsx +22 -28
- package/mobile/src/ui-kit/LocationDialog/SelectedLocation.tsx +27 -0
- package/mobile/src/ui-kit/PopupManager/PopupManager.tsx +3 -0
- package/package.json +5 -5
- package/src/EventBus/EventBus.ts +1 -36
- package/src/EventBus/defaultEventBus.ts +0 -10
- package/src/components/CarouselTariffsCard/CarouselTariffsCard.tsx +1 -1
- package/src/components/ContentPage/ContentPage.tsx +2 -0
- package/src/components/ExchangeRateTile/ExchangeRateTile.tsx +1 -1
- package/src/components/Header/HeaderSecondaryMenu.tsx +1 -1
- package/src/components/OfficesAtmsMap/AtmsMap.tsx +1 -1
- package/src/components/OfficesAtmsMap/OfficesMap.tsx +1 -1
- package/src/components/StickyBottomMenu/BurgerMenuDialog.tsx +1 -1
- package/src/hooks/useLocation.ts +25 -47
- package/src/hooks/useRegions.ts +4 -1
- package/src/ui-kit/DialogManager/useDialogsList.ts +3 -0
- package/src/ui-kit/FormField/Fields/AddressFactField.tsx +1 -1
- package/src/ui-kit/FormField/validators.ts +4 -3
- package/src/ui-kit/Input/InputControl.tsx +5 -2
- package/src/ui-kit/LocationDialog/LocationDialog.tsx +22 -28
- package/src/ui-kit/LocationDialog/SelectedLocation.tsx +27 -0
- package/src/ui-kit/PopupManager/PopupManager.tsx +3 -0
package/src/hooks/useLocation.ts
CHANGED
|
@@ -1,55 +1,33 @@
|
|
|
1
|
-
import { useCallback
|
|
1
|
+
import { useCallback } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { useAsyncData } from '@redneckz/uni-jsx/lib/hooks/useAsyncData';
|
|
3
|
+
import { useLocalStore } from '@redneckz/uni-jsx/lib/Store/useLocalStore';
|
|
3
4
|
import { API_BASE_URI } from '../api/apiBaseUrl';
|
|
4
|
-
import {
|
|
5
|
-
import { useLatestEvent } from '../EventBus/useLatestEvent';
|
|
6
|
-
import { fetchJSONUnsafe, type FetchJSONUnsafeType } from '../utils/fetchJSON';
|
|
5
|
+
import { fetchJSON } from '../utils/fetchJSON';
|
|
7
6
|
import { type Region } from './useRegions';
|
|
8
7
|
|
|
9
8
|
const REGION_URL = `${API_BASE_URI}/region`;
|
|
10
|
-
const LOCATION_STORAGE_KEY = 'location';
|
|
11
|
-
|
|
12
|
-
export function useLocation(defaultLocation = 'Москва'): [Region, (_: Region) => void] {
|
|
13
|
-
const [currentLocation, fireCurrentLocation] = useLatestEvent(
|
|
14
|
-
defaultEventBus,
|
|
15
|
-
'location',
|
|
16
|
-
restoreLocation() ?? { name: defaultLocation },
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const selectCurrentLocation = useCallback((_: Region) => {
|
|
20
|
-
storeLocation(_);
|
|
21
|
-
fireCurrentLocation(_);
|
|
22
|
-
}, []);
|
|
23
|
-
|
|
24
|
-
const { data } = useAsyncData(
|
|
25
|
-
hasStoredLocation() ? null : REGION_URL,
|
|
26
|
-
fetchJSONUnsafe as FetchJSONUnsafeType<Region>,
|
|
27
|
-
);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (data && !hasStoredLocation()) {
|
|
30
|
-
fireCurrentLocation(data);
|
|
31
|
-
}
|
|
32
|
-
}, [data]);
|
|
33
9
|
|
|
34
|
-
|
|
10
|
+
interface LocationStore {
|
|
11
|
+
location: Region;
|
|
35
12
|
}
|
|
36
13
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
14
|
+
export function useLocation(defaultLocation = 'Москва'): Region {
|
|
15
|
+
const locationStore = useLocalStore<LocationStore>();
|
|
16
|
+
|
|
17
|
+
return locationStore.location ?? { name: defaultLocation };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useDefaultLocation(defaultLocation = 'Москва') {
|
|
21
|
+
const locationStore = useLocalStore<LocationStore>();
|
|
22
|
+
|
|
23
|
+
const preselectLocation = useCallback(async () => {
|
|
24
|
+
if (!locationStore.location) {
|
|
25
|
+
const region = await fetchJSON<Region>(REGION_URL);
|
|
26
|
+
locationStore.location = region ?? { name: defaultLocation };
|
|
27
|
+
}
|
|
28
|
+
}, [locationStore, defaultLocation]);
|
|
29
|
+
|
|
30
|
+
useAsyncData(REGION_URL, preselectLocation);
|
|
31
|
+
|
|
32
|
+
return locationStore;
|
|
33
|
+
}
|
package/src/hooks/useRegions.ts
CHANGED
|
@@ -14,8 +14,11 @@ export interface Region {
|
|
|
14
14
|
branches?: string[];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
const EMPTY_REGIONS: Region[] = [];
|
|
18
|
+
|
|
19
|
+
// TODO Почему url можно менять? Разве смысл не в инкапсуляции api url. Тоже под рефакторинг попадает
|
|
17
20
|
export function useRegions(url: string = REGIONS_URL): Region[] {
|
|
18
21
|
const { data } = useAsyncData(url, fetchJSONUnsafe as FetchJSONUnsafeType<Region[]>);
|
|
19
22
|
|
|
20
|
-
return Array.isArray(data) ? data :
|
|
23
|
+
return Array.isArray(data) ? data : EMPTY_REGIONS;
|
|
21
24
|
}
|
|
@@ -15,7 +15,7 @@ export const AddressFactField = JSX<CustomFieldProps>(({ field, input }) => {
|
|
|
15
15
|
if (value) {
|
|
16
16
|
field('addressFact')?.onChange?.(field('addressRegistration').value);
|
|
17
17
|
}
|
|
18
|
-
}, [value]);
|
|
18
|
+
}, [value, field('addressRegistration').value]);
|
|
19
19
|
|
|
20
20
|
const onDaDataChange = useCallback((item: DaDataSuggestion) => {
|
|
21
21
|
field?.(fieldName)?.onChange?.({
|
|
@@ -5,6 +5,8 @@ import { validator } from '../../validation/validator';
|
|
|
5
5
|
|
|
6
6
|
const ERROR_MESSAGE = 'Некорректно заполненное поле';
|
|
7
7
|
|
|
8
|
+
const ADDRESS_ERROR_MESSAGE = 'Укажите регион, город/населенный пункт, улицу, дом';
|
|
9
|
+
|
|
8
10
|
export const defaultValidator = (errorMsg?: string) => required(errorMsg ?? ERROR_MESSAGE);
|
|
9
11
|
|
|
10
12
|
export const defaultSelectValidator = (errorMsg?: string) =>
|
|
@@ -71,12 +73,11 @@ export const emailValidator = (errorMsg: string) =>
|
|
|
71
73
|
const addressDaDataValidate = (address: Address) =>
|
|
72
74
|
Boolean(address.region && address.city && address.house);
|
|
73
75
|
|
|
74
|
-
export const addressDaDataValidator = () =>
|
|
75
|
-
validator(addressDaDataValidate)('Укажите регион, город/населенный пункт, улицу, дом, квартиру');
|
|
76
|
+
export const addressDaDataValidator = () => validator(addressDaDataValidate)(ADDRESS_ERROR_MESSAGE);
|
|
76
77
|
|
|
77
78
|
export const addressOrganizationValidator = () =>
|
|
78
79
|
validator((address: Address) => Boolean(address.fiasCode && address.city && address.house))(
|
|
79
|
-
|
|
80
|
+
ADDRESS_ERROR_MESSAGE,
|
|
80
81
|
);
|
|
81
82
|
|
|
82
83
|
export const codeWordValidator = (errorMsg?: string) =>
|
|
@@ -33,8 +33,11 @@ export const InputControl = JSX<InputProps>(
|
|
|
33
33
|
const popupRef = useOutsideClick<HTMLDivElement>(close);
|
|
34
34
|
|
|
35
35
|
const handleChange = useCallback(
|
|
36
|
-
(v: string) =>
|
|
37
|
-
|
|
36
|
+
(v: string) => {
|
|
37
|
+
dadata && !isOpen && open();
|
|
38
|
+
maxLength ? v.length <= maxLength && onChange(v) : onChange(v);
|
|
39
|
+
},
|
|
40
|
+
[dadata, isOpen, onChange],
|
|
38
41
|
);
|
|
39
42
|
|
|
40
43
|
const inputRef = useInputPopup({
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { JSX } from '@redneckz/uni-jsx';
|
|
2
|
-
import { useCallback, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
|
+
import { useCallback, useMemo, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
3
3
|
import { type BranchesHeader, type ForeignOfficeProps } from '../../data/HeaderData';
|
|
4
|
-
import {
|
|
5
|
-
import { useLocation } from '../../hooks/useLocation';
|
|
4
|
+
import { useDefaultLocation } from '../../hooks/useLocation';
|
|
6
5
|
import { useRegions, type Region } from '../../hooks/useRegions';
|
|
7
6
|
import { groupBy } from '../../utils/groupBy';
|
|
8
7
|
import { jaroWinklerDistance } from '../../utils/jaroWinklerDistance';
|
|
9
8
|
import { Dialog } from '../DialogManager/Dialog';
|
|
10
9
|
import { useDialogManager } from '../DialogManager/useDialogManager';
|
|
11
|
-
import { LinkWrapper } from '../LinkWrapper/LinkWrapper';
|
|
12
|
-
import { Paragraph } from '../Paragraph/Paragraph';
|
|
13
10
|
import { Text } from '../Text/Text';
|
|
14
11
|
import { renderForeignOffices } from './renderForeignOffices';
|
|
15
12
|
import { renderRegion } from './renderRegion';
|
|
16
13
|
import { renderRegionGroup } from './renderRegionGroup';
|
|
17
14
|
import { SearchBar } from './SearchBar';
|
|
15
|
+
import { SelectedLocation } from './SelectedLocation';
|
|
18
16
|
|
|
19
17
|
const SEARCH_TERM_MIN_LENGTH = 3;
|
|
20
18
|
|
|
@@ -24,24 +22,29 @@ export interface LocationDialogProps {
|
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
export const LocationDialog = JSX<LocationDialogProps>(({ foreignOffices, branches }) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const link = useLink();
|
|
30
|
-
const { href } = link({ href: `/branches/${currentLocation.slug}` });
|
|
25
|
+
const locationStore = useDefaultLocation(branches?.default);
|
|
31
26
|
|
|
32
27
|
const [query, setQuery] = useState('');
|
|
33
28
|
|
|
34
|
-
const
|
|
35
|
-
|
|
29
|
+
const rawRegions = useRegions();
|
|
30
|
+
const regions = useMemo(
|
|
31
|
+
(): Region[] => cleanUpRegions(rawRegions).sort((a, b) => a.name.localeCompare(b.name)),
|
|
32
|
+
[rawRegions],
|
|
33
|
+
);
|
|
34
|
+
const regionsGroupByLetter = useMemo(
|
|
35
|
+
(): Map<string, Region[]> => groupBy(regions, regionFirstLetter),
|
|
36
|
+
[regions],
|
|
36
37
|
);
|
|
37
|
-
const regionsGroupByLetter: Map<string, Region[]> = groupBy(regions, regionFirstLetter);
|
|
38
38
|
|
|
39
39
|
const { close } = useDialogManager();
|
|
40
40
|
|
|
41
|
-
const handleChangeLocation = useCallback(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const handleChangeLocation = useCallback(
|
|
42
|
+
(_: Region) => {
|
|
43
|
+
locationStore.location = _;
|
|
44
|
+
close();
|
|
45
|
+
},
|
|
46
|
+
[locationStore],
|
|
47
|
+
);
|
|
45
48
|
|
|
46
49
|
return (
|
|
47
50
|
<Dialog
|
|
@@ -51,16 +54,7 @@ export const LocationDialog = JSX<LocationDialogProps>(({ foreignOffices, branch
|
|
|
51
54
|
<Text size="text-h4" color="text-primary-text">
|
|
52
55
|
Выберите филиал
|
|
53
56
|
</Text>
|
|
54
|
-
{
|
|
55
|
-
<div className="mb-s">
|
|
56
|
-
<Paragraph size="text-l" color="text-primary-text">
|
|
57
|
-
Сейчас выбран:
|
|
58
|
-
<LinkWrapper href={href} className="inline mx-2xs text-primary-main">
|
|
59
|
-
{currentLocation.name}
|
|
60
|
-
</LinkWrapper>
|
|
61
|
-
</Paragraph>
|
|
62
|
-
</div>
|
|
63
|
-
) : null}
|
|
57
|
+
<SelectedLocation defaultLocation={branches?.default} />
|
|
64
58
|
<SearchBar onSearch={setQuery} searchTerm={query} />
|
|
65
59
|
</div>
|
|
66
60
|
}
|
|
@@ -86,10 +80,10 @@ export const LocationDialog = JSX<LocationDialogProps>(({ foreignOffices, branch
|
|
|
86
80
|
);
|
|
87
81
|
});
|
|
88
82
|
|
|
89
|
-
const regionFirstLetter = (region: Region) => region.name?.charAt(0)
|
|
83
|
+
const regionFirstLetter = (region: Region) => region.name?.charAt(0) ?? '';
|
|
90
84
|
|
|
91
85
|
const cleanUpRegions = (regions: Region[]) =>
|
|
92
86
|
regions.map((region) => ({
|
|
93
87
|
...region,
|
|
94
|
-
name: region.name?.replace(/республика|область|край'/gi, '').trim()
|
|
88
|
+
name: region.name?.replace(/республика|область|край'/gi, '').trim() ?? '',
|
|
95
89
|
}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { JSX } from '@redneckz/uni-jsx';
|
|
2
|
+
import { useLink } from '../../hooks/useLink';
|
|
3
|
+
import { useLocation } from '../../hooks/useLocation';
|
|
4
|
+
import { LinkWrapper } from '../LinkWrapper/LinkWrapper';
|
|
5
|
+
import { Paragraph } from '../Paragraph/Paragraph';
|
|
6
|
+
|
|
7
|
+
interface SelectedLocationProps {
|
|
8
|
+
defaultLocation?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const SelectedLocation = JSX<SelectedLocationProps>(({ defaultLocation }) => {
|
|
12
|
+
const currentLocation = useLocation(defaultLocation);
|
|
13
|
+
|
|
14
|
+
const link = useLink();
|
|
15
|
+
const { href } = link({ href: `/branches/${currentLocation.slug}` });
|
|
16
|
+
|
|
17
|
+
return currentLocation ? (
|
|
18
|
+
<div className="mb-s">
|
|
19
|
+
<Paragraph size="text-l" color="text-primary-text">
|
|
20
|
+
Сейчас выбран:
|
|
21
|
+
<LinkWrapper href={href} className="inline mx-2xs text-primary-main">
|
|
22
|
+
{currentLocation.name}
|
|
23
|
+
</LinkWrapper>
|
|
24
|
+
</Paragraph>
|
|
25
|
+
</div>
|
|
26
|
+
) : null;
|
|
27
|
+
});
|