react-dadata
Version:
React-компонент для подсказок адресов, организаций и банков с помощью сервиса DaData.ru
74 lines (73 loc) • 4.26 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import React from 'react';
import { BaseSuggestions } from '../../base-suggestions';
import { HighlightWords } from '../../highlight-words';
var PartyBelarusSuggestions = /** @class */ (function (_super) {
__extends(PartyBelarusSuggestions, _super);
function PartyBelarusSuggestions() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.loadSuggestionsUrl = 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party_by';
/**
* Структура запроса для подсказок по организациям в Беларуси 🇧🇾
* @see https://dadata.ru/api/suggest/party_by/
*/
_this.getLoadSuggestionsData = function () {
var _a, _b;
var _c = _this.props, count = _c.count, filterStatus = _c.filterStatus, filterType = _c.filterType;
var query = _this.state.query;
var requestPayload = {
query: query,
count: count || 10,
filters: [],
};
// Ограничение по статусу организации
if (filterStatus) {
for (var i = 0; i < filterStatus.length; i++) {
(_a = requestPayload.filters) === null || _a === void 0 ? void 0 : _a.push({
status: filterStatus[i],
});
}
}
// Ограничение по типу организации
if (filterType) {
for (var i = 0; i < filterType.length; i++) {
(_b = requestPayload.filters) === null || _b === void 0 ? void 0 : _b.push({
type: filterType[i],
});
}
}
return requestPayload;
};
// В России ИНН допускает коллизии, и там существует свойство hid
// В Беларуси такого свойства нет, поэтому используем UNP + full_name_by + registration_date
_this.getSuggestionKey = function (suggestion) {
return suggestion.data.unp + suggestion.data.full_name_by + suggestion.data.registration_date;
};
_this.renderOption = function (suggestion) {
var _a = _this.props, renderOption = _a.renderOption, highlightClassName = _a.highlightClassName;
var query = _this.state.query;
return renderOption ? (renderOption(suggestion, query)) : (React.createElement("div", null,
React.createElement("div", { className: suggestion.data.status === 'LIQUIDATED' ? 'react-dadata__suggestion--line-through' : undefined },
React.createElement(HighlightWords, { highlightClassName: highlightClassName || 'react-dadata--highlighted', words: _this.getHighlightWords(), text: suggestion.value })),
React.createElement("div", { className: "react-dadata__suggestion-subtitle" }, suggestion.data.address && (React.createElement("div", { className: "react-dadata__suggestion-subtitle-item" },
React.createElement(HighlightWords, { highlightClassName: highlightClassName || 'react-dadata--highlighted', words: _this.getHighlightWords(), text: suggestion.data.address }))))));
};
return _this;
}
return PartyBelarusSuggestions;
}(BaseSuggestions));
export { PartyBelarusSuggestions };