@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.
- package/package.json +139 -141
- package/src/GlobalErrorBoundary.jsx +31 -0
- package/src/SilentErrorFallback.jsx +68 -0
- package/src/TrackingProviderWrapper.jsx +40 -0
- package/src/_tests_/__mocks__/MockTranslationProvider.jsx +21 -0
- package/src/_tests_/__mocks__/ckeditor.js +45 -0
- package/src/_tests_/__mocks__/fileMock.js +1 -0
- package/src/_tests_/__mocks__/useranalytics.js +5 -0
- package/src/_tests_/views/components/Dashboard/DashboardUI.test.jsx +137 -0
- package/src/_tests_/views/components/Dashboard/DashboardUIMock.js +877 -0
- package/src/_tests_/views/components/ForgotPassword/ForgotPassword.test.jsx +314 -0
- package/src/_tests_/views/components/LocationDirective/LocationDirective.test.jsx.disable +229 -0
- package/src/_tests_/views/components/LocationDirective/mockLocationDirective.js +810 -0
- package/src/_tests_/views/components/LocationType/MockLocationType.js +42259 -0
- package/src/_tests_/views/components/LocationType/addlocationtype.test.jsx.disable +276 -0
- package/src/_tests_/views/components/LocationType/editlocationtype.test.jsx.disable +262 -0
- package/src/_tests_/views/components/LocationType/locationtype.test.jsx.disable +148 -0
- package/src/_tests_/views/components/Profile/UpdateProfileModalData.js +4396 -0
- package/src/_tests_/views/components/Profile/updateprofilemodal.test.jsx +282 -0
- package/src/_tests_/views/components/SideBar/MockSideBar.js +1379 -0
- package/src/_tests_/views/components/SideBar/SideBar.test.jsx +98 -0
- package/src/_tests_/views/components/SystemConfig/ManageSystemConfig/AddManageSystemConfig.test.jsx.disable +164 -0
- package/src/_tests_/views/components/SystemConfig/ManageSystemConfig/UpdateManageSystemConfig.test.jsx.disable +157 -0
- package/src/_tests_/views/components/SystemConfig/MockSystemConfig.js +1280 -0
- package/src/_tests_/views/components/SystemConfig/SystemConfig.test.jsx.disable +165 -0
- package/src/_tests_/views/components/login/Login.test.jsx +276 -0
- package/src/_tests_/views/components/login/MockAuthorise.js +2414 -0
- package/src/_tests_/views/components/login/ServiceResponse.js +595 -0
- package/src/_tests_/views/components/user/MockManageUser.js +7965 -0
- package/src/_tests_/views/components/user/manageuser.test.jsx.disable +989 -0
- package/src/_tests_/views/components/user/mockUsersData.js +582 -0
- package/src/assets/img/OASISLogin.png +0 -0
- package/src/assets/img/bahaarNew.png +0 -0
- package/src/assets/img/dnhdd4K.png +0 -0
- package/src/assets/img/govtofup.png +0 -0
- package/src/assets/img/sewarural4K.png +0 -0
- package/src/assets/img/techo4K.png +0 -0
- package/src/assets/img/up4K.png +0 -0
- package/src/common/HolidayList.jsx +573 -0
- package/src/common/MalaciaousInputUtil.js +23 -0
- package/src/common/SafeHtml.jsx +17 -0
- package/src/common/VersionManager.jsx +109 -0
- package/src/common/constants/PerformanceDashboard.js +514 -0
- package/src/common/constants/app.constant.js +781 -0
- package/src/common/constants/cccVerificationConstants.js +18 -0
- package/src/common/constants/fhsrConstant.js +33 -0
- package/src/common/constants/gvk-verification.constant.js +76 -0
- package/src/common/constants/search.constant.js +23 -0
- package/src/common/constants/teleconsulatationConstant.jsx +1339 -0
- package/src/common/directives/SearchTemplate.jsx +784 -0
- package/src/common/directives/SearchTemplate.scss +14 -0
- package/src/common/dynamicView/DynamicView.jsx +353 -0
- package/src/common/dynamicView/InputFieldComponent.jsx +1501 -0
- package/src/common/dynamicView/InputViewComponent.jsx +298 -0
- package/src/common/dynamicView/InputViewComponent.scss +15 -0
- package/src/common/env.js +5 -0
- package/src/common/filters/locationNameFilter.js +26 -0
- package/src/common/fontAwesomeIcons/FontAwesomeIcons.jsx +27 -0
- package/src/common/fontAwesomeIcons/FontAwesomeIconsNames.js +1968 -0
- package/src/common/fontPreferences/fontSizeProvider.jsx +34 -0
- package/src/common/fontPreferences/fontSizeSelector.jsx +116 -0
- package/src/common/getAssignedFeature/getAssignedFeature.js +32 -0
- package/src/common/interceptors/AxiosInterceptor.js +216 -0
- package/src/common/languageTranslator/TranslationContext.js +5 -0
- package/src/common/languageTranslator/TranslationProvider.jsx +24 -0
- package/src/common/languageTranslator/i18n.js +49 -0
- package/src/common/services/AuthenticateService.js +116 -0
- package/src/common/services/DownloadFile.js +35 -0
- package/src/common/services/ForgotPassword.js +18 -0
- package/src/common/services/FormConfiguratorService.js +195 -0
- package/src/common/services/GlobalApis.js +84 -0
- package/src/common/services/InterceptorNavigationService.js +17 -0
- package/src/common/services/LocationService.js +65 -0
- package/src/common/services/LocationType.js +11 -0
- package/src/common/services/QueryBuilder.js +36 -0
- package/src/common/services/Roles.js +28 -0
- package/src/common/services/SyncWithServer.js +15 -0
- package/src/common/services/SystemConfig.js +15 -0
- package/src/common/services/TranslationService.js +70 -0
- package/src/common/services/TwoFactorService.js +7 -0
- package/src/common/services/Users.js +91 -0
- package/src/common/services/Webtasks.js +27 -0
- package/src/common/services/util/Convert-pad-data-to-API-format.jsx +167 -0
- package/src/common/services/util/Convert-to-UI-format.jsx +82 -0
- package/src/common/services/util/EmptyPrescriptionPadData.jsx +11 -0
- package/src/common/services/util/GeneralUtil.js +456 -0
- package/src/common/services/util/Prescription-pad-util.js +339 -0
- package/src/common/services/util/PrescriptionPadData.js +67 -0
- package/src/common/services/util/PrescriptionpadCommonUtil.js +96 -0
- package/src/common/services/util/ReportFieldUtil.jsx +398 -0
- package/src/common/services/util/WebSocketContext.jsx +261 -0
- package/src/common/syncWithServer/SyncWithServerDialog.jsx +170 -0
- package/src/common/syncWithServer/SyncWithServerDialogSkeleton.jsx +67 -0
- package/src/common/tests/CustomWrapper.jsx +49 -0
- package/src/common/tests/TranslationWrapper.jsx +38 -0
- package/src/common/themeProvider/ColorInputs.jsx +97 -0
- package/src/common/themeProvider/EditableColorInput.jsx +128 -0
- package/src/common/themeProvider/ThemeEditor.jsx +319 -0
- package/src/common/themeProvider/ThemeProvider.jsx +210 -0
- package/src/common/themeProvider/themeConfig.js +558 -0
- package/src/common/toaster/toaster.jsx +30 -0
- package/src/firebaseConfig.js +24 -0
- package/src/global.scss +221 -0
- package/src/hooks/.gitkeep +0 -0
- package/src/hooks/useAESEncryption.js +56 -0
- package/src/hooks/useCaching.js +43 -0
- package/src/hooks/useDebounce.js +34 -0
- package/src/hooks/useDebounceFn.js +50 -0
- package/src/hooks/useDownloadPdf.js +358 -0
- package/src/hooks/useDownloadXlsx.js +55 -0
- package/src/hooks/useListValueFieldValues.js +30 -0
- package/src/hooks/useLocationHierarchies.js +63 -0
- package/src/hooks/useLocationHierarchyTranslate.js +16 -0
- package/src/hooks/useOnline.js +27 -0
- package/src/hooks/usePagination.js +63 -0
- package/src/hooks/useRefreshToken.js +87 -0
- package/src/hooks/useScript.js +25 -0
- package/src/hooks/useStopwatch.js +75 -0
- package/src/hooks/useTrackEvent.js +22 -0
- package/src/hooks/useWebAudioRecorder.js +115 -0
- package/src/layout/LoaderComponet.jsx +22 -0
- package/src/layout/LoaderContext.jsx +29 -0
- package/src/layout/mainLayout/AdaptiveZoom.jsx +27 -0
- package/src/layout/mainLayout/Chatbot.jsx +243 -0
- package/src/layout/mainLayout/Layout.jsx +445 -0
- package/src/layout/mainLayout/Profile/UpdateProfileModal.jsx +684 -0
- package/src/layout/mainLayout/header/LogoutModal.jsx +131 -0
- package/src/layout/mainLayout/header/Navbar.jsx +1677 -0
- package/src/layout/mainLayout/header/Navbar.scss +4 -0
- package/src/layout/mainLayout/header/index.js +0 -0
- package/src/layout/mainLayout/sidebar/SideBar.jsx +1402 -0
- package/src/layout/mainLayout/sidebar/Sidebar.css +159 -0
- package/src/layout/mainLayout/sidebar/index.js +0 -0
- package/src/logo.svg +1 -0
- package/src/reportWebVitals.js +13 -0
- package/src/setupFirebaseMessaging.js +28 -0
- package/src/setupTests.js +8 -0
- package/src/store/actions/AuthenticationActions.js +0 -0
- package/src/store/actions/ReportsActions.js +0 -0
- package/src/store/actions/TranslationAction.js +0 -0
- package/src/store/index.js +8 -0
- package/src/store/reducer.js +46 -0
- package/src/store/reducers/AuthenticationReducer.js +50 -0
- package/src/store/reducers/CalendarEventReducer.js +41 -0
- package/src/store/reducers/ConditionClipboardReducer.js +45 -0
- package/src/store/reducers/FeatureReducer.js +27 -0
- package/src/store/reducers/FormConfiguratorReducer.js +38 -0
- package/src/store/reducers/LoadingReducer.js +20 -0
- package/src/store/reducers/MembersAuthenticationReducer.js +28 -0
- package/src/store/reducers/PrescriptionPadReducer.js +329 -0
- package/src/store/reducers/QuestionaireReducer.js +29 -0
- package/src/store/reducers/ReportsReducer.js +24 -0
- package/src/store/reducers/SkeletonReducer.js +20 -0
- package/src/store/reducers/ThemeReducer.js +106 -0
- package/src/store/reducers/TranslationReducer.js +126 -0
- package/src/store/reducers/dashboardEditorSlice.js +77 -0
- package/src/store/reducers/districtHealthDashboardSlice.js +58 -0
- package/src/store/reducers/immunizationSlice.js +234 -0
- package/src/store/slices/dashboardPagesSlice.js +51 -0
- package/src/utils/.gitkeep +0 -0
- package/src/utils/FormConstants.js +2629 -0
- package/src/utils/GujaratTopoChart.jsx +483 -0
- package/src/utils/UUIDgenerator.js +8 -0
- package/src/utils/appointment-utils/appointment-utils.js +123 -0
- package/src/utils/feature.js +42 -0
- package/src/utils/getThemeColor.js +12 -0
- package/src/utils/localStorageHelper.js +11 -0
- package/src/utils/notifications/enable-push-notifications.js +27 -0
- package/src/utils/resolveAppliedStyle.js +11 -0
- package/src/utils/themeConfigs.js +1483 -0
- package/src/views/custom-components/.gitkeep +0 -0
- package/src/views/custom-components/AgIconButton/RIf.jsx +14 -0
- package/src/views/custom-components/AgIconButton/button.jsx +108 -0
- package/src/views/custom-components/AgIconButton/waterDrop.jsx +95 -0
- package/src/views/custom-components/AgIconButton/waterDrop.scss +37 -0
- package/src/views/custom-components/AlertPlaceholder.jsx +32 -0
- package/src/views/custom-components/AllFaIconsSelector.jsx +56 -0
- package/src/views/custom-components/CkEditor/CkEditor.js +102 -0
- package/src/views/custom-components/CustomAccordion.jsx +72 -0
- package/src/views/custom-components/CustomActionIcons.jsx +118 -0
- package/src/views/custom-components/CustomAutoComplete.jsx +188 -0
- package/src/views/custom-components/CustomCheckBox.jsx +60 -0
- package/src/views/custom-components/CustomConfirmationModal.jsx +118 -0
- package/src/views/custom-components/CustomCountrySelect.jsx +129 -0
- package/src/views/custom-components/CustomDatePicker.jsx +122 -0
- package/src/views/custom-components/CustomDropdown.jsx +191 -0
- package/src/views/custom-components/CustomFileUpload.jsx +387 -0
- package/src/views/custom-components/CustomFullCalendar.jsx +514 -0
- package/src/views/custom-components/CustomInfiniteScroll.jsx +126 -0
- package/src/views/custom-components/CustomRadioComponent.jsx +65 -0
- package/src/views/custom-components/CustomStatsComponent.jsx +114 -0
- package/src/views/custom-components/CustomSvgUpload.jsx +170 -0
- package/src/views/custom-components/CustomSwitch.jsx +37 -0
- package/src/views/custom-components/CustomTabPanel.jsx +19 -0
- package/src/views/custom-components/CustomTextArea.jsx +62 -0
- package/src/views/custom-components/CustomTextArea.scss +27 -0
- package/src/views/custom-components/CustomTextField.jsx +116 -0
- package/src/views/custom-components/CustomToggleSwitch.jsx +138 -0
- package/src/views/custom-components/CustomTooltip.jsx +51 -0
- package/src/views/custom-components/CustomZoomImage.jsx +134 -0
- package/src/views/custom-components/CustomizedTable/CustomizedTableV2.jsx +1407 -0
- package/src/views/custom-components/CustomizedTable/VirtualizeTableBody.jsx +295 -0
- package/src/views/custom-components/CustomizedTable/helper.jsx +159 -0
- package/src/views/custom-components/CustomizedTable.jsx +532 -0
- package/src/views/custom-components/EditInputField.jsx +174 -0
- package/src/views/custom-components/FieldDescription.jsx +22 -0
- package/src/views/custom-components/FileDisplayComponent.jsx +138 -0
- package/src/views/custom-components/FormItem.jsx +53 -0
- package/src/views/custom-components/GenericChart.jsx +80 -0
- package/src/views/custom-components/InfoBadge.jsx +60 -0
- package/src/views/custom-components/PostgresEditor.jsx +801 -0
- package/src/views/custom-components/ResizableEditAutocompleteField.jsx +249 -0
- package/src/views/custom-components/ResizableEditInputField.jsx +215 -0
- package/src/views/custom-components/ResizeableEditSelectField.jsx +197 -0
- package/src/views/custom-components/SideOverlay.jsx +113 -0
- package/src/views/custom-components/SideOverlay.scss +42 -0
- package/src/views/custom-components/calendar.scss +571 -0
- package/src/views/feature-components/.gitkeep +0 -0
- package/src/views/feature-components/Dashboard/DashboardUI.jsx +1043 -0
- package/src/views/feature-components/Dashboard/DhnddModal/AshaDataQualityVerificationModal.jsx +278 -0
- package/src/views/feature-components/Dashboard/PinFeatureModal.jsx +143 -0
- package/src/views/feature-components/Dashboard/QuickLinks.jsx +163 -0
- package/src/views/feature-components/Dashboard/Taskbar.jsx +56 -0
- package/src/views/feature-components/Dashboard/WebtasksFilterForm.jsx +109 -0
- package/src/views/feature-components/Dashboard/WidgetCard.jsx +161 -0
- package/src/views/feature-components/Dashboard/actionModal.jsx +263 -0
- package/src/views/feature-components/Dashboard/ekavachModal/HealthWorkerIncorrectDetailsModal.jsx +332 -0
- package/src/views/feature-components/Dashboard/ekavachModal/MoMaternalDeathVerifcationModal.jsx +275 -0
- package/src/views/feature-components/Dashboard/ekavachModal/MoVerficationForChildScreeningMoadal.jsx +566 -0
- package/src/views/feature-components/FeatureUsageAnalytics/FeatureUsageAnalytics.jsx +989 -0
- package/src/views/feature-components/Features/NewServerManagement.jsx +217 -0
- package/src/views/feature-components/Features/ServerManagement.scss +120 -0
- package/src/views/feature-components/ForgotPassword/ForgotPassword.jsx +226 -0
- package/src/views/feature-components/LocationDirective/LocationDirective.jsx +992 -0
- package/src/views/feature-components/LocationDirective/LocationDirectiveV2.jsx +909 -0
- package/src/views/feature-components/NotFound.jsx +66 -0
- package/src/views/feature-components/Onboarding/Onboarding.jsx +1400 -0
- package/src/views/feature-components/Skeletons.js +115 -0
- package/src/views/feature-components/Unauthorized.jsx +48 -0
- package/src/views/feature-components/VerifyRoute.jsx +88 -0
- package/src/views/feature-components/YearlyRecap/YearlyRecap.jsx +357 -0
- package/src/views/feature-components/YearlyRecap/components/RecapSlide.jsx +183 -0
- package/src/views/feature-components/YearlyRecap/languageTranslator/TranslationContext.js +5 -0
- package/src/views/feature-components/YearlyRecap/languageTranslator/TranslationProvider.jsx +26 -0
- package/src/views/feature-components/YearlyRecap/languageTranslator/i18n.js +46 -0
- package/src/views/feature-components/YearlyRecap/languageTranslator/translations.json +167 -0
- package/src/views/feature-components/YearlyRecap/slides/IntroSlide.jsx +233 -0
- package/src/views/feature-components/YearlyRecap/slides/MaternalHealthSlide.jsx +146 -0
- package/src/views/feature-components/YearlyRecap/slides/MetricSlide.jsx +227 -0
- package/src/views/feature-components/YearlyRecap/slides/OutroSlide.jsx +701 -0
- package/src/views/feature-components/YearlyRecap/slides/ReachSlide.jsx +273 -0
- package/src/views/feature-components/login/Login.jsx +840 -0
- package/src/views/feature-components/login/Login.scss +154 -0
- package/src/views/feature-components/login/LoginConfigurator.jsx +1149 -0
- package/src/views/feature-components/login/TwoFactorSetupModal.jsx +411 -0
- package/src/views/feature-components/login/simplifyMenu.js +45 -0
- package/src/views/feature-components/system-config/ManageSystemConfigs.jsx +284 -0
- package/src/views/feature-components/system-config/SystemConfig.jsx +299 -0
- package/src/views/feature-components/users/ChangePasswordModal.jsx +243 -0
- package/src/views/feature-components/users/PasswordField.jsx +56 -0
- package/dist/index.css +0 -1
- package/dist/index.js +0 -32001
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import pdfMake from 'pdfmake/build/pdfmake';
|
|
2
|
+
import vfs from '@/assets/fonts/vfs_fonts';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import { FormConfiguratorUtil } from '@argusoft/medplat-form-engine';
|
|
5
|
+
import { evaluateExpressionCore, evaluateConditionCore, normalize } from '@argusoft/medplat-form-engine';
|
|
6
|
+
|
|
7
|
+
pdfMake.vfs = {
|
|
8
|
+
...vfs,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
pdfMake.addFonts({
|
|
12
|
+
Roboto: {
|
|
13
|
+
normal: 'Roboto-Regular.ttf',
|
|
14
|
+
bold: 'Roboto-Medium.ttf',
|
|
15
|
+
italics: 'Roboto-Regular.ttf',
|
|
16
|
+
bolditalics: 'Roboto-Regular.ttf',
|
|
17
|
+
},
|
|
18
|
+
MuktaVaani: {
|
|
19
|
+
normal: 'MuktaVaani-Regular.ttf',
|
|
20
|
+
bold: 'MuktaVaani-Regular.ttf',
|
|
21
|
+
italics: 'MuktaVaani-Regular.ttf',
|
|
22
|
+
bolditalics: 'MuktaVaani-Regular.ttf',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Custom hook to generate and download PDFs with English & Gujarati text.
|
|
28
|
+
* @returns {Function} - A function to download PDF
|
|
29
|
+
*/
|
|
30
|
+
const useDownloadPdf = () => {
|
|
31
|
+
/**
|
|
32
|
+
* Function to download PDF
|
|
33
|
+
* @param {Object} config - Configuration for the PDF
|
|
34
|
+
* @param {Array<string> | string} config.title - Title of the PDF (single string or array of lines)
|
|
35
|
+
* @param {Array<string>} config.columns - Table column headers
|
|
36
|
+
* @param {Array<string>} config.keys - Keys to extract data dynamically
|
|
37
|
+
* @param {Array<Object>} config.data - JSON data to convert to rows
|
|
38
|
+
* @param {string} config.fileName - Name of the downloaded file
|
|
39
|
+
* @param {string} config.headerText - Custom header text
|
|
40
|
+
* @param {string} config.footerText - Custom footer text
|
|
41
|
+
* @param {string} config.orientation - Orientation of the PDF ("portrait" or "landscape")
|
|
42
|
+
*/
|
|
43
|
+
const downloadPdf = ({
|
|
44
|
+
title,
|
|
45
|
+
columns,
|
|
46
|
+
keys,
|
|
47
|
+
data,
|
|
48
|
+
fileName = 'data.pdf',
|
|
49
|
+
headerText = 'Header',
|
|
50
|
+
footerText = 'Page',
|
|
51
|
+
orientation = 'portrait',
|
|
52
|
+
layout = 'table',
|
|
53
|
+
gridColumns = 2,
|
|
54
|
+
gridConfig = null,
|
|
55
|
+
conditionContext = null,
|
|
56
|
+
}) => {
|
|
57
|
+
const isGujarati = (text) => /[\u0A80-\u0AFF]/.test(text);
|
|
58
|
+
|
|
59
|
+
const content = [];
|
|
60
|
+
|
|
61
|
+
if (title) {
|
|
62
|
+
const titleContent = Array.isArray(title)
|
|
63
|
+
? title.map((line) => ({
|
|
64
|
+
text: line,
|
|
65
|
+
font: isGujarati(line) ? 'MuktaVaani' : 'Roboto',
|
|
66
|
+
alignment: 'center',
|
|
67
|
+
fontSize: 14,
|
|
68
|
+
margin: [0, 5],
|
|
69
|
+
}))
|
|
70
|
+
: [
|
|
71
|
+
{
|
|
72
|
+
text: title,
|
|
73
|
+
font: isGujarati(title) ? 'MuktaVaani' : 'Roboto',
|
|
74
|
+
alignment: 'center',
|
|
75
|
+
fontSize: 14,
|
|
76
|
+
margin: [0, 5],
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
content.push(...titleContent);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const updatedColumns = ['S.No', ...columns];
|
|
83
|
+
|
|
84
|
+
const getPathValue = (source, path) =>
|
|
85
|
+
path.split('.').reduce((acc, segment) => (acc === null || acc === undefined ? undefined : acc[segment]), source);
|
|
86
|
+
|
|
87
|
+
const resolveValue = (value, valueType = null, contextRowData = {}, isCustomValue = false) => {
|
|
88
|
+
if (isCustomValue) return normalize(value);
|
|
89
|
+
if (value === null || value === undefined) return normalize(value);
|
|
90
|
+
|
|
91
|
+
let resolvedValue = value;
|
|
92
|
+
|
|
93
|
+
if (typeof value === 'string' && value.startsWith('__')) {
|
|
94
|
+
try {
|
|
95
|
+
resolvedValue = FormConfiguratorUtil.evaluate(
|
|
96
|
+
value,
|
|
97
|
+
conditionContext?.iteratorIndicesMap || {},
|
|
98
|
+
conditionContext?.formIndexes || {},
|
|
99
|
+
conditionContext?.getValues,
|
|
100
|
+
{ dayjs, ...(conditionContext?.dependencies || {}) }
|
|
101
|
+
);
|
|
102
|
+
} catch {
|
|
103
|
+
resolvedValue = null;
|
|
104
|
+
}
|
|
105
|
+
} else if (typeof value === 'string' && !isCustomValue) {
|
|
106
|
+
if (Object.prototype.hasOwnProperty.call(contextRowData, value)) {
|
|
107
|
+
resolvedValue = contextRowData[value];
|
|
108
|
+
} else if (value.includes('.')) {
|
|
109
|
+
const pathValue = getPathValue(contextRowData, value);
|
|
110
|
+
if (pathValue !== undefined) resolvedValue = pathValue;
|
|
111
|
+
} else if (conditionContext?.getValues) {
|
|
112
|
+
const formValue = conditionContext.getValues(value);
|
|
113
|
+
if (formValue !== undefined) resolvedValue = formValue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const targetType = valueType;
|
|
118
|
+
if (targetType === 'listValueFieldValue' || targetType === 'location')
|
|
119
|
+
return typeof resolvedValue === 'string' ? Number(resolvedValue) : resolvedValue;
|
|
120
|
+
if (targetType === 'boolean') return resolvedValue === 'true' || resolvedValue === true;
|
|
121
|
+
if (targetType === 'date' && dayjs(resolvedValue).isValid()) return dayjs(resolvedValue).startOf('day').valueOf();
|
|
122
|
+
if (targetType === 'dateAndTime' && dayjs(resolvedValue).isValid())
|
|
123
|
+
return dayjs(resolvedValue).startOf('minute').valueOf();
|
|
124
|
+
|
|
125
|
+
return normalize(resolvedValue);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const evaluateCondition = (condition, contextCellValue, contextRowData) =>
|
|
129
|
+
evaluateConditionCore({
|
|
130
|
+
condition,
|
|
131
|
+
evaluator: resolveValue,
|
|
132
|
+
contextCellValue: contextCellValue,
|
|
133
|
+
contextRowData: contextRowData,
|
|
134
|
+
type: null,
|
|
135
|
+
isStyleMode: false,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const evaluateExpression = (expression, item) =>
|
|
139
|
+
evaluateExpressionCore({
|
|
140
|
+
expression,
|
|
141
|
+
contextCellValue: null,
|
|
142
|
+
contextRowData: item,
|
|
143
|
+
conditionKey: 'visibility',
|
|
144
|
+
evaluateConditionFunc: evaluateCondition,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const renderPrefixSuffixElements = (configArr, item) => {
|
|
148
|
+
if (!configArr) return [];
|
|
149
|
+
const resolvedConfigs = Array.isArray(configArr) ? configArr : [configArr];
|
|
150
|
+
if (resolvedConfigs.length === 0) return [];
|
|
151
|
+
|
|
152
|
+
const match = resolvedConfigs.find(
|
|
153
|
+
(c) =>
|
|
154
|
+
typeof c === 'object' && !c.isDefault && c.appliedConditions && evaluateExpression(c.appliedConditions, item)
|
|
155
|
+
);
|
|
156
|
+
const def = resolvedConfigs.find((c) => typeof c === 'object' && c.isDefault);
|
|
157
|
+
const single = resolvedConfigs.length === 1 ? resolvedConfigs[0] : null;
|
|
158
|
+
const c =
|
|
159
|
+
match ||
|
|
160
|
+
def ||
|
|
161
|
+
(single && (typeof single === 'string' || (typeof single === 'object' && !single.appliedConditions))
|
|
162
|
+
? single
|
|
163
|
+
: null);
|
|
164
|
+
|
|
165
|
+
if (!c) return [];
|
|
166
|
+
let val, textVal, element;
|
|
167
|
+
if (typeof c === 'string') {
|
|
168
|
+
val = item[c];
|
|
169
|
+
} else if (c.iconValue) {
|
|
170
|
+
return [{ svg: c.iconValue, width: 10, height: 10, margin: [0, 0, 3, 0] }];
|
|
171
|
+
} else {
|
|
172
|
+
val = item[c.fieldValue || c.fieldKey || c.key];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (val !== undefined && val !== null && val !== '') {
|
|
176
|
+
textVal = val.toString();
|
|
177
|
+
element = {
|
|
178
|
+
text: textVal,
|
|
179
|
+
fontSize: 8.5,
|
|
180
|
+
font: isGujarati(textVal) ? 'MuktaVaani' : 'Roboto',
|
|
181
|
+
margin: [0, 0, 3, 0],
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return element ? [element] : [];
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
let mainContent;
|
|
188
|
+
|
|
189
|
+
const renderCard = (item, index) => {
|
|
190
|
+
const prefixColumn = [
|
|
191
|
+
{ text: `${index + 1}.`, bold: true, fontSize: 8.5, color: '#64748b', margin: [0, 0, 0, 4] },
|
|
192
|
+
...renderPrefixSuffixElements(gridConfig?.prefix, item),
|
|
193
|
+
];
|
|
194
|
+
const middleColumn = [];
|
|
195
|
+
['title', 'subtitle', 'description'].forEach((key) => {
|
|
196
|
+
const val = item[gridConfig?.[key]]?.toString().trim();
|
|
197
|
+
if (val) {
|
|
198
|
+
middleColumn.push({
|
|
199
|
+
text: val,
|
|
200
|
+
bold: key !== 'description',
|
|
201
|
+
fontSize: key === 'title' ? 10 : key === 'subtitle' ? 8 : 7.5,
|
|
202
|
+
font: isGujarati(val) ? 'MuktaVaani' : 'Roboto',
|
|
203
|
+
color: key === 'title' ? '#1e293b' : key === 'subtitle' ? '#2563eb' : '#64748b',
|
|
204
|
+
margin: [0, 0, 0, key === 'description' ? 4 : 2],
|
|
205
|
+
italics: key === 'description',
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const rightColumn = [];
|
|
211
|
+
['badge', 'tag'].forEach((key) => {
|
|
212
|
+
const val = item[gridConfig?.[key]]?.toString().trim();
|
|
213
|
+
if (val) {
|
|
214
|
+
rightColumn.push({
|
|
215
|
+
table: {
|
|
216
|
+
body: [
|
|
217
|
+
[
|
|
218
|
+
{
|
|
219
|
+
text: val,
|
|
220
|
+
fontSize: 6.5,
|
|
221
|
+
color: key === 'badge' ? '#1d4ed8' : '#166534',
|
|
222
|
+
bold: true,
|
|
223
|
+
margin: [key === 'badge' ? 3 : 4, 1],
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
layout: {
|
|
229
|
+
hLineWidth: () => 0.4,
|
|
230
|
+
vLineWidth: () => 0.4,
|
|
231
|
+
hLineColor: () => (key === 'badge' ? '#1d4ed8' : '#166534'),
|
|
232
|
+
vLineColor: () => (key === 'badge' ? '#1d4ed8' : '#166534'),
|
|
233
|
+
fillColor: () => (key === 'badge' ? '#dbeafe' : '#dcfce7'),
|
|
234
|
+
},
|
|
235
|
+
margin: [0, 0, 0, 4],
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
const suffixElements = renderPrefixSuffixElements(gridConfig?.suffix, item);
|
|
240
|
+
if (suffixElements.length > 0) rightColumn.push(...suffixElements);
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
table: {
|
|
244
|
+
widths: ['*'],
|
|
245
|
+
body: [
|
|
246
|
+
[
|
|
247
|
+
{
|
|
248
|
+
stack: [
|
|
249
|
+
{
|
|
250
|
+
columns: [
|
|
251
|
+
{ stack: prefixColumn, width: 'auto', margin: [0, 0, 8, 0] },
|
|
252
|
+
{ stack: middleColumn, width: '*' },
|
|
253
|
+
{ stack: rightColumn, width: 'auto', alignment: 'right', margin: [8, 0, 0, 0] },
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
padding: [8, 8, 8, 8],
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
layout: {
|
|
263
|
+
hLineWidth: (i) => (i === 0 || i === 1 ? 0.8 : 0),
|
|
264
|
+
vLineWidth: (i) => (i === 0 || i === 1 ? 0.8 : 0),
|
|
265
|
+
hLineColor: () => '#cbd5e1',
|
|
266
|
+
vLineColor: () => '#cbd5e1',
|
|
267
|
+
},
|
|
268
|
+
margin: [0, 4, 0, 4],
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
if (layout === 'grid') {
|
|
273
|
+
const cards = data.map((item, index) => renderCard(item, index));
|
|
274
|
+
const effectiveGridColumns = gridColumns > 2 ? 2 : gridColumns;
|
|
275
|
+
const rows = [];
|
|
276
|
+
for (let i = 0; i < cards.length; i += effectiveGridColumns) {
|
|
277
|
+
rows.push({ columns: cards.slice(i, i + effectiveGridColumns), columnGap: 10 });
|
|
278
|
+
}
|
|
279
|
+
mainContent = { stack: rows };
|
|
280
|
+
} else {
|
|
281
|
+
const rows = data.map((item, index) => {
|
|
282
|
+
return [
|
|
283
|
+
{ text: index + 1, fontSize: 10 },
|
|
284
|
+
...keys.map((key) => {
|
|
285
|
+
const value = item[key];
|
|
286
|
+
if (typeof value === 'object') {
|
|
287
|
+
return {
|
|
288
|
+
text: Object.entries(value)
|
|
289
|
+
.map(([k, v]) => `${k} - ${v}`)
|
|
290
|
+
.join('\n'),
|
|
291
|
+
fontSize: 10,
|
|
292
|
+
font: isGujarati(value) ? 'MuktaVaani' : 'Roboto',
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
const temp = value?.toString() || '';
|
|
296
|
+
return {
|
|
297
|
+
text: temp,
|
|
298
|
+
fontSize: 10,
|
|
299
|
+
font: isGujarati(temp) ? 'MuktaVaani' : 'Roboto',
|
|
300
|
+
};
|
|
301
|
+
}),
|
|
302
|
+
];
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
mainContent = {
|
|
306
|
+
table: {
|
|
307
|
+
headerRows: 1,
|
|
308
|
+
widths: updatedColumns.map(() => '*'),
|
|
309
|
+
body: [
|
|
310
|
+
updatedColumns.map((col) => ({
|
|
311
|
+
text: col,
|
|
312
|
+
fillColor: '#243a50',
|
|
313
|
+
color: '#ffffff',
|
|
314
|
+
bold: true,
|
|
315
|
+
fontSize: 10,
|
|
316
|
+
})),
|
|
317
|
+
...rows,
|
|
318
|
+
],
|
|
319
|
+
},
|
|
320
|
+
layout: {
|
|
321
|
+
fillColor: (rowIndex) => (rowIndex === 0 ? '#243a50' : null),
|
|
322
|
+
hLineWidth: () => 0.1,
|
|
323
|
+
vLineWidth: () => 0.1,
|
|
324
|
+
},
|
|
325
|
+
margin: [0, 10],
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const docDefinition = {
|
|
330
|
+
pageOrientation: orientation,
|
|
331
|
+
content: [...content, mainContent],
|
|
332
|
+
footer: (currentPage, pageCount) => {
|
|
333
|
+
return {
|
|
334
|
+
text: `Page ${currentPage} of ${pageCount} | ${footerText}`,
|
|
335
|
+
alignment: 'left',
|
|
336
|
+
margin: [14, 0],
|
|
337
|
+
fontSize: 8,
|
|
338
|
+
font: isGujarati(footerText) ? 'MuktaVaani' : 'Roboto',
|
|
339
|
+
};
|
|
340
|
+
},
|
|
341
|
+
header: {
|
|
342
|
+
text: headerText,
|
|
343
|
+
alignment: 'left',
|
|
344
|
+
margin: [14, 10],
|
|
345
|
+
fontSize: 10,
|
|
346
|
+
font: isGujarati(headerText) ? 'MuktaVaani' : 'Roboto',
|
|
347
|
+
},
|
|
348
|
+
defaultStyle: {
|
|
349
|
+
font: 'MuktaVaani',
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
pdfMake.createPdf(docDefinition).download(fileName);
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
return downloadPdf;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
export default useDownloadPdf;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as XLSX from 'xlsx-js-style';
|
|
2
|
+
import { saveAs } from 'file-saver';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom hook to generate and download Excel files using exceljs.
|
|
7
|
+
*
|
|
8
|
+
* @returns {function} A function to download Excel files.
|
|
9
|
+
*/
|
|
10
|
+
export function useDownloadXlsx() {
|
|
11
|
+
/**
|
|
12
|
+
* Downloads an Excel file.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} config - Configuration for the Excel download
|
|
15
|
+
* @param {Array<string>} config.columns - Columns (headers) for the Excel file.
|
|
16
|
+
* @param {Array<string>} config.keys - Keys to extract data dynamically from each object.
|
|
17
|
+
* @param {Array<Object>} config.data - Data to be included in the Excel file (array of objects).
|
|
18
|
+
* @param {string} config.filename - The name of the file to be downloaded (default: "download.xlsx").
|
|
19
|
+
*/
|
|
20
|
+
const downloadXlsx = useCallback(async ({ columns, keys, data, filename = 'download.xlsx' }) => {
|
|
21
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
22
|
+
console.error('Data must be a non-empty array.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const workbook = XLSX.utils.book_new();
|
|
27
|
+
|
|
28
|
+
const worksheetData = [
|
|
29
|
+
['S.No', ...columns],
|
|
30
|
+
...data.map((item, index) => [
|
|
31
|
+
index + 1,
|
|
32
|
+
...keys.map((key) => {
|
|
33
|
+
if (typeof item[key] === 'object' && item[key] !== null) {
|
|
34
|
+
return Object.entries(item[key])
|
|
35
|
+
.map(([subKey, value]) => `${subKey} - ${value}`)
|
|
36
|
+
.join('\n');
|
|
37
|
+
}
|
|
38
|
+
return item[key];
|
|
39
|
+
}),
|
|
40
|
+
]),
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const worksheet = XLSX.utils.aoa_to_sheet(worksheetData);
|
|
44
|
+
|
|
45
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
|
|
46
|
+
|
|
47
|
+
const workbookOutput = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
|
|
48
|
+
const blob = new Blob([workbookOutput], {
|
|
49
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
50
|
+
});
|
|
51
|
+
saveAs(blob, filename);
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
return downloadXlsx;
|
|
55
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FormConfiguratorUtil } from '@argusoft/medplat-form-engine';
|
|
2
|
+
import useCaching from '@/hooks/useCaching';
|
|
3
|
+
|
|
4
|
+
const notFound = -1;
|
|
5
|
+
|
|
6
|
+
const useListValueFieldValues = () => {
|
|
7
|
+
const { peekCache, updateCache } = useCaching();
|
|
8
|
+
|
|
9
|
+
const fetchListValueFieldValues = async (ids) => {
|
|
10
|
+
const uniqueIds = [...new Set(ids)];
|
|
11
|
+
const idsToFetch = uniqueIds?.filter((id) => !peekCache(['lvfvd', id]));
|
|
12
|
+
const data = await FormConfiguratorUtil.fetchListValueDetailByIds(idsToFetch || []);
|
|
13
|
+
data?.forEach(({ id, value }) => {
|
|
14
|
+
updateCache(['lvfvd', id], value);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const getListValueFieldValue = async (id) => {
|
|
19
|
+
const data = peekCache(['lvfvd', id]) || notFound;
|
|
20
|
+
if (data === -1) {
|
|
21
|
+
await fetchListValueFieldValues([id]);
|
|
22
|
+
return peekCache(['lvfvd', id]) || notFound;
|
|
23
|
+
}
|
|
24
|
+
return data || notFound;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return { fetchListValueFieldValues, getListValueFieldValue };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default useListValueFieldValues;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { FormConfiguratorUtil } from '@argusoft/medplat-form-engine';
|
|
2
|
+
import { useSelector } from 'react-redux';
|
|
3
|
+
import useCaching from '@/hooks/useCaching';
|
|
4
|
+
|
|
5
|
+
const locationNotFound = { locationName: -1 };
|
|
6
|
+
|
|
7
|
+
const useLocationHierarchies = () => {
|
|
8
|
+
const { getCachedData, peekCache, updateCache } = useCaching();
|
|
9
|
+
const lang = useSelector((state) => state.Translation.translationLanguage);
|
|
10
|
+
|
|
11
|
+
const fetchHierarchies = async (ids) => {
|
|
12
|
+
const uniqueLocationIds = [...new Set(ids)];
|
|
13
|
+
|
|
14
|
+
// Filter out IDs that are already safely cached
|
|
15
|
+
const missingIds = uniqueLocationIds.filter((id) => {
|
|
16
|
+
const cachedData = peekCache(['locationHierarchy', id, lang]);
|
|
17
|
+
return !cachedData;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (missingIds.length === 0) {
|
|
21
|
+
return; // All requested IDs are already in the cache!
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const data = await FormConfiguratorUtil.fetchLocationHierarchyByIds(
|
|
26
|
+
missingIds,
|
|
27
|
+
lang
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
data?.forEach(({ locationId, locationName, locationHierarchy }) => {
|
|
31
|
+
updateCache(['locationHierarchy', locationId, lang], {
|
|
32
|
+
locationName,
|
|
33
|
+
locationHierarchy,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getHierarchy = async (id) => {
|
|
39
|
+
const data = await getCachedData({
|
|
40
|
+
cacheKey: ['locationHierarchy', id, lang],
|
|
41
|
+
fetchFn: async () => {
|
|
42
|
+
const response = await FormConfiguratorUtil.fetchLocationHierarchyByIds([id], lang);
|
|
43
|
+
if (!response || response.length === 0) {
|
|
44
|
+
// Throwing an error prevents React Query from caching this empty response
|
|
45
|
+
throw new Error(`Location Hierarchy not found for id: ${id}`);
|
|
46
|
+
}
|
|
47
|
+
const result = response[0];
|
|
48
|
+
return {
|
|
49
|
+
locationName: result.locationName,
|
|
50
|
+
locationHierarchy: result.locationHierarchy
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
staleTime: Infinity,
|
|
54
|
+
cacheTime: 1000 * 60 * 30, // 30 minutes
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return data || locationNotFound;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return { fetchHierarchies, getHierarchy };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default useLocationHierarchies;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useTranslateProvider } from '@/common/languageTranslator/TranslationContext';
|
|
2
|
+
|
|
3
|
+
const useLocationHierarchyTranslate = () => {
|
|
4
|
+
const { translate } = useTranslateProvider();
|
|
5
|
+
|
|
6
|
+
const translateLocationHierarchy = (hierarchy) => {
|
|
7
|
+
const hierarchyValues = hierarchy?.split(' > ');
|
|
8
|
+
const translatedHierarchyValues = hierarchyValues?.map((h) => translate(h));
|
|
9
|
+
const translatedHierarchy = translatedHierarchyValues?.join(' > ');
|
|
10
|
+
return translatedHierarchy;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
return { translateLocationHierarchy };
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default useLocationHierarchyTranslate;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useOnline = () => {
|
|
4
|
+
const [isOnline, setUseOnline] = useState(true);
|
|
5
|
+
|
|
6
|
+
const handleOnline = () => {
|
|
7
|
+
setUseOnline(true);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const handleOffline = () => {
|
|
11
|
+
setUseOnline(false);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
window.addEventListener('online', handleOnline);
|
|
16
|
+
window.addEventListener('offline', handleOffline);
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
window.removeEventListener('online', handleOnline);
|
|
20
|
+
window.removeEventListener('offline', handleOffline);
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
return isOnline;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default useOnline;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dynamic pagination hook that supports both infinite and traditional pagination.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} params - Parameters for pagination.
|
|
7
|
+
* @param {Array} params.key - Query key for React Query.
|
|
8
|
+
* @param {Function} params.queryFn - Query function that accepts an object with { limit, offset, searchString }.
|
|
9
|
+
* @param {number} [params.limit=100] - Number of items per page.
|
|
10
|
+
* @param {number} [params.currentPage] - Current page number (used only for traditional pagination).
|
|
11
|
+
* @param {string|null} [params.searchString=null] - Optional search term.
|
|
12
|
+
* @param {'infinite' | 'traditional'} [params.paginationType='infinite'] - Type of pagination to use.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Object} - Returns the result object from the React Query hook.
|
|
15
|
+
*/
|
|
16
|
+
const usePagination = ({
|
|
17
|
+
key,
|
|
18
|
+
queryFn,
|
|
19
|
+
limit = 100,
|
|
20
|
+
staleTime = 0,
|
|
21
|
+
currentPage = 1,
|
|
22
|
+
searchString = null,
|
|
23
|
+
paginationType = 'infinite',
|
|
24
|
+
enabled = true,
|
|
25
|
+
}) => {
|
|
26
|
+
if (paginationType === 'infinite') {
|
|
27
|
+
// Infinite scrolling pagination
|
|
28
|
+
const infiniteQuery = useInfiniteQuery({
|
|
29
|
+
staleTime: staleTime,
|
|
30
|
+
queryKey: key,
|
|
31
|
+
queryFn,
|
|
32
|
+
initialPageParam: { limit, offset: (currentPage - 1) * limit, searchString },
|
|
33
|
+
getNextPageParam: (lastPage, allPages, lastPageParam) => {
|
|
34
|
+
// Check if the last fetched page contains enough items to fetch another page
|
|
35
|
+
return lastPage?.length >= lastPageParam.limit
|
|
36
|
+
? {
|
|
37
|
+
...lastPageParam,
|
|
38
|
+
offset: lastPageParam.offset + lastPageParam.limit,
|
|
39
|
+
searchString,
|
|
40
|
+
}
|
|
41
|
+
: undefined;
|
|
42
|
+
},
|
|
43
|
+
enabled,
|
|
44
|
+
});
|
|
45
|
+
return infiniteQuery;
|
|
46
|
+
} else {
|
|
47
|
+
// Traditional (page-based) pagination
|
|
48
|
+
const traditionalQuery = useQuery({
|
|
49
|
+
queryKey: [...key, currentPage],
|
|
50
|
+
queryFn: () =>
|
|
51
|
+
queryFn({
|
|
52
|
+
limit,
|
|
53
|
+
offset: (currentPage - 1) * limit, // Subtract 1 from currentPage since it's 1-based
|
|
54
|
+
searchString,
|
|
55
|
+
}),
|
|
56
|
+
enabled,
|
|
57
|
+
keepPreviousData: true,
|
|
58
|
+
});
|
|
59
|
+
return traditionalQuery;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default usePagination;
|