@argusoft/medplat-app-shell 1.0.6 → 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,1501 @@
|
|
|
1
|
+
import React, { useState, useEffect, lazy, Suspense } from 'react';
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
const LocationSelectionComponent = lazy(
|
|
4
|
+
() => import('@/views/feature-components/LocationDirective/LocationDirectiveV2')
|
|
5
|
+
);
|
|
6
|
+
import { TextField, MenuItem, Select, FormControl, FormGroup, Autocomplete } from '@mui/material';
|
|
7
|
+
import Grid from '@mui/material/Grid2';
|
|
8
|
+
import '@/common/dynamicView/InputViewComponent.scss';
|
|
9
|
+
import CustomTextField from '@/views/custom-components/CustomTextField';
|
|
10
|
+
import { showToast } from '@/common/toaster/toaster';
|
|
11
|
+
|
|
12
|
+
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
|
|
13
|
+
|
|
14
|
+
import { LocalizationProvider } from '@mui/x-date-pickers';
|
|
15
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
16
|
+
import dayjs from 'dayjs';
|
|
17
|
+
import CustomDatePicker from '@/views/custom-components/CustomDatePicker';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* InputFieldComponent for handling various input types dynamically.
|
|
21
|
+
*
|
|
22
|
+
* This component manages different types of inputs such as date, month,
|
|
23
|
+
* selectize, and handles validations, state changes, and default values.
|
|
24
|
+
*
|
|
25
|
+
* @module InputFieldComponent
|
|
26
|
+
* @param {Object} props - The component props.
|
|
27
|
+
* @param {Object} props.config - Configuration object for the component.
|
|
28
|
+
* @param {Object} props.data - Current data state to be updated.
|
|
29
|
+
* @param {Function} props.setData - Function to update the data state.
|
|
30
|
+
* @param {Function} props.fieldChangeCallback - Callback function for field changes.
|
|
31
|
+
* @param {Function} props.fieldSelectizeCallback - Callback for selectize field changes.
|
|
32
|
+
* @param {boolean} [props.setDefaultValue=false] - Flag to set default values.
|
|
33
|
+
* @param {Function} props.locationChange - Callback for location changes.
|
|
34
|
+
* @param {Object} props.control - Control object for managing input states.
|
|
35
|
+
* @param {Object} props.errors - Error object for field validations.
|
|
36
|
+
*
|
|
37
|
+
* @returns {JSX.Element} The rendered component.
|
|
38
|
+
*/
|
|
39
|
+
export const InputFieldComponent = ({
|
|
40
|
+
config,
|
|
41
|
+
data,
|
|
42
|
+
setData,
|
|
43
|
+
fieldChangeCallback,
|
|
44
|
+
fieldSelectizeCallback,
|
|
45
|
+
setDefaultValue = false,
|
|
46
|
+
locationChange,
|
|
47
|
+
control,
|
|
48
|
+
errors,
|
|
49
|
+
dataTestId,
|
|
50
|
+
locations,
|
|
51
|
+
setLocations,
|
|
52
|
+
uiLocationId,
|
|
53
|
+
changedUsingUi,
|
|
54
|
+
setFetchUptoLevelLimit,
|
|
55
|
+
|
|
56
|
+
selectedLocation,
|
|
57
|
+
setSelectedLocation,
|
|
58
|
+
setUiLocations = () => { },
|
|
59
|
+
setUiSelectedLocation = () => { },
|
|
60
|
+
allDistrictReq,
|
|
61
|
+
setAllDistrictReq,
|
|
62
|
+
allBlockReq,
|
|
63
|
+
setAllBlockReq,
|
|
64
|
+
allPhcReq,
|
|
65
|
+
setAllPhcReq,
|
|
66
|
+
clearPreviousLocation,
|
|
67
|
+
triggerFirstRun,
|
|
68
|
+
locationPartSelected,
|
|
69
|
+
}) => {
|
|
70
|
+
// const [selectedLocation, setSelectedLocation] = useState(config?.selectedLocation ? config?.selectedLocation : {});
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (selectedLocation?.finalSelected && config?.fieldType === 'location') {
|
|
73
|
+
locationChange(config.fieldName, selectedLocation);
|
|
74
|
+
}
|
|
75
|
+
}, [selectedLocation]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (config?.selectedLocation && Object.keys(config.selectedLocation).length > 0) {
|
|
78
|
+
setSelectedLocation(config.selectedLocation);
|
|
79
|
+
}
|
|
80
|
+
}, [config.selectedLocation]);
|
|
81
|
+
useEffect(() => { }, [locations]);
|
|
82
|
+
useEffect(() => { }, [locations]);
|
|
83
|
+
|
|
84
|
+
const [selectizeForComboOptions, setSelectizeForComboOptions] = useState([]);
|
|
85
|
+
const [selectedSelectizeForCombo, setSelectedSelectizeForCombo] = useState(null);
|
|
86
|
+
const [selectizeForMultiOptions, setSelectizeForMultiOptions] = useState([]);
|
|
87
|
+
const [selectedSelectizeForMulti, setSelectedSelectizeForMulti] = useState(null);
|
|
88
|
+
|
|
89
|
+
const [onlyMonthFrom, setOnlyMonthFrom] = useState('');
|
|
90
|
+
const [onlyMonthTo, setOnlyMonthTo] = useState('');
|
|
91
|
+
const [dateFrom, setDateFrom] = useState('');
|
|
92
|
+
const [dateTo, setDateTo] = useState('');
|
|
93
|
+
|
|
94
|
+
const [minDate, setMinDate] = useState(null);
|
|
95
|
+
const [maxDate, setMaxDate] = useState(null);
|
|
96
|
+
const [fixedMinDate, setfixedMinDate] = useState(null);
|
|
97
|
+
const [fixedMaxDate, setfixedMaxDate] = useState(null);
|
|
98
|
+
const [minDateSelected, setMinDateSelected] = useState(false);
|
|
99
|
+
const [maxDateSelected, setMaxDateSelected] = useState(false);
|
|
100
|
+
|
|
101
|
+
const [minMonth, setMinMonth] = useState(null);
|
|
102
|
+
const [maxMonth, setMaxMonth] = useState(null);
|
|
103
|
+
const [fixedMinMonth, setfixedMinMonth] = useState(null);
|
|
104
|
+
const [fixedMaxMonth, setfixedMaxMonth] = useState(null);
|
|
105
|
+
|
|
106
|
+
const [mergedObj, setMergedObj] = useState({});
|
|
107
|
+
const [isDisabledFromConfiguration, setIsDisabledFromConfiguration] = useState(false);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Handles the field value change.
|
|
111
|
+
*
|
|
112
|
+
* @function fieldValueChanged
|
|
113
|
+
* @param {string} fieldName - The name of the field.
|
|
114
|
+
* @param {any} fieldValue - The new value of the field.
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (triggerFirstRun > 0) {
|
|
120
|
+
setMinDateSelected(false);
|
|
121
|
+
setMaxDateSelected(false);
|
|
122
|
+
setMinDate(null);
|
|
123
|
+
setMaxDate(null);
|
|
124
|
+
setMinMonth(null);
|
|
125
|
+
setMaxMonth(null);
|
|
126
|
+
setSelectedSelectizeForCombo(null);
|
|
127
|
+
setSelectedSelectizeForMulti(null);
|
|
128
|
+
}
|
|
129
|
+
}, [triggerFirstRun]);
|
|
130
|
+
|
|
131
|
+
const fieldValueChanged = (fieldName, fieldValue) => {
|
|
132
|
+
if (config.fieldChangeCallback) {
|
|
133
|
+
fieldChangeCallback(fieldName, fieldValue);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Normalizes a given date to remove time information.
|
|
139
|
+
*
|
|
140
|
+
* @function normalizeDate
|
|
141
|
+
* @param {Date|string} date - The date to normalize.
|
|
142
|
+
* @returns {Date} The normalized date.
|
|
143
|
+
*/
|
|
144
|
+
function normalizeDate(date) {
|
|
145
|
+
const normalizedDate = new Date(date);
|
|
146
|
+
normalizedDate.setHours(0, 0, 0, 0); // Set time to 00:00:00
|
|
147
|
+
return normalizedDate;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Validates and sets the minimum date value.
|
|
152
|
+
*
|
|
153
|
+
* @function minDateFieldValidation
|
|
154
|
+
* @param {string} fieldName - The name of the field.
|
|
155
|
+
* @param {any} fieldValue - The new value for the field.
|
|
156
|
+
*/
|
|
157
|
+
const minDateFieldValidation = (fieldName, fieldValue) => {
|
|
158
|
+
if (fieldValue) {
|
|
159
|
+
setMinDateSelected(true);
|
|
160
|
+
setMinDate(normalizeDate(fieldValue));
|
|
161
|
+
|
|
162
|
+
const dateObject = normalizeDate(fieldValue);
|
|
163
|
+
const updatedData = { ...data };
|
|
164
|
+
updatedData[fieldName] = dateObject;
|
|
165
|
+
|
|
166
|
+
updatedData[`${dateFrom}_1`] = fieldValue;
|
|
167
|
+
updatedData[dateFrom] = dateObject;
|
|
168
|
+
setData(updatedData);
|
|
169
|
+
fieldValueChanged(fieldName, dateObject.toString());
|
|
170
|
+
} else {
|
|
171
|
+
setMinDate(null);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Validates and sets the maximum date value.
|
|
177
|
+
*
|
|
178
|
+
* @function maxDateFieldValidation
|
|
179
|
+
* @param {string} fieldName - The name of the field.
|
|
180
|
+
* @param {any} fieldValue - The new value for the field.
|
|
181
|
+
*/
|
|
182
|
+
const maxDateFieldValidation = (fieldName, fieldValue) => {
|
|
183
|
+
if (fieldValue) {
|
|
184
|
+
setMaxDateSelected(true);
|
|
185
|
+
|
|
186
|
+
setMaxDate(normalizeDate(fieldValue));
|
|
187
|
+
|
|
188
|
+
const dateObject = normalizeDate(fieldValue);
|
|
189
|
+
const updatedData = { ...data };
|
|
190
|
+
updatedData[fieldName] = dateObject;
|
|
191
|
+
updatedData[`${dateTo}_1`] = fieldValue;
|
|
192
|
+
updatedData[dateTo] = dateObject;
|
|
193
|
+
setData(updatedData);
|
|
194
|
+
fieldValueChanged(fieldName, dateObject.toString());
|
|
195
|
+
} else {
|
|
196
|
+
setMaxDate(null);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Validates and sets the minimum month value.
|
|
202
|
+
*
|
|
203
|
+
* @function minMonthFieldValidation
|
|
204
|
+
* @param {string} fieldName - The name of the field.
|
|
205
|
+
* @param {any} fieldValue - The new value for the field.
|
|
206
|
+
*/
|
|
207
|
+
const minMonthFieldValidation = (fieldName, fieldValue) => {
|
|
208
|
+
if (fieldValue) {
|
|
209
|
+
const [year, month] = fieldValue.format('YYYY-MM').split('-');
|
|
210
|
+
const dateObject = new Date(year, month - 1, 1);
|
|
211
|
+
const updatedData = { ...data };
|
|
212
|
+
updatedData[fieldName] = dateObject;
|
|
213
|
+
updatedData[onlyMonthFrom] = dateObject;
|
|
214
|
+
updatedData[`${onlyMonthFrom}_1`] = fieldValue;
|
|
215
|
+
setMinMonth(normalizeDate(fieldValue));
|
|
216
|
+
setData(updatedData);
|
|
217
|
+
fieldValueChanged(fieldName, dateObject.toString());
|
|
218
|
+
} else {
|
|
219
|
+
setMinMonth(null);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Validates and sets the maximum month value.
|
|
225
|
+
*
|
|
226
|
+
* @function maxMonthFieldValidation
|
|
227
|
+
* @param {string} fieldName - The name of the field.
|
|
228
|
+
* @param {any} fieldValue - The new value for the field.
|
|
229
|
+
*/
|
|
230
|
+
const maxMonthFieldValidation = (fieldName, fieldValue) => {
|
|
231
|
+
if (fieldValue) {
|
|
232
|
+
const [year, month] = fieldValue.format('YYYY-MM').split('-');
|
|
233
|
+
const dateObject = new Date(year, month - 1, 1);
|
|
234
|
+
setMaxMonth(new Date(fieldValue));
|
|
235
|
+
const updatedData = { ...data };
|
|
236
|
+
updatedData[onlyMonthTo] = dateObject;
|
|
237
|
+
updatedData[fieldName] = dateObject;
|
|
238
|
+
updatedData[`${onlyMonthTo}_1`] = fieldValue;
|
|
239
|
+
setData(updatedData);
|
|
240
|
+
fieldValueChanged(fieldName, dateObject.toString());
|
|
241
|
+
} else {
|
|
242
|
+
setMaxMonth(null);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Checks the configuration to determine if the field should be disabled.
|
|
248
|
+
*
|
|
249
|
+
* @function checkDisableFromConfig
|
|
250
|
+
*/
|
|
251
|
+
const checkDisableFromConfig = () => {
|
|
252
|
+
const equals = config.configJson?.disabledWhenStatusEqual?.includes(data?.status);
|
|
253
|
+
const notequals = config.configJson?.disabledWhenStatusNotEqual?.includes(data?.status);
|
|
254
|
+
|
|
255
|
+
if (equals || notequals) {
|
|
256
|
+
setIsDisabledFromConfiguration(true);
|
|
257
|
+
} else {
|
|
258
|
+
setIsDisabledFromConfiguration(false);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Merges multiple objects into a target object.
|
|
264
|
+
*
|
|
265
|
+
* @function mergeObjects
|
|
266
|
+
* @param {Object} target - The target object to merge into.
|
|
267
|
+
* @param {...Object} sources - The source objects to merge.
|
|
268
|
+
* @returns {Object} The merged object.
|
|
269
|
+
*/
|
|
270
|
+
const mergeObjects = (target, ...sources) => {
|
|
271
|
+
sources.forEach((source) => {
|
|
272
|
+
if (source) {
|
|
273
|
+
Object.assign(target, source);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
return target;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Sets default values for fields based on the configuration.
|
|
281
|
+
*
|
|
282
|
+
* @function setDefault
|
|
283
|
+
*/
|
|
284
|
+
const setDefault = () => {
|
|
285
|
+
const fieldName = config?.resourceCategoryItemFieldDto?.fieldName;
|
|
286
|
+
const defaultValueConfig = config?.configJson?.defaultValue;
|
|
287
|
+
const fieldType = config?.resourceCategoryItemFieldDto?.fieldType;
|
|
288
|
+
if (!data[fieldName] && defaultValueConfig) {
|
|
289
|
+
let defaultValue;
|
|
290
|
+
switch (fieldType) {
|
|
291
|
+
case 'text':
|
|
292
|
+
case 'number':
|
|
293
|
+
case 'currency':
|
|
294
|
+
defaultValue = defaultValueConfig;
|
|
295
|
+
break;
|
|
296
|
+
case 'combo':
|
|
297
|
+
case 'multiselect':
|
|
298
|
+
case 'autocomplete':
|
|
299
|
+
defaultValue = config?.resourceCategoryItemFieldDto?.resourceCategoryItemFieldOptionList?.find(
|
|
300
|
+
(option) => option.id === defaultValueConfig
|
|
301
|
+
);
|
|
302
|
+
break;
|
|
303
|
+
case 'date':
|
|
304
|
+
if (defaultValueConfig?.isToday) {
|
|
305
|
+
defaultValue = new Date(); // Assuming today's date
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
308
|
+
default:
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
if (defaultValue) {
|
|
312
|
+
data({ ...data, [fieldName]: defaultValue });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Handles changes in data and performs necessary validations and updates.
|
|
319
|
+
*
|
|
320
|
+
* @function handleDataChange
|
|
321
|
+
*/
|
|
322
|
+
const handleDataChange = () => {
|
|
323
|
+
if (data?.isRetrieved) {
|
|
324
|
+
checkDisableFromConfig(); // Call the function to check if it should be disabled
|
|
325
|
+
|
|
326
|
+
if (config?.resourceCategoryItemFieldDto?.fieldType === 'person') {
|
|
327
|
+
const fieldValue = data[config?.resourceCategoryItemFieldDto?.fieldName];
|
|
328
|
+
|
|
329
|
+
if (fieldValue?.isOrg) {
|
|
330
|
+
if (data?.address) {
|
|
331
|
+
data.address.isDisabled = true;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
if (config?.fieldName) {
|
|
340
|
+
setOnlyMonthFrom('from_' + config.fieldName);
|
|
341
|
+
setOnlyMonthTo('to_' + config.fieldName);
|
|
342
|
+
setDateFrom('from_' + config.fieldName);
|
|
343
|
+
setDateTo('to_' + config.fieldName);
|
|
344
|
+
}
|
|
345
|
+
let merged = mergedObj;
|
|
346
|
+
if (config?.resourceCategoryItemFieldDto) {
|
|
347
|
+
merged = mergeObjects(merged, config.resourceCategoryItemFieldDto);
|
|
348
|
+
if (merged.configJson) {
|
|
349
|
+
merged = mergeObjects(merged, merged.configJson);
|
|
350
|
+
}
|
|
351
|
+
if (config.configJson) {
|
|
352
|
+
merged = mergeObjects(merged, config.configJson);
|
|
353
|
+
}
|
|
354
|
+
setMergedObj(merged);
|
|
355
|
+
}
|
|
356
|
+
if (config?.configJson?.isFormula) {
|
|
357
|
+
let formula = config.configJson.formula;
|
|
358
|
+
if (config.configJson?.formulaFieldsMap) {
|
|
359
|
+
Object.keys(config.configJson.formulaFieldsMap).forEach((fieldVariable) => {
|
|
360
|
+
const fieldName = config.configJson.formulaFieldsMap[fieldVariable];
|
|
361
|
+
const fieldValue = data[fieldName];
|
|
362
|
+
if (fieldValue) {
|
|
363
|
+
const value = fieldValue instanceof Date ? fieldValue.getTime() : fieldValue;
|
|
364
|
+
formula = formula.replace(new RegExp(fieldVariable, 'g'), value);
|
|
365
|
+
} else {
|
|
366
|
+
formula = null;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
try {
|
|
371
|
+
const calculatedValue = Function('"use strict";return (' + formula + ')')();
|
|
372
|
+
data[config.resourceCategoryItemFieldDto.fieldName] = calculatedValue;
|
|
373
|
+
} catch (error) {
|
|
374
|
+
console.error(error);
|
|
375
|
+
data[config.resourceCategoryItemFieldDto.fieldName] = 0;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (setDefaultValue) {
|
|
381
|
+
setDefault();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (config.fieldType === 'selectizeForCombo') {
|
|
385
|
+
handleSelectizeInputChange(config.fieldType, '');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (config.fieldType === 'selectizeForMulti') {
|
|
389
|
+
handleSelectizeInputChange(config.fieldType, '');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
handleDataChange();
|
|
393
|
+
|
|
394
|
+
if (config.ckSetCustomMinMonth && (config.setCustomMinMonth || config.setCustomMinMonth === 0)) {
|
|
395
|
+
setfixedMinMonth(new Date().setMonth(new Date().getMonth() + Number(config.setCustomMinMonth)));
|
|
396
|
+
}
|
|
397
|
+
if (config.ckSetCustomMaxMonth && (config.setCustomMaxMonth || config.setCustomMaxMonth === 0)) {
|
|
398
|
+
setfixedMaxMonth(new Date().setMonth(new Date().getMonth() + Number(config.setCustomMaxMonth)));
|
|
399
|
+
}
|
|
400
|
+
if (config.ckSetFixedMinMonth && config.setFixedMinMonth) {
|
|
401
|
+
setfixedMinMonth(new Date(config.setFixedMinMonth).getTime());
|
|
402
|
+
}
|
|
403
|
+
if (config.ckSetFixedMaxMonth && config.setFixedMaxMonth) {
|
|
404
|
+
setfixedMaxMonth(new Date(config.setFixedMaxMonth).getTime());
|
|
405
|
+
}
|
|
406
|
+
if (config.setMonthRange) {
|
|
407
|
+
setfixedMinMonth(new Date().setMonth(new Date().getMonth() - Number(config.setMonthRange)));
|
|
408
|
+
setfixedMaxMonth(new Date().getTime());
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (config.setDateRange) {
|
|
412
|
+
setfixedMinDate(new Date(new Date().setDate(new Date().getDate() - Number(config.setDateRange))));
|
|
413
|
+
setfixedMaxDate(new Date());
|
|
414
|
+
}
|
|
415
|
+
if (config.ckSetCustomMinDate && (config.setCustomMinDate || config.setCustomMinDate === 0)) {
|
|
416
|
+
setfixedMinDate(new Date(new Date().setDate(new Date().getDate() + Number(config.setCustomMinDate))));
|
|
417
|
+
}
|
|
418
|
+
if (config.ckSetCustomMaxDate && (config.setCustomMaxDate || config.setCustomMaxDate === 0)) {
|
|
419
|
+
setfixedMaxDate(new Date(new Date().setDate(new Date().getDate() + Number(config.setCustomMaxDate))));
|
|
420
|
+
}
|
|
421
|
+
if (config.ckSetFixedMinDate && config.setFixedMinDate) {
|
|
422
|
+
setfixedMinDate(new Date(config.setFixedMinDate));
|
|
423
|
+
}
|
|
424
|
+
if (config.ckSetFixedMaxDate && config.setFixedMaxDate) {
|
|
425
|
+
setfixedMaxDate(new Date(config.setFixedMaxDate));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// if (config.isSetDefault && config.isSetDefault === true) {
|
|
429
|
+
switch (config.fieldType) {
|
|
430
|
+
case 'dateFromTo':
|
|
431
|
+
handleDateFromTo(config);
|
|
432
|
+
break;
|
|
433
|
+
case 'date':
|
|
434
|
+
handleDate(config);
|
|
435
|
+
break;
|
|
436
|
+
case 'onlyMonthFromTo':
|
|
437
|
+
handleOnlyMonthFromTo(config);
|
|
438
|
+
break;
|
|
439
|
+
case 'onlyMonth':
|
|
440
|
+
handleOnlyMonth(config);
|
|
441
|
+
break;
|
|
442
|
+
case 'dateNTime':
|
|
443
|
+
handleDateNTime(config);
|
|
444
|
+
break;
|
|
445
|
+
default:
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
// }
|
|
449
|
+
}, [config, data, dateFrom, dateTo, onlyMonthFrom, onlyMonthTo]);
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Handles setting default values for date range fields.
|
|
453
|
+
*
|
|
454
|
+
* @function handleDateFromTo
|
|
455
|
+
* @param {Object} config - The configuration object for the field.
|
|
456
|
+
*/
|
|
457
|
+
const handleDateFromTo = (config) => {
|
|
458
|
+
let updatedData = { ...data };
|
|
459
|
+
|
|
460
|
+
if (!data[dateFrom] && !data[dateTo]) {
|
|
461
|
+
if (config.isSetDefault && config.isSetDefault === true) {
|
|
462
|
+
switch (config.defaultValueOption) {
|
|
463
|
+
case 'yesterday&lastndays':
|
|
464
|
+
updatedData = {
|
|
465
|
+
...updatedData,
|
|
466
|
+
[dateTo]: new Date(new Date().setDate(new Date().getDate() - 1)),
|
|
467
|
+
[dateFrom]: new Date(new Date().setDate(new Date().getDate() - (config.setLastNdays + 1))),
|
|
468
|
+
[`${dateTo}_1`]: new Date(new Date().setDate(new Date().getDate() - 1)),
|
|
469
|
+
[`${dateFrom}_1`]: new Date(new Date().setDate(new Date().getDate() - (config.setLastNdays + 1))),
|
|
470
|
+
};
|
|
471
|
+
setMinDate(updatedData[dateFrom]);
|
|
472
|
+
setMaxDate(updatedData[dateTo]);
|
|
473
|
+
break;
|
|
474
|
+
|
|
475
|
+
case 'today&yesterday':
|
|
476
|
+
updatedData = {
|
|
477
|
+
...updatedData,
|
|
478
|
+
[dateTo]: new Date(new Date().setDate(new Date().getDate())),
|
|
479
|
+
[dateFrom]: new Date(new Date().setDate(new Date().getDate() - 1)),
|
|
480
|
+
[`${dateTo}_1`]: new Date(new Date().setDate(new Date().getDate())),
|
|
481
|
+
[`${dateFrom}_1`]: new Date(new Date().setDate(new Date().getDate() - 1)),
|
|
482
|
+
};
|
|
483
|
+
setMinDate(updatedData[dateFrom]);
|
|
484
|
+
setMaxDate(updatedData[dateTo]);
|
|
485
|
+
break;
|
|
486
|
+
|
|
487
|
+
case 'today&lastndays':
|
|
488
|
+
updatedData = {
|
|
489
|
+
...updatedData,
|
|
490
|
+
[dateTo]: new Date(new Date().setDate(new Date().getDate())),
|
|
491
|
+
[dateFrom]: new Date(new Date().setDate(new Date().getDate() - config.setLastNdays)),
|
|
492
|
+
[`${dateTo}_1`]: new Date(new Date().setDate(new Date().getDate())),
|
|
493
|
+
[`${dateFrom}_1`]: new Date(new Date().setDate(new Date().getDate() - (config.setLastNdays + 1))),
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
setMinDate(updatedData[dateFrom]);
|
|
497
|
+
setMaxDate(updatedData[dateTo]);
|
|
498
|
+
break;
|
|
499
|
+
|
|
500
|
+
default:
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
setData(updatedData);
|
|
504
|
+
}
|
|
505
|
+
} else {
|
|
506
|
+
if (data[dateFrom]) {
|
|
507
|
+
setMinDate(new Date(data[dateFrom]));
|
|
508
|
+
}
|
|
509
|
+
if (data[dateTo]) {
|
|
510
|
+
setMaxDate(new Date(data[dateTo]));
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Handles setting default values for a single date field.
|
|
517
|
+
*
|
|
518
|
+
* @function handleDate
|
|
519
|
+
* @param {Object} config - The configuration object for the field.
|
|
520
|
+
*/
|
|
521
|
+
const handleDate = (config) => {
|
|
522
|
+
let updatedData = { ...data };
|
|
523
|
+
if (!data[config.fieldName]) {
|
|
524
|
+
if (config.isSetDefault && config.isSetDefault === true) {
|
|
525
|
+
switch (config.defaultValueOption) {
|
|
526
|
+
case 'today':
|
|
527
|
+
updatedData = {
|
|
528
|
+
...updatedData,
|
|
529
|
+
[config.fieldName]: new Date(),
|
|
530
|
+
[`${config.fieldName}_1`]: new Date(),
|
|
531
|
+
};
|
|
532
|
+
break;
|
|
533
|
+
case 'yesterday':
|
|
534
|
+
updatedData = {
|
|
535
|
+
...updatedData,
|
|
536
|
+
[config.fieldName]: new Date(new Date().setDate(new Date().getDate() - 1)),
|
|
537
|
+
[`${config.fieldName}_1`]: new Date(new Date().setDate(new Date().getDate() - 1)),
|
|
538
|
+
};
|
|
539
|
+
break;
|
|
540
|
+
case 'lastndays':
|
|
541
|
+
updatedData = {
|
|
542
|
+
...updatedData,
|
|
543
|
+
[config.fieldName]: new Date(new Date().setDate(new Date().getDate() - config.setLastNdays)),
|
|
544
|
+
[`${config.fieldName}_1`]: new Date(new Date().setDate(new Date().getDate() - config.setLastNdays)),
|
|
545
|
+
};
|
|
546
|
+
break;
|
|
547
|
+
default:
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
setData(updatedData);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// Update data directly
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Handles setting default values for month range fields.
|
|
559
|
+
*
|
|
560
|
+
* @function handleOnlyMonthFromTo
|
|
561
|
+
* @param {Object} config - The configuration object for the field.
|
|
562
|
+
*/
|
|
563
|
+
const handleOnlyMonthFromTo = (config) => {
|
|
564
|
+
let updatedData = { ...data };
|
|
565
|
+
if (!data[onlyMonthFrom] && !data[onlyMonthTo]) {
|
|
566
|
+
if (config.isSetDefault && config.isSetDefault === true) {
|
|
567
|
+
switch (config.defaultValueOption) {
|
|
568
|
+
case 'currentmonth&lastmonth':
|
|
569
|
+
updatedData = {
|
|
570
|
+
...updatedData,
|
|
571
|
+
[onlyMonthFrom]: new Date(new Date().setMonth(new Date().getMonth() - 1, 1)), // Start of last month
|
|
572
|
+
[onlyMonthTo]: new Date(new Date().setMonth(new Date().getMonth(), 1)), // Start of current month
|
|
573
|
+
[`${onlyMonthFrom}_1`]: new Date(new Date().setMonth(new Date().getMonth() - 1, 1)), // Start of last month
|
|
574
|
+
[`${onlyMonthTo}_1`]: new Date(new Date().setMonth(new Date().getMonth(), 1)),
|
|
575
|
+
};
|
|
576
|
+
setMinMonth(updatedData[onlyMonthFrom]);
|
|
577
|
+
setMaxMonth(updatedData[onlyMonthTo]);
|
|
578
|
+
break;
|
|
579
|
+
|
|
580
|
+
case 'current&lastnmonth':
|
|
581
|
+
updatedData = {
|
|
582
|
+
...updatedData,
|
|
583
|
+
[onlyMonthFrom]: new Date(new Date().setMonth(new Date().getMonth() - config.setLastNmonths, 1)), // Start of last N months
|
|
584
|
+
[onlyMonthTo]: new Date(new Date().setMonth(new Date().getMonth(), 1)), // Start of current month
|
|
585
|
+
[`${onlyMonthFrom}_1`]: new Date(new Date().setMonth(new Date().getMonth() - config.setLastNmonths, 1)), // Start of last month
|
|
586
|
+
[`${onlyMonthTo}_1`]: new Date(new Date().setMonth(new Date().getMonth(), 1)),
|
|
587
|
+
};
|
|
588
|
+
setMinMonth(updatedData[onlyMonthFrom]);
|
|
589
|
+
setMaxMonth(updatedData[onlyMonthTo]);
|
|
590
|
+
break;
|
|
591
|
+
|
|
592
|
+
default:
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
setData(updatedData);
|
|
596
|
+
}
|
|
597
|
+
} else {
|
|
598
|
+
if (data[onlyMonthFrom]) {
|
|
599
|
+
setMinMonth(new Date(data[onlyMonthFrom]));
|
|
600
|
+
}
|
|
601
|
+
if (data[onlyMonthTo]) {
|
|
602
|
+
setMaxMonth(new Date(data[onlyMonthTo]));
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
/**
|
|
607
|
+
* Handles setting default values for a single month field.
|
|
608
|
+
*
|
|
609
|
+
* @function handleOnlyMonth
|
|
610
|
+
* @param {Object} config - The configuration object for the field.
|
|
611
|
+
*/
|
|
612
|
+
const handleOnlyMonth = (config) => {
|
|
613
|
+
let updatedData = { ...data };
|
|
614
|
+
if (!data[config.fieldName]) {
|
|
615
|
+
if (config.isSetDefault && config.isSetDefault === true) {
|
|
616
|
+
switch (config.defaultValueOption) {
|
|
617
|
+
case 'currentmonth':
|
|
618
|
+
updatedData = {
|
|
619
|
+
...updatedData,
|
|
620
|
+
[config.fieldName]: new Date(new Date().setMonth(new Date().getMonth(), 1)),
|
|
621
|
+
[`${config.fieldName}_1`]: new Date(new Date().setMonth(new Date().getMonth(), 1)),
|
|
622
|
+
};
|
|
623
|
+
break;
|
|
624
|
+
|
|
625
|
+
case 'lastmonth':
|
|
626
|
+
updatedData = {
|
|
627
|
+
...updatedData,
|
|
628
|
+
[config.fieldName]: new Date(new Date().setMonth(new Date().getMonth() - 1, 1)),
|
|
629
|
+
[`${config.fieldName}_1`]: new Date(new Date().setMonth(new Date().getMonth() - 1, 1)),
|
|
630
|
+
};
|
|
631
|
+
break;
|
|
632
|
+
|
|
633
|
+
default:
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
setData(updatedData);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Handles setting default values for date and time fields.
|
|
643
|
+
*
|
|
644
|
+
* @function handleDateNTime
|
|
645
|
+
* @param {Object} config - The configuration object for the field.
|
|
646
|
+
*/
|
|
647
|
+
const handleDateNTime = (config) => {
|
|
648
|
+
let updatedData = { ...data };
|
|
649
|
+
|
|
650
|
+
if (!data[config.fieldName]) {
|
|
651
|
+
if (config.isSetDefault && config.isSetDefault === true) {
|
|
652
|
+
switch (config.defaultValueOption) {
|
|
653
|
+
case 'today':
|
|
654
|
+
updatedData = {
|
|
655
|
+
...updatedData,
|
|
656
|
+
[config.fieldName]: normalizeDate(new Date()), // Set today's date
|
|
657
|
+
};
|
|
658
|
+
break;
|
|
659
|
+
|
|
660
|
+
case 'yesterday':
|
|
661
|
+
updatedData = {
|
|
662
|
+
...updatedData,
|
|
663
|
+
[config.fieldName]: normalizeDate(new Date(new Date().setDate(new Date().getDate() - 1))), // Set yesterday's date
|
|
664
|
+
};
|
|
665
|
+
break;
|
|
666
|
+
|
|
667
|
+
case 'lastndays':
|
|
668
|
+
updatedData = {
|
|
669
|
+
...updatedData,
|
|
670
|
+
[config.fieldName]: normalizeDate(
|
|
671
|
+
new Date(new Date().setDate(new Date().getDate() - config.setLastNdays))
|
|
672
|
+
), // Set date n days ago
|
|
673
|
+
};
|
|
674
|
+
break;
|
|
675
|
+
|
|
676
|
+
default:
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
setData(updatedData);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Handles changes to a specific field's value.
|
|
686
|
+
*
|
|
687
|
+
* @function handleFieldChange
|
|
688
|
+
* @param {string} fieldName - The name of the field being updated.
|
|
689
|
+
* @param {*} value - The new value for the field.
|
|
690
|
+
*/
|
|
691
|
+
const handleFieldChange = (fieldName, value) => {
|
|
692
|
+
setData({ ...data, [fieldName]: value });
|
|
693
|
+
fieldChangeCallback(fieldName, value);
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const handleFieldChangeOnlyDate = (fieldName, value) => {
|
|
697
|
+
setData({ ...data, [fieldName]: new Date(value), [`${fieldName}_1`]: value });
|
|
698
|
+
fieldChangeCallback(fieldName, new Date(dayjs(value)));
|
|
699
|
+
};
|
|
700
|
+
const handleFieldChangeOnlyMonth = (fieldName, value) => {
|
|
701
|
+
setData({ ...data, [fieldName]: new Date(dayjs(value).startOf('month')), [`${fieldName}_1`]: value });
|
|
702
|
+
fieldChangeCallback(fieldName, new Date(dayjs(value).startOf('month')));
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Handles changes to date and time fields.
|
|
707
|
+
*
|
|
708
|
+
* @function handleDateNTimeChange
|
|
709
|
+
* @param {string} fieldName - The name of the field being updated.
|
|
710
|
+
* @param {Object} date - The date object representing the new date.
|
|
711
|
+
*/
|
|
712
|
+
const handleDateNTimeChange = (fieldName, date) => {
|
|
713
|
+
if (date?.$d) {
|
|
714
|
+
errors[config.fieldName] = null;
|
|
715
|
+
setData({ ...data, [fieldName]: date?.$d });
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
/**
|
|
719
|
+
* Handles input changes for selectize components.
|
|
720
|
+
*
|
|
721
|
+
* @function handleSelectizeInputChange
|
|
722
|
+
* @param {string} configType - The type of selectize input.
|
|
723
|
+
* @param {string} value - The new input value.
|
|
724
|
+
*/
|
|
725
|
+
const handleSelectizeInputChange = async (configType, value) => {
|
|
726
|
+
if (configType === 'selectizeForCombo') {
|
|
727
|
+
try {
|
|
728
|
+
const res = await fieldSelectizeCallback(config.fieldName, value);
|
|
729
|
+
|
|
730
|
+
setSelectizeForComboOptions(res);
|
|
731
|
+
} catch (error) {
|
|
732
|
+
console.error(error);
|
|
733
|
+
showToast({ message: `Errror in loading ${config.fieldName}`, type: 'error' });
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
if (configType === 'selectizeForMulti') {
|
|
737
|
+
try {
|
|
738
|
+
const res = fieldSelectizeCallback(config.fieldName, value);
|
|
739
|
+
setSelectizeForMultiOptions(res.data);
|
|
740
|
+
} catch (error) {
|
|
741
|
+
console.error(error);
|
|
742
|
+
showToast({ message: `Errror in loading ${config.fieldName}`, type: 'error' });
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Handles changes to selectize options.
|
|
749
|
+
*
|
|
750
|
+
* @function handleSelectizeChange
|
|
751
|
+
* @param {string} configType - The type of selectize input.
|
|
752
|
+
* @param {*} value - The new value for the selectize input.
|
|
753
|
+
*/
|
|
754
|
+
const handleSelectizeChange = (configType, value) => {
|
|
755
|
+
if (configType === 'selectizeForCombo') {
|
|
756
|
+
setSelectedSelectizeForCombo(value);
|
|
757
|
+
}
|
|
758
|
+
if (configType === 'selectizeForMulti') {
|
|
759
|
+
setSelectedSelectizeForMulti(value);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
handleFieldChange(config.fieldName, value?.value);
|
|
763
|
+
|
|
764
|
+
fieldValueChanged(config.fieldName, value?.value);
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
const renderInputField = () => {
|
|
768
|
+
switch (config.fieldType) {
|
|
769
|
+
case 'number':
|
|
770
|
+
return (
|
|
771
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
772
|
+
<label>
|
|
773
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
774
|
+
</label>
|
|
775
|
+
<CustomTextField
|
|
776
|
+
control={control}
|
|
777
|
+
id={config.fieldName}
|
|
778
|
+
name={config.fieldName}
|
|
779
|
+
type="number"
|
|
780
|
+
errors={errors}
|
|
781
|
+
onChange={(e) => {
|
|
782
|
+
handleFieldChange(config.fieldName, e.target.value);
|
|
783
|
+
}}
|
|
784
|
+
dataTestId={dataTestId}
|
|
785
|
+
label=""
|
|
786
|
+
size="small"
|
|
787
|
+
rules={{
|
|
788
|
+
required: {
|
|
789
|
+
value: config.isMandatory,
|
|
790
|
+
message: config.requiredMessage || `Enter the ${config.displayName}`,
|
|
791
|
+
},
|
|
792
|
+
minLength: {
|
|
793
|
+
value: config.minLength,
|
|
794
|
+
message: config.minLengthMessage || `Minimum length is ${config.minLength}`,
|
|
795
|
+
},
|
|
796
|
+
maxLength: {
|
|
797
|
+
value: config.maxLength,
|
|
798
|
+
message: config.maxLengthMessage || `Maximum length is ${config.maxLength}`,
|
|
799
|
+
},
|
|
800
|
+
validate: {
|
|
801
|
+
decimalAllowed: (value) => {
|
|
802
|
+
if (config.decimalAllowed) {
|
|
803
|
+
return /^-?\d*(\.\d+)?$/.test(value) || 'Invalid decimal number';
|
|
804
|
+
}
|
|
805
|
+
// Disallow decimals
|
|
806
|
+
if (value) {
|
|
807
|
+
return /^\d+$/.test(value) || 'Decimals are not allowed';
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
negativeAllowed: (value) => {
|
|
811
|
+
if (config.negativeAllowed) {
|
|
812
|
+
// Allow negative numbers
|
|
813
|
+
return /^-?\d*\.?\d*$/.test(value) || 'Invalid number format';
|
|
814
|
+
}
|
|
815
|
+
// Disallow negative numbers
|
|
816
|
+
return /^\d*\.?\d*$/.test(value) || 'Negative numbers are not allowed';
|
|
817
|
+
},
|
|
818
|
+
},
|
|
819
|
+
}}
|
|
820
|
+
/>
|
|
821
|
+
</FormControl>
|
|
822
|
+
);
|
|
823
|
+
|
|
824
|
+
case 'boolean':
|
|
825
|
+
return (
|
|
826
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
827
|
+
<label>
|
|
828
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
829
|
+
</label>
|
|
830
|
+
<Controller
|
|
831
|
+
name={config.fieldName}
|
|
832
|
+
control={control}
|
|
833
|
+
defaultValue=""
|
|
834
|
+
rules={{
|
|
835
|
+
validate: (value) => {
|
|
836
|
+
if (config.isMandatory && value == '') {
|
|
837
|
+
return `Please select ${config.fieldName}`;
|
|
838
|
+
}
|
|
839
|
+
return true;
|
|
840
|
+
},
|
|
841
|
+
}}
|
|
842
|
+
render={({ field }) => (
|
|
843
|
+
<Select
|
|
844
|
+
{...field}
|
|
845
|
+
size="small"
|
|
846
|
+
disabled={isDisabledFromConfiguration}
|
|
847
|
+
value={field.value || ''}
|
|
848
|
+
error={errors[config.fieldName]}
|
|
849
|
+
onChange={(e) => {
|
|
850
|
+
field.onChange(e.target.value);
|
|
851
|
+
handleFieldChange(config.fieldName, e.target.value);
|
|
852
|
+
}}
|
|
853
|
+
data-testid={dataTestId}
|
|
854
|
+
>
|
|
855
|
+
<MenuItem value="">Select</MenuItem>
|
|
856
|
+
<MenuItem value={config.yesValue || 'true'}>true</MenuItem>
|
|
857
|
+
<MenuItem value={config.noValue || 'false'}>false</MenuItem>
|
|
858
|
+
</Select>
|
|
859
|
+
)}
|
|
860
|
+
/>
|
|
861
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
862
|
+
</FormControl>
|
|
863
|
+
);
|
|
864
|
+
|
|
865
|
+
case 'comboForReport':
|
|
866
|
+
return (
|
|
867
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
868
|
+
<label>
|
|
869
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
870
|
+
</label>
|
|
871
|
+
<Controller
|
|
872
|
+
name={config.fieldName}
|
|
873
|
+
control={control}
|
|
874
|
+
defaultValue="" // Setting the default value
|
|
875
|
+
rules={{
|
|
876
|
+
required: {
|
|
877
|
+
value: config.isMandatory,
|
|
878
|
+
message: config.requiredMessage || `Please select ${config.displayName}`,
|
|
879
|
+
},
|
|
880
|
+
}}
|
|
881
|
+
render={({ field }) => (
|
|
882
|
+
<Select
|
|
883
|
+
{...field}
|
|
884
|
+
size="small"
|
|
885
|
+
disabled={isDisabledFromConfiguration}
|
|
886
|
+
className={config.inputClass}
|
|
887
|
+
value={field.value || ''}
|
|
888
|
+
onChange={(e) => {
|
|
889
|
+
field.onChange(e.target.value);
|
|
890
|
+
handleFieldChange(config.fieldName, e.target.value);
|
|
891
|
+
}}
|
|
892
|
+
data-testid={dataTestId}
|
|
893
|
+
>
|
|
894
|
+
{/* <MenuItem value="">Select</MenuItem> */}
|
|
895
|
+
{config?.optionsByQuery?.map((option) => (
|
|
896
|
+
<MenuItem key={option.key} value={option.key}>
|
|
897
|
+
{option.value}
|
|
898
|
+
</MenuItem>
|
|
899
|
+
))}
|
|
900
|
+
</Select>
|
|
901
|
+
)}
|
|
902
|
+
/>
|
|
903
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
904
|
+
</FormControl>
|
|
905
|
+
);
|
|
906
|
+
|
|
907
|
+
case 'multiselectForReport':
|
|
908
|
+
return (
|
|
909
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
910
|
+
<label>
|
|
911
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
912
|
+
</label>
|
|
913
|
+
<Controller
|
|
914
|
+
name={config.fieldName}
|
|
915
|
+
control={control}
|
|
916
|
+
defaultValue={[]} // Default as an empty array for multi-select
|
|
917
|
+
rules={{
|
|
918
|
+
required: {
|
|
919
|
+
value: config.isMandatory,
|
|
920
|
+
message: config.requiredMessage || `Please select ${config.displayName}`,
|
|
921
|
+
},
|
|
922
|
+
}}
|
|
923
|
+
render={({ field }) => (
|
|
924
|
+
<Select
|
|
925
|
+
{...field} // Integrating with react-hook-form
|
|
926
|
+
multiple // Enables multi-select
|
|
927
|
+
size="small"
|
|
928
|
+
disabled={isDisabledFromConfiguration}
|
|
929
|
+
className={config.inputClass}
|
|
930
|
+
value={field.value || []} // Ensure it's an array for multiple selections
|
|
931
|
+
onChange={(e) => {
|
|
932
|
+
field.onChange(e.target.value);
|
|
933
|
+
handleFieldChange(config.fieldName, e.target.value);
|
|
934
|
+
}}
|
|
935
|
+
renderValue={(selected) => selected.join(', ')} // Customize how selected items are displayed
|
|
936
|
+
data-testid={dataTestId}
|
|
937
|
+
>
|
|
938
|
+
{/* <MenuItem >Select</MenuItem> */}
|
|
939
|
+
{config?.optionsByQuery?.map((option) => (
|
|
940
|
+
<MenuItem key={option.key} value={option.key}>
|
|
941
|
+
{option.value}
|
|
942
|
+
</MenuItem>
|
|
943
|
+
))}
|
|
944
|
+
</Select>
|
|
945
|
+
)}
|
|
946
|
+
/>
|
|
947
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
948
|
+
</FormControl>
|
|
949
|
+
);
|
|
950
|
+
|
|
951
|
+
case 'date':
|
|
952
|
+
return (
|
|
953
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
954
|
+
<label>
|
|
955
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
956
|
+
</label>
|
|
957
|
+
<CustomDatePicker
|
|
958
|
+
control={control}
|
|
959
|
+
name={config.fieldName}
|
|
960
|
+
format="DD/MM/YYYY"
|
|
961
|
+
rules={{
|
|
962
|
+
required: {
|
|
963
|
+
value: config.isMandatory,
|
|
964
|
+
message: `Enter the ${config.displayName}`,
|
|
965
|
+
},
|
|
966
|
+
}}
|
|
967
|
+
onChange={(newValue) => {
|
|
968
|
+
handleFieldChangeOnlyDate(config.fieldName, newValue);
|
|
969
|
+
}}
|
|
970
|
+
errors={errors}
|
|
971
|
+
maxDate={fixedMaxDate ? dayjs(fixedMaxDate) : maxDate ? dayjs(maxDate) : null}
|
|
972
|
+
minDate={fixedMinDate ? dayjs(fixedMinDate) : minDate ? dayjs(minDate) : null}
|
|
973
|
+
dataTestId={dataTestId}
|
|
974
|
+
/>
|
|
975
|
+
</FormControl>
|
|
976
|
+
);
|
|
977
|
+
|
|
978
|
+
case 'dateFromTo':
|
|
979
|
+
return (
|
|
980
|
+
<FormGroup>
|
|
981
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
982
|
+
<label>
|
|
983
|
+
From {config.displayName}
|
|
984
|
+
{config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
985
|
+
</label>
|
|
986
|
+
<CustomDatePicker
|
|
987
|
+
control={control}
|
|
988
|
+
name={`from_${config.fieldName}`}
|
|
989
|
+
format="DD/MM/YYYY"
|
|
990
|
+
rules={{
|
|
991
|
+
required: {
|
|
992
|
+
value: config.isMandatory || maxDateSelected, // Required if mandatory or max date selected
|
|
993
|
+
message: `Enter from ${config.displayName}`, // Custom required message
|
|
994
|
+
},
|
|
995
|
+
}}
|
|
996
|
+
onChange={(newValue) => {
|
|
997
|
+
// const formattedDate = newValue ? dayjs(newValue).format('YYYY-MM-DD') : '';
|
|
998
|
+
minDateFieldValidation(config.fieldName, newValue); // pass dayjs object for validation
|
|
999
|
+
}}
|
|
1000
|
+
errors={errors}
|
|
1001
|
+
maxDate={
|
|
1002
|
+
fixedMaxDate
|
|
1003
|
+
? (() => {
|
|
1004
|
+
const maxDateValue = maxDate || fixedMaxDate;
|
|
1005
|
+
return dayjs(maxDateValue);
|
|
1006
|
+
})()
|
|
1007
|
+
: maxDate
|
|
1008
|
+
? dayjs(maxDate)
|
|
1009
|
+
: null
|
|
1010
|
+
}
|
|
1011
|
+
minDate={fixedMinDate ? dayjs(fixedMinDate) : null}
|
|
1012
|
+
dataTestId={dataTestId}
|
|
1013
|
+
/>
|
|
1014
|
+
</FormControl>
|
|
1015
|
+
|
|
1016
|
+
{/* To Date Field */}
|
|
1017
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1018
|
+
<label>
|
|
1019
|
+
To {config.displayName}
|
|
1020
|
+
{config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1021
|
+
</label>
|
|
1022
|
+
<CustomDatePicker
|
|
1023
|
+
control={control}
|
|
1024
|
+
name={`to_${config.fieldName}`}
|
|
1025
|
+
format="DD/MM/YYYY"
|
|
1026
|
+
rules={{
|
|
1027
|
+
required: {
|
|
1028
|
+
value: config.isMandatory || minDateSelected, // Required if mandatory or min date selected
|
|
1029
|
+
message: `Enter to ${config.displayName}`, // Custom required message
|
|
1030
|
+
},
|
|
1031
|
+
}}
|
|
1032
|
+
onChange={(newValue) => {
|
|
1033
|
+
maxDateFieldValidation(config.fieldName, newValue); // pass dayjs object for validation
|
|
1034
|
+
}}
|
|
1035
|
+
errors={errors}
|
|
1036
|
+
maxDate={fixedMaxDate ? dayjs(fixedMaxDate) : null}
|
|
1037
|
+
minDate={
|
|
1038
|
+
fixedMinDate
|
|
1039
|
+
? (() => {
|
|
1040
|
+
const minDateValue = minDate || fixedMinDate;
|
|
1041
|
+
return dayjs(minDateValue);
|
|
1042
|
+
})()
|
|
1043
|
+
: minDate
|
|
1044
|
+
? dayjs(minDate)
|
|
1045
|
+
: null
|
|
1046
|
+
}
|
|
1047
|
+
dataTestId={dataTestId}
|
|
1048
|
+
/>
|
|
1049
|
+
</FormControl>
|
|
1050
|
+
</FormGroup>
|
|
1051
|
+
);
|
|
1052
|
+
case 'onlyMonth':
|
|
1053
|
+
return (
|
|
1054
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1055
|
+
<label>
|
|
1056
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1057
|
+
</label>
|
|
1058
|
+
<CustomDatePicker
|
|
1059
|
+
control={control}
|
|
1060
|
+
name={config.fieldName}
|
|
1061
|
+
format="MM/YYYY"
|
|
1062
|
+
views={['month', 'year']}
|
|
1063
|
+
rules={{
|
|
1064
|
+
required: {
|
|
1065
|
+
value: config.isMandatory, // Make required based on the config or maxDateSelected
|
|
1066
|
+
message: `Enter from ${config.displayName}`, // Custom required message
|
|
1067
|
+
},
|
|
1068
|
+
}}
|
|
1069
|
+
onChange={(newValue) => {
|
|
1070
|
+
handleFieldChangeOnlyMonth(config.fieldName, newValue); // pass dayjs object for validation
|
|
1071
|
+
}}
|
|
1072
|
+
errors={errors}
|
|
1073
|
+
maxDate={fixedMaxMonth ? dayjs(fixedMaxMonth) : null}
|
|
1074
|
+
minDate={fixedMinMonth ? dayjs(fixedMinMonth) : null}
|
|
1075
|
+
dataTestId={dataTestId}
|
|
1076
|
+
/>
|
|
1077
|
+
</FormControl>
|
|
1078
|
+
);
|
|
1079
|
+
case 'onlyMonthFromTo':
|
|
1080
|
+
return (
|
|
1081
|
+
<FormGroup>
|
|
1082
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1083
|
+
<label>
|
|
1084
|
+
{config.displayName} From
|
|
1085
|
+
{config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1086
|
+
</label>
|
|
1087
|
+
<CustomDatePicker
|
|
1088
|
+
control={control}
|
|
1089
|
+
name={`from_${config.fieldName}`}
|
|
1090
|
+
format="YYYY/MM"
|
|
1091
|
+
openTo="month"
|
|
1092
|
+
views={['year', 'month']}
|
|
1093
|
+
rules={{
|
|
1094
|
+
required: {
|
|
1095
|
+
value: config.isMandatory, // Make required based on the config or maxDateSelected
|
|
1096
|
+
message: `Enter from ${config.displayName}`, // Custom required message
|
|
1097
|
+
},
|
|
1098
|
+
validate: (value) => {
|
|
1099
|
+
if (config.isMandatory && !value) {
|
|
1100
|
+
return `Please select a month for ${config.displayName} (From)`;
|
|
1101
|
+
}
|
|
1102
|
+
},
|
|
1103
|
+
}}
|
|
1104
|
+
onChange={(newValue) => {
|
|
1105
|
+
minMonthFieldValidation(config.fieldName, newValue); // pass dayjs object for validation
|
|
1106
|
+
}}
|
|
1107
|
+
errors={errors}
|
|
1108
|
+
maxDate={
|
|
1109
|
+
fixedMaxMonth
|
|
1110
|
+
? (() => {
|
|
1111
|
+
const maxMonthValue = maxMonth ? dayjs(maxMonth) : dayjs(fixedMaxMonth);
|
|
1112
|
+
return maxMonthValue;
|
|
1113
|
+
})()
|
|
1114
|
+
: maxMonth
|
|
1115
|
+
? dayjs(maxMonth)
|
|
1116
|
+
: null
|
|
1117
|
+
}
|
|
1118
|
+
minDate={fixedMinMonth ? dayjs(fixedMinMonth) : null}
|
|
1119
|
+
dataTestId={dataTestId}
|
|
1120
|
+
/>
|
|
1121
|
+
</FormControl>
|
|
1122
|
+
|
|
1123
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1124
|
+
<label>
|
|
1125
|
+
{config.displayName} To
|
|
1126
|
+
{config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1127
|
+
</label>
|
|
1128
|
+
<CustomDatePicker
|
|
1129
|
+
control={control}
|
|
1130
|
+
name={`to_${config.fieldName}`}
|
|
1131
|
+
format="YYYY/MM"
|
|
1132
|
+
openTo="month"
|
|
1133
|
+
views={['year', 'month']}
|
|
1134
|
+
rules={{
|
|
1135
|
+
required: {
|
|
1136
|
+
value: config.isMandatory, // Make required based on the config or minDateSelected
|
|
1137
|
+
message: `Enter to ${config.displayName}`, // Custom required message
|
|
1138
|
+
},
|
|
1139
|
+
}}
|
|
1140
|
+
onChange={(newValue) => {
|
|
1141
|
+
maxMonthFieldValidation(config.fieldName, newValue); // pass dayjs object for validation
|
|
1142
|
+
}}
|
|
1143
|
+
errors={errors}
|
|
1144
|
+
maxDate={fixedMaxMonth ? dayjs(fixedMaxMonth) : null}
|
|
1145
|
+
minDate={
|
|
1146
|
+
fixedMinMonth
|
|
1147
|
+
? (() => {
|
|
1148
|
+
const formattedMinMonth = minMonth ? dayjs(minMonth) : dayjs(fixedMinMonth);
|
|
1149
|
+
return formattedMinMonth;
|
|
1150
|
+
})()
|
|
1151
|
+
: minMonth
|
|
1152
|
+
? dayjs(minMonth)
|
|
1153
|
+
: null
|
|
1154
|
+
}
|
|
1155
|
+
dataTestId={dataTestId}
|
|
1156
|
+
/>
|
|
1157
|
+
</FormControl>
|
|
1158
|
+
</FormGroup>
|
|
1159
|
+
);
|
|
1160
|
+
|
|
1161
|
+
case 'email':
|
|
1162
|
+
return (
|
|
1163
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1164
|
+
<label>
|
|
1165
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1166
|
+
</label>
|
|
1167
|
+
<CustomTextField
|
|
1168
|
+
control={control}
|
|
1169
|
+
id={config.fieldName}
|
|
1170
|
+
name={config.fieldName}
|
|
1171
|
+
type="email" // Set type to 'email' for validation
|
|
1172
|
+
errors={errors}
|
|
1173
|
+
label=""
|
|
1174
|
+
onChange={(e) => {
|
|
1175
|
+
handleFieldChange(config.fieldName, e.target.value);
|
|
1176
|
+
}}
|
|
1177
|
+
size="small"
|
|
1178
|
+
rules={{
|
|
1179
|
+
required: {
|
|
1180
|
+
value: config.isMandatory,
|
|
1181
|
+
message: `Enter the ${config.displayName}`, // Custom required message
|
|
1182
|
+
},
|
|
1183
|
+
pattern: {
|
|
1184
|
+
value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, // Regular expression to validate email format
|
|
1185
|
+
message: 'Please enter a valid email address',
|
|
1186
|
+
},
|
|
1187
|
+
}}
|
|
1188
|
+
dataTestId={dataTestId}
|
|
1189
|
+
/>
|
|
1190
|
+
</FormControl>
|
|
1191
|
+
);
|
|
1192
|
+
|
|
1193
|
+
case 'selectizeForCombo':
|
|
1194
|
+
return (
|
|
1195
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1196
|
+
<label>
|
|
1197
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1198
|
+
</label>
|
|
1199
|
+
<Controller
|
|
1200
|
+
name={config.fieldName} // Adjust name to match your form field
|
|
1201
|
+
control={control}
|
|
1202
|
+
defaultValue="" // Default value
|
|
1203
|
+
rules={{
|
|
1204
|
+
required: {
|
|
1205
|
+
value: config.isMandatory,
|
|
1206
|
+
message: `Select the ${config.displayName}`,
|
|
1207
|
+
},
|
|
1208
|
+
}}
|
|
1209
|
+
render={({ field }) => (
|
|
1210
|
+
<Autocomplete
|
|
1211
|
+
{...field}
|
|
1212
|
+
options={selectizeForComboOptions || []}
|
|
1213
|
+
size="small"
|
|
1214
|
+
value={selectedSelectizeForCombo || field.value}
|
|
1215
|
+
getOptionLabel={(option) => option.value || ''}
|
|
1216
|
+
isOptionEqualToValue={(option, value) => option.key === value.key}
|
|
1217
|
+
renderInput={(params) => <TextField {...params} error={!!errors[config.fieldName]} />}
|
|
1218
|
+
onInputChange={(_, val) => handleSelectizeInputChange('selectizeForCombo', val)}
|
|
1219
|
+
onChange={(e, val) => {
|
|
1220
|
+
field.onChange(val);
|
|
1221
|
+
handleSelectizeChange('selectizeForCombo', val);
|
|
1222
|
+
}}
|
|
1223
|
+
data-testid={dataTestId}
|
|
1224
|
+
/>
|
|
1225
|
+
)}
|
|
1226
|
+
/>
|
|
1227
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
1228
|
+
</FormControl>
|
|
1229
|
+
);
|
|
1230
|
+
case 'selectizeForMulti':
|
|
1231
|
+
return (
|
|
1232
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1233
|
+
<label>
|
|
1234
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1235
|
+
</label>
|
|
1236
|
+
<Controller
|
|
1237
|
+
name={config.fieldName} // Adjust name to match your form field
|
|
1238
|
+
control={control}
|
|
1239
|
+
defaultValue="" // Default value
|
|
1240
|
+
rules={{
|
|
1241
|
+
required: {
|
|
1242
|
+
value: config.isMandatory,
|
|
1243
|
+
message: `Select the ${config.displayName}`,
|
|
1244
|
+
},
|
|
1245
|
+
}}
|
|
1246
|
+
render={({ field }) => (
|
|
1247
|
+
<Autocomplete
|
|
1248
|
+
{...field}
|
|
1249
|
+
options={selectizeForMultiOptions || []}
|
|
1250
|
+
size="small"
|
|
1251
|
+
value={selectedSelectizeForMulti || field.value}
|
|
1252
|
+
getOptionLabel={(option) => option.value || ''}
|
|
1253
|
+
isOptionEqualToValue={(option, value) => option.key === value.key}
|
|
1254
|
+
renderInput={(params) => <TextField {...params} error={!!errors[config.fieldName]} />}
|
|
1255
|
+
onInputChange={(_, val) => handleSelectizeInputChange('selectizeForMulti', val)}
|
|
1256
|
+
onChange={(e, val) => {
|
|
1257
|
+
field.onChange(val);
|
|
1258
|
+
handleSelectizeChange('selectizeForMulti', val);
|
|
1259
|
+
}}
|
|
1260
|
+
data-testid={dataTestId}
|
|
1261
|
+
/>
|
|
1262
|
+
)}
|
|
1263
|
+
/>
|
|
1264
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
1265
|
+
</FormControl>
|
|
1266
|
+
);
|
|
1267
|
+
|
|
1268
|
+
case 'location':
|
|
1269
|
+
return (
|
|
1270
|
+
<Suspense>
|
|
1271
|
+
<LocationSelectionComponent
|
|
1272
|
+
selectedLocation={config?.selectedLocation || selectedLocation}
|
|
1273
|
+
setSelectedLocation={setSelectedLocation}
|
|
1274
|
+
locations={locations}
|
|
1275
|
+
setLocations={setLocations}
|
|
1276
|
+
templateType="inline"
|
|
1277
|
+
fetchAccordingToUserAoi={config.fetchAccordingToUserAoi}
|
|
1278
|
+
demographicFilterRequired={config.demographicFilterRequired}
|
|
1279
|
+
requiredUptoLevel={config.requiredUptoLevel || 0}
|
|
1280
|
+
fetchUptoLevel={config.fetchUptoLevel}
|
|
1281
|
+
childForm={true}
|
|
1282
|
+
uiLocationId={uiLocationId}
|
|
1283
|
+
changedUsingUi={changedUsingUi}
|
|
1284
|
+
setFetchUptoLevelLimit={setFetchUptoLevelLimit}
|
|
1285
|
+
setUiLocations={setUiLocations}
|
|
1286
|
+
setUiSelectedLocation={setUiSelectedLocation}
|
|
1287
|
+
allDistrictReq={allDistrictReq}
|
|
1288
|
+
setAllDistrictReq={setAllDistrictReq}
|
|
1289
|
+
allBlockReq={allBlockReq}
|
|
1290
|
+
setAllBlockReq={setAllBlockReq}
|
|
1291
|
+
allPhcReq={allPhcReq}
|
|
1292
|
+
setAllPhcReq={setAllPhcReq}
|
|
1293
|
+
clearPreviousLocation={clearPreviousLocation}
|
|
1294
|
+
triggerFirstRun={triggerFirstRun}
|
|
1295
|
+
locationBreadCrumbSelected={locationPartSelected}
|
|
1296
|
+
multipleOnLevel={config.multipleOnLevel }
|
|
1297
|
+
/>
|
|
1298
|
+
</Suspense>
|
|
1299
|
+
);
|
|
1300
|
+
|
|
1301
|
+
case 'dateNTime':
|
|
1302
|
+
return (
|
|
1303
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1304
|
+
<label>
|
|
1305
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1306
|
+
</label>
|
|
1307
|
+
|
|
1308
|
+
<Controller
|
|
1309
|
+
name={config.fieldName}
|
|
1310
|
+
control={control}
|
|
1311
|
+
rules={{
|
|
1312
|
+
required: {
|
|
1313
|
+
value: config.isMandatory,
|
|
1314
|
+
message: config.requiredMessage || `Enter the ${config.displayName}`,
|
|
1315
|
+
},
|
|
1316
|
+
}}
|
|
1317
|
+
render={({ field, fieldState }) => (
|
|
1318
|
+
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
1319
|
+
<DateTimePicker
|
|
1320
|
+
sx={{ width: '100%' }}
|
|
1321
|
+
format="DD/MM/YYYY hh:mm A"
|
|
1322
|
+
maxDate={fixedMaxDate ? dayjs(fixedMaxDate) : null}
|
|
1323
|
+
minDate={fixedMinDate ? dayjs(fixedMinDate) : null}
|
|
1324
|
+
slotProps={{
|
|
1325
|
+
textField: {
|
|
1326
|
+
size: 'small',
|
|
1327
|
+
error: !!fieldState.error,
|
|
1328
|
+
inputProps: {
|
|
1329
|
+
'data-testid': `${dataTestId}`,
|
|
1330
|
+
},
|
|
1331
|
+
},
|
|
1332
|
+
}}
|
|
1333
|
+
{...field}
|
|
1334
|
+
onChange={(date) => {
|
|
1335
|
+
field.onChange(date);
|
|
1336
|
+
handleDateNTimeChange(config.fieldName, date); // Keep the value as a Dayjs object
|
|
1337
|
+
}}
|
|
1338
|
+
value={field.value ? dayjs(field.value) : null} // Ensure value is a Dayjs object or null
|
|
1339
|
+
// data-testid={dataTestId}
|
|
1340
|
+
/>
|
|
1341
|
+
</LocalizationProvider>
|
|
1342
|
+
)}
|
|
1343
|
+
/>
|
|
1344
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
1345
|
+
</FormControl>
|
|
1346
|
+
);
|
|
1347
|
+
case 'dateRangePicker':
|
|
1348
|
+
return (
|
|
1349
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1350
|
+
<label>
|
|
1351
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1352
|
+
</label>
|
|
1353
|
+
<Controller
|
|
1354
|
+
name={config.fieldName}
|
|
1355
|
+
control={control}
|
|
1356
|
+
defaultValue={{
|
|
1357
|
+
startDate: '',
|
|
1358
|
+
endDate: '',
|
|
1359
|
+
}}
|
|
1360
|
+
rules={{
|
|
1361
|
+
validate: (value) => {
|
|
1362
|
+
const { startDate, endDate } = value;
|
|
1363
|
+
const errors = {};
|
|
1364
|
+
|
|
1365
|
+
if (config.isMandatory && (!startDate || !endDate)) {
|
|
1366
|
+
return `Please select both start and end dates for ${config.displayName}`;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
return Object.keys(errors).length ? errors : true;
|
|
1370
|
+
},
|
|
1371
|
+
}}
|
|
1372
|
+
render={({ field, fieldState }) => (
|
|
1373
|
+
<Grid container spacing={1}>
|
|
1374
|
+
{/* Start Date Input */}
|
|
1375
|
+
<Grid item xs={12}>
|
|
1376
|
+
<TextField
|
|
1377
|
+
type="date"
|
|
1378
|
+
fullWidth
|
|
1379
|
+
size="small"
|
|
1380
|
+
disabled={isDisabledFromConfiguration}
|
|
1381
|
+
value={field.value.startDate || ''}
|
|
1382
|
+
onChange={(e) => {
|
|
1383
|
+
field.onChange({ ...field.value, startDate: e.target.value });
|
|
1384
|
+
setData({ ...data, [config.fieldName]: { ...field.value, startDate: e.target.value } });
|
|
1385
|
+
}}
|
|
1386
|
+
inputProps={{
|
|
1387
|
+
min: fixedMinDate ? dayjs(fixedMinDate).format('YYYY-MM-DD') : undefined,
|
|
1388
|
+
max:
|
|
1389
|
+
field.value.endDate || (fixedMaxDate ? dayjs(fixedMaxDate).format('YYYY-MM-DD') : undefined),
|
|
1390
|
+
}}
|
|
1391
|
+
data-testid={`${dataTestId}-from`}
|
|
1392
|
+
error={!!fieldState.error}
|
|
1393
|
+
slotProps={{
|
|
1394
|
+
inputLabel: { shrink: true },
|
|
1395
|
+
}}
|
|
1396
|
+
/>
|
|
1397
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
1398
|
+
</Grid>
|
|
1399
|
+
{/* End Date Input */}
|
|
1400
|
+
<Grid item xs={12}>
|
|
1401
|
+
<TextField
|
|
1402
|
+
type="date"
|
|
1403
|
+
fullWidth
|
|
1404
|
+
size="small"
|
|
1405
|
+
disabled={isDisabledFromConfiguration}
|
|
1406
|
+
value={field.value.endDate || ''}
|
|
1407
|
+
onChange={(e) => {
|
|
1408
|
+
field.onChange({ ...field.value, endDate: e.target.value });
|
|
1409
|
+
setData({ ...data, [config.fieldName]: { ...field.value, endDate: e.target.value } });
|
|
1410
|
+
}}
|
|
1411
|
+
inputProps={{
|
|
1412
|
+
min:
|
|
1413
|
+
field.value.startDate ||
|
|
1414
|
+
(fixedMinDate ? dayjs(fixedMinDate).format('YYYY-MM-DD') : undefined),
|
|
1415
|
+
max: fixedMaxDate ? dayjs(fixedMaxDate).format('YYYY-MM-DD') : undefined,
|
|
1416
|
+
}}
|
|
1417
|
+
data-testid={`${dataTestId}-to`}
|
|
1418
|
+
error={!!fieldState.error}
|
|
1419
|
+
slotProps={{ inputLabel: { shrink: true } }}
|
|
1420
|
+
/>
|
|
1421
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
1422
|
+
</Grid>
|
|
1423
|
+
</Grid>
|
|
1424
|
+
)}
|
|
1425
|
+
/>
|
|
1426
|
+
</FormControl>
|
|
1427
|
+
);
|
|
1428
|
+
case 'singleCheckbox':
|
|
1429
|
+
return (
|
|
1430
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1431
|
+
<label>
|
|
1432
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1433
|
+
</label>
|
|
1434
|
+
<Controller
|
|
1435
|
+
name={config.fieldName}
|
|
1436
|
+
control={control}
|
|
1437
|
+
defaultValue={false} // Default value for checkbox is false
|
|
1438
|
+
rules={{
|
|
1439
|
+
required: config.isMandatory ? `${config.displayName} is required` : false,
|
|
1440
|
+
}}
|
|
1441
|
+
render={({ field }) => (
|
|
1442
|
+
<div className="control control-checkbox">
|
|
1443
|
+
<input
|
|
1444
|
+
type="checkbox"
|
|
1445
|
+
checked={field.value}
|
|
1446
|
+
onChange={(e) => {
|
|
1447
|
+
field.onChange(e.target.checked);
|
|
1448
|
+
handleFieldChange(config.fieldName, e.target.checked); // Handle the change event
|
|
1449
|
+
}}
|
|
1450
|
+
data-testid={dataTestId}
|
|
1451
|
+
/>
|
|
1452
|
+
<div className="control_indicator"></div>
|
|
1453
|
+
{errors[config.fieldName] && <p className="error-help-text">{errors[config.fieldName].message}</p>}
|
|
1454
|
+
</div>
|
|
1455
|
+
)}
|
|
1456
|
+
/>
|
|
1457
|
+
</FormControl>
|
|
1458
|
+
);
|
|
1459
|
+
default:
|
|
1460
|
+
return (
|
|
1461
|
+
<FormControl fullWidth sx={{ marginBottom: '5px' }}>
|
|
1462
|
+
<label>
|
|
1463
|
+
{config.displayName} {config.isMandatory && <span style={{ color: 'red' }}>*</span>}
|
|
1464
|
+
</label>
|
|
1465
|
+
<CustomTextField
|
|
1466
|
+
control={control}
|
|
1467
|
+
id={config.fieldName}
|
|
1468
|
+
name={config.fieldName}
|
|
1469
|
+
errors={errors}
|
|
1470
|
+
label=""
|
|
1471
|
+
size="small"
|
|
1472
|
+
onChange={(e) => {
|
|
1473
|
+
handleFieldChange(config.fieldName, e.target.value);
|
|
1474
|
+
}}
|
|
1475
|
+
rules={{
|
|
1476
|
+
required: {
|
|
1477
|
+
value: config.isMandatory,
|
|
1478
|
+
message: config.requiredMessage || 'This field is required',
|
|
1479
|
+
},
|
|
1480
|
+
minLength: config.minLength
|
|
1481
|
+
? {
|
|
1482
|
+
value: config.minLength,
|
|
1483
|
+
message: config.minLengthMessage || `Minimum length is ${config.minLength}`,
|
|
1484
|
+
}
|
|
1485
|
+
: undefined,
|
|
1486
|
+
maxLength: config.maxLength
|
|
1487
|
+
? {
|
|
1488
|
+
value: config.maxLength,
|
|
1489
|
+
message: config.maxLengthMessage || `Maximum length is ${config.maxLength}`,
|
|
1490
|
+
}
|
|
1491
|
+
: undefined,
|
|
1492
|
+
}}
|
|
1493
|
+
dataTestId={dataTestId}
|
|
1494
|
+
/>
|
|
1495
|
+
</FormControl>
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
|
|
1500
|
+
return renderInputField();
|
|
1501
|
+
};
|