@argusoft/medplat-app-shell 1.0.5 → 1.0.7

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.
Files changed (263) hide show
  1. package/package.json +139 -141
  2. package/src/GlobalErrorBoundary.jsx +31 -0
  3. package/src/SilentErrorFallback.jsx +68 -0
  4. package/src/TrackingProviderWrapper.jsx +40 -0
  5. package/src/_tests_/__mocks__/MockTranslationProvider.jsx +21 -0
  6. package/src/_tests_/__mocks__/ckeditor.js +45 -0
  7. package/src/_tests_/__mocks__/fileMock.js +1 -0
  8. package/src/_tests_/__mocks__/useranalytics.js +5 -0
  9. package/src/_tests_/views/components/Dashboard/DashboardUI.test.jsx +137 -0
  10. package/src/_tests_/views/components/Dashboard/DashboardUIMock.js +877 -0
  11. package/src/_tests_/views/components/ForgotPassword/ForgotPassword.test.jsx +314 -0
  12. package/src/_tests_/views/components/LocationDirective/LocationDirective.test.jsx.disable +229 -0
  13. package/src/_tests_/views/components/LocationDirective/mockLocationDirective.js +810 -0
  14. package/src/_tests_/views/components/LocationType/MockLocationType.js +42259 -0
  15. package/src/_tests_/views/components/LocationType/addlocationtype.test.jsx.disable +276 -0
  16. package/src/_tests_/views/components/LocationType/editlocationtype.test.jsx.disable +262 -0
  17. package/src/_tests_/views/components/LocationType/locationtype.test.jsx.disable +148 -0
  18. package/src/_tests_/views/components/Profile/UpdateProfileModalData.js +4396 -0
  19. package/src/_tests_/views/components/Profile/updateprofilemodal.test.jsx +282 -0
  20. package/src/_tests_/views/components/SideBar/MockSideBar.js +1379 -0
  21. package/src/_tests_/views/components/SideBar/SideBar.test.jsx +98 -0
  22. package/src/_tests_/views/components/SystemConfig/ManageSystemConfig/AddManageSystemConfig.test.jsx.disable +164 -0
  23. package/src/_tests_/views/components/SystemConfig/ManageSystemConfig/UpdateManageSystemConfig.test.jsx.disable +157 -0
  24. package/src/_tests_/views/components/SystemConfig/MockSystemConfig.js +1280 -0
  25. package/src/_tests_/views/components/SystemConfig/SystemConfig.test.jsx.disable +165 -0
  26. package/src/_tests_/views/components/login/Login.test.jsx +276 -0
  27. package/src/_tests_/views/components/login/MockAuthorise.js +2414 -0
  28. package/src/_tests_/views/components/login/ServiceResponse.js +595 -0
  29. package/src/_tests_/views/components/user/MockManageUser.js +7965 -0
  30. package/src/_tests_/views/components/user/manageuser.test.jsx.disable +989 -0
  31. package/src/_tests_/views/components/user/mockUsersData.js +582 -0
  32. package/src/assets/img/OASISLogin.png +0 -0
  33. package/src/assets/img/bahaarNew.png +0 -0
  34. package/src/assets/img/dnhdd4K.png +0 -0
  35. package/src/assets/img/govtofup.png +0 -0
  36. package/src/assets/img/sewarural4K.png +0 -0
  37. package/src/assets/img/techo4K.png +0 -0
  38. package/src/assets/img/up4K.png +0 -0
  39. package/src/common/HolidayList.jsx +573 -0
  40. package/src/common/MalaciaousInputUtil.js +23 -0
  41. package/src/common/SafeHtml.jsx +17 -0
  42. package/src/common/VersionManager.jsx +109 -0
  43. package/src/common/constants/PerformanceDashboard.js +514 -0
  44. package/src/common/constants/app.constant.js +781 -0
  45. package/src/common/constants/cccVerificationConstants.js +18 -0
  46. package/src/common/constants/fhsrConstant.js +33 -0
  47. package/src/common/constants/gvk-verification.constant.js +76 -0
  48. package/src/common/constants/search.constant.js +23 -0
  49. package/src/common/constants/teleconsulatationConstant.jsx +1339 -0
  50. package/src/common/directives/SearchTemplate.jsx +784 -0
  51. package/src/common/directives/SearchTemplate.scss +14 -0
  52. package/src/common/dynamicView/DynamicView.jsx +353 -0
  53. package/src/common/dynamicView/InputFieldComponent.jsx +1501 -0
  54. package/src/common/dynamicView/InputViewComponent.jsx +298 -0
  55. package/src/common/dynamicView/InputViewComponent.scss +15 -0
  56. package/src/common/env.js +5 -0
  57. package/src/common/filters/locationNameFilter.js +26 -0
  58. package/src/common/fontAwesomeIcons/FontAwesomeIcons.jsx +27 -0
  59. package/src/common/fontAwesomeIcons/FontAwesomeIconsNames.js +1968 -0
  60. package/src/common/fontPreferences/fontSizeProvider.jsx +34 -0
  61. package/src/common/fontPreferences/fontSizeSelector.jsx +116 -0
  62. package/src/common/getAssignedFeature/getAssignedFeature.js +32 -0
  63. package/src/common/interceptors/AxiosInterceptor.js +216 -0
  64. package/src/common/languageTranslator/TranslationContext.js +5 -0
  65. package/src/common/languageTranslator/TranslationProvider.jsx +24 -0
  66. package/src/common/languageTranslator/i18n.js +49 -0
  67. package/src/common/services/AuthenticateService.js +116 -0
  68. package/src/common/services/DownloadFile.js +35 -0
  69. package/src/common/services/ForgotPassword.js +18 -0
  70. package/src/common/services/FormConfiguratorService.js +195 -0
  71. package/src/common/services/GlobalApis.js +84 -0
  72. package/src/common/services/InterceptorNavigationService.js +17 -0
  73. package/src/common/services/LocationService.js +65 -0
  74. package/src/common/services/LocationType.js +11 -0
  75. package/src/common/services/QueryBuilder.js +36 -0
  76. package/src/common/services/Roles.js +28 -0
  77. package/src/common/services/SyncWithServer.js +15 -0
  78. package/src/common/services/SystemConfig.js +15 -0
  79. package/src/common/services/TranslationService.js +70 -0
  80. package/src/common/services/TwoFactorService.js +7 -0
  81. package/src/common/services/Users.js +91 -0
  82. package/src/common/services/Webtasks.js +27 -0
  83. package/src/common/services/util/Convert-pad-data-to-API-format.jsx +167 -0
  84. package/src/common/services/util/Convert-to-UI-format.jsx +82 -0
  85. package/src/common/services/util/EmptyPrescriptionPadData.jsx +11 -0
  86. package/src/common/services/util/GeneralUtil.js +456 -0
  87. package/src/common/services/util/Prescription-pad-util.js +339 -0
  88. package/src/common/services/util/PrescriptionPadData.js +67 -0
  89. package/src/common/services/util/PrescriptionpadCommonUtil.js +96 -0
  90. package/src/common/services/util/ReportFieldUtil.jsx +398 -0
  91. package/src/common/services/util/WebSocketContext.jsx +261 -0
  92. package/src/common/syncWithServer/SyncWithServerDialog.jsx +170 -0
  93. package/src/common/syncWithServer/SyncWithServerDialogSkeleton.jsx +67 -0
  94. package/src/common/tests/CustomWrapper.jsx +49 -0
  95. package/src/common/tests/TranslationWrapper.jsx +38 -0
  96. package/src/common/themeProvider/ColorInputs.jsx +97 -0
  97. package/src/common/themeProvider/EditableColorInput.jsx +128 -0
  98. package/src/common/themeProvider/ThemeEditor.jsx +319 -0
  99. package/src/common/themeProvider/ThemeProvider.jsx +210 -0
  100. package/src/common/themeProvider/themeConfig.js +558 -0
  101. package/src/common/toaster/toaster.jsx +30 -0
  102. package/src/firebaseConfig.js +24 -0
  103. package/src/global.scss +221 -0
  104. package/src/hooks/.gitkeep +0 -0
  105. package/src/hooks/useAESEncryption.js +56 -0
  106. package/src/hooks/useCaching.js +43 -0
  107. package/src/hooks/useDebounce.js +34 -0
  108. package/src/hooks/useDebounceFn.js +50 -0
  109. package/src/hooks/useDownloadPdf.js +358 -0
  110. package/src/hooks/useDownloadXlsx.js +55 -0
  111. package/src/hooks/useListValueFieldValues.js +30 -0
  112. package/src/hooks/useLocationHierarchies.js +63 -0
  113. package/src/hooks/useLocationHierarchyTranslate.js +16 -0
  114. package/src/hooks/useOnline.js +27 -0
  115. package/src/hooks/usePagination.js +63 -0
  116. package/src/hooks/useRefreshToken.js +87 -0
  117. package/src/hooks/useScript.js +25 -0
  118. package/src/hooks/useStopwatch.js +75 -0
  119. package/src/hooks/useTrackEvent.js +22 -0
  120. package/src/hooks/useWebAudioRecorder.js +115 -0
  121. package/src/layout/LoaderComponet.jsx +22 -0
  122. package/src/layout/LoaderContext.jsx +29 -0
  123. package/src/layout/mainLayout/AdaptiveZoom.jsx +27 -0
  124. package/src/layout/mainLayout/Chatbot.jsx +243 -0
  125. package/src/layout/mainLayout/Layout.jsx +445 -0
  126. package/src/layout/mainLayout/Profile/UpdateProfileModal.jsx +684 -0
  127. package/src/layout/mainLayout/header/LogoutModal.jsx +131 -0
  128. package/src/layout/mainLayout/header/Navbar.jsx +1677 -0
  129. package/src/layout/mainLayout/header/Navbar.scss +4 -0
  130. package/src/layout/mainLayout/header/index.js +0 -0
  131. package/src/layout/mainLayout/sidebar/SideBar.jsx +1402 -0
  132. package/src/layout/mainLayout/sidebar/Sidebar.css +159 -0
  133. package/src/layout/mainLayout/sidebar/index.js +0 -0
  134. package/src/logo.svg +1 -0
  135. package/src/reportWebVitals.js +13 -0
  136. package/src/setupFirebaseMessaging.js +28 -0
  137. package/src/setupTests.js +8 -0
  138. package/src/store/actions/AuthenticationActions.js +0 -0
  139. package/src/store/actions/ReportsActions.js +0 -0
  140. package/src/store/actions/TranslationAction.js +0 -0
  141. package/src/store/index.js +8 -0
  142. package/src/store/reducer.js +46 -0
  143. package/src/store/reducers/AuthenticationReducer.js +50 -0
  144. package/src/store/reducers/CalendarEventReducer.js +41 -0
  145. package/src/store/reducers/ConditionClipboardReducer.js +45 -0
  146. package/src/store/reducers/FeatureReducer.js +27 -0
  147. package/src/store/reducers/FormConfiguratorReducer.js +38 -0
  148. package/src/store/reducers/LoadingReducer.js +20 -0
  149. package/src/store/reducers/MembersAuthenticationReducer.js +28 -0
  150. package/src/store/reducers/PrescriptionPadReducer.js +329 -0
  151. package/src/store/reducers/QuestionaireReducer.js +29 -0
  152. package/src/store/reducers/ReportsReducer.js +24 -0
  153. package/src/store/reducers/SkeletonReducer.js +20 -0
  154. package/src/store/reducers/ThemeReducer.js +106 -0
  155. package/src/store/reducers/TranslationReducer.js +126 -0
  156. package/src/store/reducers/dashboardEditorSlice.js +77 -0
  157. package/src/store/reducers/districtHealthDashboardSlice.js +58 -0
  158. package/src/store/reducers/immunizationSlice.js +234 -0
  159. package/src/store/slices/dashboardPagesSlice.js +51 -0
  160. package/src/utils/.gitkeep +0 -0
  161. package/src/utils/FormConstants.js +2629 -0
  162. package/src/utils/GujaratTopoChart.jsx +483 -0
  163. package/src/utils/UUIDgenerator.js +8 -0
  164. package/src/utils/appointment-utils/appointment-utils.js +123 -0
  165. package/src/utils/feature.js +42 -0
  166. package/src/utils/getThemeColor.js +12 -0
  167. package/src/utils/localStorageHelper.js +11 -0
  168. package/src/utils/notifications/enable-push-notifications.js +27 -0
  169. package/src/utils/resolveAppliedStyle.js +11 -0
  170. package/src/utils/themeConfigs.js +1483 -0
  171. package/src/views/custom-components/.gitkeep +0 -0
  172. package/src/views/custom-components/AgIconButton/RIf.jsx +14 -0
  173. package/src/views/custom-components/AgIconButton/button.jsx +108 -0
  174. package/src/views/custom-components/AgIconButton/waterDrop.jsx +95 -0
  175. package/src/views/custom-components/AgIconButton/waterDrop.scss +37 -0
  176. package/src/views/custom-components/AlertPlaceholder.jsx +32 -0
  177. package/src/views/custom-components/AllFaIconsSelector.jsx +56 -0
  178. package/src/views/custom-components/CkEditor/CkEditor.js +102 -0
  179. package/src/views/custom-components/CustomAccordion.jsx +72 -0
  180. package/src/views/custom-components/CustomActionIcons.jsx +118 -0
  181. package/src/views/custom-components/CustomAutoComplete.jsx +188 -0
  182. package/src/views/custom-components/CustomCheckBox.jsx +60 -0
  183. package/src/views/custom-components/CustomConfirmationModal.jsx +118 -0
  184. package/src/views/custom-components/CustomCountrySelect.jsx +129 -0
  185. package/src/views/custom-components/CustomDatePicker.jsx +122 -0
  186. package/src/views/custom-components/CustomDropdown.jsx +191 -0
  187. package/src/views/custom-components/CustomFileUpload.jsx +387 -0
  188. package/src/views/custom-components/CustomFullCalendar.jsx +514 -0
  189. package/src/views/custom-components/CustomInfiniteScroll.jsx +126 -0
  190. package/src/views/custom-components/CustomRadioComponent.jsx +65 -0
  191. package/src/views/custom-components/CustomStatsComponent.jsx +114 -0
  192. package/src/views/custom-components/CustomSvgUpload.jsx +170 -0
  193. package/src/views/custom-components/CustomSwitch.jsx +37 -0
  194. package/src/views/custom-components/CustomTabPanel.jsx +19 -0
  195. package/src/views/custom-components/CustomTextArea.jsx +62 -0
  196. package/src/views/custom-components/CustomTextArea.scss +27 -0
  197. package/src/views/custom-components/CustomTextField.jsx +116 -0
  198. package/src/views/custom-components/CustomToggleSwitch.jsx +138 -0
  199. package/src/views/custom-components/CustomTooltip.jsx +51 -0
  200. package/src/views/custom-components/CustomZoomImage.jsx +134 -0
  201. package/src/views/custom-components/CustomizedTable/CustomizedTableV2.jsx +1407 -0
  202. package/src/views/custom-components/CustomizedTable/VirtualizeTableBody.jsx +295 -0
  203. package/src/views/custom-components/CustomizedTable/helper.jsx +159 -0
  204. package/src/views/custom-components/CustomizedTable.jsx +532 -0
  205. package/src/views/custom-components/EditInputField.jsx +174 -0
  206. package/src/views/custom-components/FieldDescription.jsx +22 -0
  207. package/src/views/custom-components/FileDisplayComponent.jsx +138 -0
  208. package/src/views/custom-components/FormItem.jsx +53 -0
  209. package/src/views/custom-components/GenericChart.jsx +80 -0
  210. package/src/views/custom-components/InfoBadge.jsx +60 -0
  211. package/src/views/custom-components/PostgresEditor.jsx +801 -0
  212. package/src/views/custom-components/ResizableEditAutocompleteField.jsx +249 -0
  213. package/src/views/custom-components/ResizableEditInputField.jsx +215 -0
  214. package/src/views/custom-components/ResizeableEditSelectField.jsx +197 -0
  215. package/src/views/custom-components/SideOverlay.jsx +113 -0
  216. package/src/views/custom-components/SideOverlay.scss +42 -0
  217. package/src/views/custom-components/calendar.scss +571 -0
  218. package/src/views/feature-components/.gitkeep +0 -0
  219. package/src/views/feature-components/Dashboard/DashboardUI.jsx +1043 -0
  220. package/src/views/feature-components/Dashboard/DhnddModal/AshaDataQualityVerificationModal.jsx +278 -0
  221. package/src/views/feature-components/Dashboard/PinFeatureModal.jsx +143 -0
  222. package/src/views/feature-components/Dashboard/QuickLinks.jsx +163 -0
  223. package/src/views/feature-components/Dashboard/Taskbar.jsx +56 -0
  224. package/src/views/feature-components/Dashboard/WebtasksFilterForm.jsx +109 -0
  225. package/src/views/feature-components/Dashboard/WidgetCard.jsx +161 -0
  226. package/src/views/feature-components/Dashboard/actionModal.jsx +263 -0
  227. package/src/views/feature-components/Dashboard/ekavachModal/HealthWorkerIncorrectDetailsModal.jsx +332 -0
  228. package/src/views/feature-components/Dashboard/ekavachModal/MoMaternalDeathVerifcationModal.jsx +275 -0
  229. package/src/views/feature-components/Dashboard/ekavachModal/MoVerficationForChildScreeningMoadal.jsx +566 -0
  230. package/src/views/feature-components/FeatureUsageAnalytics/FeatureUsageAnalytics.jsx +989 -0
  231. package/src/views/feature-components/Features/NewServerManagement.jsx +217 -0
  232. package/src/views/feature-components/Features/ServerManagement.scss +120 -0
  233. package/src/views/feature-components/ForgotPassword/ForgotPassword.jsx +226 -0
  234. package/src/views/feature-components/LocationDirective/LocationDirective.jsx +992 -0
  235. package/src/views/feature-components/LocationDirective/LocationDirectiveV2.jsx +909 -0
  236. package/src/views/feature-components/NotFound.jsx +66 -0
  237. package/src/views/feature-components/Onboarding/Onboarding.jsx +1400 -0
  238. package/src/views/feature-components/Skeletons.js +115 -0
  239. package/src/views/feature-components/Unauthorized.jsx +48 -0
  240. package/src/views/feature-components/VerifyRoute.jsx +88 -0
  241. package/src/views/feature-components/YearlyRecap/YearlyRecap.jsx +357 -0
  242. package/src/views/feature-components/YearlyRecap/components/RecapSlide.jsx +183 -0
  243. package/src/views/feature-components/YearlyRecap/languageTranslator/TranslationContext.js +5 -0
  244. package/src/views/feature-components/YearlyRecap/languageTranslator/TranslationProvider.jsx +26 -0
  245. package/src/views/feature-components/YearlyRecap/languageTranslator/i18n.js +46 -0
  246. package/src/views/feature-components/YearlyRecap/languageTranslator/translations.json +167 -0
  247. package/src/views/feature-components/YearlyRecap/slides/IntroSlide.jsx +233 -0
  248. package/src/views/feature-components/YearlyRecap/slides/MaternalHealthSlide.jsx +146 -0
  249. package/src/views/feature-components/YearlyRecap/slides/MetricSlide.jsx +227 -0
  250. package/src/views/feature-components/YearlyRecap/slides/OutroSlide.jsx +701 -0
  251. package/src/views/feature-components/YearlyRecap/slides/ReachSlide.jsx +273 -0
  252. package/src/views/feature-components/login/Login.jsx +840 -0
  253. package/src/views/feature-components/login/Login.scss +154 -0
  254. package/src/views/feature-components/login/LoginConfigurator.jsx +1149 -0
  255. package/src/views/feature-components/login/TwoFactorSetupModal.jsx +411 -0
  256. package/src/views/feature-components/login/simplifyMenu.js +45 -0
  257. package/src/views/feature-components/system-config/ManageSystemConfigs.jsx +284 -0
  258. package/src/views/feature-components/system-config/SystemConfig.jsx +299 -0
  259. package/src/views/feature-components/users/ChangePasswordModal.jsx +243 -0
  260. package/src/views/feature-components/users/PasswordField.jsx +56 -0
  261. package/dist/index.css +0 -1
  262. package/dist/index.js +0 -32001
  263. package/dist/index.js.map +0 -1
@@ -0,0 +1,398 @@
1
+ import moment from 'moment';
2
+
3
+ import SafeHtml from '@/common/SafeHtml.jsx';
4
+ // import { showToast } from '@/common/toaster/toaster';
5
+ export const extractFieldValueFromData = (containers, data) => {
6
+ Object.keys(containers || {}).forEach((key) => {
7
+ let containerFields = [];
8
+ if (Array.isArray(containers[key])) {
9
+ containerFields = containers[key];
10
+ }
11
+ containerFields?.forEach((field) => {
12
+ const value = data[field.fieldName];
13
+ if (value !== undefined) {
14
+ if (field.fieldType === 'date') {
15
+ field.value = moment(value).format('MM/DD/YYYY');
16
+ } else if (field.fieldType === 'dateNTime') {
17
+ field.value = moment(value).format('YYYY/MM/DD HH:mm:ss');
18
+ } else if (field.fieldType === 'onlyMonth') {
19
+ field.value = moment(value).format('MM/DD/YYYY');
20
+ } else {
21
+ field.value = value;
22
+ }
23
+ }
24
+ });
25
+ });
26
+ return containers;
27
+ };
28
+
29
+ export const extractDataFromField = (containers, data) => {
30
+ data = {};
31
+
32
+ Object.keys(containers || {}).forEach((key) => {
33
+ let containerFields = [];
34
+ if (Array.isArray(containers[key])) {
35
+ containerFields = containers[key];
36
+ }
37
+
38
+ containerFields?.forEach((field) => {
39
+ if (field.value !== undefined && field.value !== null) {
40
+ if (field.fieldType === 'date' || field.fieldType === 'onlyMonth') {
41
+ data[field.fieldName] = new Date(moment(field.value).format('MM/DD/YYYY'));
42
+ } else if (field.fieldType === 'dateNTime') {
43
+ data[field.fieldName] = new Date(moment(field.value, 'MM/DD/YYYY HH:mm:ss').format('YYYY-MM-DD HH:mm:ss'));
44
+ } else if (field.fieldType === 'dateRangePicker') {
45
+ data[field.fieldName] = {
46
+ startDate: field.value.startDate,
47
+ endDate: new Date(moment(field.value.endDate, 'MM/DD/YYYY HH:mm:ss').format('YYYY-MM-DD HH:mm:ss')),
48
+ };
49
+ } else {
50
+ data[field.fieldName] = field.value;
51
+ }
52
+ }
53
+ });
54
+ });
55
+
56
+ return data;
57
+ };
58
+
59
+ function replaceDateFields(temp, fieldsContainer, data) {
60
+ const dateFields = temp.match(/\$(.*?)\$/g);
61
+
62
+ if (!dateFields) return temp;
63
+
64
+ dateFields.forEach((field) => {
65
+ const keyString = field.slice(1, -1); // remove $...$
66
+
67
+ let replacingValue = fieldsContainer.find((f) => f.fieldName === keyString);
68
+
69
+ // Handle from_ prefix
70
+ if (!replacingValue) {
71
+ replacingValue = fieldsContainer.find((f) => 'from_' + f.fieldName === keyString);
72
+
73
+ if (replacingValue && replacingValue.value) {
74
+ replacingValue = { ...replacingValue, value: replacingValue.value };
75
+ }
76
+ }
77
+
78
+ // Handle to_ prefix
79
+ if (!replacingValue) {
80
+ replacingValue = fieldsContainer.find((f) => 'to_' + f.fieldName === keyString);
81
+ if (replacingValue && replacingValue.value) {
82
+ replacingValue = { ...replacingValue, value: replacingValue.value };
83
+ }
84
+ }
85
+
86
+ // Format date fields
87
+ if (replacingValue && replacingValue.value && replacingValue.fieldType === 'date') {
88
+ replacingValue = { ...replacingValue, value: replacingValue.value };
89
+ } else if (replacingValue && replacingValue.value && replacingValue.fieldType === 'dateFromTo') {
90
+ if ('from_' + replacingValue.fieldName === keyString) {
91
+ replacingValue = { ...replacingValue, value: formatDate(data['from_' + replacingValue.fieldName]) };
92
+ }
93
+ if ('to_' + replacingValue.fieldName === keyString) {
94
+ replacingValue = { ...replacingValue, value: formatDate(data['to_' + replacingValue.fieldName]) };
95
+ }
96
+ } else if (replacingValue && replacingValue.value && replacingValue.fieldType === 'onlyMonthFromTo') {
97
+ if ('from_' + replacingValue.fieldName === keyString) {
98
+ replacingValue = { ...replacingValue, value: formatMonth(data['from_' + replacingValue.fieldName]) };
99
+ }
100
+ if ('to_' + replacingValue.fieldName === keyString) {
101
+ replacingValue = { ...replacingValue, value: formatMonth(data['to_' + replacingValue.fieldName]) };
102
+ }
103
+ }
104
+
105
+ // Replace in temp
106
+ if (replacingValue && replacingValue.value) {
107
+ temp = temp.replace(new RegExp('\\$' + keyString + '\\$', 'g'), replacingValue.value);
108
+ } else {
109
+ temp = temp.replace(new RegExp('\\$' + keyString + '\\$', 'g'), 'null');
110
+ }
111
+ });
112
+
113
+ return temp;
114
+ }
115
+
116
+ // function formatDate(dateInput) {
117
+ // console.log(dateInput)
118
+ // const date = new Date(dateInput);
119
+ // console.log(date)
120
+ // if (isNaN(date)) return null;
121
+ // const mm = String(date.getMonth() + 1).padStart(2, '0');
122
+ // const dd = String(date.getDate()).padStart(2, '0');
123
+ // const yyyy = date.getFullYear();
124
+ // return `${mm}/${dd}/${yyyy}`;
125
+ // }
126
+
127
+ function formatDate(dateInput) {
128
+ // dd/mm/yyyy
129
+
130
+ const [day, month, year] = dateInput.split('/');
131
+
132
+ // const date = new Date(`${year}-${month}-${day}`);
133
+
134
+ // console.log(date);
135
+ // if (isNaN(date)) return null;
136
+ // const mm = String(date.getMonth() + 1).padStart(2, '0');
137
+ // const dd = String(date.getDate()).padStart(2, '0');
138
+ // const yyyy = date.getFullYear();
139
+ return `${month}/${day}/${year}`;
140
+ }
141
+
142
+ function formatMonth(dateInput) {
143
+ // dd/mm/yyyy
144
+
145
+ const [month, year] = dateInput.split('/');
146
+
147
+ // const date = new Date(`${year}-${month}-${day}`);
148
+
149
+ // console.log(date);
150
+ // if (isNaN(date)) return null;
151
+ // const mm = String(date.getMonth() + 1).padStart(2, '0');
152
+ // const dd = String(date.getDate()).padStart(2, '0');
153
+ // const yyyy = date.getFullYear();
154
+ return `${month}/01/${year}`;
155
+ }
156
+
157
+ // Example usage:
158
+ // let temp = '{"from_date":"$from_date$","to_date":"$to_date$"}';
159
+ // let fieldsContainer = [
160
+ // { fieldName: 'date', fieldType: 'date', value: '2025-08-10' },
161
+ // { fieldName: 'range', fieldType: 'dateFromTo', value: '' },
162
+ // ];
163
+ // let data = { from_date: '01/08/2025', to_date: '05/08/2025' };
164
+
165
+ // temp = replaceDateFields(temp, fieldsContainer, data);
166
+ // console.log(temp);
167
+
168
+ export const generateTableData = (
169
+ tableData,
170
+ configJson,
171
+ locationListSearch,
172
+ parentLocationListSearch,
173
+ checkLineListwise,
174
+ downloadLinelistExcel,
175
+ setShowLineList,
176
+ currentLocationId,
177
+ canDrillDown
178
+ ) => {
179
+ const thead = [];
180
+ let allowDrillDown = false;
181
+ const tbody = [];
182
+ let containers = configJson.containers;
183
+ let data = configJson.filterDisplay;
184
+ data = data?.reduce((acc, item) => {
185
+ acc[item.fieldName] = item.value;
186
+ return acc;
187
+ }, {});
188
+ const locationField = containers?.fieldsContainer?.find(
189
+ (container) => container?.fieldType === 'location'
190
+ );
191
+ if (locationField) {
192
+ const isMultiSelect =
193
+ Array.isArray(
194
+ locationField?.selectedLocation?.finalSelected?.optionSelected
195
+ ) && locationField.selectedLocation.finalSelected.optionSelected.length > 1;
196
+ allowDrillDown = !isMultiSelect;
197
+ }
198
+ const locationLevelSelected =
199
+ configJson.locationLevelSelected ?? locationField?.selectedLocation?.finalSelected?.optionSelected?.level ?? 0;
200
+ if (tableData && tableData.length > 0) {
201
+ const tableColumns = Object.keys(tableData[0]);
202
+ tableColumns.forEach((column) => {
203
+ let headPushed = false;
204
+
205
+ let label = column.includes('percent_col') ? '%' : column;
206
+ containers?.tableFieldContainer?.forEach((tableField) => {
207
+ if (
208
+ column === tableField.fieldName &&
209
+ tableField.isLink === true &&
210
+ (!tableField.locationLevelForLink ||
211
+ tableField.locationLevelForLink == '' ||
212
+ (locationLevelSelected !== undefined &&
213
+ locationLevelSelected !== null &&
214
+ locationLevelSelected >= tableField.locationLevelForLink))
215
+ ) {
216
+ const regex =
217
+ /([a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*?)\(\{\s*"id"\s*:\s*"([^"]+)"\s*,\s*"queryParams"\s*:\s*(\{.*\})\s*\}\)/;
218
+ const match = tableField?.customState.match(regex);
219
+ const targetUuid = match?.[2];
220
+ const hasDrillDownPermission = canDrillDown;
221
+
222
+ if (hasDrillDownPermission) {
223
+ setShowLineList(true, targetUuid);
224
+ }
225
+
226
+ thead.push({
227
+ field: column,
228
+ label: label,
229
+ align: 'left',
230
+ isLink: hasDrillDownPermission,
231
+ disabled: (row) => {
232
+ const value = row[column];
233
+ return value === 0 || value === null;
234
+ },
235
+ onClick: hasDrillDownPermission
236
+ ? (row) => {
237
+ const lineListwise = checkLineListwise();
238
+ if (lineListwise) {
239
+ const formatToCamelCase = (str) => str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
240
+ let path;
241
+ if (match) {
242
+ let structure = match[1].replace(/\./g, '/');
243
+ structure = formatToCamelCase(structure);
244
+ structure = structure.replace(/^techo\//, '/ui/medplat/');
245
+
246
+ const id = match[2];
247
+ let queryParams;
248
+
249
+ try {
250
+ let rawQueryParams = match[3];
251
+ let rowFields = rawQueryParams.match(/@(.*?)@/g);
252
+ if (rowFields) {
253
+ rowFields.forEach((field) => {
254
+ const fieldName = field.slice(1, -1);
255
+ rawQueryParams = rawQueryParams.replace(new RegExp(field, 'g'), row[fieldName]);
256
+ });
257
+ }
258
+ let dateFields = rawQueryParams.match(/\$(.*?)\$/g);
259
+ if (dateFields) {
260
+ rawQueryParams = replaceDateFields(rawQueryParams, containers.fieldsContainer, data);
261
+ }
262
+ queryParams = encodeURIComponent(rawQueryParams);
263
+ } catch {
264
+ queryParams = 'null';
265
+ }
266
+ path = `${structure}/${id}?queryParams=${queryParams}`;
267
+ path = path.replace(/^techo\//, '/ui/medplat/');
268
+ } else {
269
+ path = tableField?.customState.replace(/\./g, '/');
270
+ path = formatToCamelCase(path);
271
+ path = path.replace(/^techo\//, '/ui/medplat/');
272
+ }
273
+ window.open(path, '_blank');
274
+ } else {
275
+ downloadLinelistExcel(row, tableField);
276
+ }
277
+ }
278
+ : undefined,
279
+ sortable: true,
280
+ isSticky: tableField.isSticky,
281
+ });
282
+
283
+
284
+ headPushed = true;
285
+ } else if (column === tableField.fieldName) {
286
+ thead.push({
287
+ field: column,
288
+ label: label,
289
+ sortable: true,
290
+ align: 'left',
291
+ isSticky: tableField.isSticky,
292
+ });
293
+
294
+ headPushed = true;
295
+ }
296
+ });
297
+
298
+ if (!headPushed) {
299
+ if ((column === 'Location' || column === 'Location Name') && allowDrillDown) {
300
+ thead.push({
301
+ field: column,
302
+ label: label,
303
+ sortable: true,
304
+ align: 'left',
305
+
306
+ render: (row) => {
307
+ if (row) {
308
+ const val = row[column]?.displayValue || row[column] || '';
309
+ const isTotal = val === 'Total' || val === '<b>Total<b>' || val === '<b>Total</b>';
310
+ const hasHiddenLocation = row.hidden_location_id;
311
+
312
+ const condition = !isTotal && allowDrillDown && hasHiddenLocation && !currentLocationId?.isLimitReached;
313
+ return (
314
+ <span
315
+ style={{
316
+ cursor: condition ? 'pointer' : 'default',
317
+ color: condition ? 'blue' : '',
318
+ textDecoration: condition ? 'underline' : 'none',
319
+ }}
320
+ onClick={() => {
321
+ if (condition) {
322
+ locationListSearch(row);
323
+ }
324
+ }}
325
+ dangerouslySetInnerHTML={{ __html: val }}
326
+ />
327
+ );
328
+ }
329
+ },
330
+ });
331
+ } else if ((column === 'Parent Location') && allowDrillDown) {
332
+ thead.push({
333
+ field: column,
334
+ label: label,
335
+ sortable: true,
336
+ align: 'left',
337
+
338
+ render: (row) => {
339
+ if (row) {
340
+ const val = row[column]?.displayValue || row[column] || '';
341
+ const isTotal = val === 'Total' || val === '<b>Total<b>' || val === '<b>Total</b>';
342
+ const condition = !isTotal && allowDrillDown && !currentLocationId?.isFirstLevel;
343
+ return (
344
+ <span
345
+ style={{
346
+ cursor: condition ? 'pointer' : 'default',
347
+ color: condition ? 'blue' : 'black',
348
+ textDecoration: condition ? 'underline' : 'none',
349
+ }}
350
+ onClick={() => {
351
+ if (condition) {
352
+ parentLocationListSearch();
353
+ }
354
+ }}
355
+ dangerouslySetInnerHTML={{ __html: val }}
356
+ />
357
+ );
358
+ }
359
+ },
360
+ });
361
+ } else {
362
+ thead.push({ field: column, label: label, sortable: true, align: 'left' });
363
+ }
364
+ }
365
+ });
366
+
367
+ tableData.forEach((rowData) => {
368
+ const rowObject = {};
369
+
370
+ Object.keys(rowData).forEach((key) => {
371
+ const columnData = thead.find((headObject) => headObject.field === key);
372
+ if (columnData) {
373
+ if (columnData.customStyle) {
374
+ const rowFields = columnData.customStyle.match(/@(.*?)@/g);
375
+ if (rowFields) {
376
+ rowFields.forEach((field) => {
377
+ const fieldName = field.substring(1, field.length - 1);
378
+ columnData.customStyle = columnData.customStyle.replace(
379
+ new RegExp(field, 'g'),
380
+ `row['${fieldName}'].displayValue`
381
+ );
382
+ });
383
+ }
384
+ }
385
+ rowObject[key] = { ...columnData, displayValue: rowData[key] || '-' };
386
+ }
387
+ });
388
+
389
+ tbody.push(rowObject);
390
+ });
391
+ }
392
+
393
+ return {
394
+ header: thead,
395
+ body: tbody,
396
+ allowDrillDown,
397
+ };
398
+ };
@@ -0,0 +1,261 @@
1
+ import React, { createContext, useContext, useRef, useState, useCallback, useEffect } from 'react';
2
+ import { Client } from '@stomp/stompjs';
3
+ import CryptoJS from 'crypto-js';
4
+ import PropTypes from 'prop-types';
5
+
6
+ const WebSocketContext = createContext(null);
7
+ export const WebSocketProvider = ({ children, userId, authToken, serverPath }) => {
8
+ // --- Refs ---
9
+ const stompClient = useRef(null);
10
+ const subscribers = useRef([]);
11
+ const authRef = useRef({ userId, authToken });
12
+ // --- State ---
13
+ const [isConnected, setIsConnected] = useState(false);
14
+ const [deviceInfo, setLocalDeviceInfo] = useState(localStorage.getItem('DeviceInfo')); // eslint-disable-line no-unused-vars
15
+ // --- Helpers ---
16
+ const getHashedUserId = (uid) => {
17
+ return uid ? CryptoJS.MD5(uid.toString()).toString() : null;
18
+ };
19
+ const setConnectionStatus = (status) => {
20
+ localStorage.setItem('isExternalDeviceConnected', status);
21
+ };
22
+ const buildWebSocketUrl = (hashedUserId, deviceType) => {
23
+ // serverPath might be "http://localhost:8181" or "https://example.com"
24
+ // Convert http -> ws, https -> wss
25
+ const wsBase = serverPath.replace(/^http/, 'ws');
26
+ // Use the native endpoint
27
+ return `${wsBase}/ws-native?userId=${hashedUserId}&deviceType=${deviceType}`;
28
+ };
29
+ // --- Core WebSocket Logic ---
30
+ const disconnect = useCallback(() => {
31
+ if (stompClient.current) {
32
+ try {
33
+ stompClient.current.deactivate();
34
+ } catch (e) {
35
+ console.error('Error during deactivation', e);
36
+ }
37
+ stompClient.current = null;
38
+ }
39
+ setIsConnected(false);
40
+ }, []);
41
+ const connect = useCallback(
42
+ (callback) => {
43
+ const currentUserId = authRef.current.userId;
44
+ const hashedUserId = getHashedUserId(currentUserId);
45
+ if (!currentUserId) {
46
+ console.warn(':no_entry: Cannot connect, no userId provided.');
47
+ return;
48
+ }
49
+ // Prevent duplicate connections
50
+ if (stompClient.current && stompClient.current.active) {
51
+ if (typeof callback === 'function') callback();
52
+ return;
53
+ }
54
+ // Cleanup stale client
55
+ if (stompClient.current) {
56
+ stompClient.current.deactivate();
57
+ }
58
+ const deviceType = 'web';
59
+ const wsUrl = buildWebSocketUrl(hashedUserId, deviceType);
60
+ const client = new Client({
61
+ // Native WebSocket, no SockJS
62
+ brokerURL: wsUrl,
63
+ connectHeaders: {
64
+ 'user-id': hashedUserId,
65
+ 'device-type': deviceType,
66
+ },
67
+ debug: (str) => {
68
+ if (str && (str.includes('ERROR') || str.includes('Connected'))) {
69
+ //
70
+ }
71
+ },
72
+ reconnectDelay: 5000,
73
+ heartbeatIncoming: 20000,
74
+ heartbeatOutgoing: 20000,
75
+ // In browser, ensure it uses WebSocket
76
+ webSocketFactory: () => new WebSocket(wsUrl),
77
+ });
78
+ // --- Event Handlers ---
79
+ client.onConnect = (frame) => { // eslint-disable-line no-unused-vars
80
+ // 1. General messages
81
+ client.subscribe('/user/queue/messages', (message) => {
82
+ try {
83
+ const incomingMessage = JSON.parse(message.body);
84
+ subscribers.current.forEach((fn) => {
85
+ try {
86
+ fn(incomingMessage);
87
+ } catch (e) {
88
+ console.error('Subscriber error:', e);
89
+ }
90
+ });
91
+ } catch (err) {
92
+ console.error('[WS] Error parsing message:', err);
93
+ }
94
+ });
95
+ // 2. Recording / control messages
96
+ client.subscribe('/user/queue/recording', (message) => {
97
+ try {
98
+ const incomingMessage = JSON.parse(message.body);
99
+ // Handle verify_credentials flow
100
+ if (incomingMessage.command === 'verify_credentials') {
101
+ const isValid = incomingMessage.token === authRef.current.authToken;
102
+ const response = {
103
+ userId: getHashedUserId(authRef.current.userId),
104
+ command: 'credentials_response',
105
+ status: isValid ? 'success' : 'failure',
106
+ message: isValid ? 'Valid credentials' : 'Invalid credentials',
107
+ };
108
+ setTimeout(() => {
109
+ try {
110
+ if (client.connected) {
111
+ client.publish({
112
+ destination: '/app/recording',
113
+ body: JSON.stringify(response),
114
+ });
115
+ }
116
+ } catch (e) {
117
+ console.error('Send error:', e);
118
+ }
119
+ }, 300);
120
+ return;
121
+ }
122
+ // Dispatch normal messages
123
+ subscribers.current.forEach((fn) => {
124
+ try {
125
+ fn(incomingMessage);
126
+ } catch (e) {
127
+ console.error('Subscriber error:', e);
128
+ }
129
+ });
130
+ } catch (err) {
131
+ console.error('[WS] Error processing recording message:', err);
132
+ }
133
+ });
134
+ if (typeof callback === 'function') callback();
135
+ };
136
+ client.onStompError = (frame) => {
137
+ console.error('Broker reported error: ' + frame.headers['message']);
138
+ console.error('Additional details: ' + frame.body);
139
+ };
140
+ client.onWebSocketClose = () => {
141
+
142
+ setIsConnected(false);
143
+ };
144
+ // Activate the client
145
+ client.activate();
146
+ stompClient.current = client;
147
+ },
148
+ [serverPath]
149
+ );
150
+ // --- Public API exposed by context ---
151
+ const subscribeToRecordingStatus = useCallback((callback) => {
152
+ if (typeof callback !== 'function') return;
153
+ if (!subscribers.current.includes(callback)) {
154
+ subscribers.current.push(callback);
155
+
156
+ }
157
+ return () => {
158
+ subscribers.current = subscribers.current.filter((cb) => cb !== callback);
159
+
160
+ };
161
+ }, []);
162
+ const clearSubscribers = useCallback(() => {
163
+ subscribers.current = [];
164
+ }, []);
165
+ const sendRecordingCommand = useCallback((command, sampleId) => {
166
+ if (!stompClient.current || !stompClient.current.connected) {
167
+ console.warn(':no_entry: Cannot send command, STOMP not connected.');
168
+ return;
169
+ }
170
+
171
+ const targetDevice = getDeviceInfo() ? JSON.parse(getDeviceInfo()) : null;
172
+ const message = {
173
+ userId: getHashedUserId(authRef.current.userId),
174
+ command,
175
+ sampleId,
176
+ sourceDeviceType: 'web',
177
+ targetDeviceType: targetDevice?.deviceType || 'mobile',
178
+ };
179
+ try {
180
+ stompClient.current.publish({
181
+ destination: '/app/recording',
182
+ body: JSON.stringify(message),
183
+ });
184
+ } catch (e) {
185
+ console.error('Failed to send command:', e);
186
+ }
187
+ }, []);
188
+ // --- Local Storage helpers ---
189
+ const setDeviceInfo = (info) => {
190
+ localStorage.setItem('DeviceInfo', info);
191
+ setLocalDeviceInfo(info);
192
+ };
193
+ const getDeviceInfo = () => {
194
+ return localStorage.getItem('DeviceInfo');
195
+ };
196
+ const getConnectionInfo = () => {
197
+ return {
198
+ wsUrl: stompClient.current?.webSocket?.url || '',
199
+ userId: getHashedUserId(authRef.current.userId),
200
+ protocol: 'stomp@1.2',
201
+ };
202
+ };
203
+ const getConnectionStatus = () => {
204
+ return localStorage.getItem('isExternalDeviceConnected');
205
+ };
206
+ useEffect(() => {
207
+ const handleBeforeUnload = () => {
208
+ localStorage.setItem('isExternalDeviceConnected', false);
209
+ };
210
+ window.addEventListener('beforeunload', handleBeforeUnload);
211
+ return () => {
212
+ window.removeEventListener('beforeunload', handleBeforeUnload);
213
+ };
214
+ }, []);
215
+
216
+ useEffect(() => {
217
+ return () => {
218
+ if (stompClient.current) {
219
+ stompClient.current.deactivate();
220
+ }
221
+ };
222
+ }, []);
223
+ // Keep auth data fresh in ref
224
+ useEffect(() => {
225
+ authRef.current = { userId, authToken };
226
+ // If user logs out (userId becomes null/undefined), disconnect
227
+ if (!userId && stompClient.current) {
228
+ disconnect();
229
+ }
230
+ }, [userId, authToken, disconnect]);
231
+
232
+ const contextValue = {
233
+ connect,
234
+ disconnect,
235
+ subscribeToRecordingStatus,
236
+ clearSubscribers,
237
+ sendRecordingCommand,
238
+ isConnected,
239
+ setConnectionStatus,
240
+ setDeviceInfo,
241
+ getDeviceInfo,
242
+ getConnectionInfo,
243
+ getConnectionStatus,
244
+ };
245
+ return <WebSocketContext.Provider value={contextValue}>{children}</WebSocketContext.Provider>;
246
+ };
247
+
248
+ WebSocketProvider.propTypes = {
249
+ children: PropTypes.node.isRequired,
250
+ userId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
251
+ authToken: PropTypes.string,
252
+ serverPath: PropTypes.string.isRequired,
253
+ };
254
+ // Custom Hook
255
+ export const useWebSocket = () => {
256
+ const context = useContext(WebSocketContext);
257
+ if (!context) {
258
+ throw new Error('useWebSocket must be used within a WebSocketProvider');
259
+ }
260
+ return context;
261
+ };