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/cjs/index.js +143 -0
- package/cjs/index.js.map +1 -1
- package/index.d.ts +35 -1
- package/index.js +141 -2
- package/index.js.map +1 -1
- package/package.json +1 -1
package/cjs/index.js
CHANGED
@@ -1244,6 +1244,145 @@ var useFillingList = function (apartmentId, formStore, fillingStore, shouldBeLoa
|
|
1244
1244
|
}, [fillingStore.fillingList, fillingStore.loader.isLoading]);
|
1245
1245
|
};
|
1246
1246
|
|
1247
|
+
var onInspectionModalOpen = function (apartmentStore, constants, openModal) {
|
1248
|
+
var inspectionsStore = apartmentStore.inspectionsStore, apartmentId = apartmentStore.apartmentId;
|
1249
|
+
var formStateName = constants.formStateName, formFieldsName = constants.formFieldsName;
|
1250
|
+
var fields = inspectionsStore.creationForm.fields;
|
1251
|
+
if (fields && fields.apartmentId !== apartmentId) {
|
1252
|
+
kuiUtils.clearIndexStores(inspectionsStore.indexDB, [formStateName, formFieldsName]);
|
1253
|
+
}
|
1254
|
+
inspectionsStore.setCanUpdateDB(true);
|
1255
|
+
if (openModal)
|
1256
|
+
openModal();
|
1257
|
+
};
|
1258
|
+
var onInspectionModalClose = function (apartmentStore, constants, closeModal) {
|
1259
|
+
var inspectionsStore = apartmentStore.inspectionsStore;
|
1260
|
+
var formStateName = constants.formStateName, formFieldsName = constants.formFieldsName;
|
1261
|
+
inspectionsStore.setCanUpdateDB(false);
|
1262
|
+
inspectionsStore.creationForm.resetForm();
|
1263
|
+
kuiUtils.clearIndexStores(inspectionsStore.indexDB, [formStateName, formFieldsName]);
|
1264
|
+
if (closeModal)
|
1265
|
+
closeModal();
|
1266
|
+
};
|
1267
|
+
|
1268
|
+
var useInspectionData = function (apartmentStore) {
|
1269
|
+
var _a;
|
1270
|
+
var apartmentId = apartmentStore.apartmentId, inspectionsStore = apartmentStore.inspectionsStore, metersStore = apartmentStore.metersStore, fillingStore = apartmentStore.fillingStore;
|
1271
|
+
var _b = react.useState(false), isMetersLoaded = _b[0], setIsMetersLoader = _b[1];
|
1272
|
+
var _c = react.useState(false), isFillingLoaded = _c[0], setIsFillingLoaded = _c[1];
|
1273
|
+
var formStore = inspectionsStore.creationForm;
|
1274
|
+
var inspectionType = (_a = formStore.fields) === null || _a === void 0 ? void 0 : _a.type;
|
1275
|
+
var canBeLoad = inspectionType
|
1276
|
+
? inspectionType === "regular" || inspectionType === "transfer"
|
1277
|
+
: undefined;
|
1278
|
+
var fillingLoading = fillingStore.loader.isLoading;
|
1279
|
+
var metersLoading = metersStore.loader.isLoading;
|
1280
|
+
var handleMetersLoad = function () { return setIsMetersLoader(true); };
|
1281
|
+
var handleFillingLoad = function () { return setIsFillingLoaded(true); };
|
1282
|
+
react.useEffect(function () {
|
1283
|
+
if (isMetersLoaded &&
|
1284
|
+
isFillingLoaded &&
|
1285
|
+
!fillingLoading &&
|
1286
|
+
!metersLoading) {
|
1287
|
+
inspectionsStore.setCanLoadDB(true);
|
1288
|
+
}
|
1289
|
+
}, [isMetersLoaded, isFillingLoaded, fillingLoading, metersLoading]);
|
1290
|
+
useMetersValues(formStore, metersStore, canBeLoad, handleMetersLoad);
|
1291
|
+
useFillingList(apartmentId || null, formStore, fillingStore, canBeLoad, handleFillingLoad);
|
1292
|
+
};
|
1293
|
+
|
1294
|
+
var EXPIRATION_TIME = 24 * 60 * 60 * 1000; // 24 часа
|
1295
|
+
var useInspectionIndexDB = function (constants, apartmentStore, openModal) {
|
1296
|
+
var dbCreationTime = constants.dbCreationTime, formFieldsName = constants.formFieldsName, formStateName = constants.formStateName, inspectionCreationFormName = constants.inspectionCreationFormName;
|
1297
|
+
var inspectionsStore = apartmentStore.inspectionsStore, apartmentId = apartmentStore.apartmentId;
|
1298
|
+
var creationForm = inspectionsStore.creationForm, actionLoader = inspectionsStore.actionLoader, indexDB = inspectionsStore.indexDB, setCanUpdateDB = inspectionsStore.setCanUpdateDB, canUpdateDB = inspectionsStore.canUpdateDB;
|
1299
|
+
var dbName = inspectionCreationFormName;
|
1300
|
+
var onupgradeneeded = function (db) {
|
1301
|
+
kuiUtils.addIndexDBStore(db, formFieldsName);
|
1302
|
+
kuiUtils.addIndexDBStore(db, formStateName);
|
1303
|
+
};
|
1304
|
+
function checkAndDeleteDB() {
|
1305
|
+
var creationTime = localStorage.getItem(dbCreationTime);
|
1306
|
+
var currentTime = Date.now();
|
1307
|
+
if (creationTime && currentTime - Number(creationTime) > EXPIRATION_TIME) {
|
1308
|
+
kuiUtils.clearIndexStores(inspectionsStore.indexDB, [
|
1309
|
+
formStateName,
|
1310
|
+
formFieldsName,
|
1311
|
+
]);
|
1312
|
+
localStorage.removeItem(dbCreationTime);
|
1313
|
+
}
|
1314
|
+
}
|
1315
|
+
var initInspectionIndexDB = function () { return __awaiter(void 0, void 0, void 0, function () {
|
1316
|
+
return __generator(this, function (_a) {
|
1317
|
+
kuiUtils.initIndexDB(dbName, onupgradeneeded, actionLoader, function (db) { return __awaiter(void 0, void 0, void 0, function () {
|
1318
|
+
var formFields;
|
1319
|
+
return __generator(this, function (_a) {
|
1320
|
+
switch (_a.label) {
|
1321
|
+
case 0:
|
1322
|
+
inspectionsStore.setIndexDB(db);
|
1323
|
+
setCanUpdateDB(false);
|
1324
|
+
checkAndDeleteDB();
|
1325
|
+
return [4 /*yield*/, kuiUtils.readFromIndexDB(db, formFieldsName, actionLoader)];
|
1326
|
+
case 1:
|
1327
|
+
formFields = _a.sent();
|
1328
|
+
if (formFields) {
|
1329
|
+
if ((formFields === null || formFields === void 0 ? void 0 : formFields.apartmentId) === apartmentId) {
|
1330
|
+
creationForm.updateFormFields(__assign(__assign({}, formFields), { date: formFields.date ? luxon.DateTime.fromISO(formFields.date) : null }));
|
1331
|
+
if (openModal)
|
1332
|
+
openModal();
|
1333
|
+
}
|
1334
|
+
}
|
1335
|
+
else {
|
1336
|
+
setCanUpdateDB(true);
|
1337
|
+
}
|
1338
|
+
return [2 /*return*/];
|
1339
|
+
}
|
1340
|
+
});
|
1341
|
+
}); });
|
1342
|
+
return [2 /*return*/];
|
1343
|
+
});
|
1344
|
+
}); };
|
1345
|
+
var initFormState = function () { return __awaiter(void 0, void 0, void 0, function () {
|
1346
|
+
var formState, formFields;
|
1347
|
+
return __generator(this, function (_a) {
|
1348
|
+
switch (_a.label) {
|
1349
|
+
case 0: return [4 /*yield*/, kuiUtils.readFromIndexDB(indexDB, formStateName, actionLoader)];
|
1350
|
+
case 1:
|
1351
|
+
formState = _a.sent();
|
1352
|
+
return [4 /*yield*/, kuiUtils.readFromIndexDB(indexDB, formFieldsName, actionLoader)];
|
1353
|
+
case 2:
|
1354
|
+
formFields = _a.sent();
|
1355
|
+
if (formState && (formFields === null || formFields === void 0 ? void 0 : formFields.apartmentId) === apartmentId) {
|
1356
|
+
creationForm.setStep(Number(formState.step));
|
1357
|
+
}
|
1358
|
+
setCanUpdateDB(true);
|
1359
|
+
return [2 /*return*/];
|
1360
|
+
}
|
1361
|
+
});
|
1362
|
+
}); };
|
1363
|
+
react.useEffect(function () {
|
1364
|
+
if (apartmentId)
|
1365
|
+
initInspectionIndexDB();
|
1366
|
+
}, [apartmentId]);
|
1367
|
+
react.useEffect(function () {
|
1368
|
+
if (inspectionsStore.canLoadDB && indexDB) {
|
1369
|
+
initFormState();
|
1370
|
+
}
|
1371
|
+
}, [inspectionsStore.canLoadDB, indexDB]);
|
1372
|
+
react.useEffect(function () {
|
1373
|
+
if (canUpdateDB) {
|
1374
|
+
var formState = {
|
1375
|
+
step: creationForm.step,
|
1376
|
+
};
|
1377
|
+
kuiUtils.addToIndexDBWithQueue(indexDB, formStateName, formState, actionLoader);
|
1378
|
+
kuiUtils.addToIndexDBWithQueue(indexDB, formFieldsName, creationForm.fields, actionLoader);
|
1379
|
+
if (!localStorage.getItem(dbCreationTime)) {
|
1380
|
+
localStorage.setItem(dbCreationTime, Date.now().toString());
|
1381
|
+
}
|
1382
|
+
}
|
1383
|
+
}, [creationForm.step]);
|
1384
|
+
};
|
1385
|
+
|
1247
1386
|
var ObjectForMapPoint = function (props) {
|
1248
1387
|
var label = props.label, onClick = props.onClick, isActive = props.isActive;
|
1249
1388
|
return (jsxRuntime.jsx(kuiBasic.Button, __assign({ size: "xs", variant: isActive ? "primary" : "white", onClick: onClick }, { children: label })));
|
@@ -1336,7 +1475,11 @@ exports.getTelecommunicationsInfoStepFields = getTelecommunicationsInfoStepField
|
|
1336
1475
|
exports.getWaterMeterFields = getWaterMeterFields;
|
1337
1476
|
exports.inspectionsRequestBody = inspectionsRequestBody;
|
1338
1477
|
exports.inspectionsRequests = inspectionsRequests;
|
1478
|
+
exports.onInspectionModalClose = onInspectionModalClose;
|
1479
|
+
exports.onInspectionModalOpen = onInspectionModalOpen;
|
1339
1480
|
exports.renderMetersSteps = renderMetersSteps;
|
1340
1481
|
exports.useFillingList = useFillingList;
|
1482
|
+
exports.useInspectionData = useInspectionData;
|
1483
|
+
exports.useInspectionIndexDB = useInspectionIndexDB;
|
1341
1484
|
exports.useMetersValues = useMetersValues;
|
1342
1485
|
//# sourceMappingURL=index.js.map
|