Skip to content

Commit

Permalink
feat(party): kazakhstan parties suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybaev committed Dec 29, 2024
1 parent 09a5652 commit d5ef5f8
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 6 deletions.
29 changes: 27 additions & 2 deletions packages/example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React, { useState } from 'react';
import './App.css';
import 'react-dadata/src/react-dadata.css';
import { AddressSuggestions, PartyBelarusSuggestions, PartySuggestions } from '../../react-dadata/src';
import {
AddressSuggestions,
PartyBelarusSuggestions,
PartyKazakhstanSuggestions,
PartySuggestions,
} from '../../react-dadata/src';

const DADATA_TOKEN = '3c2e964517d7358776e07d7d699cc2b0626dac54';

Expand All @@ -10,7 +15,9 @@ function App() {
return <div className="App">Пожалуйста, установите ваш API токен для DaData в `example/src/App.tsx:5`</div>;
}

const [suggestionsType, setSuggestionsType] = useState<'address' | 'party_russia' | 'party_belarus'>('address');
const [suggestionsType, setSuggestionsType] = useState<
'address' | 'party_russia' | 'party_belarus' | 'party_kazakhstan'
>('address');

return (
<div className="App">
Expand Down Expand Up @@ -48,6 +55,17 @@ function App() {
/>
<label htmlFor="suggestionsType-party_belarus">Компании в Беларуси 🇧🇾</label>
</div>
<div>
<input
id="suggestionsType-party_kazakhstan"
type="radio"
name="suggestionsType"
value="party_kazakhstan"
checked={suggestionsType === 'party_kazakhstan'}
onChange={() => setSuggestionsType('party_kazakhstan')}
/>
<label htmlFor="suggestionsType-party_kazakhstan">Компании в Казахстане 🇰🇿</label>
</div>
</div>
{suggestionsType === 'address' && (
<AddressSuggestions token={DADATA_TOKEN} inputProps={{ placeholder: 'Введите адрес...' }} selectOnBlur />
Expand All @@ -66,6 +84,13 @@ function App() {
selectOnBlur
/>
)}
{suggestionsType === 'party_kazakhstan' && (
<PartyKazakhstanSuggestions
token={DADATA_TOKEN}
inputProps={{ placeholder: '🇰🇿 Введите название компании, БИН' }}
selectOnBlur
/>
)}
</div>
);
}
Expand Down
22 changes: 20 additions & 2 deletions packages/react-dadata/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const [value, setValue] = useState();
<PartySuggestions token="API_KEY" value={value} onChange={setValue} />;
```

#### Дополнительные параметры для компонента организаций
#### Дополнительные параметры для компонента организаций в России

| Свойство | Обязательный | Тип | Описание |
|----------------------|--------------|-----------|----------------------------------------------------------------|
Expand All @@ -198,13 +198,31 @@ const [value, setValue] = useState();
<PartyBelarusSuggestions token="API_KEY" value={value} onChange={setValue} />;
```

#### Дополнительные параметры для компонента организаций
#### Дополнительные параметры для компонента организаций в Беларуси

| Свойство | Обязательный | Тип | Описание |
|----------------------|--------------|-----------|----------------------------------------------------------------|
| filterStatus | Нет | `DaDataPartyBelarusStatus[]` | Фильтр по статусу организации, параметр status в запросе |
| filterType | Нет | `DaDataPartyType[]` | Фильтр по типу организации, параметр type в запросе |

### Организации в Казахстане 🇰🇿

```jsx
import { PartyKazakhstanSuggestions } from 'react-dadata';
import 'react-dadata/dist/react-dadata.css';

const [value, setValue] = useState();

<PartyKazakhstanSuggestions token="API_KEY" value={value} onChange={setValue} />;
```

#### Дополнительные параметры для компонента организаций в Казахстане

| Свойство | Обязательный | Тип | Описание |
|----------------------|--------------|-----------|----------------------------------------------------------------|
| filterType | Нет | `DaDataPartyKazakhstanType[]` | Фильтр по типу организации, параметр type в запросе |


### Банки

```jsx
Expand Down
12 changes: 12 additions & 0 deletions packages/react-dadata/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ import type {
DaDataSuggestion,
} from './types';
import { PartyBelarusSuggestions } from './variants/party_belarus/party-belarus';
import { PartyKazakhstanSuggestions } from './variants/party_kazakhstan/party-kazakhstan';
import type {
DaDataPartyKazakhstan,
DaDataPartyKazakhstanStatus,
DaDataPartyKazakhstanType,
} from './variants/party_kazakhstan/party-kazakhstan-types';

type DaDataAddressSuggestion = DaDataSuggestion<DaDataAddress>;
type DaDataPartySuggestion = DaDataSuggestion<DaDataParty>;
type DaDataPartyRussiaSuggestion = DaDataSuggestion<DaDataPartyRussia>;
type DaDataPartyBelarusSuggestion = DaDataSuggestion<DaDataPartyBelarus>;
type DaDataPartyKazakhstanSuggestion = DaDataSuggestion<DaDataPartyKazakhstan>;
type DaDataBankSuggestion = DaDataSuggestion<DaDataBank>;
type DaDataFioSuggestion = DaDataSuggestion<DaDataFio>;
type DaDataEmailSuggestion = DaDataSuggestion<DaDataEmail>;
Expand All @@ -37,6 +44,7 @@ export {
AddressSuggestions,
PartySuggestions,
PartyBelarusSuggestions,
PartyKazakhstanSuggestions,
BankSuggestions,
FioSuggestions,
EmailSuggestions,
Expand All @@ -46,6 +54,7 @@ export {
type DaDataPartySuggestion,
type DaDataPartyRussiaSuggestion,
type DaDataPartyBelarusSuggestion,
type DaDataPartyKazakhstanSuggestion,
type DaDataAddressBounds,
type DaDataPartyType,
type DaDataPartyRussia,
Expand All @@ -54,6 +63,9 @@ export {
type DaDataPartyStatus,
type DaDataPartyBelarus,
type DaDataPartyBelarusStatus,
type DaDataPartyKazakhstan,
type DaDataPartyKazakhstanStatus,
type DaDataPartyKazakhstanType,
type DaDataBank,
type DaDataBankStatus,
type DaDataBankType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Типы для подсказок по компаниям в Казахстане 🇰🇿
*/

export type DaDataPartyKazakhstanStatus = 'ACTIVE' | 'INACTIVE' | 'LIQUIDATING' | 'LIQUIDATED' | 'SUSPENDED';

export type DaDataPartyKazakhstanType =
| 'LEGAL'
| 'BRANCH'
| 'INDIVIDUAL'
| 'INDIVIDUAL_JOINT_VENTURE'
| 'FOREIGN_BRANCH';

export interface DaDataPartyKazakhstan {
bin: string;
registration_date: string;
status: DaDataPartyKazakhstanStatus;
type: DaDataPartyKazakhstanType;
name_ru: string;
name_kz: string;
fio: string;
kato: string;
address_ru: string;
address_kz: string;
address_settlement_ru: string;
address_settlement_kz: string;
address_local: string;
oked: string;
oked_name_ru: string;
oked_name_kz: string;
krp: string;
krp_name_ru: string;
krp_name_kz: string;
kse: string;
kse_name_ru: string;
kse_name_kz: string;
kfs: string;
kfs_name_ru: string;
kfs_name_kz: string;
}

type DaDataPartyKazakhstanRequestFilterItem = { type: DaDataPartyKazakhstanType };

export interface DaDataPartyKazakhstanRequestPayload extends Record<string, unknown> {
query: string;
count: number;
filters?: DaDataPartyKazakhstanRequestFilterItem[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { type ReactNode } from 'react';
import { type BaseProps, BaseSuggestions } from '../../BaseSuggestions';
import { HighlightWords } from '../../HighlightWords';
import type { DaDataSuggestion } from '../../types';
import type {
DaDataPartyKazakhstan,
DaDataPartyKazakhstanRequestPayload,
DaDataPartyKazakhstanType,
} from './party-kazakhstan-types';

interface Props extends BaseProps<DaDataPartyKazakhstan> {
filterType?: DaDataPartyKazakhstanType[];
}

export class PartyKazakhstanSuggestions extends BaseSuggestions<
DaDataPartyKazakhstan,
Props,
DaDataPartyKazakhstanRequestPayload
> {
loadSuggestionsUrl = 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party_kz';

/**
* Структура запроса для подсказок по организациям в Казахстане 🇰🇿
* @see https://dadata.ru/api/suggest/party_kz/
*/
getLoadSuggestionsData = () => {
const { count, filterType } = this.props;
const { query } = this.state;

const requestPayload: DaDataPartyKazakhstanRequestPayload = {
query,
count: count || 10,
filters: [],
};

// Ограничение по типу организации
if (filterType) {
for (let i = 0; i < filterType.length; i++) {
requestPayload.filters?.push({
type: filterType[i],
});
}
}

return requestPayload;
};

// В России ИНН допускает коллизии, и там существует свойство hid
// В Беларуси такого свойства нет, поэтому используем БИН + name_kz + registration_date
protected getSuggestionKey = (suggestion: DaDataSuggestion<DaDataPartyKazakhstan>): string =>
suggestion.data.bin + suggestion.data.name_kz + suggestion.data.registration_date;

protected renderOption = (suggestion: DaDataSuggestion<DaDataPartyKazakhstan>): ReactNode => {
const { renderOption, highlightClassName } = this.props;
const { query } = this.state;

return renderOption ? (
renderOption(suggestion, query)
) : (
<div>
<div className={suggestion.data.status === 'LIQUIDATED' ? 'react-dadata__suggestion--line-through' : undefined}>
<HighlightWords
highlightClassName={highlightClassName || 'react-dadata--highlighted'}
words={this.getHighlightWords()}
text={suggestion.value}
/>
</div>
<div className="react-dadata__suggestion-subtitle">
{suggestion.data.address_ru && (
<div className="react-dadata__suggestion-subtitle-item">
<HighlightWords
highlightClassName={highlightClassName || 'react-dadata--highlighted'}
words={this.getHighlightWords()}
text={suggestion.data.address_ru}
/>
</div>
)}
</div>
</div>
);
};
}
22 changes: 20 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const [value, setValue] = useState();
<PartySuggestions token="API_KEY" value={value} onChange={setValue} />;
```

#### Дополнительные параметры для компонента организаций
#### Дополнительные параметры для компонента организаций в России

| Свойство | Обязательный | Тип | Описание |
|----------------------|--------------|-----------|----------------------------------------------------------------|
Expand All @@ -198,13 +198,31 @@ const [value, setValue] = useState();
<PartyBelarusSuggestions token="API_KEY" value={value} onChange={setValue} />;
```

#### Дополнительные параметры для компонента организаций
#### Дополнительные параметры для компонента организаций в Беларуси

| Свойство | Обязательный | Тип | Описание |
|----------------------|--------------|-----------|----------------------------------------------------------------|
| filterStatus | Нет | `DaDataPartyBelarusStatus[]` | Фильтр по статусу организации, параметр status в запросе |
| filterType | Нет | `DaDataPartyType[]` | Фильтр по типу организации, параметр type в запросе |

### Организации в Казахстане 🇰🇿

```jsx
import { PartyKazakhstanSuggestions } from 'react-dadata';
import 'react-dadata/dist/react-dadata.css';

const [value, setValue] = useState();

<PartyKazakhstanSuggestions token="API_KEY" value={value} onChange={setValue} />;
```

#### Дополнительные параметры для компонента организаций в Казахстане

| Свойство | Обязательный | Тип | Описание |
|----------------------|--------------|-----------|----------------------------------------------------------------|
| filterType | Нет | `DaDataPartyKazakhstanType[]` | Фильтр по типу организации, параметр type в запросе |


### Банки

```jsx
Expand Down

0 comments on commit d5ef5f8

Please sign in to comment.