@argusoft/medplat-app-shell 1.0.6 → 1.0.8

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 (264) 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/store/slices/dashboardSlice.js +14 -0
  161. package/src/utils/.gitkeep +0 -0
  162. package/src/utils/FormConstants.js +2629 -0
  163. package/src/utils/GujaratTopoChart.jsx +483 -0
  164. package/src/utils/UUIDgenerator.js +8 -0
  165. package/src/utils/appointment-utils/appointment-utils.js +123 -0
  166. package/src/utils/feature.js +42 -0
  167. package/src/utils/getThemeColor.js +12 -0
  168. package/src/utils/localStorageHelper.js +11 -0
  169. package/src/utils/notifications/enable-push-notifications.js +27 -0
  170. package/src/utils/resolveAppliedStyle.js +11 -0
  171. package/src/utils/themeConfigs.js +1483 -0
  172. package/src/views/custom-components/.gitkeep +0 -0
  173. package/src/views/custom-components/AgIconButton/RIf.jsx +14 -0
  174. package/src/views/custom-components/AgIconButton/button.jsx +108 -0
  175. package/src/views/custom-components/AgIconButton/waterDrop.jsx +95 -0
  176. package/src/views/custom-components/AgIconButton/waterDrop.scss +37 -0
  177. package/src/views/custom-components/AlertPlaceholder.jsx +32 -0
  178. package/src/views/custom-components/AllFaIconsSelector.jsx +56 -0
  179. package/src/views/custom-components/CkEditor/CkEditor.js +102 -0
  180. package/src/views/custom-components/CustomAccordion.jsx +72 -0
  181. package/src/views/custom-components/CustomActionIcons.jsx +118 -0
  182. package/src/views/custom-components/CustomAutoComplete.jsx +188 -0
  183. package/src/views/custom-components/CustomCheckBox.jsx +60 -0
  184. package/src/views/custom-components/CustomConfirmationModal.jsx +118 -0
  185. package/src/views/custom-components/CustomCountrySelect.jsx +129 -0
  186. package/src/views/custom-components/CustomDatePicker.jsx +122 -0
  187. package/src/views/custom-components/CustomDropdown.jsx +191 -0
  188. package/src/views/custom-components/CustomFileUpload.jsx +387 -0
  189. package/src/views/custom-components/CustomFullCalendar.jsx +514 -0
  190. package/src/views/custom-components/CustomInfiniteScroll.jsx +126 -0
  191. package/src/views/custom-components/CustomRadioComponent.jsx +65 -0
  192. package/src/views/custom-components/CustomStatsComponent.jsx +114 -0
  193. package/src/views/custom-components/CustomSvgUpload.jsx +170 -0
  194. package/src/views/custom-components/CustomSwitch.jsx +37 -0
  195. package/src/views/custom-components/CustomTabPanel.jsx +19 -0
  196. package/src/views/custom-components/CustomTextArea.jsx +62 -0
  197. package/src/views/custom-components/CustomTextArea.scss +27 -0
  198. package/src/views/custom-components/CustomTextField.jsx +116 -0
  199. package/src/views/custom-components/CustomToggleSwitch.jsx +138 -0
  200. package/src/views/custom-components/CustomTooltip.jsx +51 -0
  201. package/src/views/custom-components/CustomZoomImage.jsx +134 -0
  202. package/src/views/custom-components/CustomizedTable/CustomizedTableV2.jsx +1407 -0
  203. package/src/views/custom-components/CustomizedTable/VirtualizeTableBody.jsx +295 -0
  204. package/src/views/custom-components/CustomizedTable/helper.jsx +159 -0
  205. package/src/views/custom-components/CustomizedTable.jsx +532 -0
  206. package/src/views/custom-components/EditInputField.jsx +174 -0
  207. package/src/views/custom-components/FieldDescription.jsx +22 -0
  208. package/src/views/custom-components/FileDisplayComponent.jsx +138 -0
  209. package/src/views/custom-components/FormItem.jsx +53 -0
  210. package/src/views/custom-components/GenericChart.jsx +80 -0
  211. package/src/views/custom-components/InfoBadge.jsx +60 -0
  212. package/src/views/custom-components/PostgresEditor.jsx +801 -0
  213. package/src/views/custom-components/ResizableEditAutocompleteField.jsx +249 -0
  214. package/src/views/custom-components/ResizableEditInputField.jsx +215 -0
  215. package/src/views/custom-components/ResizeableEditSelectField.jsx +197 -0
  216. package/src/views/custom-components/SideOverlay.jsx +113 -0
  217. package/src/views/custom-components/SideOverlay.scss +42 -0
  218. package/src/views/custom-components/calendar.scss +571 -0
  219. package/src/views/feature-components/.gitkeep +0 -0
  220. package/src/views/feature-components/Dashboard/DashboardUI.jsx +1043 -0
  221. package/src/views/feature-components/Dashboard/DhnddModal/AshaDataQualityVerificationModal.jsx +278 -0
  222. package/src/views/feature-components/Dashboard/PinFeatureModal.jsx +143 -0
  223. package/src/views/feature-components/Dashboard/QuickLinks.jsx +163 -0
  224. package/src/views/feature-components/Dashboard/Taskbar.jsx +56 -0
  225. package/src/views/feature-components/Dashboard/WebtasksFilterForm.jsx +109 -0
  226. package/src/views/feature-components/Dashboard/WidgetCard.jsx +161 -0
  227. package/src/views/feature-components/Dashboard/actionModal.jsx +263 -0
  228. package/src/views/feature-components/Dashboard/ekavachModal/HealthWorkerIncorrectDetailsModal.jsx +332 -0
  229. package/src/views/feature-components/Dashboard/ekavachModal/MoMaternalDeathVerifcationModal.jsx +275 -0
  230. package/src/views/feature-components/Dashboard/ekavachModal/MoVerficationForChildScreeningMoadal.jsx +566 -0
  231. package/src/views/feature-components/FeatureUsageAnalytics/FeatureUsageAnalytics.jsx +989 -0
  232. package/src/views/feature-components/Features/NewServerManagement.jsx +217 -0
  233. package/src/views/feature-components/Features/ServerManagement.scss +120 -0
  234. package/src/views/feature-components/ForgotPassword/ForgotPassword.jsx +226 -0
  235. package/src/views/feature-components/LocationDirective/LocationDirective.jsx +992 -0
  236. package/src/views/feature-components/LocationDirective/LocationDirectiveV2.jsx +909 -0
  237. package/src/views/feature-components/NotFound.jsx +66 -0
  238. package/src/views/feature-components/Onboarding/Onboarding.jsx +1400 -0
  239. package/src/views/feature-components/Skeletons.js +115 -0
  240. package/src/views/feature-components/Unauthorized.jsx +48 -0
  241. package/src/views/feature-components/VerifyRoute.jsx +88 -0
  242. package/src/views/feature-components/YearlyRecap/YearlyRecap.jsx +357 -0
  243. package/src/views/feature-components/YearlyRecap/components/RecapSlide.jsx +183 -0
  244. package/src/views/feature-components/YearlyRecap/languageTranslator/TranslationContext.js +5 -0
  245. package/src/views/feature-components/YearlyRecap/languageTranslator/TranslationProvider.jsx +26 -0
  246. package/src/views/feature-components/YearlyRecap/languageTranslator/i18n.js +46 -0
  247. package/src/views/feature-components/YearlyRecap/languageTranslator/translations.json +167 -0
  248. package/src/views/feature-components/YearlyRecap/slides/IntroSlide.jsx +233 -0
  249. package/src/views/feature-components/YearlyRecap/slides/MaternalHealthSlide.jsx +146 -0
  250. package/src/views/feature-components/YearlyRecap/slides/MetricSlide.jsx +227 -0
  251. package/src/views/feature-components/YearlyRecap/slides/OutroSlide.jsx +701 -0
  252. package/src/views/feature-components/YearlyRecap/slides/ReachSlide.jsx +273 -0
  253. package/src/views/feature-components/login/Login.jsx +840 -0
  254. package/src/views/feature-components/login/Login.scss +154 -0
  255. package/src/views/feature-components/login/LoginConfigurator.jsx +1149 -0
  256. package/src/views/feature-components/login/TwoFactorSetupModal.jsx +411 -0
  257. package/src/views/feature-components/login/simplifyMenu.js +45 -0
  258. package/src/views/feature-components/system-config/ManageSystemConfigs.jsx +284 -0
  259. package/src/views/feature-components/system-config/SystemConfig.jsx +299 -0
  260. package/src/views/feature-components/users/ChangePasswordModal.jsx +243 -0
  261. package/src/views/feature-components/users/PasswordField.jsx +56 -0
  262. package/dist/index.css +0 -1
  263. package/dist/index.js +0 -32001
  264. package/dist/index.js.map +0 -1
