@redneckz/wildless-cms-uni-blocks 0.14.671 → 0.14.673

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 (109) hide show
  1. package/bundle/api/RetailAPI/getCardTypes.d.ts +8 -0
  2. package/bundle/api/RetailAPI/getPaymentSystems.d.ts +4 -0
  3. package/bundle/bundle.umd.js +53 -14
  4. package/bundle/bundle.umd.min.js +1 -1
  5. package/bundle/ui-kit/FormField/Fields/PaymentSystemField.d.ts +0 -2
  6. package/bundle/ui-kit/YandexMap/YandexMap.d.ts +1 -0
  7. package/dist/api/RetailAPI/doRequest.js +1 -1
  8. package/dist/api/RetailAPI/doRequest.js.map +1 -1
  9. package/dist/api/RetailAPI/getCardTypes.d.ts +8 -0
  10. package/dist/api/RetailAPI/getCardTypes.js +13 -0
  11. package/dist/api/RetailAPI/getCardTypes.js.map +1 -0
  12. package/dist/api/RetailAPI/getPaymentSystems.d.ts +4 -0
  13. package/dist/api/RetailAPI/getPaymentSystems.js +15 -0
  14. package/dist/api/RetailAPI/getPaymentSystems.js.map +1 -0
  15. package/dist/components/CreditCardForm/formStateMap.js +1 -2
  16. package/dist/components/CreditCardForm/formStateMap.js.map +1 -1
  17. package/dist/ui-kit/FormField/Fields/AddressRetailField.js +1 -1
  18. package/dist/ui-kit/FormField/Fields/AddressRetailField.js.map +1 -1
  19. package/dist/ui-kit/FormField/Fields/CardCategoryField.js +11 -3
  20. package/dist/ui-kit/FormField/Fields/CardCategoryField.js.map +1 -1
  21. package/dist/ui-kit/FormField/Fields/PaymentSystemField.d.ts +0 -2
  22. package/dist/ui-kit/FormField/Fields/PaymentSystemField.js +11 -6
  23. package/dist/ui-kit/FormField/Fields/PaymentSystemField.js.map +1 -1
  24. package/dist/ui-kit/YandexMap/YandexMap.d.ts +1 -0
  25. package/dist/ui-kit/YandexMap/YandexMap.js +11 -2
  26. package/dist/ui-kit/YandexMap/YandexMap.js.map +1 -1
  27. package/lib/api/RetailAPI/doRequest.js +1 -1
  28. package/lib/api/RetailAPI/doRequest.js.map +1 -1
  29. package/lib/api/RetailAPI/getCardTypes.d.ts +8 -0
  30. package/lib/api/RetailAPI/getCardTypes.js +10 -0
  31. package/lib/api/RetailAPI/getCardTypes.js.map +1 -0
  32. package/lib/api/RetailAPI/getPaymentSystems.d.ts +4 -0
  33. package/lib/api/RetailAPI/getPaymentSystems.js +12 -0
  34. package/lib/api/RetailAPI/getPaymentSystems.js.map +1 -0
  35. package/lib/components/CreditCardForm/formStateMap.js +1 -2
  36. package/lib/components/CreditCardForm/formStateMap.js.map +1 -1
  37. package/lib/ui-kit/FormField/Fields/AddressRetailField.js +1 -1
  38. package/lib/ui-kit/FormField/Fields/AddressRetailField.js.map +1 -1
  39. package/lib/ui-kit/FormField/Fields/CardCategoryField.js +11 -3
  40. package/lib/ui-kit/FormField/Fields/CardCategoryField.js.map +1 -1
  41. package/lib/ui-kit/FormField/Fields/PaymentSystemField.d.ts +0 -2
  42. package/lib/ui-kit/FormField/Fields/PaymentSystemField.js +10 -5
  43. package/lib/ui-kit/FormField/Fields/PaymentSystemField.js.map +1 -1
  44. package/lib/ui-kit/YandexMap/YandexMap.d.ts +1 -0
  45. package/lib/ui-kit/YandexMap/YandexMap.js +11 -2
  46. package/lib/ui-kit/YandexMap/YandexMap.js.map +1 -1
  47. package/mobile/bundle/api/RetailAPI/getCardTypes.d.ts +8 -0
  48. package/mobile/bundle/api/RetailAPI/getPaymentSystems.d.ts +4 -0
  49. package/mobile/bundle/bundle.umd.js +53 -14
  50. package/mobile/bundle/bundle.umd.min.js +1 -1
  51. package/mobile/bundle/ui-kit/FormField/Fields/PaymentSystemField.d.ts +0 -2
  52. package/mobile/bundle/ui-kit/YandexMap/YandexMap.d.ts +1 -0
  53. package/mobile/dist/api/RetailAPI/doRequest.js +1 -1
  54. package/mobile/dist/api/RetailAPI/doRequest.js.map +1 -1
  55. package/mobile/dist/api/RetailAPI/getCardTypes.d.ts +8 -0
  56. package/mobile/dist/api/RetailAPI/getCardTypes.js +13 -0
  57. package/mobile/dist/api/RetailAPI/getCardTypes.js.map +1 -0
  58. package/mobile/dist/api/RetailAPI/getPaymentSystems.d.ts +4 -0
  59. package/mobile/dist/api/RetailAPI/getPaymentSystems.js +15 -0
  60. package/mobile/dist/api/RetailAPI/getPaymentSystems.js.map +1 -0
  61. package/mobile/dist/components/CreditCardForm/formStateMap.js +1 -2
  62. package/mobile/dist/components/CreditCardForm/formStateMap.js.map +1 -1
  63. package/mobile/dist/ui-kit/FormField/Fields/AddressRetailField.js +1 -1
  64. package/mobile/dist/ui-kit/FormField/Fields/AddressRetailField.js.map +1 -1
  65. package/mobile/dist/ui-kit/FormField/Fields/CardCategoryField.js +11 -3
  66. package/mobile/dist/ui-kit/FormField/Fields/CardCategoryField.js.map +1 -1
  67. package/mobile/dist/ui-kit/FormField/Fields/PaymentSystemField.d.ts +0 -2
  68. package/mobile/dist/ui-kit/FormField/Fields/PaymentSystemField.js +11 -6
  69. package/mobile/dist/ui-kit/FormField/Fields/PaymentSystemField.js.map +1 -1
  70. package/mobile/dist/ui-kit/YandexMap/YandexMap.d.ts +1 -0
  71. package/mobile/dist/ui-kit/YandexMap/YandexMap.js +11 -2
  72. package/mobile/dist/ui-kit/YandexMap/YandexMap.js.map +1 -1
  73. package/mobile/lib/api/RetailAPI/doRequest.js +1 -1
  74. package/mobile/lib/api/RetailAPI/doRequest.js.map +1 -1
  75. package/mobile/lib/api/RetailAPI/getCardTypes.d.ts +8 -0
  76. package/mobile/lib/api/RetailAPI/getCardTypes.js +10 -0
  77. package/mobile/lib/api/RetailAPI/getCardTypes.js.map +1 -0
  78. package/mobile/lib/api/RetailAPI/getPaymentSystems.d.ts +4 -0
  79. package/mobile/lib/api/RetailAPI/getPaymentSystems.js +12 -0
  80. package/mobile/lib/api/RetailAPI/getPaymentSystems.js.map +1 -0
  81. package/mobile/lib/components/CreditCardForm/formStateMap.js +1 -2
  82. package/mobile/lib/components/CreditCardForm/formStateMap.js.map +1 -1
  83. package/mobile/lib/ui-kit/FormField/Fields/AddressRetailField.js +1 -1
  84. package/mobile/lib/ui-kit/FormField/Fields/AddressRetailField.js.map +1 -1
  85. package/mobile/lib/ui-kit/FormField/Fields/CardCategoryField.js +11 -3
  86. package/mobile/lib/ui-kit/FormField/Fields/CardCategoryField.js.map +1 -1
  87. package/mobile/lib/ui-kit/FormField/Fields/PaymentSystemField.d.ts +0 -2
  88. package/mobile/lib/ui-kit/FormField/Fields/PaymentSystemField.js +10 -5
  89. package/mobile/lib/ui-kit/FormField/Fields/PaymentSystemField.js.map +1 -1
  90. package/mobile/lib/ui-kit/YandexMap/YandexMap.d.ts +1 -0
  91. package/mobile/lib/ui-kit/YandexMap/YandexMap.js +11 -2
  92. package/mobile/lib/ui-kit/YandexMap/YandexMap.js.map +1 -1
  93. package/mobile/src/api/RetailAPI/doRequest.ts +1 -1
  94. package/mobile/src/api/RetailAPI/getCardTypes.ts +20 -0
  95. package/mobile/src/api/RetailAPI/getPaymentSystems.ts +21 -0
  96. package/mobile/src/components/CreditCardForm/formStateMap.tsx +1 -2
  97. package/mobile/src/ui-kit/FormField/Fields/AddressRetailField.tsx +6 -1
  98. package/mobile/src/ui-kit/FormField/Fields/CardCategoryField.tsx +12 -3
  99. package/mobile/src/ui-kit/FormField/Fields/PaymentSystemField.tsx +12 -6
  100. package/mobile/src/ui-kit/YandexMap/YandexMap.tsx +58 -45
  101. package/package.json +1 -1
  102. package/src/api/RetailAPI/doRequest.ts +1 -1
  103. package/src/api/RetailAPI/getCardTypes.ts +20 -0
  104. package/src/api/RetailAPI/getPaymentSystems.ts +21 -0
  105. package/src/components/CreditCardForm/formStateMap.tsx +1 -2
  106. package/src/ui-kit/FormField/Fields/AddressRetailField.tsx +6 -1
  107. package/src/ui-kit/FormField/Fields/CardCategoryField.tsx +12 -3
  108. package/src/ui-kit/FormField/Fields/PaymentSystemField.tsx +12 -6
  109. package/src/ui-kit/YandexMap/YandexMap.tsx +58 -45
