@egovernments/digit-ui-libraries 1.0.139 → 1.3.0-beta

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/dist/index.umd.js DELETED
@@ -1,981 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('i18next'), require('axios'), require('react-i18next'), require('i18next-react-postprocessor'), require('date-fns')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react', 'i18next', 'axios', 'react-i18next', 'i18next-react-postprocessor', 'date-fns'], factory) :
4
- (global = global || self, factory(global.digitUiLibraries = {}, global.react, global.i18next, global.axios, global.reactI18next, global.ReactPostprocessor, global.dateFns));
5
- }(this, (function (exports, React, i18next, Axios, reactI18next, ReactPostprocessor, dateFns) {
6
- React = React && Object.prototype.hasOwnProperty.call(React, 'default') ? React['default'] : React;
7
- i18next = i18next && Object.prototype.hasOwnProperty.call(i18next, 'default') ? i18next['default'] : i18next;
8
- Axios = Axios && Object.prototype.hasOwnProperty.call(Axios, 'default') ? Axios['default'] : Axios;
9
- ReactPostprocessor = ReactPostprocessor && Object.prototype.hasOwnProperty.call(ReactPostprocessor, 'default') ? ReactPostprocessor['default'] : ReactPostprocessor;
10
-
11
- function _extends() {
12
- _extends = Object.assign || function (target) {
13
- for (var i = 1; i < arguments.length; i++) {
14
- var source = arguments[i];
15
-
16
- for (var key in source) {
17
- if (Object.prototype.hasOwnProperty.call(source, key)) {
18
- target[key] = source[key];
19
- }
20
- }
21
- }
22
-
23
- return target;
24
- };
25
-
26
- return _extends.apply(this, arguments);
27
- }
28
-
29
- var ifObjectContainsArray = function ifObjectContainsArray(object) {
30
- if (Array.isArray(object)) {
31
- return {
32
- hasArray: true,
33
- value: object
34
- };
35
- }
36
-
37
- for (var property in object) {
38
- if (object.hasOwnProperty(property)) {
39
- var element = object[property];
40
-
41
- if (Array.isArray(element)) {
42
- return {
43
- hasArray: true,
44
- value: element
45
- };
46
- }
47
- }
48
- }
49
-
50
- return {
51
- hasArray: false,
52
- value: []
53
- };
54
- };
55
-
56
- var defaultConfigCopy = {};
57
- var sectionToBeUpdated = {};
58
- var currentUpdatableSection = [];
59
- var selectedProperty = "";
60
-
61
- var MergeConfigObj = function MergeConfigObj(defaultConfig, deltaConfig) {
62
- defaultConfigCopy = JSON.parse(JSON.stringify(defaultConfig));
63
- var deltaConfigCopy = JSON.parse(JSON.stringify(deltaConfig));
64
- processStateConfig(deltaConfigCopy);
65
- return defaultConfigCopy;
66
- };
67
-
68
- var processStateConfig = function processStateConfig(deltaConfig) {
69
- if (Array.isArray(deltaConfig)) {
70
- deltaConfig.forEach(function (forms) {
71
- sectionToBeUpdated = {};
72
- InitSectionToUpdate(forms);
73
- });
74
- }
75
- };
76
-
77
- var InitSectionToUpdate = function InitSectionToUpdate(forms) {
78
- if (forms.id && !forms.__property__) {
79
- GetCurrentUpdatableSection(forms.id, defaultConfigCopy);
80
- }
81
-
82
- if (forms.__property__ && forms.__action__) {
83
- selectedProperty = forms.__property__;
84
- currentUpdatableSection = currentUpdatableSection.length === 0 ? defaultConfigCopy : currentUpdatableSection;
85
- findSectionById(selectedProperty, currentUpdatableSection);
86
- seachInDefaultConfig(forms.__property__, forms);
87
- } else if (Array.isArray(forms)) {
88
- forms.forEach(function (form) {
89
- InitSectionToUpdate(form);
90
- });
91
- } else if (ifObjectContainsArray(forms).hasArray) {
92
- var array = ifObjectContainsArray(forms).value;
93
- InitSectionToUpdate(array);
94
- } else {
95
- throw new Error("__property__ or __action__ not found");
96
- }
97
- };
98
-
99
- var GetCurrentUpdatableSection = function GetCurrentUpdatableSection(id, defaultConfigCopy) {
100
- if (Array.isArray(defaultConfigCopy)) {
101
- for (var i = 0; i < defaultConfigCopy.length; i++) {
102
- if (defaultConfigCopy[i].id === id) {
103
- currentUpdatableSection.push(defaultConfigCopy[i]);
104
- } else if (ifObjectContainsArray(defaultConfigCopy[i]).hasArray) {
105
- var array = ifObjectContainsArray(defaultConfigCopy[i]).value;
106
- GetCurrentUpdatableSection(id, array);
107
- }
108
- }
109
- }
110
- };
111
-
112
- var findSectionById = function findSectionById(id, currentUpdatableSection) {
113
- if (Array.isArray(currentUpdatableSection)) {
114
- for (var i = 0; i < currentUpdatableSection.length; i++) {
115
- if (currentUpdatableSection[i].id === id) {
116
- sectionToBeUpdated = currentUpdatableSection;
117
- } else if (ifObjectContainsArray(currentUpdatableSection[i]).hasArray) {
118
- var arr = ifObjectContainsArray(currentUpdatableSection[i]).value;
119
- findSectionById(id, arr);
120
- }
121
- }
122
- }
123
-
124
- return sectionToBeUpdated;
125
- };
126
-
127
- var seachInDefaultConfig = function seachInDefaultConfig(id, action) {
128
- if (!Array.isArray(sectionToBeUpdated) && !sectionToBeUpdated.id) {
129
- throw new Error("id not found");
130
- }
131
-
132
- if (sectionToBeUpdated.id === id) {
133
- actionHandler(action, id, sectionToBeUpdated);
134
- } else if (Array.isArray(sectionToBeUpdated)) {
135
- sectionToBeUpdated.forEach(function (section) {
136
- if (section.id === id) {
137
- actionHandler(action, id, sectionToBeUpdated);
138
- }
139
- });
140
- } else if (ifObjectContainsArray(sectionToBeUpdated).hasArray) {
141
- sectionToBeUpdated = ifObjectContainsArray(sectionToBeUpdated).value;
142
- seachInDefaultConfig(id, action);
143
- }
144
- };
145
-
146
- var actionHandler = function actionHandler(action, id, fieldList) {
147
- var index = getIndex(id, fieldList);
148
-
149
- if (!action) {
150
- console.log("no action found");
151
- return;
152
- }
153
-
154
- if (action.__action__ === "UPDATE") {
155
- updateAt(index, action, fieldList);
156
- deleteExtraKeys(action);
157
- }
158
-
159
- if (action.__action__ === "DELETE") {
160
- deleteAt(index, fieldList);
161
- deleteExtraKeys(action);
162
- }
163
-
164
- if (["INSERT_AFTER", "INSERT_BEFORE"].includes(action.__action__)) {
165
- handleInsertion(index, action, fieldList);
166
- }
167
- };
168
-
169
- var handleInsertion = function handleInsertion(index, action, fields) {
170
- index = action.__action__ === "INSERT_BEFORE" ? index : index + 1;
171
- insertAt(index, action, fields);
172
- deleteExtraKeys(action);
173
- };
174
-
175
- var getIndex = function getIndex(propertyValue, fields) {
176
- var index = fields.findIndex(function (option) {
177
- return option.id === propertyValue;
178
- });
179
- return index;
180
- };
181
-
182
- var insertAt = function insertAt(index, data, fields) {
183
- if (!data.id) {
184
- throw new Error("id is required is required to insert a record");
185
- }
186
-
187
- fields.splice(index, 0, data);
188
- };
189
-
190
- var updateAt = function updateAt(index, data, fields) {
191
- if (fields[index].id !== data.id) {
192
- throw new Error("id " + data.id + " not matched");
193
- }
194
-
195
- fields[index] = _extends({}, fields[index], data);
196
- };
197
-
198
- var deleteAt = function deleteAt(index, fields) {
199
- fields.splice(index, 1);
200
- };
201
-
202
- var deleteExtraKeys = function deleteExtraKeys(data) {
203
- delete data.__action__;
204
- delete data.__property__;
205
- };
206
-
207
- var getMergedConfig = function getMergedConfig(defaultConfig, deltaConfig) {
208
- var mergedConfigObj = defaultConfig;
209
-
210
- for (var key in deltaConfig) {
211
- if (deltaConfig.hasOwnProperty(key)) {
212
- var mergedConfig = MergeConfigObj(defaultConfig[key], deltaConfig[key]);
213
- mergedConfigObj[key] = mergedConfig;
214
- }
215
- }
216
-
217
- return mergedConfigObj;
218
- };
219
-
220
- var Urls = {
221
- MDMS: "/egov-mdms-service/v1/_search",
222
- WorkFlow: "/egov-workflow-v2/egov-wf/businessservice/_search",
223
- WorkFlowProcessSearch: "/egov-workflow-v2/egov-wf/process/_search",
224
- localization: "/localization/messages/v1/_search",
225
- location: {
226
- localities: "/egov-location/location/v11/boundarys/_search?hierarchyTypeCode=ADMIN&boundaryType=Locality"
227
- },
228
- pgr_search: "/pgr-services/v2/request/_search",
229
- pgr_update: "/pgr-services/v2/request/_update"
230
- };
231
-
232
- var localStoreSupport = function localStoreSupport() {
233
- try {
234
- return "sessionStorage" in window && window["sessionStorage"] !== null;
235
- } catch (e) {
236
- return false;
237
- }
238
- };
239
-
240
- var storageClass = window.sessionStorage;
241
-
242
- var k = function k(key) {
243
- return "eGov.Rainmaker." + key;
244
- };
245
-
246
- var Storage = {
247
- get: function get(key) {
248
- if (localStoreSupport() && key) {
249
- var valueInStorage = storageClass.getItem(k(key));
250
- return valueInStorage && valueInStorage !== "undefined" ? JSON.parse(valueInStorage) : null;
251
- } else if (typeof window !== "undefined") {
252
- return window && window.eGov && window.eGov.Storage && window.eGov.Storage[k(key)];
253
- } else {
254
- return null;
255
- }
256
- },
257
- set: function set(key, value) {
258
- if (localStoreSupport()) {
259
- storageClass.setItem(k(key), JSON.stringify(value));
260
- } else if (typeof window !== "undefined") {
261
- window.eGov = window.eGov || {};
262
- window.eGov.Storage = window.eGov.Storage || {};
263
- window.eGov.Storage[k(key)] = value;
264
- }
265
- },
266
- del: function del(key) {
267
- if (localStoreSupport()) {
268
- storageClass.removeItem(k(key));
269
- } else if (typeof window !== "undefined") {
270
- window.eGov = window.eGov || {};
271
- window.eGov.Storage = window.eGov.Storage || {};
272
- delete window.eGov.Storage[k(key)];
273
- }
274
- }
275
- };
276
-
277
- Axios.interceptors.request.use(function (req) {
278
- document.body.classList.add("loader");
279
- return req;
280
- });
281
- Axios.interceptors.response.use(function (res) {
282
- document.body.classList.remove("loader");
283
- return res;
284
- }, function (err) {
285
- document.body.classList.remove("loader");
286
- return err;
287
- });
288
- var requestInfo = {
289
- apiId: "Rainmaker",
290
- action: "",
291
- did: 1,
292
- key: "",
293
- msgId: "20170310130900|en_IN",
294
- requesterId: "",
295
- ts: 1513579888683,
296
- ver: ".01",
297
- authToken: Storage.get("citizen.token")
298
- };
299
- var userServiceData = {
300
- userInfo: {
301
- id: 23349,
302
- uuid: "530968f3-76b3-4fd1-b09d-9e22eb1f85df",
303
- userName: "9404052047",
304
- name: "Aniket T",
305
- mobileNumber: "9404052047",
306
- emailId: "xc@gmail.com",
307
- locale: null,
308
- type: "CITIZEN",
309
- roles: [{
310
- name: "Citizen",
311
- code: "CITIZEN",
312
- tenantId: "pb"
313
- }],
314
- active: true,
315
- tenantId: "pb"
316
- }
317
- };
318
- var Request = function Request(_ref) {
319
- var _ref$method = _ref.method,
320
- method = _ref$method === void 0 ? "POST" : _ref$method,
321
- url = _ref.url,
322
- _ref$data = _ref.data,
323
- data = _ref$data === void 0 ? {} : _ref$data,
324
- _ref$useCache = _ref.useCache,
325
- useCache = _ref$useCache === void 0 ? false : _ref$useCache,
326
- _ref$params = _ref.params,
327
- params = _ref$params === void 0 ? {} : _ref$params,
328
- auth = _ref.auth,
329
- userService = _ref.userService;
330
-
331
- try {
332
- var key = "";
333
-
334
- if (method.toUpperCase() === "POST") {
335
- data.RequestInfo = {
336
- apiId: "Rainmaker"
337
- };
338
-
339
- if (auth) {
340
- data.RequestInfo = _extends({}, data.RequestInfo, requestInfo);
341
- }
342
-
343
- if (userService) {
344
- data.RequestInfo = _extends({}, data.RequestInfo, userServiceData);
345
- }
346
- }
347
-
348
- if (useCache) {
349
- key = method.toUpperCase() + "." + url + "." + JSON.stringify(params, null, 0) + "." + JSON.stringify(data, null, 0);
350
- var value = Storage.get(key);
351
-
352
- if (value) {
353
- return Promise.resolve(value);
354
- }
355
- } else {
356
- params._ = Date.now();
357
- }
358
-
359
- return Promise.resolve(Axios({
360
- method: method,
361
- url: url,
362
- data: data,
363
- params: params
364
- })).then(function (res) {
365
- if (useCache) {
366
- Storage.set(key, res.data);
367
- }
368
-
369
- return res.data;
370
- });
371
- } catch (e) {
372
- return Promise.reject(e);
373
- }
374
- };
375
- var SortByName = function SortByName(na, nb) {
376
- if (na < nb) {
377
- return -1;
378
- }
379
-
380
- if (na > nb) {
381
- return 1;
382
- }
383
-
384
- return 0;
385
- };
386
- var GetCitiesWithi18nKeys = function GetCitiesWithi18nKeys(MdmsRes, moduleCode) {
387
- var cityList = MdmsRes.tenant.citymodule && MdmsRes.tenant.citymodule.filter(function (module) {
388
- return module.code === moduleCode;
389
- })[0].tenants || [];
390
- var citiesMap = cityList.map(function (city) {
391
- return city.code;
392
- });
393
- var cities = MdmsRes.tenant.tenants.filter(function (city) {
394
- return citiesMap.includes(city.code);
395
- }).map(function (_ref2) {
396
- var code = _ref2.code,
397
- name = _ref2.name,
398
- logoId = _ref2.logoId,
399
- emailId = _ref2.emailId,
400
- address = _ref2.address,
401
- contactNumber = _ref2.contactNumber;
402
- return {
403
- code: code,
404
- name: name,
405
- logoId: logoId,
406
- emailId: emailId,
407
- address: address,
408
- contactNumber: contactNumber,
409
- i18nKey: "TENANT_TENANTS_" + code.replace(".", "_").toUpperCase()
410
- };
411
- }).sort(function (cityA, cityB) {
412
- var na = cityA.name.toLowerCase(),
413
- nb = cityB.name.toLowerCase();
414
- return SortByName(na, nb);
415
- });
416
- return cities;
417
- };
418
-
419
- var LOCALE_LIST = function LOCALE_LIST(locale) {
420
- return "Locale." + locale + ".List";
421
- };
422
-
423
- var LOCALE_MODULE = function LOCALE_MODULE(locale, module) {
424
- return "Locale." + locale + "." + module;
425
- };
426
-
427
- var TransformArrayToObj = function TransformArrayToObj(traslationList) {
428
- return traslationList.reduce(function (obj, item) {
429
- return obj[item.code] = item.message, obj;
430
- }, {});
431
- };
432
-
433
- var LocalizationStore = {
434
- getList: function getList(locale) {
435
- return Storage.get(LOCALE_LIST(locale)) || [];
436
- },
437
- store: function store(locale, modules, messages) {
438
- modules.forEach(function (module) {
439
- var Locales = LocalizationStore.getList(locale);
440
-
441
- if (!Locales.includes(module)) {
442
- Locales.push(module);
443
- Storage.set(LOCALE_LIST(locale), Locales);
444
- var moduleMessages = messages.filter(function (message) {
445
- return message.module === module;
446
- });
447
- Storage.set(LOCALE_MODULE(locale, module), moduleMessages);
448
- }
449
- });
450
- },
451
- get: function get(locale, modules) {
452
- var storedModules = LocalizationStore.getList(locale);
453
- var newModules = modules.filter(function (module) {
454
- return !storedModules.includes(module);
455
- });
456
- var messages = [];
457
- storedModules.forEach(function (module) {
458
- messages.push.apply(messages, Storage.get(LOCALE_MODULE(locale, module)));
459
- });
460
- return [newModules, messages];
461
- },
462
- updateResources: function updateResources(locale, messages) {
463
- var locales = TransformArrayToObj(messages);
464
- i18next.addResources(locale.split("_")[0], "translations", locales);
465
- }
466
- };
467
- var LocalizationService = {
468
- getLocale: function (_ref) {
469
- var _ref$modules = _ref.modules,
470
- modules = _ref$modules === void 0 ? [] : _ref$modules,
471
- _ref$locale = _ref.locale,
472
- locale = _ref$locale === void 0 ? "en_IN" : _ref$locale,
473
- tenantId = _ref.tenantId;
474
-
475
- try {
476
- var _temp3 = function _temp3() {
477
- LocalizationStore.store(locale, modules, messages);
478
- LocalizationStore.updateResources(locale, messages);
479
- return messages;
480
- };
481
-
482
- if (locale.indexOf("_IN") === -1) {
483
- locale += "_IN";
484
- }
485
-
486
- var _LocalizationStore$ge = LocalizationStore.get(locale, modules),
487
- newModules = _LocalizationStore$ge[0],
488
- messages = _LocalizationStore$ge[1];
489
-
490
- var _temp4 = function () {
491
- if (newModules.length > 0) {
492
- return Promise.resolve(Request({
493
- url: Urls.localization,
494
- params: {
495
- module: newModules.join(","),
496
- locale: locale,
497
- tenantId: tenantId
498
- },
499
- useCache: false
500
- })).then(function (data) {
501
- messages.push.apply(messages, data.messages);
502
- });
503
- }
504
- }();
505
-
506
- return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
507
- } catch (e) {
508
- return Promise.reject(e);
509
- }
510
- }
511
- };
512
-
513
- var initRequestBody = function initRequestBody(tenantId) {
514
- return {
515
- MdmsCriteria: {
516
- tenantId: tenantId,
517
- moduleDetails: [{
518
- moduleName: "common-masters",
519
- masterDetails: [{
520
- name: "Department"
521
- }, {
522
- name: "Designation"
523
- }, {
524
- name: "StateInfo"
525
- }]
526
- }, {
527
- moduleName: "tenant",
528
- masterDetails: [{
529
- name: "tenants"
530
- }, {
531
- name: "citymodule"
532
- }]
533
- }]
534
- }
535
- };
536
- };
537
-
538
- var getCriteria = function getCriteria(_ref) {
539
- var tenantId = _ref.tenantId,
540
- moduleDetails = _ref.moduleDetails;
541
- return {
542
- MdmsCriteria: {
543
- tenantId: tenantId,
544
- moduleDetails: moduleDetails
545
- }
546
- };
547
- };
548
-
549
- var GetEgovLocations = function GetEgovLocations(MdmsRes) {
550
- return MdmsRes["egov-location"].TenantBoundary[0].boundary.children.map(function (obj) {
551
- return {
552
- name: obj.localname,
553
- i18nKey: obj.localname
554
- };
555
- });
556
- };
557
-
558
- var GetServiceDefs = function GetServiceDefs(MdmsRes) {
559
- return MdmsRes["RAINMAKER-PGR"].ServiceDefs.filter(function (def) {
560
- return def.active;
561
- });
562
- };
563
-
564
- var transformResponse = function transformResponse(type, MdmsRes, moduleCode) {
565
- if (moduleCode === void 0) {
566
- moduleCode = "PGR";
567
- }
568
-
569
- switch (type) {
570
- case "citymodule":
571
- return GetCitiesWithi18nKeys(MdmsRes, moduleCode);
572
-
573
- case "egovLocation":
574
- return GetEgovLocations(MdmsRes);
575
-
576
- case "serviceDefs":
577
- return GetServiceDefs(MdmsRes);
578
-
579
- default:
580
- return MdmsRes;
581
- }
582
- };
583
-
584
- var MdmsService = {
585
- init: function init(stateCode) {
586
- if (stateCode === void 0) {
587
- stateCode = "pb";
588
- }
589
-
590
- return Request({
591
- url: Urls.MDMS,
592
- data: initRequestBody(stateCode),
593
- useCache: true,
594
- method: "POST",
595
- params: {
596
- tenantId: stateCode
597
- }
598
- });
599
- },
600
- call: function call(details, stateCode) {
601
- if (stateCode === void 0) {
602
- stateCode = "pb";
603
- }
604
-
605
- return Request({
606
- url: Urls.MDMS,
607
- data: getCriteria(details),
608
- useCache: true,
609
- method: "POST",
610
- params: {
611
- tenantId: stateCode
612
- }
613
- });
614
- },
615
- getDataByCriteria: function (mdmsDetails) {
616
- try {
617
- var moduleCode = "PGR";
618
- return Promise.resolve(MdmsService.call(mdmsDetails.details)).then(function (_ref2) {
619
- var MdmsRes = _ref2.MdmsRes;
620
- return transformResponse(mdmsDetails.type, MdmsRes, moduleCode);
621
- });
622
- } catch (e) {
623
- return Promise.reject(e);
624
- }
625
- }
626
- };
627
-
628
- var WorkflowService = {
629
- init: function init(stateCode, businessServices) {
630
- if (stateCode === void 0) {
631
- stateCode = "pb";
632
- }
633
-
634
- if (businessServices === void 0) {
635
- businessServices = "PGR";
636
- }
637
-
638
- return Request({
639
- url: Urls.WorkFlow,
640
- useCache: true,
641
- method: "POST",
642
- params: {
643
- tenantId: stateCode,
644
- businessServices: businessServices
645
- },
646
- auth: true
647
- });
648
- },
649
- getByBusinessId: function getByBusinessId(stateCode, businessIds) {
650
- if (stateCode === void 0) {
651
- stateCode = "pb";
652
- }
653
-
654
- return Request({
655
- url: Urls.WorkFlowProcessSearch,
656
- useCache: false,
657
- method: "POST",
658
- params: {
659
- tenantId: stateCode,
660
- businessIds: businessIds,
661
- history: true
662
- },
663
- auth: true
664
- });
665
- },
666
- getNextAction: function (stateCode, currentState) {
667
- if (stateCode === void 0) {
668
- stateCode = "pb";
669
- }
670
-
671
- try {
672
- var role = Storage.get("role") || "CITIZEN";
673
- return Promise.resolve(WorkflowService.init(stateCode, "PGR")).then(function (res) {
674
- var selectedState = res.BusinessServices[0].states.filter(function (state) {
675
- return state.state === currentState;
676
- })[0];
677
- var actions = selectedState.actions && selectedState.actions.filter(function (state) {
678
- return state.roles.includes(role);
679
- }) || [];
680
- return actions;
681
- });
682
- } catch (e) {
683
- return Promise.reject(e);
684
- }
685
- }
686
- };
687
-
688
- var StoreService = {
689
- defaultData: function (stateCode, cityCode, moduleCode) {
690
- try {
691
- return Promise.resolve(MdmsService.init(stateCode)).then(function (_ref) {
692
- var MdmsRes = _ref.MdmsRes;
693
- return Promise.resolve(WorkflowService.init(cityCode, moduleCode)).then(function (_ref2) {
694
- var BusinessServices = _ref2.BusinessServices;
695
- var stateInfo = MdmsRes["common-masters"].StateInfo[0];
696
- var cities = GetCitiesWithi18nKeys(MdmsRes, moduleCode);
697
- var defaultData = {
698
- languages: stateInfo.hasLocalisation ? stateInfo.languages : [{
699
- label: "ENGLISH",
700
- value: "en_IN"
701
- }],
702
- stateInfo: {
703
- code: stateInfo.code,
704
- name: stateInfo.name,
705
- logoUrl: stateInfo.logoUrl
706
- },
707
- cities: cities,
708
- cityCode: cityCode,
709
- businessServices: BusinessServices
710
- };
711
- return Promise.resolve(LocalizationService.getLocale({
712
- modules: ["rainmaker-common", "rainmaker-" + moduleCode.toLowerCase(), "rainmaker-" + stateCode.toLowerCase(), "rainmaker-" + cityCode.toLowerCase()],
713
- locale: defaultData.languages[0].value,
714
- tenantId: stateCode
715
- })).then(function (_LocalizationService$) {
716
- defaultData.locales = _LocalizationService$;
717
- return defaultData;
718
- });
719
- });
720
- });
721
- } catch (e) {
722
- return Promise.reject(e);
723
- }
724
- }
725
- };
726
-
727
- var useStore = function useStore(defaultConfig, _ref) {
728
- var deltaConfig = _ref.deltaConfig,
729
- stateCode = _ref.stateCode,
730
- cityCode = _ref.cityCode,
731
- moduleCode = _ref.moduleCode;
732
-
733
- var _React$useState = React.useState({}),
734
- defaultStore = _React$useState[0],
735
- setDefaultStore = _React$useState[1];
736
-
737
- React.useEffect(function () {
738
- var config = window.Digit.Config.mergeConfig(defaultConfig, deltaConfig);
739
- StoreService.defaultData(stateCode, cityCode, moduleCode).then(function (defaultData) {
740
- var store = _extends({
741
- config: config
742
- }, defaultData);
743
-
744
- setDefaultStore(store);
745
- });
746
- }, [defaultConfig, stateCode, cityCode, moduleCode]);
747
- return defaultStore;
748
- };
749
-
750
- var i18nextConfig = {
751
- lng: "en",
752
- fallbackLng: "en",
753
- debug: false,
754
- ns: ["translations"],
755
- defaultNS: "translations",
756
- keySeparator: false,
757
- saveMissing: false,
758
- saveMissingTo: "current",
759
- interpolation: {
760
- escapeValue: false,
761
- formatSeparator: ","
762
- },
763
- postProcess: ["reactPostprocessor"],
764
- react: {
765
- wait: true,
766
- useSuspense: true,
767
- bindI18n: "loaded",
768
- bindI18nStore: "added"
769
- },
770
- resources: {
771
- en: {
772
- translation: {
773
- welcome: "Welcome"
774
- }
775
- }
776
- }
777
- };
778
- var initI18n = function initI18n() {
779
- i18next.use(new ReactPostprocessor()).use(reactI18next.initReactI18next).init(i18nextConfig);
780
- };
781
-
782
- var Pages = Object.freeze({
783
- PGR_LIST: "pgr-list",
784
- PGR_NEW_COMPLAINT: "pgr-new-complaint",
785
- PGR_SEARCH: "pgr-search-complaint"
786
- });
787
-
788
- var ConfigActionTypes = Object.freeze({
789
- CONFIG_UPDATE: "CONFIG_UPDATE"
790
- });
791
-
792
- var Enums = {
793
- Pages: Pages,
794
- ConfigActionTypes: ConfigActionTypes
795
- };
796
-
797
- var LocationService = {
798
- getLocalities: function getLocalities(_ref) {
799
- var tenantId = _ref.tenantId;
800
- return Request({
801
- url: Urls.location.localities,
802
- params: {
803
- tenantId: tenantId.toLowerCase()
804
- },
805
- useCache: true
806
- });
807
- }
808
- };
809
-
810
- var ADMIN_CODE = function ADMIN_CODE(_ref) {
811
- var tenantId = _ref.tenantId,
812
- hierarchyType = _ref.hierarchyType;
813
- return tenantId.replace(".", "_").toUpperCase() + "_" + hierarchyType.code;
814
- };
815
-
816
- var getLocalities = function getLocalities(tenantBoundry) {
817
- var adminCode = ADMIN_CODE(tenantBoundry);
818
- return tenantBoundry.boundary.map(function (boundaryObj) {
819
- return _extends({}, boundaryObj, {
820
- i18nkey: adminCode + "_" + boundaryObj.code
821
- });
822
- });
823
- };
824
-
825
- var LocalityService = {
826
- get: function get(tenantBoundry) {
827
- return getLocalities(tenantBoundry);
828
- }
829
- };
830
-
831
- var PGRService = {
832
- search: function search(stateCode, fiters) {
833
- if (stateCode === void 0) {
834
- stateCode = "pb";
835
- }
836
-
837
- if (fiters === void 0) {
838
- fiters = {};
839
- }
840
-
841
- return Request({
842
- url: Urls.pgr_search,
843
- useCache: false,
844
- userInfo: true,
845
- method: "POST",
846
- auth: true,
847
- userService: true,
848
- params: _extends({
849
- tenantId: stateCode
850
- }, fiters)
851
- });
852
- },
853
- create: function create(details, stateCode) {
854
- if (stateCode === void 0) {
855
- stateCode = "pb";
856
- }
857
-
858
- return Request({
859
- url: Urls.MDMS,
860
- data: details,
861
- useCache: true,
862
- method: "POST",
863
- params: {
864
- tenantId: stateCode
865
- }
866
- });
867
- },
868
- update: function update(details, stateCode) {
869
- if (stateCode === void 0) {
870
- stateCode = "pb";
871
- }
872
-
873
- return Request({
874
- url: Urls.pgr_update,
875
- data: details,
876
- useCache: true,
877
- auth: true,
878
- method: "POST",
879
- params: {
880
- tenantId: stateCode
881
- }
882
- });
883
- },
884
- count: function count(details, stateCode) {
885
- if (stateCode === void 0) {
886
- stateCode = "pb";
887
- }
888
-
889
- return Request({
890
- url: Urls.MDMS,
891
- data: details,
892
- useCache: true,
893
- method: "POST",
894
- params: {
895
- tenantId: stateCode
896
- }
897
- });
898
- }
899
- };
900
-
901
- var ConvertTimestampToDate = function ConvertTimestampToDate(timestamp, dateFormat) {
902
- if (dateFormat === void 0) {
903
- dateFormat = "d-MMM-yyyy";
904
- }
905
-
906
- return dateFns.format(dateFns.toDate(timestamp), dateFormat);
907
- };
908
-
909
- var dateUtils = {
910
- __proto__: null,
911
- ConvertTimestampToDate: ConvertTimestampToDate
912
- };
913
-
914
- var UploadServices = {
915
- Filestorage: function (filedata) {
916
- try {
917
- var formData = new FormData();
918
- formData.append("file", filedata, filedata.name);
919
- formData.append("tenantId", "pb.amritsar");
920
- formData.append("module", "property-upload");
921
- var config = {
922
- method: "post",
923
- url: "/filestore/v1/files",
924
- data: formData
925
- };
926
- return Promise.resolve(Axios(config));
927
- } catch (e) {
928
- return Promise.reject(e);
929
- }
930
- },
931
- Filefetch: function (filesArray, tenantId) {
932
- try {
933
- var config = {
934
- method: "get",
935
- url: "/filestore/v1/files/url",
936
- params: {
937
- tenantId: tenantId,
938
- fileStoreIds: filesArray.join(",")
939
- }
940
- };
941
- return Promise.resolve(Axios(config));
942
- } catch (e) {
943
- return Promise.reject(e);
944
- }
945
- }
946
- };
947
-
948
- var setupLibraries = function setupLibraries(Library, props) {
949
- window.Digit = window.Digit || {};
950
- window.Digit[Library] = window.Digit[Library] || {};
951
- window.Digit[Library] = _extends({}, window.Digit[Library], props);
952
- };
953
-
954
- var initLibraries = function initLibraries() {
955
- setupLibraries("Config", {
956
- mergeConfig: getMergedConfig
957
- });
958
- setupLibraries("Services", {
959
- useStore: useStore
960
- });
961
- setupLibraries("Translation", {
962
- initI18n: initI18n
963
- });
964
- setupLibraries("Enums", Enums);
965
- setupLibraries("SessionStorage", Storage);
966
- setupLibraries("LocationService", LocationService);
967
- setupLibraries("LocalityService", LocalityService);
968
- setupLibraries("LocalizationService", LocalizationService);
969
- setupLibraries("PGRService", PGRService);
970
- setupLibraries("DateUtils", dateUtils);
971
- setupLibraries("workflowService", WorkflowService);
972
- setupLibraries("MDMSService", MdmsService);
973
- setupLibraries("UploadServices", UploadServices);
974
- initI18n();
975
- };
976
-
977
- exports.Enums = Enums;
978
- exports.default = initLibraries;
979
-
980
- })));
981
- //# sourceMappingURL=index.umd.js.map