@@ -0,0 +1,191 @@
1
+ import React, { useMemo } from 'react';
2
+ import { FormControl, TextField, Typography, Box } from '@mui/material';
3
+ import PropTypes from 'prop-types';
4
+ import { Controller, get } from 'react-hook-form';
5
+ import Autocomplete from '@mui/material/Autocomplete';
6
+
7
+ export default function CustomDropdown({
8
+ control,
9
+ name,
10
+ options,
11
+ onChange,
12
+ rules = {},
13
+ size = 'small',
14
+ displayName,
15
+ optionValue,
16
+ optionKey,
17
+ errors,
18
+ multiple = false,
19
+ isNullSelectDisabled = true,
20
+ dataTestId,
21
+ id,
22
+ dropdownZindex,
23
+ defaultValue,
24
+ getOptionDisabled,
25
+ disableClearable = false,
26
+ disabled,
27
+ isSortedOptions = false,
28
+ disablePortal = false,
29
+ sx,
30
+ errorMessage,
31
+ ...props
32
+ }) {
33
+ const error = get(errors, name);
34
+
35
+ const placeholderOption = { [optionValue || 'value']: '', [displayName || 'label']: props.placeholder || 'Select' };
36
+
37
+ const sortedOptions = useMemo(() => {
38
+ let opts = options || [];
39
+ if (isSortedOptions && opts.length) {
40
+ opts = [...opts].sort((a, b) => {
41
+ const aValue = typeof a === 'object' ? a[displayName] : a;
42
+ const bValue = typeof b === 'object' ? b[displayName] : b;
43
+ if (typeof aValue === 'string' && typeof bValue === 'string') {
44
+ return aValue.localeCompare(bValue);
45
+ }
46
+ return aValue > bValue ? 1 : -1;
47
+ });
48
+ }
49
+ if (!isNullSelectDisabled && !multiple) {
50
+ return [placeholderOption, ...opts];
51
+ }
52
+ return opts;
53
+ }, [options, isSortedOptions, isNullSelectDisabled, multiple]);
54
+
55
+ return (
56
+ <FormControl fullWidth error={!!error}>
57
+ <Controller
58
+ name={name}
59
+ control={control}
60
+ rules={rules}
61
+ defaultValue={defaultValue}
62
+ render={({ field }) => (
63
+ <Autocomplete
64
+ disablePortal={disablePortal}
65
+ disabled={disabled}
66
+ {...field}
67
+ multiple={multiple}
68
+ options={sortedOptions}
69
+ disableClearable={disableClearable && (isNullSelectDisabled || multiple)}
70
+ getOptionLabel={(option) =>
71
+ option && typeof option === 'object' ? String(option?.[displayName] || '') : String(option || '')
72
+ }
73
+ isOptionEqualToValue={(option, value) =>
74
+ optionValue ? option?.[optionValue] === value?.[optionValue] : option === value
75
+ }
76
+ data-testid={dataTestId}
77
+ id={id}
78
+ value={
79
+ multiple
80
+ ? sortedOptions.filter((opt) =>
81
+ field.value?.some?.((val) => (optionValue ? val === opt[optionValue] : val === opt))
82
+ )
83
+ : sortedOptions.find((opt) => (optionValue ? opt[optionValue] === field.value : opt === field.value)) ||
84
+ null
85
+ }
86
+ onChange={(event, value) => {
87
+ const isPlaceholder =
88
+ !multiple && optionValue ? value?.[optionValue] === '' : value === placeholderOption;
89
+
90
+ const target = {
91
+ name,
92
+ value: multiple
93
+ ? (Array.isArray(value) ? value : []).map((v) => (optionValue ? v?.[optionValue] : v)).filter(Boolean)
94
+ : isPlaceholder
95
+ ? ''
96
+ : optionValue
97
+ ? value?.[optionValue] || ''
98
+ : value || '',
99
+ };
100
+
101
+ onChange?.({ ...event, target });
102
+ field.onChange(target.value);
103
+ }}
104
+ getOptionDisabled={getOptionDisabled}
105
+ renderInput={(params) => (
106
+ <TextField
107
+ {...params}
108
+ size={size}
109
+ error={!!error}
110
+ placeholder={isNullSelectDisabled ? 'Select an option' : ''}
111
+ sx={{
112
+ backgroundColor: '#F8FAFC',
113
+ borderColor: error ? 'red' : 'rgba(0, 0, 0, 0.23)',
114
+ ...sx,
115
+ }}
116
+ // onChange={(e) => {
117
+ // const value = e.target.value === '' ? '' : e.target.value;
118
+ // field.onChange(value);
119
+ // }}
120
+ {...props}
121
+ />
122
+ )}
123
+ slotProps={{
124
+ paper: {
125
+ sx: {
126
+ borderRadius: '1rem',
127
+ boxShadow: '0px 2px 10px rgba(0, 0, 0, 0.1)',
128
+ border: '1px solid #E0E0E0',
129
+ my: 1,
130
+ },
131
+ },
132
+ popper: {
133
+ sx: {
134
+ ...(dropdownZindex && { zIndex: dropdownZindex }),
135
+ },
136
+ },
137
+ }}
138
+ renderOption={(props, option, { index }) => (
139
+ <Box
140
+ {...props}
141
+ key={optionKey ? option[optionKey] : optionValue ? option[optionValue] : `option-${index}`}
142
+ sx={{
143
+ borderRadius: '16px',
144
+ mx: 1,
145
+ my: 0.5,
146
+ px: 2,
147
+ py: 1,
148
+ }}
149
+ data-testid={`${dataTestId}-option-${optionValue ? option[optionValue] : `option-${index}`}`}
150
+ >
151
+ <Typography variant="body2">{displayName ? option[displayName] : option}</Typography>
152
+ </Box>
153
+ )}
154
+ />
155
+ )}
156
+ />
157
+ {error && (
158
+ <p data-testid="custom-error-message" className="error-helper-text">
159
+ {errorMessage || error?.message}
160
+ </p>
161
+ )}
162
+ </FormControl>
163
+ );
164
+ }
165
+
166
+ CustomDropdown.propTypes = {
167
+ control: PropTypes.any,
168
+ name: PropTypes.string.isRequired,
169
+ options: PropTypes.array.isRequired,
170
+ onChange: PropTypes.func,
171
+ size: PropTypes.string,
172
+ displayName: PropTypes.string,
173
+ optionValue: PropTypes.string,
174
+ optionKey: PropTypes.string,
175
+ errors: PropTypes.object,
176
+ multiple: PropTypes.bool,
177
+ isNullSelectDisabled: PropTypes.bool,
178
+ dataTestId: PropTypes.string,
179
+ defaultValue: PropTypes.any,
180
+ id: PropTypes.any,
181
+ rules: PropTypes.any,
182
+ sx: PropTypes.object,
183
+ getOptionDisabled: PropTypes.any,
184
+ disableClearable: PropTypes.any,
185
+ disabled: PropTypes.bool,
186
+ isSortedOptions: PropTypes.bool,
187
+ disablePortal: PropTypes.bool,
188
+ errorMessage: PropTypes.string,
189
+ placeholder: PropTypes.string,
190
+ dropdownZindex: PropTypes.number,
191
+ };
@@ -0,0 +1,387 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import {
3
+ Alert,
4
+ Button,
5
+ Chip,
6
+ FormControl,
7
+ IconButton,
8
+ LinearProgress,
9
+ Paper,
10
+ Table,
11
+ TableBody,
12
+ TableCell,
13
+ TableContainer,
14
+ TableHead,
15
+ TableRow,
16
+ Tooltip,
17
+ Typography,
18
+ } from '@mui/material';
19
+ import GeneralUtil from '@/common/services/util/GeneralUtil';
20
+ import { Box } from '@mui/system';
21
+ import { showToast } from '@/common/toaster/toaster';
22
+ import { api } from '@/common/interceptors/AxiosInterceptor';
23
+ import { get } from 'react-hook-form';
24
+ import FileDisplayComponent from '@/views/custom-components/FileDisplayComponent';
25
+ import PropTypes from 'prop-types';
26
+ import FontAwesomeIcons from '@/common/fontAwesomeIcons/FontAwesomeIcons';
27
+
28
+ const wrapperSx = {
29
+ display: 'flex',
30
+ alignItems: 'center',
31
+ backgroundColor: 'white',
32
+ padding: '1rem',
33
+ margin: '1rem 0',
34
+ borderRadius: '10px',
35
+ };
36
+
37
+ const CustomFileUpload = ({
38
+ formControl,
39
+ name,
40
+ editing,
41
+ accept = '*',
42
+ uploadButtonName = 'UPLOAD',
43
+ maxNoOfFiles = 1,
44
+ _moduleName = 'TECHO',
45
+ isTemporary = true,
46
+ errors,
47
+ }) => {
48
+ const error = get(errors, name);
49
+ const [uploadFiles, setUploadFiles] = useState([]);
50
+ const fileInputRef = useRef(null);
51
+ const [isLoading, setIsLoading] = useState(false);
52
+ const [uploadProgress, setUploadProgress] = useState(0);
53
+ const [uploadRate, setUploadRate] = useState(0);
54
+ const [eta, setEta] = useState('');
55
+ const [fileNameToFileIdMap, setFileNameToFileIdMap] = useState({});
56
+ const [referenceId, setReferenceId] = useState(-1);
57
+ const [openDisplayComp, setOpenDisplayComp] = useState(false);
58
+
59
+ useEffect(() => {
60
+ if (formControl.formState.isSubmitted || formControl.getFieldState(name).isTouched) {
61
+ formControl.trigger(name, { shouldFocus: true });
62
+ }
63
+ }, [JSON.stringify(uploadFiles)]);
64
+
65
+ useEffect(() => {
66
+ let id = formControl.getValues(name);
67
+ if (id && editing) {
68
+ fetchFileDetails(id);
69
+ }
70
+ }, [editing]);
71
+
72
+ const fetchFileDetails = async (id) => {
73
+ api
74
+ .get(`/document/fetchFileDetails/${id}`)
75
+ .then((res) => {
76
+ if (res) {
77
+ let data = res.data;
78
+ const newFile = {
79
+ id: id,
80
+ actualFileName: data.fileName,
81
+ fileType: data.fileType,
82
+ size: data.fileSize,
83
+ image: '',
84
+ progress: 0,
85
+ isLoading: true,
86
+ documentId: data.id,
87
+ };
88
+ setReferenceId(data.mediaReferenceId);
89
+ setOpenDisplayComp(true);
90
+ setUploadFiles((prevFiles) => [...prevFiles, newFile]);
91
+ }
92
+ })
93
+ .catch((err) => {
94
+ console.log(err);
95
+ });
96
+ };
97
+
98
+ const handleFileChange = async (event) => {
99
+ if (uploadFiles.length + 1 > maxNoOfFiles) {
100
+ showToast({ message: 'Max no of files reached', type: 'error' });
101
+ return;
102
+ }
103
+ try {
104
+ const file = event.target.files[0];
105
+ if (!file) return;
106
+
107
+ if (fileInputRef.current) fileInputRef.current.value = '';
108
+
109
+ if (uploadFiles.some((item) => item.actualFileName === file.name && item.size === file.size)) {
110
+ showToast({ message: 'File already uploaded!', type: 'info' });
111
+ return;
112
+ }
113
+
114
+ setIsLoading(true);
115
+ const startTime = Date.now();
116
+ let dataToUpload = {
117
+ fieldKey: name,
118
+ referenceIdKey: referenceId,
119
+ filesToUpload: [file],
120
+ };
121
+
122
+ api
123
+ .post(
124
+ `/document/uploaddocumentV2?isTemporary=${isTemporary}`,
125
+ { ...dataToUpload },
126
+ {
127
+ type: 'fileUpload',
128
+ showLoader: false,
129
+ onUploadProgress: (progressEvent) => {
130
+ const { loaded, total } = progressEvent;
131
+ const currentTime = Date.now();
132
+
133
+ const percentage = Math.round((loaded * 100) / total);
134
+ setUploadProgress(percentage);
135
+
136
+ const elapsedSeconds = (currentTime - startTime) / 1000;
137
+ const rate = loaded / 1024 / elapsedSeconds;
138
+ setUploadRate(rate.toFixed(2));
139
+
140
+ const remainingBytes = total - loaded;
141
+ const estimatedTime = remainingBytes / (rate * 1024);
142
+ const etaMinutes = Math.floor(estimatedTime / 60);
143
+ const etaSeconds = Math.floor(estimatedTime % 60);
144
+ setEta(`${etaMinutes}m ${etaSeconds}s`);
145
+ },
146
+ }
147
+ )
148
+ .then((res) => {
149
+ setFileNameToFileIdMap({ ...fileNameToFileIdMap, ...{ [file.name]: res.data.docIds[0] } });
150
+ setReferenceId(res.data.referenceId || -1);
151
+
152
+ formControl.setValue(
153
+ name,
154
+ formControl.getValues(name)
155
+ ? (() =>
156
+ maxNoOfFiles > 1
157
+ ? [formControl.getValues(name), ...res.data.docIds]
158
+ : [formControl.getValues(name), res.data.docIds])()
159
+ : res.data.docIds,
160
+ {
161
+ shouldTouch: true,
162
+ }
163
+ );
164
+
165
+ setIsLoading(false);
166
+
167
+ const newFile = {
168
+ actualFileName: file.name,
169
+ fileType: file.type,
170
+ size: file.size,
171
+ image: file.type.startsWith('image') ? URL.createObjectURL(file) : null,
172
+ progress: 0,
173
+ isLoading: true,
174
+ documentId: res.data.docIds[0],
175
+ };
176
+ setOpenDisplayComp(false);
177
+ setUploadFiles((prevFiles) => [...prevFiles, newFile]);
178
+ })
179
+ .catch(() => {
180
+ showToast({
181
+ message: 'File not uploaded!',
182
+ type: 'error',
183
+ });
184
+ setIsLoading(false);
185
+ });
186
+ } catch (error) {
187
+ console.log(error);
188
+ }
189
+ };
190
+
191
+ const handleFileRemove = (file) => {
192
+ if (Object.prototype.hasOwnProperty.call(fileNameToFileIdMap, file.actualFileName)) {
193
+ setFileNameToFileIdMap((prevState) => {
194
+ delete prevState[file.actualFileName];
195
+ formControl.setValue(name, Object.values(prevState), {
196
+ shouldTouch: true,
197
+ });
198
+ return prevState;
199
+ });
200
+ }
201
+ formControl.setValue(name, null);
202
+ setUploadFiles((prevFiles) => prevFiles.filter((f) => f.actualFileName !== file.actualFileName));
203
+ };
204
+
205
+ const getIcon = (fileType) => {
206
+ if (fileType === 'video/mp4') {
207
+ return <FontAwesomeIcons iconName="faFileVideo" />;
208
+ } else {
209
+ return <FontAwesomeIcons iconName="faFileArrowUp" />;
210
+ }
211
+ };
212
+
213
+ return (
214
+ <Box sx={wrapperSx} boxShadow={5}>
215
+ <FormControl fullWidth error={!!error}>
216
+ <Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
217
+ <Box>
218
+ <Button
219
+ component="label"
220
+ variant="contained"
221
+ size="small"
222
+ startIcon={<FontAwesomeIcons iconName="faPlusSquare" />}
223
+ disabled={isLoading}
224
+ >
225
+ {uploadButtonName}
226
+ <input
227
+ type="file"
228
+ hidden
229
+ onChange={handleFileChange}
230
+ required={true}
231
+ accept={accept}
232
+ ref={fileInputRef}
233
+ />
234
+ </Button>
235
+ </Box>
236
+ <Box>
237
+ <Tooltip title="Maximum no of files" arrow sx={{ mr: 1 }}>
238
+ <Chip label={`${uploadFiles?.length} / ${maxNoOfFiles}`} variant="filled" color="primary" />
239
+ </Tooltip>
240
+ </Box>
241
+ </Box>
242
+ {isLoading && (
243
+ <Box sx={{ width: '100%', mt: 1 }}>
244
+ <Typography variant="body1">File Upload Progress</Typography>
245
+ <LinearProgress variant="determinate" value={uploadProgress} />
246
+ <Box sx={{ display: 'flex', justifyContent: 'space-between', mt: 1 }}>
247
+ <Typography variant="body2">Progress: {uploadProgress}%</Typography>
248
+ <Typography variant="body2">Rate: {uploadRate} KB/s</Typography>
249
+ <Typography variant="body2">ETA: {eta}</Typography>
250
+ </Box>
251
+ </Box>
252
+ )}
253
+
254
+ <Box sx={{ mt: 1 }}>
255
+ {uploadFiles?.length > 0 ? (
256
+ <TableContainer component={Paper}>
257
+ <Table size="small">
258
+ <TableHead
259
+ sx={{
260
+ backgroundColor: 'background.default',
261
+ }}
262
+ >
263
+ <TableRow>
264
+ <TableCell
265
+ align="center"
266
+ sx={{
267
+ fontSize: '1rem',
268
+ fontWeight: 'bold',
269
+ }}
270
+ >
271
+ #
272
+ </TableCell>
273
+ <TableCell
274
+ align="center"
275
+ sx={{
276
+ fontSize: '1rem',
277
+ fontWeight: 'bold',
278
+ }}
279
+ >
280
+ View
281
+ </TableCell>
282
+ <TableCell
283
+ align="center"
284
+ sx={{
285
+ fontSize: '1rem',
286
+ fontWeight: 'bold',
287
+ }}
288
+ >
289
+ Name
290
+ </TableCell>
291
+ <TableCell
292
+ align="center"
293
+ sx={{
294
+ fontSize: '1rem',
295
+ fontWeight: 'bold',
296
+ }}
297
+ >
298
+ Type
299
+ </TableCell>
300
+ <TableCell
301
+ align="center"
302
+ sx={{
303
+ fontSize: '1rem',
304
+ fontWeight: 'bold',
305
+ }}
306
+ >
307
+ Size
308
+ </TableCell>
309
+ <TableCell
310
+ align="center"
311
+ sx={{
312
+ fontSize: '1rem',
313
+ fontWeight: 'bold',
314
+ }}
315
+ >
316
+ Action
317
+ </TableCell>
318
+ </TableRow>
319
+ </TableHead>
320
+ <TableBody>
321
+ {uploadFiles?.map((file, index) => (
322
+ <TableRow key={file?.documentId}>
323
+ <TableCell align="center">{index + 1}</TableCell>
324
+ <TableCell
325
+ align="center"
326
+ sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}
327
+ >
328
+ {file.fileType.startsWith('image') ? (
329
+ (() =>
330
+ openDisplayComp ? (
331
+ <div style={{ maxHeight: '100px', alignSelf: 'center' }}>
332
+ <FileDisplayComponent id={file.id} style={{ height: '50px', width: '50px' }} />
333
+ </div>
334
+ ) : (
335
+ <img
336
+ src={file?.image}
337
+ alt={file?.actualFileName || 'Uploaded file'}
338
+ style={{ maxHeight: '100px', alignSelf: 'center' }}
339
+ />
340
+ ))()
341
+ ) : (
342
+ <>{getIcon(file.fileType)}</>
343
+ )}
344
+ </TableCell>
345
+ <TableCell align="center">{file.actualFileName}</TableCell>
346
+ <TableCell align="center">{file.fileType}</TableCell>
347
+ <TableCell align="center">{(file.size / 1024).toFixed(2)}KB</TableCell>
348
+ <TableCell align="center">
349
+ <IconButton
350
+ color="error"
351
+ onClick={() => {
352
+ handleFileRemove(file);
353
+ }}
354
+ >
355
+ <FontAwesomeIcons iconName="faWindowClose" />
356
+ </IconButton>
357
+ </TableCell>
358
+ </TableRow>
359
+ ))}
360
+ </TableBody>
361
+ </Table>
362
+ </TableContainer>
363
+ ) : (
364
+ <Alert severity="info" variant="outlined">
365
+ No Files Added!
366
+ </Alert>
367
+ )}
368
+ </Box>
369
+ {error && <p className="error-helper-text">{error?.message}</p>}
370
+ </FormControl>
371
+ </Box>
372
+ );
373
+ };
374
+
375
+ CustomFileUpload.propTypes = {
376
+ formControl: PropTypes.any,
377
+ name: PropTypes.any,
378
+ editing: PropTypes.any,
379
+ accept: PropTypes.any,
380
+ uploadButtonName: PropTypes.any,
381
+ maxNoOfFiles: PropTypes.any,
382
+ _moduleName: PropTypes.any,
383
+ isTemporary: PropTypes.any,
384
+ errors: PropTypes.any,
385
+ };
386
+
387
+ export default CustomFileUpload;