-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(party): kazakhstan parties suggestions
- Loading branch information
1 parent
09a5652
commit d5ef5f8
Showing
6 changed files
with
209 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/react-dadata/src/variants/party_kazakhstan/party-kazakhstan-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]; | ||
} |
82 changes: 82 additions & 0 deletions
82
packages/react-dadata/src/variants/party_kazakhstan/party-kazakhstan.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters