kui-crm_actions 0.0.130 → 0.0.132

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/index.d.ts CHANGED
@@ -992,6 +992,40 @@ type AddedMetersBlockProps = {
992
992
 
993
993
  declare const AddedMetersBlock: (props: AddedMetersBlockProps) => JSX.Element | null;
994
994
 
995
+ declare type InspectionsLiteStoreInterface = {
996
+ creationForm: MultistepForm<any>;
997
+ actionLoader: Loader;
998
+ indexDB: any;
999
+ canUpdateDB: boolean;
1000
+ canLoadDB: boolean;
1001
+ setCanLoadDB: (value: boolean) => void;
1002
+ setCanUpdateDB: (value: boolean) => void;
1003
+ setIndexDB: (db: any) => void;
1004
+ };
1005
+ declare type ApartmentLiteStoreInterface = {
1006
+ metersStore: ApartmentMetersStoreInterface;
1007
+ fillingStore: FillingListStore;
1008
+ inspectionsStore: InspectionsLiteStoreInterface;
1009
+ apartmentId?: number | null;
1010
+ };
1011
+ declare type InspectionIndexDBConstants = {
1012
+ dbCreationTime: string;
1013
+ formFieldsName: string;
1014
+ formStateName: string;
1015
+ inspectionCreationFormName: string;
1016
+ };
1017
+ declare type InspectionFieldsIndexDBConstants = {
1018
+ formFieldsName: string;
1019
+ formStateName: string;
1020
+ };
1021
+
1022
+ declare const onInspectionModalOpen: (apartmentStore: ApartmentLiteStoreInterface, constants: InspectionFieldsIndexDBConstants, openModal?: (() => void) | undefined) => void;
1023
+ declare const onInspectionModalClose: (apartmentStore: ApartmentLiteStoreInterface, constants: InspectionFieldsIndexDBConstants, closeModal?: (() => void) | undefined) => void;
1024
+
1025
+ declare const useInspectionData: (apartmentStore: ApartmentLiteStoreInterface) => void;
1026
+
1027
+ declare const useInspectionIndexDB: (constants: InspectionIndexDBConstants, apartmentStore: ApartmentLiteStoreInterface, openModal?: (() => void) | undefined) => void;
1028
+
995
1029
  declare type InspectionFieldsSettings = {
996
1030
  [key: string]: InputParams<any>;
997
1031
  };
@@ -1070,4 +1104,4 @@ type ApartmentPointProps = {
1070
1104
 
1071
1105
  declare const ObjectForMapPoint: (props: ApartmentPointProps) => JSX.Element;
1072
1106
 
1073
- export { AddedMetersBlock, AdditionalInfoFieldsSchema, AdditionalInfoStepFields, AdditionalInfoStepSchema, ApartmentInspectionModel, ApartmentInspectionParams, ApartmentLinkParams, ApartmentPaymentsFormFields, BasicApartmentInfoFieldsSchema, BasicApartmentInfoStepFields, BasicApartmentInfoStepSchema, CommonInspectionFields, CommonInspectionFormFields, DetailApartmentInfoFieldsSchema, DetailApartmentInfoStepFields, DetailApartmentInfoStepSchema, FillingCheckParams, FillingInfoFieldsSchema, FillingInfoFormFields, FillingInfoStepFields, FillingListInfoStepFields, FillingListStore, HouseInfoFieldsSchema, HouseInfoStepFields, HouseInfoStepSchema, HouseServicesInfoFieldsSchema, HouseServicesInfoStepFields, HouseServicesInfoStepSchema, InitialInspectionFieldsBody, InitialInspectionFormFields, InitialInspectionInfoFields, InitialInspectionPostBody, InitialInspectionRoomParams, InspectionAppraisalLiteModel, _default as InspectionFeedback, InspectionFieldsSettings, InspectionFillingCard, InspectionFillingCardProps, InspectionFillingItemFields, InspectionFillingListFields, InspectionFillingParams, InspectionImpairmentLiteModel, InspectionMeterCommonFields, InspectionMeterFields, InspectionMeterValueModel, InspectionMetersStepFields, InspectionPartialMetersStepFields, InspectionRoomImagesParams, InspectionRoomPhotoRequest, InspectionRoomsImagesFields, InventoryInspectionFieldsBody, InventoryInspectionFormFields, InventoryInspectionPostBody, InventoryMeterInfoFields, InventoryMeterModel, MeterInfoStepProps, MeterValueModel, MeterValuesFields, MetersInfoFieldsSchema, MetersInfoStepFields, MetersInfoStepSchema, MetroStationParams, ObjectForMapCard, ObjectForMapOverlay, ObjectForMapParams, ObjectForMapPoint, PartialMeterInfoFields, PartialMeterInfoStepProps, PartialMeterModel, PostApartmentInspectionRequest, RegularInspectionFormFields, RegularInspectionPostBody, RegularlyInspectionFieldsBody, RoomImagesParams, RoomsApartmentInfoFieldsSchema, RoomsApartmentInfoStepFields, RoomsApartmentInfoStepSchema, SecurityApartmentInfoFieldsSchema, SecurityApartmentInfoStepFields, SecurityApartmentInfoStepSchema, TelecommunicationsInfoFieldsSchema, TelecommunicationsInfoStepFields, TelecommunicationsInfoStepSchema, TenantParams, TransferInspectionFieldsBody, TransferInspectionFormFields, TransferInspectionPostBody, TransferInspectionTypes, WaterMeterFieldsSchema, apartmentFields, getAdditionalInfoStepFields, getBasicApartmentInfoFields, getDetailApartmentInfoFields, getFillingInfoFields, getHouseInfoStep, getHouseServicesInfoStep, getInventoryMeterFields, getMetersInfoStepFields, getPartialMeterInfoSchema, getRoomsApartmentInfoFields, getRoomsImagesSteps, getSecurityApartmentInfoFields, getTelecommunicationsInfoStepFields, getWaterMeterFields, inspectionsRequestBody, inspectionsRequests, renderMetersSteps, useFillingList, useMetersValues };
1107
+ export { AddedMetersBlock, AdditionalInfoFieldsSchema, AdditionalInfoStepFields, AdditionalInfoStepSchema, ApartmentInspectionModel, ApartmentInspectionParams, ApartmentLinkParams, ApartmentPaymentsFormFields, BasicApartmentInfoFieldsSchema, BasicApartmentInfoStepFields, BasicApartmentInfoStepSchema, CommonInspectionFields, CommonInspectionFormFields, DetailApartmentInfoFieldsSchema, DetailApartmentInfoStepFields, DetailApartmentInfoStepSchema, FillingCheckParams, FillingInfoFieldsSchema, FillingInfoFormFields, FillingInfoStepFields, FillingListInfoStepFields, FillingListStore, HouseInfoFieldsSchema, HouseInfoStepFields, HouseInfoStepSchema, HouseServicesInfoFieldsSchema, HouseServicesInfoStepFields, HouseServicesInfoStepSchema, InitialInspectionFieldsBody, InitialInspectionFormFields, InitialInspectionInfoFields, InitialInspectionPostBody, InitialInspectionRoomParams, InspectionAppraisalLiteModel, _default as InspectionFeedback, InspectionFieldsSettings, InspectionFillingCard, InspectionFillingCardProps, InspectionFillingItemFields, InspectionFillingListFields, InspectionFillingParams, InspectionImpairmentLiteModel, InspectionMeterCommonFields, InspectionMeterFields, InspectionMeterValueModel, InspectionMetersStepFields, InspectionPartialMetersStepFields, InspectionRoomImagesParams, InspectionRoomPhotoRequest, InspectionRoomsImagesFields, InventoryInspectionFieldsBody, InventoryInspectionFormFields, InventoryInspectionPostBody, InventoryMeterInfoFields, InventoryMeterModel, MeterInfoStepProps, MeterValueModel, MeterValuesFields, MetersInfoFieldsSchema, MetersInfoStepFields, MetersInfoStepSchema, MetroStationParams, ObjectForMapCard, ObjectForMapOverlay, ObjectForMapParams, ObjectForMapPoint, PartialMeterInfoFields, PartialMeterInfoStepProps, PartialMeterModel, PostApartmentInspectionRequest, RegularInspectionFormFields, RegularInspectionPostBody, RegularlyInspectionFieldsBody, RoomImagesParams, RoomsApartmentInfoFieldsSchema, RoomsApartmentInfoStepFields, RoomsApartmentInfoStepSchema, SecurityApartmentInfoFieldsSchema, SecurityApartmentInfoStepFields, SecurityApartmentInfoStepSchema, TelecommunicationsInfoFieldsSchema, TelecommunicationsInfoStepFields, TelecommunicationsInfoStepSchema, TenantParams, TransferInspectionFieldsBody, TransferInspectionFormFields, TransferInspectionPostBody, TransferInspectionTypes, WaterMeterFieldsSchema, apartmentFields, getAdditionalInfoStepFields, getBasicApartmentInfoFields, getDetailApartmentInfoFields, getFillingInfoFields, getHouseInfoStep, getHouseServicesInfoStep, getInventoryMeterFields, getMetersInfoStepFields, getPartialMeterInfoSchema, getRoomsApartmentInfoFields, getRoomsImagesSteps, getSecurityApartmentInfoFields, getTelecommunicationsInfoStepFields, getWaterMeterFields, inspectionsRequestBody, inspectionsRequests, onInspectionModalClose, onInspectionModalOpen, renderMetersSteps, useFillingList, useInspectionData, useInspectionIndexDB, useMetersValues };
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as yup from 'yup';
2
2
  import { NumberField, requests, uploadFiles, ImageStore, FileStore, matchesAPIFillingTypes, CountryAutocomplete, RegionAutocomplete, CityAutocomplete, HouseTypesValues, WallMaterialsValues, SlabsTypesValues, GasTypesValues, BooleanValues, positiveNumberSchema, defaultRequiredMessage, RenovationTypeValues, RenovationStyleValues, RoomTypeValues, RoomTypesValues, ParkingTypesValues, fieldWithConditionSchema, getApartmentPaymentFields, phoneWithConditionSchema, getNumbersValues, TVTypesValues, phoneNonRequiredSchema, InputFileWithVisibility, FillingTypeValues, FillingTagsAutocomplete, getMeterValuesFieldsSchema, basicFieldsOfNewResourceMeter, meterUnitLabel, FormWrapper, MeterTypeRadioGroup, InputByType, Tooltip, ApartmentsAgent, PreviewContent, Link, UserBadge, useMapCards, MapOverlay } from 'kui-crm';
3
3
  import _ from 'lodash';
4
- import { clearNotValidFields, getPhoneNumberFromPhoneParams, resHandler, callPromises, getPhoneParamsFromString, addToArrayByCondition, Loader } from 'kui-utils';
4
+ import { clearNotValidFields, getPhoneNumberFromPhoneParams, resHandler, callPromises, getPhoneParamsFromString, addToArrayByCondition, Loader, clearIndexStores, addToIndexDBWithQueue, initIndexDB, readFromIndexDB, addIndexDBStore } from 'kui-utils';
5
5
  import to from 'await-to-js';
6
6
  import { DateTime } from 'luxon';
7
7
  import { InputWithAddressAutocomplete, DependentInput, CheckboxWithController, InputPhoneWithForm, InputFile } from 'kui-complex';
@@ -1215,6 +1215,145 @@ var useFillingList = function (apartmentId, formStore, fillingStore, shouldBeLoa
1215
1215
  }, [fillingStore.fillingList, fillingStore.loader.isLoading]);
1216
1216
  };