@@ -1,15 +1,24 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useLeadFormData } from '../../../hooks/useLeadFormData';
2
+ import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { getCardTypes, type CardTypeData } from '../../../api/RetailAPI/getCardTypes';
3
4
  import { type CustomFieldProps } from '../CustomFieldProps';
4
5
  import { SelectField } from '../SelectField';
5
6
 
6
7
  export const CardCategoryField = JSX<CustomFieldProps>(({ field, input }) => {
7
- const { data: cardCategory } = useLeadFormData('CARD_TYPE');
8
+ const [cardTypes, setCardTypes] = useState<CardTypeData[]>([]);
9
+ const selectedPaymentSystem = field('paymentSystem').value;
10
+
11
+ useEffect(() => {
12
+ (async () => {
13
+ const fetchedCardTypes = await getCardTypes(selectedPaymentSystem as string);
14
+ setCardTypes(fetchedCardTypes);
15
+ })();
16
+ }, [selectedPaymentSystem]);
8
17
 
9
18
  return (
10
19
  <SelectField
11
20
  field={field}
12
- source={cardCategory}
21
+ source={cardTypes}
13
22
  label="Категория карты"
14
23
  fieldName="cardCategory"
15
24
  input={input}
@@ -1,23 +1,29 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
+ import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { getPaymentSystems } from '../../../api/RetailAPI/getPaymentSystems';
2
4
  import { type RadioButtonItem } from '../../RadioButtonGroup/RadioButtonGroup';
3
5
  import { RadioButtonGroupControl } from '../../RadioButtonGroup/RadioButtonGroupControl';
4
6
  import { type CustomFieldProps } from '../CustomFieldProps';
5
7
  import { validatorObj } from '../getObjectValidator';
6
8
  import { getValidation } from '../getValidation';
7
9
 
8
- export const PAYMENT_SYSTEM_TYPES: RadioButtonItem[] = [
9
- { id: 'mir', text: 'Карта МИР' },
10
- { id: 'union_pay', text: 'UnionPay' },
11
- ];
12
-
13
10
  export const PaymentSystemField = JSX<CustomFieldProps>(({ field, input }) => {
14
11
  const { value, onChange } = field('paymentSystem');
15
12
 
13
+ const [paymentSystemOptions, setPaymentSystemOptions] = useState<RadioButtonItem[]>([]);
14
+
15
+ useEffect(() => {
16
+ (async () => {
17
+ const fetchedPaymentSystems = await getPaymentSystems();
18
+ setPaymentSystemOptions(fetchedPaymentSystems || []);
19
+ })();
20
+ }, []);
21
+
16
22
  return (
17
23
  <RadioButtonGroupControl
18
24
  label="Платежная система"
19
25
  orientation="horizontal"
20
- items={PAYMENT_SYSTEM_TYPES}
26
+ items={paymentSystemOptions}
21
27
  value={value}
22
28
  onChange={(_) => onChange?.(_)}
23
29
  {...getValidation(field('paymentSystem'), validatorObj.paymentSystem, input?.required)}
@@ -16,6 +16,7 @@ interface YandexMapProps {
16
16
  className?: string;
17
17
  zoom?: number;
18
18
  isLoad?: boolean;
19
+ selectedAddress?: string;
19
20
  }
20
21
 
21
22
  export const DEFAULT_CENTER_COORDS = [55.753995, 37.614069];
@@ -24,59 +25,71 @@ export const DEFAULT_CENTER_COORDS = [55.753995, 37.614069];
24
25
  // Сейчас реализован поиск среди тестовых данных
25
26
  // TODO: Также выяснить что делать когда ничего не найдено
26
27
  // TODO: На макетах также когда есть поле поиска нет кнопки открыть на карте.
27
- export const YandexMap = JSX<YandexMapProps>(({ points, className = '', zoom = 5, isLoad }) => {
28
- const map = useRef<ymaps.Map | null>(null);
28
+ export const YandexMap = JSX<YandexMapProps>(
29
+ ({ points, className = '', zoom = 5, isLoad, selectedAddress }) => {
30
+ const map = useRef<ymaps.Map | null>(null);
29
31
 
30
- const parentDiv = useRef<HTMLElement>(null);
32
+ const parentDiv = useRef<HTMLElement>(null);
31
33
 
32
- const yandexMaps = useYandexMaps();
34
+ const yandexMaps = useYandexMaps();
33
35
 
34
- useEffect(() => {
35
- if (map.current) {
36
- renderClusterer({ yandexMaps, map: map.current, points, isLoad });
37
- } else {
38
- yandexMaps?.ready(() => {
39
- // Ready function may be called few times, but must be called once
40
- if (map.current) {
41
- renderClusterer({ yandexMaps, map: map.current, points, isLoad });
42
-
43
- return;
44
- }
36
+ useEffect(() => {
37
+ if (map.current) {
38
+ renderClusterer({ yandexMaps, map: map.current, points, isLoad });
39
+ } else {
40
+ yandexMaps?.ready(() => {
41
+ // Ready function may be called few times, but must be called once
42
+ if (map.current) {
43
+ renderClusterer({ yandexMaps, map: map.current, points, isLoad });
44
+
45
+ return;
46
+ }
47
+
48
+ map.current = new yandexMaps.Map(parentDiv.current, {
49
+ center: getCenterPoint(points),
50
+ zoom,
51
+ controls: [],
52
+ suppressMapOpenBlock: true,
53
+ });
45
54
 
46
- map.current = new yandexMaps.Map(parentDiv.current, {
47
- center: getCenterPoint(points),
48
- zoom,
49
- controls: [],
50
- suppressMapOpenBlock: true,
55
+ renderClusterer({ yandexMaps, map: map.current, points, isLoad });
51
56
  });
57
+ }
58
+
59
+ // zoom к выбранному отделению банка в рамках задачи по retail
60
+ if (map.current && selectedAddress) {
61
+ yandexMaps?.geocode(selectedAddress).then((res) => {
62
+ const firstGeoObject = res.geoObjects.get(0);
63
+ const coords = firstGeoObject.geometry.getCoordinates() as number[];
64
+ map.current.setCenter(coords);
65
+ map.current.setZoom(18);
66
+ });
67
+ }
68
+ }, [yandexMaps, points, zoom, isLoad, selectedAddress]);
52
69
 
53
- renderClusterer({ yandexMaps, map: map.current, points, isLoad });
54
- });
70
+ if (!yandexMaps) {
71
+ return null;
55
72
  }
56
- }, [yandexMaps, points, zoom, isLoad]);
57
-
58
- if (!yandexMaps) {
59
- return null;
60
- }
61
-
62
- const zIndex = 'z-10';
63
-
64
- return (
65
- <div ref={parentDiv} className={style('relative', 'w-full', className)}>
66
- {isLoad ? <Loader /> : null}
67
- <div
68
- className={style(
69
- 'absolute right-2 top-52 z-10 w-12 overflow-hidden border border-transparent rounded-md',
70
- zIndex,
71
- )}
72
- >
73
- <ZoomButton yandexMaps={map} />
74
- <ZoomButton yandexMaps={map} direction="out" />
73
+
74
+ const zIndex = 'z-10';
75
+
76
+ return (
77
+ <div ref={parentDiv} className={style('relative', 'w-full', className)}>
78
+ {isLoad ? <Loader /> : null}
79
+ <div
80
+ className={style(
81
+ 'absolute right-2 top-52 z-10 w-12 overflow-hidden border border-transparent rounded-md',
82
+ zIndex,
83
+ )}
84
+ >
85
+ <ZoomButton yandexMaps={map} />
86
+ <ZoomButton yandexMaps={map} direction="out" />
87
+ </div>
88
+ {renderUserGeolocation(map, yandexMaps, style('right-2 top-80', zIndex))}
75
89
  </div>
76
- {renderUserGeolocation(map, yandexMaps, style('right-2 top-80', zIndex))}
77
- </div>
78
- );
79
- });
90
+ );
91
+ },
92
+ );
80
93
 
81
94
  const getCenterPoint = (points?: BalloonPoints[]) => {
82
95
  const centerCoords = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redneckz/wildless-cms-uni-blocks",
3
- "version": "0.14.671",
3
+ "version": "0.14.673",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "ЦК",
@@ -21,7 +21,7 @@ export async function doRequest(
21
21
  method: 'POST' | 'GET' | 'PUT',
22
22
  body?: any,
23
23
  ): Promise<Response> {
24
- return await fetch(`${API_BASE_URI}${url}`, {
24
+ return globalThis?.fetch?.(`${API_BASE_URI}${url}`, {
25
25
  method,
26
26
  headers: {
27
27
  'Content-Type': 'application/json',
@@ -0,0 +1,20 @@
1
+ import { doRequest } from './doRequest';
2
+
3
+ export type CardTypeData = {
4
+ type: string;
5
+ key: string;
6
+ value: string;
7
+ displayOrder: number;
8
+ description: string;
9
+ };
10
+
11
+ export const getCardTypes = async (paymentSystemType: string) => {
12
+ const response: Response = await doRequest('/dictionaryFiltered', 'POST', {
13
+ type: 'CARD_TYPE',
14
+ presets: { paymentSystemType, creditProgramId: 13 },
15
+ });
16
+
17
+ const data: CardTypeData[] = await response?.json();
18
+
19
+ return data;
20
+ };
@@ -0,0 +1,21 @@
1
+ import { doRequest } from './doRequest';
2
+
3
+ type PaymentSystemResponse = {
4
+ paymentSystems?: {
5
+ name: string;
6
+ type: string;
7
+ }[];
8
+ };
9
+
10
+ export const getPaymentSystems = async () => {
11
+ const response: Response = await doRequest('/public-data/creditProgramConditions', 'POST', {
12
+ creditProgramId: 13,
13
+ });
14
+
15
+ const data: PaymentSystemResponse = await response?.json();
16
+
17
+ return data?.paymentSystems?.map((paymentSystem) => ({
18
+ id: paymentSystem.type,
19
+ text: paymentSystem.name,
20
+ }));
21
+ };
@@ -1,9 +1,8 @@
1
- import { PAYMENT_SYSTEM_TYPES } from '../../ui-kit/FormField/Fields/PaymentSystemField';
2
1
  import { type FormState } from '../ApplicationLeadForm/getInitialFormState';
3
2
 
4
3
  export const formStateMap: Partial<FormState>[] = [
5
4
  {
6
- paymentSystem: PAYMENT_SYSTEM_TYPES[0].id,
5
+ paymentSystem: '',
7
6
  currency: 'rub',
8
7
  codeWord: '',
9
8
  },
@@ -56,7 +56,12 @@ export const AddressRetailField = JSX<CustomFieldProps>(({ field, input }) => {
56
56
  />
57
57
  <div className="h-[600px]">
58
58
  <ClientOnly>
59
- <YandexMap points={points} isLoad={!data} className="h-full" />
59
+ <YandexMap
60
+ points={points}
61
+ isLoad={!data}
62
+ className="h-full"
63
+ selectedAddress={fieldBranch?.value?.text}
64
+ />
60
65
  </ClientOnly>
61
66
  </div>
62
67
  </div>
@@ -1,15 +1,24 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
- import { useLeadFormData } from '../../../hooks/useLeadFormData';
2
+ import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { getCardTypes, type CardTypeData } from '../../../api/RetailAPI/getCardTypes';
3
4
  import { type CustomFieldProps } from '../CustomFieldProps';
4
5
  import { SelectField } from '../SelectField';
5
6
 
6
7
  export const CardCategoryField = JSX<CustomFieldProps>(({ field, input }) => {
7
- const { data: cardCategory } = useLeadFormData('CARD_TYPE');
8
+ const [cardTypes, setCardTypes] = useState<CardTypeData[]>([]);
9
+ const selectedPaymentSystem = field('paymentSystem').value;
10
+
11
+ useEffect(() => {
12
+ (async () => {
13
+ const fetchedCardTypes = await getCardTypes(selectedPaymentSystem as string);
14
+ setCardTypes(fetchedCardTypes);
15
+ })();
16
+ }, [selectedPaymentSystem]);
8
17
 
9
18
  return (
10
19
  <SelectField
11
20
  field={field}
12
- source={cardCategory}
21
+ source={cardTypes}
13
22
  label="Категория карты"
14
23
  fieldName="cardCategory"
15
24
  input={input}
@@ -1,23 +1,29 @@
1
1
  import { JSX } from '@redneckz/uni-jsx';
2
+ import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
3
+ import { getPaymentSystems } from '../../../api/RetailAPI/getPaymentSystems';
2
4
  import { type RadioButtonItem } from '../../RadioButtonGroup/RadioButtonGroup';
3
5
  import { RadioButtonGroupControl } from '../../RadioButtonGroup/RadioButtonGroupControl';
4
6
  import { type CustomFieldProps } from '../CustomFieldProps';
5
7
  import { validatorObj } from '../getObjectValidator';
6
8
  import { getValidation } from '../getValidation';
7
9
 
8
- export const PAYMENT_SYSTEM_TYPES: RadioButtonItem[] = [
9
- { id: 'mir', text: 'Карта МИР' },
10
- { id: 'union_pay', text: 'UnionPay' },
11
- ];
12
-
13
10
  export const PaymentSystemField = JSX<CustomFieldProps>(({ field, input }) => {
14
11
  const { value, onChange } = field('paymentSystem');
15
12
 
13
+ const [paymentSystemOptions, setPaymentSystemOptions] = useState<RadioButtonItem[]>([]);
14
+
15
+ useEffect(() => {
16
+ (async () => {
17
+ const fetchedPaymentSystems = await getPaymentSystems();
18
+ setPaymentSystemOptions(fetchedPaymentSystems || []);
19
+ })();
20
+ }, []);
21
+
16
22
  return (
17
23
  <RadioButtonGroupControl
18
24
  label="Платежная система"
19
25
  orientation="horizontal"
20
- items={PAYMENT_SYSTEM_TYPES}
26
+ items={paymentSystemOptions}
21
27
  value={value}
22
28
  onChange={(_) => onChange?.(_)}
23
29
  {...getValidation(field('paymentSystem'), validatorObj.paymentSystem, input?.required)}
@@ -16,6 +16,7 @@ interface YandexMapProps {
16
16
  className?: string;
17
17
  zoom?: number;
18
18
  isLoad?: boolean;
19
+ selectedAddress?: string;
19
20
  }
20
21
 
21
22
  export const DEFAULT_CENTER_COORDS = [55.753995, 37.614069];
@@ -24,59 +25,71 @@ export const DEFAULT_CENTER_COORDS = [55.753995, 37.614069];
24
25
  // Сейчас реализован поиск среди тестовых данных
25
26
  // TODO: Также выяснить что делать когда ничего не найдено
26
27
  // TODO: На макетах также когда есть поле поиска нет кнопки открыть на карте.
27
- export const YandexMap = JSX<YandexMapProps>(({ points, className = '', zoom = 5, isLoad }) => {
28
- const map = useRef<ymaps.Map | null>(null);
28
+ export const YandexMap = JSX<YandexMapProps>(
29
+ ({ points, className = '', zoom = 5, isLoad, selectedAddress }) => {
30
+ const map = useRef<ymaps.Map | null>(null);
29
31
 
30
- const parentDiv = useRef<HTMLElement>(null);
32
+ const parentDiv = useRef<HTMLElement>(null);
31
33
 
32
- const yandexMaps = useYandexMaps();
34
+ const yandexMaps = useYandexMaps();
33
35
 
34
- useEffect(() => {
35
- if (map.current) {
36
- renderClusterer({ yandexMaps, map: map.current, points, isLoad });
37
- } else {
38
- yandexMaps?.ready(() => {
39
- // Ready function may be called few times, but must be called once
40
- if (map.current) {
41
- renderClusterer({ yandexMaps, map: map.current, points, isLoad });
42
-
43
- return;
44
- }
36
+ useEffect(() => {
37
+ if (map.current) {
38
+ renderClusterer({ yandexMaps, map: map.current, points, isLoad });
39
+ } else {
40
+ yandexMaps?.ready(() => {
41
+ // Ready function may be called few times, but must be called once
42
+ if (map.current) {
43
+ renderClusterer({ yandexMaps, map: map.current, points, isLoad });
44
+
45
+ return;
46
+ }
47
+
48
+ map.current = new yandexMaps.Map(parentDiv.current, {
49
+ center: getCenterPoint(points),
50
+ zoom,
51
+ controls: [],
52
+ suppressMapOpenBlock: true,
53
+ });
45
54
 
46
- map.current = new yandexMaps.Map(parentDiv.current, {
47
- center: getCenterPoint(points),
48
- zoom,
49
- controls: [],
50
- suppressMapOpenBlock: true,
55
+ renderClusterer({ yandexMaps, map: map.current, points, isLoad });
51
56
  });
57
+ }
58
+
59
+ // zoom к выбранному отделению банка в рамках задачи по retail
60
+ if (map.current && selectedAddress) {
61
+ yandexMaps?.geocode(selectedAddress).then((res) => {
62
+ const firstGeoObject = res.geoObjects.get(0);
63
+ const coords = firstGeoObject.geometry.getCoordinates() as number[];
64
+ map.current.setCenter(coords);
65
+ map.current.setZoom(18);
66
+ });
67
+ }
68
+ }, [yandexMaps, points, zoom, isLoad, selectedAddress]);
52
69
 
53
- renderClusterer({ yandexMaps, map: map.current, points, isLoad });
54
- });
70
+ if (!yandexMaps) {
71
+ return null;
55
72
  }
56
- }, [yandexMaps, points, zoom, isLoad]);
57
-
58
- if (!yandexMaps) {
59
- return null;
60
- }
61
-
62
- const zIndex = 'z-10';
63
-
64
- return (
65
- <div ref={parentDiv} className={style('relative', 'w-full', className)}>
66
- {isLoad ? <Loader /> : null}
67
- <div
68
- className={style(
69
- 'absolute right-2 top-52 z-10 w-12 overflow-hidden border border-transparent rounded-md',
70
- zIndex,
71
- )}
72
- >
73
- <ZoomButton yandexMaps={map} />
74
- <ZoomButton yandexMaps={map} direction="out" />
73
+
74
+ const zIndex = 'z-10';
75
+
76
+ return (
77
+ <div ref={parentDiv} className={style('relative', 'w-full', className)}>
78
+ {isLoad ? <Loader /> : null}
79
+ <div
80
+ className={style(
81
+ 'absolute right-2 top-52 z-10 w-12 overflow-hidden border border-transparent rounded-md',
82
+ zIndex,
83
+ )}
84
+ >
85
+ <ZoomButton yandexMaps={map} />
86
+ <ZoomButton yandexMaps={map} direction="out" />
87
+ </div>
88
+ {renderUserGeolocation(map, yandexMaps, style('right-2 top-80', zIndex))}
75
89
  </div>
76
- {renderUserGeolocation(map, yandexMaps, style('right-2 top-80', zIndex))}
77
- </div>
78
- );
79
- });
90
+ );
91
+ },
92
+ );
80
93
 
81
94
  const getCenterPoint = (points?: BalloonPoints[]) => {
82
95
  const centerCoords = [