kui-crm 0.0.87 → 0.0.88

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/cjs/index.js CHANGED
@@ -364,7 +364,7 @@ var CitiesStore = /** @class */ (function () {
364
364
  return CitiesStore;
365
365
  }());
366
366
 
367
- var useAutocomplete = function (filter, paginator, fetchAll, defaultFilter, withoutRequest) {
367
+ var useAutocomplete = function (filter, paginator, fetchAll, isOpen, defaultFilter, withoutRequest) {
368
368
  React.useEffect(function () {
369
369
  if (defaultFilter)
370
370
  filter.updateFilterQuery(defaultFilter);
@@ -373,10 +373,13 @@ var useAutocomplete = function (filter, paginator, fetchAll, defaultFilter, with
373
373
  paginator.startFetching();
374
374
  }, []);
375
375
  React.useEffect(function () {
376
- if (paginator.isFetching && !paginator.isFinishPage && !withoutRequest) {
376
+ if (paginator.isFetching &&
377
+ !paginator.isFinishPage &&
378
+ !withoutRequest &&
379
+ isOpen) {
377
380
  fetchAll();
378
381
  }
379
- }, [fetchAll, paginator.isFetching]);
382
+ }, [fetchAll, paginator.isFetching, isOpen]);
380
383
  kuiUtils.useDebounce(filter.searchQuery, 500, function () {
381
384
  paginator.clearOffset();
382
385
  paginator.startFetching();
@@ -401,17 +404,18 @@ var useAutocomplete = function (filter, paginator, fetchAll, defaultFilter, with
401
404
  };
402
405
 
403
406
  function CityAutocomplete(props) {
407
+ var _a = React.useState(false), isOpen = _a[0], setIsOpen = _a[1];
404
408
  var form = props.form, name = props.name, label = props.label, onSelect = props.onSelect, regionName = props.regionName, otherProps = __rest(props, ["form", "name", "label", "onSelect", "regionName"]);
405
409
  var citiesStoreRef = React.useRef(new CitiesStore());
406
- var _a = React.useState(false), isMounted = _a[0], setIsMounted = _a[1];
410
+ var _b = React.useState(false), isMounted = _b[0], setIsMounted = _b[1];
407
411
  var inputRef = React.useRef(null);
408
- var _b = citiesStoreRef.current, cities = _b.cities, fetchCities = _b.fetchCities, paginator = _b.paginator, filter = _b.filter, loader = _b.loader;
412
+ var _c = citiesStoreRef.current, cities = _c.cities, fetchCities = _c.fetchCities, paginator = _c.paginator, filter = _c.filter, loader = _c.loader;
409
413
  var isLoading = loader.isLoading;
410
414
  var region = reactHookForm.useWatch({
411
415
  control: form.control,
412
416
  name: regionName,
413
417
  });
414
- var _c = useAutocomplete(filter, paginator, fetchCities, (region === null || region === void 0 ? void 0 : region.id) ? "&region=".concat(region.id) : ""), onSearchItem = _c.onSearchItem, onScrollEnd = _c.onScrollEnd;
418
+ var _d = useAutocomplete(filter, paginator, fetchCities, isOpen, (region === null || region === void 0 ? void 0 : region.id) ? "&region=".concat(region.id) : ""), onSearchItem = _d.onSearchItem, onScrollEnd = _d.onScrollEnd;
415
419
  var onSelectItem = function (item) {
416
420
  form.setValue("".concat(name, ".id"), item === null || item === void 0 ? void 0 : item.id);
417
421
  form.setValue("".concat(name, ".name"), item === null || item === void 0 ? void 0 : item.name, { shouldValidate: true });
@@ -431,7 +435,7 @@ function CityAutocomplete(props) {
431
435
  }
432
436
  setIsMounted(true);
433
437
  }, [region === null || region === void 0 ? void 0 : region.id]);
434
- return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, isLoading: isLoading, options: cities, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, inputRef: inputRef }, otherProps)));
438
+ return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, isLoading: isLoading, options: cities, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, inputRef: inputRef, onOpen: setIsOpen }, otherProps)));
435
439
  }
436
440
  CityAutocomplete.defaultProps = {
437
441
  label: "City",
@@ -471,18 +475,19 @@ var CountriesStore = /** @class */ (function () {
471
475
  }());
472
476
 
473
477
  function CountryAutocomplete(props) {
478
+ var _a = React.useState(false), isOpen = _a[0], setIsOpen = _a[1];
474
479
  var form = props.form, name = props.name, label = props.label, defaultFilter = props.defaultFilter, onSelect = props.onSelect, otherProps = __rest(props, ["form", "name", "label", "defaultFilter", "onSelect"]);
475
480
  var countriesStoreRef = React.useRef(new CountriesStore());
476
- var _a = countriesStoreRef.current, countries = _a.countries, fetchCountries = _a.fetchCountries, paginator = _a.paginator, filter = _a.filter, loader = _a.loader;
481
+ var _b = countriesStoreRef.current, countries = _b.countries, fetchCountries = _b.fetchCountries, paginator = _b.paginator, filter = _b.filter, loader = _b.loader;
477
482
  var isLoading = loader.isLoading;
478
- var _b = useAutocomplete(filter, paginator, fetchCountries, defaultFilter), onSearchItem = _b.onSearchItem, onScrollEnd = _b.onScrollEnd;
483
+ var _c = useAutocomplete(filter, paginator, fetchCountries, isOpen, defaultFilter), onSearchItem = _c.onSearchItem, onScrollEnd = _c.onScrollEnd;
479
484
  var onSelectItem = function (item) {
480
485
  form.setValue("".concat(name, ".id"), item === null || item === void 0 ? void 0 : item.id);
481
486
  form.setValue("".concat(name, ".name"), item === null || item === void 0 ? void 0 : item.name, { shouldValidate: true });
482
487
  if (onSelect)
483
488
  onSelect(item);
484
489
  };
485
- return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, isLoading: isLoading, options: countries, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd }, otherProps)));
490
+ return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, isLoading: isLoading, options: countries, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, onOpen: setIsOpen }, otherProps)));
486
491
  }
487
492
  CountryAutocomplete.defaultProps = {
488
493
  label: "Country",
@@ -591,17 +596,18 @@ var RegionsStore = /** @class */ (function () {
591
596
  }());
592
597
 
593
598
  function RegionAutocomplete(props) {
599
+ var _a = React.useState(false), isOpen = _a[0], setIsOpen = _a[1];
594
600
  var form = props.form, name = props.name, label = props.label, onSelect = props.onSelect, countryName = props.countryName, otherProps = __rest(props, ["form", "name", "label", "onSelect", "countryName"]);
595
601
  var regionsStoreRef = React.useRef(new RegionsStore());
596
- var _a = React.useState(false), isMounted = _a[0], setIsMounted = _a[1];
602
+ var _b = React.useState(false), isMounted = _b[0], setIsMounted = _b[1];
597
603
  var inputRef = React.useRef(null);
598
- var _b = regionsStoreRef.current, regions = _b.regions, fetchRegions = _b.fetchRegions, paginator = _b.paginator, filter = _b.filter, loader = _b.loader;
604
+ var _c = regionsStoreRef.current, regions = _c.regions, fetchRegions = _c.fetchRegions, paginator = _c.paginator, filter = _c.filter, loader = _c.loader;
599
605
  var isLoading = loader.isLoading;
600
606
  var country = reactHookForm.useWatch({
601
607
  control: form.control,
602
608
  name: countryName,
603
609
  });
604
- var _c = useAutocomplete(filter, paginator, fetchRegions, (country === null || country === void 0 ? void 0 : country.id) ? "&country=".concat(country.id) : ""), onSearchItem = _c.onSearchItem, onScrollEnd = _c.onScrollEnd;
610
+ var _d = useAutocomplete(filter, paginator, fetchRegions, isOpen, (country === null || country === void 0 ? void 0 : country.id) ? "&country=".concat(country.id) : ""), onSearchItem = _d.onSearchItem, onScrollEnd = _d.onScrollEnd;
605
611
  var onSelectItem = function (item) {
606
612
  form.setValue("".concat(name, ".id"), item === null || item === void 0 ? void 0 : item.id);
607
613
  form.setValue("".concat(name, ".name"), item === null || item === void 0 ? void 0 : item.name, { shouldValidate: true });
@@ -621,7 +627,7 @@ function RegionAutocomplete(props) {
621
627
  }
622
628
  setIsMounted(true);
623
629
  }, [country === null || country === void 0 ? void 0 : country.id]);
624
- return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, isLoading: isLoading, options: regions, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, inputRef: inputRef }, otherProps)));
630
+ return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, isLoading: isLoading, options: regions, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, inputRef: inputRef, onOpen: setIsOpen }, otherProps)));
625
631
  }
626
632
  RegionAutocomplete.defaultProps = {
627
633
  label: "Region",
@@ -1518,14 +1524,15 @@ var CompaniesStore = /** @class */ (function () {
1518
1524
 
1519
1525
  function CompanyAutocomplete(props) {
1520
1526
  var _this = this;
1527
+ var _a = React.useState(false), isOpen = _a[0], setIsOpen = _a[1];
1521
1528
  var form = props.form, name = props.name, label = props.label, handleSelect = props.handleSelect, forApartment = props.forApartment, otherProps = __rest(props, ["form", "name", "label", "handleSelect", "forApartment"]);
1522
1529
  var companiesStore = React.useRef(new CompaniesStore());
1523
- var _a = companiesStore.current, companies = _a.companies, paginator = _a.paginator, fetchAll = _a.fetchAll, loader = _a.loader, filter = _a.filter;
1530
+ var _b = companiesStore.current, companies = _b.companies, paginator = _b.paginator, fetchAll = _b.fetchAll, loader = _b.loader, filter = _b.filter;
1524
1531
  var logo = reactHookForm.useWatch({
1525
1532
  control: form.control,
1526
1533
  name: "".concat(name, ".logo"),
1527
1534
  });
1528
- var _b = useAutocomplete(filter, paginator, fetchAll), onSearchItem = _b.onSearchItem, onScrollEnd = _b.onScrollEnd;
1535
+ var _c = useAutocomplete(filter, paginator, fetchAll, isOpen), onSearchItem = _c.onSearchItem, onScrollEnd = _c.onScrollEnd;
1529
1536
  var onSearch = function (value) {
1530
1537
  if (forApartment) {
1531
1538
  if (value) {
@@ -1562,7 +1569,7 @@ function CompanyAutocomplete(props) {
1562
1569
  filter.updateFilterQuery("&for_apartment=".concat(forApartment));
1563
1570
  }
1564
1571
  }, [forApartment]);
1565
- return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(TwoOptionForAutocomplete, { option: option })); }, options: companies, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), isLoading: loader.isLoading, onSelectItem: onSelectItem, onSearchItem: onSearch, handleScrollEnd: onScrollEnd, creatingLabel: "Add new company", endComponent: logo && jsxRuntime.jsx(SquarePreviewImage, { size: "sm", imageSrc: logo }), renderCreatingModal: function (modalProps) { return (jsxRuntime.jsx(CompanyCreationModal$1, __assign({ createCompany: onCreate }, modalProps))); } }, otherProps)));
1572
+ return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(TwoOptionForAutocomplete, { option: option })); }, options: companies, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), isLoading: loader.isLoading, onSelectItem: onSelectItem, onSearchItem: onSearch, handleScrollEnd: onScrollEnd, creatingLabel: "Add new company", endComponent: logo && jsxRuntime.jsx(SquarePreviewImage, { size: "sm", imageSrc: logo }), renderCreatingModal: function (modalProps) { return (jsxRuntime.jsx(CompanyCreationModal$1, __assign({ createCompany: onCreate }, modalProps))); }, onOpen: setIsOpen }, otherProps)));
1566
1573
  }
1567
1574
  CompanyAutocomplete.defaultProps = {
1568
1575
  label: "Company",
@@ -2398,17 +2405,18 @@ var DistrictsStore = /** @class */ (function () {
2398
2405
  }());
2399
2406
 
2400
2407
  function DistrictAutocomplete(props) {
2408
+ var _a = React.useState(false), isOpen = _a[0], setIsOpen = _a[1];
2401
2409
  var form = props.form, name = props.name, label = props.label, onSelect = props.onSelect, cityName = props.cityName, otherProps = __rest(props, ["form", "name", "label", "onSelect", "cityName"]);
2402
2410
  var districtsStoreRef = React.useRef(new DistrictsStore());
2403
- var _a = React.useState(false), isMounted = _a[0], setIsMounted = _a[1];
2411
+ var _b = React.useState(false), isMounted = _b[0], setIsMounted = _b[1];
2404
2412
  var inputRef = React.useRef(null);
2405
- var _b = districtsStoreRef.current, districts = _b.districts, fetchDistricts = _b.fetchDistricts, paginator = _b.paginator, filter = _b.filter, loader = _b.loader;
2413
+ var _c = districtsStoreRef.current, districts = _c.districts, fetchDistricts = _c.fetchDistricts, paginator = _c.paginator, filter = _c.filter, loader = _c.loader;
2406
2414
  var isLoading = loader.isLoading;
2407
2415
  var city = reactHookForm.useWatch({
2408
2416
  control: form.control,
2409
2417
  name: cityName,
2410
2418
  });
2411
- var _c = useAutocomplete(filter, paginator, fetchDistricts, (city === null || city === void 0 ? void 0 : city.id) ? "&city=".concat(city.id) : ""), onSearchItem = _c.onSearchItem, onScrollEnd = _c.onScrollEnd;
2419
+ var _d = useAutocomplete(filter, paginator, fetchDistricts, isOpen, (city === null || city === void 0 ? void 0 : city.id) ? "&city=".concat(city.id) : ""), onSearchItem = _d.onSearchItem, onScrollEnd = _d.onScrollEnd;
2412
2420
  var onSelectItem = function (item) {
2413
2421
  form.setValue("".concat(name, ".id"), item === null || item === void 0 ? void 0 : item.id);
2414
2422
  form.setValue("".concat(name, ".name"), item === null || item === void 0 ? void 0 : item.name, { shouldValidate: true });
@@ -2428,7 +2436,7 @@ function DistrictAutocomplete(props) {
2428
2436
  }
2429
2437
  setIsMounted(true);
2430
2438
  }, [city === null || city === void 0 ? void 0 : city.id]);
2431
- return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, isLoading: isLoading, options: districts, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, inputRef: inputRef }, otherProps)));
2439
+ return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, isLoading: isLoading, options: districts, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, inputRef: inputRef, onOpen: setIsOpen }, otherProps)));
2432
2440
  }
2433
2441
  DistrictAutocomplete.defaultProps = {
2434
2442
  label: "District",
@@ -2672,6 +2680,7 @@ function TariffCreationModal(props) {
2672
2680
  function TariffGroupAutocomplete(props) {
2673
2681
  var _this = this;
2674
2682
  var form = props.form, name = props.name, label = props.label, resource = props.resource, filterQuery = props.filter, filterRequired = props.filterRequired, otherProps = __rest(props, ["form", "name", "label", "resource", "filter", "filterRequired"]);
2683
+ var _a = React.useState(false), isOpen = _a[0], setIsOpen = _a[1];
2675
2684
  var tariffsStoreRef = React.useRef(new TariffsLiteStore());
2676
2685
  var tariffsStore = tariffsStoreRef.current;
2677
2686
  var tariffs = tariffsStore.tariffs, paginator = tariffsStore.paginator, fetchAll = tariffsStore.fetchAll, loader = tariffsStore.loader, filter = tariffsStore.filter;
@@ -2680,7 +2689,7 @@ function TariffGroupAutocomplete(props) {
2680
2689
  fetchAll(resource);
2681
2690
  }
2682
2691
  }, [resource, filter.filterQuery]);
2683
- var _a = useAutocomplete(filter, paginator, fetchAllByResource), onSearchItem = _a.onSearchItem, onScrollEnd = _a.onScrollEnd;
2692
+ var _b = useAutocomplete(filter, paginator, fetchAllByResource, isOpen), onSearchItem = _b.onSearchItem, onScrollEnd = _b.onScrollEnd;
2684
2693
  var onSelectItem = function (item) {
2685
2694
  form.setValue("".concat(name, ".id"), item === null || item === void 0 ? void 0 : item.id);
2686
2695
  form.setValue("".concat(name, ".type"), resource);
@@ -2702,7 +2711,7 @@ function TariffGroupAutocomplete(props) {
2702
2711
  React.useEffect(function () {
2703
2712
  filter.updateFilterQuery(filterQuery);
2704
2713
  }, [filterQuery]);
2705
- return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, options: tariffs, isLoading: loader.isLoading, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, creatingLabel: "Add new tariff group", renderCreatingModal: function (modalProps) { return (jsxRuntime.jsx(TariffCreationModal, __assign({ creationForm: tariffsStore.creationForm, createTariff: onCreate, defaultResource: resource }, modalProps))); } }, otherProps)));
2714
+ return (jsxRuntime.jsx(kuiComplex.InputWithAutocomplete, __assign({ renderOption: function (option) { return (jsxRuntime.jsx(kuiComplex.AutocompleteOption, { label: option.name })); }, options: tariffs, isLoading: loader.isLoading, label: label, form: form, name: "".concat(name, ".name"), hideName: "".concat(name, ".id"), onSelectItem: onSelectItem, onSearchItem: onSearchItem, handleScrollEnd: onScrollEnd, creatingLabel: "Add new tariff group", renderCreatingModal: function (modalProps) { return (jsxRuntime.jsx(TariffCreationModal, __assign({ creationForm: tariffsStore.creationForm, createTariff: onCreate, defaultResource: resource }, modalProps))); }, onOpen: setIsOpen }, otherProps)));
2706
2715
  }
2707
2716
  TariffGroupAutocomplete.defaultProps = {
2708
2717
  name: "tariffGroup",