1217
1217
 
1218
+ var onInspectionModalOpen = function (apartmentStore, constants, openModal) {
1219
+ var inspectionsStore = apartmentStore.inspectionsStore, apartmentId = apartmentStore.apartmentId;
1220
+ var formStateName = constants.formStateName, formFieldsName = constants.formFieldsName;
1221
+ var fields = inspectionsStore.creationForm.fields;
1222
+ if (fields && fields.apartmentId !== apartmentId) {
1223
+ clearIndexStores(inspectionsStore.indexDB, [formStateName, formFieldsName]);
1224
+ }
1225
+ inspectionsStore.setCanUpdateDB(true);
1226
+ if (openModal)
1227
+ openModal();
1228
+ };
1229
+ var onInspectionModalClose = function (apartmentStore, constants, closeModal) {
1230
+ var inspectionsStore = apartmentStore.inspectionsStore;
1231
+ var formStateName = constants.formStateName, formFieldsName = constants.formFieldsName;
1232
+ inspectionsStore.setCanUpdateDB(false);
1233
+ inspectionsStore.creationForm.resetForm();
1234
+ clearIndexStores(inspectionsStore.indexDB, [formStateName, formFieldsName]);
1235
+ if (closeModal)
1236
+ closeModal();
1237
+ };
1238
+
1239
+ var useInspectionData = function (apartmentStore) {
1240
+ var _a;
1241
+ var apartmentId = apartmentStore.apartmentId, inspectionsStore = apartmentStore.inspectionsStore, metersStore = apartmentStore.metersStore, fillingStore = apartmentStore.fillingStore;
1242
+ var _b = useState(false), isMetersLoaded = _b[0], setIsMetersLoader = _b[1];
1243
+ var _c = useState(false), isFillingLoaded = _c[0], setIsFillingLoaded = _c[1];
1244
+ var formStore = inspectionsStore.creationForm;
1245
+ var inspectionType = (_a = formStore.fields) === null || _a === void 0 ? void 0 : _a.type;
1246
+ var canBeLoad = inspectionType
1247
+ ? inspectionType === "regular" || inspectionType === "transfer"
1248
+ : undefined;
1249
+ var fillingLoading = fillingStore.loader.isLoading;
1250
+ var metersLoading = metersStore.loader.isLoading;
1251
+ var handleMetersLoad = function () { return setIsMetersLoader(true); };
1252
+ var handleFillingLoad = function () { return setIsFillingLoaded(true); };
1253
+ useEffect(function () {
1254
+ if (isMetersLoaded &&
1255
+ isFillingLoaded &&
1256
+ !fillingLoading &&
1257
+ !metersLoading) {
1258
+ inspectionsStore.setCanLoadDB(true);
1259
+ }
1260
+ }, [isMetersLoaded, isFillingLoaded, fillingLoading, metersLoading]);
1261
+ useMetersValues(formStore, metersStore, canBeLoad, handleMetersLoad);
1262
+ useFillingList(apartmentId || null, formStore, fillingStore, canBeLoad, handleFillingLoad);
1263
+ };
1264
+
1265
+ var EXPIRATION_TIME = 24 * 60 * 60 * 1000; // 24 часа
1266
+ var useInspectionIndexDB = function (constants, apartmentStore, openModal) {
1267
+ var dbCreationTime = constants.dbCreationTime, formFieldsName = constants.formFieldsName, formStateName = constants.formStateName, inspectionCreationFormName = constants.inspectionCreationFormName;
1268
+ var inspectionsStore = apartmentStore.inspectionsStore, apartmentId = apartmentStore.apartmentId;
1269
+ var creationForm = inspectionsStore.creationForm, actionLoader = inspectionsStore.actionLoader, indexDB = inspectionsStore.indexDB, setCanUpdateDB = inspectionsStore.setCanUpdateDB, canUpdateDB = inspectionsStore.canUpdateDB;
1270
+ var dbName = inspectionCreationFormName;
1271
+ var onupgradeneeded = function (db) {
1272
+ addIndexDBStore(db, formFieldsName);
1273
+ addIndexDBStore(db, formStateName);
1274
+ };
1275
+ function checkAndDeleteDB() {
1276
+ var creationTime = localStorage.getItem(dbCreationTime);
1277
+ var currentTime = Date.now();
1278
+ if (creationTime && currentTime - Number(creationTime) > EXPIRATION_TIME) {
1279
+ clearIndexStores(inspectionsStore.indexDB, [
1280
+ formStateName,
1281
+ formFieldsName,
1282
+ ]);
1283
+ localStorage.removeItem(dbCreationTime);
1284
+ }
1285
+ }
1286
+ var initInspectionIndexDB = function () { return __awaiter(void 0, void 0, void 0, function () {
1287
+ return __generator(this, function (_a) {
1288
+ initIndexDB(dbName, onupgradeneeded, actionLoader, function (db) { return __awaiter(void 0, void 0, void 0, function () {
1289
+ var formFields;
1290
+ return __generator(this, function (_a) {
1291
+ switch (_a.label) {
1292
+ case 0:
1293
+ inspectionsStore.setIndexDB(db);
1294
+ setCanUpdateDB(false);
1295
+ checkAndDeleteDB();
1296
+ return [4 /*yield*/, readFromIndexDB(db, formFieldsName, actionLoader)];
1297
+ case 1:
1298
+ formFields = _a.sent();
1299
+ if (formFields) {
1300
+ if ((formFields === null || formFields === void 0 ? void 0 : formFields.apartmentId) === apartmentId) {
1301
+ creationForm.updateFormFields(__assign(__assign({}, formFields), { date: formFields.date ? DateTime.fromISO(formFields.date) : null }));
1302
+ if (openModal)
1303
+ openModal();
1304
+ }
1305
+ }
1306
+ else {
1307
+ setCanUpdateDB(true);
1308
+ }
1309
+ return [2 /*return*/];
1310
+ }
1311
+ });
1312
+ }); });
1313
+ return [2 /*return*/];
1314
+ });
1315
+ }); };
1316
+ var initFormState = function () { return __awaiter(void 0, void 0, void 0, function () {
1317
+ var formState, formFields;
1318
+ return __generator(this, function (_a) {
1319
+ switch (_a.label) {
1320
+ case 0: return [4 /*yield*/, readFromIndexDB(indexDB, formStateName, actionLoader)];
1321
+ case 1:
1322
+ formState = _a.sent();
1323
+ return [4 /*yield*/, readFromIndexDB(indexDB, formFieldsName, actionLoader)];
1324
+ case 2:
1325
+ formFields = _a.sent();
1326
+ if (formState && (formFields === null || formFields === void 0 ? void 0 : formFields.apartmentId) === apartmentId) {
1327
+ creationForm.setStep(Number(formState.step));
1328
+ }
1329
+ setCanUpdateDB(true);
1330
+ return [2 /*return*/];
1331
+ }
1332
+ });
1333
+ }); };
1334
+ useEffect(function () {
1335
+ if (apartmentId)
1336
+ initInspectionIndexDB();
1337
+ }, [apartmentId]);
1338
+ useEffect(function () {
1339
+ if (inspectionsStore.canLoadDB && indexDB) {
1340
+ initFormState();
1341
+ }
1342
+ }, [inspectionsStore.canLoadDB, indexDB]);
1343
+ useEffect(function () {
1344
+ if (canUpdateDB) {
1345
+ var formState = {
1346
+ step: creationForm.step,
1347
+ };
1348
+ addToIndexDBWithQueue(indexDB, formStateName, formState, actionLoader);
1349
+ addToIndexDBWithQueue(indexDB, formFieldsName, creationForm.fields, actionLoader);
1350
+ if (!localStorage.getItem(dbCreationTime)) {
1351
+ localStorage.setItem(dbCreationTime, Date.now().toString());
1352
+ }
1353
+ }
1354
+ }, [creationForm.step]);
1355
+ };
1356
+
1218
1357
  var ObjectForMapPoint = function (props) {
1219
1358
  var label = props.label, onClick = props.onClick, isActive = props.isActive;
1220
1359
  return (jsx(Button, __assign({ size: "xs", variant: isActive ? "primary" : "white", onClick: onClick }, { children: label })));
@@ -1262,5 +1401,5 @@ var ObjectForMapOverlay = function (props) {
1262
1401
  var StyledWrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n position: relative;\n"], ["\n position: relative;\n"])));
1263
1402
  var templateObject_1;
1264
1403
 
1265
- export { AddedMetersBlock, AdditionalInfoFieldsSchema, AdditionalInfoStepSchema, BasicApartmentInfoFieldsSchema, BasicApartmentInfoStepSchema, DetailApartmentInfoFieldsSchema, DetailApartmentInfoStepSchema, FillingInfoFieldsSchema, FillingListStore, HouseInfoFieldsSchema, HouseInfoStepSchema, HouseServicesInfoFieldsSchema, HouseServicesInfoStepSchema, index as InspectionFeedback, InspectionFillingCard, InventoryMeterInfoFields, MetersInfoFieldsSchema, MetersInfoStepSchema, ObjectForMapCard, ObjectForMapOverlay, ObjectForMapPoint, RoomsApartmentInfoFieldsSchema, RoomsApartmentInfoStepSchema, SecurityApartmentInfoFieldsSchema, SecurityApartmentInfoStepSchema, TelecommunicationsInfoFieldsSchema, TelecommunicationsInfoStepSchema, WaterMeterFieldsSchema, apartmentFields, getAdditionalInfoStepFields, getBasicApartmentInfoFields, getDetailApartmentInfoFields, getFillingInfoFields, getHouseInfoStep, getHouseServicesInfoStep, getInventoryMeterFields, getMetersInfoStepFields, getPartialMeterInfoSchema, getRoomsApartmentInfoFields, getRoomsImagesSteps, getSecurityApartmentInfoFields, getTelecommunicationsInfoStepFields, getWaterMeterFields, inspectionsRequestBody, inspectionsRequests, renderMetersSteps, useFillingList, useMetersValues };
1404
+ export { AddedMetersBlock, AdditionalInfoFieldsSchema, AdditionalInfoStepSchema, BasicApartmentInfoFieldsSchema, BasicApartmentInfoStepSchema, DetailApartmentInfoFieldsSchema, DetailApartmentInfoStepSchema, FillingInfoFieldsSchema, FillingListStore, HouseInfoFieldsSchema, HouseInfoStepSchema, HouseServicesInfoFieldsSchema, HouseServicesInfoStepSchema, index as InspectionFeedback, InspectionFillingCard, InventoryMeterInfoFields, MetersInfoFieldsSchema, MetersInfoStepSchema, ObjectForMapCard, ObjectForMapOverlay, ObjectForMapPoint, RoomsApartmentInfoFieldsSchema, RoomsApartmentInfoStepSchema, SecurityApartmentInfoFieldsSchema, SecurityApartmentInfoStepSchema, TelecommunicationsInfoFieldsSchema, TelecommunicationsInfoStepSchema, WaterMeterFieldsSchema, apartmentFields, getAdditionalInfoStepFields, getBasicApartmentInfoFields, getDetailApartmentInfoFields, getFillingInfoFields, getHouseInfoStep, getHouseServicesInfoStep, getInventoryMeterFields, getMetersInfoStepFields, getPartialMeterInfoSchema, getRoomsApartmentInfoFields, getRoomsImagesSteps, getSecurityApartmentInfoFields, getTelecommunicationsInfoStepFields, getWaterMeterFields, inspectionsRequestBody, inspectionsRequests, onInspectionModalClose, onInspectionModalOpen, renderMetersSteps, useFillingList, useInspectionData, useInspectionIndexDB, useMetersValues };
1266
1405
  //# sourceMappingURL=index.js.map