From c21a5d4f6004451ce64a1edd9cbaf73314f9bfe0 Mon Sep 17 00:00:00 2001 From: GaurishN Date: Fri, 29 Nov 2024 18:41:08 +0530 Subject: [PATCH 1/2] handled default_value & validation save in advanced properties --- ui/src/components/AdvancePropertise/index.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/src/components/AdvancePropertise/index.tsx b/ui/src/components/AdvancePropertise/index.tsx index 314601c4f..727f6dac7 100644 --- a/ui/src/components/AdvancePropertise/index.tsx +++ b/ui/src/components/AdvancePropertise/index.tsx @@ -123,7 +123,7 @@ const AdvancePropertise = (props: SchemaProps) => { { ...props?.value, [field?.charAt(0)?.toUpperCase() + field?.slice(1)]: (event.target as HTMLInputElement)?.value, - validationRegex: '', + validationRegex: currentToggleStates?.validationRegex || '', minChars: currentToggleStates?.minChars, maxChars:currentToggleStates?.maxChars, mandatory: currentToggleStates?.mandatory, @@ -134,6 +134,7 @@ const AdvancePropertise = (props: SchemaProps) => { embedObjects: embedObjectslabels, minRange: currentToggleStates?.minRange, maxRange: currentToggleStates?.maxRange, + default_value: currentToggleStates?.default_value, }, checkBoxChanged ); @@ -159,7 +160,7 @@ const AdvancePropertise = (props: SchemaProps) => { props?.rowId, { [field?.charAt(0)?.toUpperCase() + field?.slice(1)]: value, - validationRegex: '', + validationRegex: currentToggleStates?.validationRegex || '', mandatory: currentToggleStates?.mandatory, multiple: currentToggleStates?.multiple, unique: false, @@ -186,7 +187,7 @@ const AdvancePropertise = (props: SchemaProps) => { props?.rowId, { [field?.charAt(0)?.toUpperCase() + field?.slice(1)]: value, - validationRegex: '', + validationRegex: currentToggleStates?.validationRegex || '', mandatory: currentToggleStates?.mandatory, multiple: currentToggleStates?.multiple, unique: false, @@ -237,7 +238,7 @@ const AdvancePropertise = (props: SchemaProps) => { props?.rowId, { ['default_value']: option?.key, - validationRegex: '', + validationRegex: currentToggleStates?.validationRegex || '', mandatory: currentToggleStates?.mandatory, multiple: currentToggleStates?.multiple, unique: false, @@ -268,7 +269,7 @@ const AdvancePropertise = (props: SchemaProps) => { props?.rowId, { ['default_value']: '', - validationRegex: '', + validationRegex: currentToggleStates?.validationRegex || '', mandatory: currentToggleStates?.mandatory, multiple: currentToggleStates?.multiple, unique: false, From bde9903185e0ce28d3a8f9dd821c2f0a2694e30a Mon Sep 17 00:00:00 2001 From: GaurishN Date: Mon, 2 Dec 2024 15:34:59 +0530 Subject: [PATCH 2/2] added custom hook to prevent back navigation --- ui/src/hooks/usePreventBackNavigation.tsx | 24 +++++++++++++++++++++++ ui/src/pages/Home/index.tsx | 2 ++ ui/src/pages/Login/index.tsx | 3 +++ ui/src/pages/Projects/index.tsx | 3 +++ ui/src/pages/RegionalLogin/index.tsx | 5 ++++- 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 ui/src/hooks/usePreventBackNavigation.tsx diff --git a/ui/src/hooks/usePreventBackNavigation.tsx b/ui/src/hooks/usePreventBackNavigation.tsx new file mode 100644 index 000000000..8e25d4533 --- /dev/null +++ b/ui/src/hooks/usePreventBackNavigation.tsx @@ -0,0 +1,24 @@ +import { useEffect } from "react"; +import { useLocation, useNavigate } from "react-router"; + +const usePreventBackNavigation = (): void => { + const navigate = useNavigate(); + const location = useLocation(); + + useEffect(() => { + // push a dummy state to the history stack + window.history.pushState(null, "", window.location.href); + + const handlePopState = () => { + navigate(location.pathname, { replace: true }); + }; + + window.addEventListener("popstate", handlePopState); + + return () => { + window.removeEventListener("popstate", handlePopState); + }; + }, [navigate, location]); + }; + +export default usePreventBackNavigation; diff --git a/ui/src/pages/Home/index.tsx b/ui/src/pages/Home/index.tsx index 0110a4fa3..9dac3cb6b 100644 --- a/ui/src/pages/Home/index.tsx +++ b/ui/src/pages/Home/index.tsx @@ -13,10 +13,12 @@ import { CS_ENTRIES } from '../../utilities/constants'; // Interface import { HomepageType } from './home.interface'; import useBlockNavigation from '../../hooks/userNavigation'; +import usePreventBackNavigation from '../../hooks/usePreventBackNavigation'; const Home = () => { const [data, setData] = useState({}); useBlockNavigation(true); + usePreventBackNavigation(); const fetchData = async () => { //check if offline CMS data field is set to true, if then read data from cms data file. diff --git a/ui/src/pages/Login/index.tsx b/ui/src/pages/Login/index.tsx index 4c7ef7fc3..f2877c802 100644 --- a/ui/src/pages/Login/index.tsx +++ b/ui/src/pages/Login/index.tsx @@ -30,6 +30,7 @@ import { userSession, requestSMSToken } from '../../services/api/login.service'; // Interface import { IProps, IStates, defaultStates, User, UserRes, LoginType } from './login.interface'; +import usePreventBackNavigation from '../../hooks/usePreventBackNavigation'; //Components import AccountPage from '../../components/AccountPage'; @@ -41,6 +42,8 @@ import { RootState } from '../../store'; const Login: FC = () => { const [data, setData] = useState({}); + usePreventBackNavigation(); + // ************* Fetch Login Data ************ const fetchData = async () => { //check if offline CMS data field is set to true, if then read data from cms data file. diff --git a/ui/src/pages/Projects/index.tsx b/ui/src/pages/Projects/index.tsx index 62cbc3d4e..db3e8b68a 100644 --- a/ui/src/pages/Projects/index.tsx +++ b/ui/src/pages/Projects/index.tsx @@ -22,6 +22,7 @@ import { validateObject } from '../../utilities/functions'; import { ProjectsType, ProjectsObj } from './projects.interface'; import { ModalObj } from '../../components/Modal/modal.interface'; import { CTA } from '../Home/home.interface'; +import usePreventBackNavigation from '../../hooks/usePreventBackNavigation'; // Components @@ -59,6 +60,8 @@ const Projects = () => { const [searchText, setSearchText] = useState(search); const [isModalOpen, setIsModalOpen] = useState(false); + usePreventBackNavigation(); + const fetchProjects = async () => { setLoadStatus(true); if (selectedOrganisation?.value) { diff --git a/ui/src/pages/RegionalLogin/index.tsx b/ui/src/pages/RegionalLogin/index.tsx index 224e4e885..9105f0b40 100644 --- a/ui/src/pages/RegionalLogin/index.tsx +++ b/ui/src/pages/RegionalLogin/index.tsx @@ -12,6 +12,7 @@ import { CS_ENTRIES } from '../../utilities/constants'; // Interface import { RegionType } from './regionalLogin.interface'; +import usePreventBackNavigation from '../../hooks/usePreventBackNavigation'; // Style import './index.scss'; @@ -37,6 +38,8 @@ const RegionalLogin = () => { const { description, heading, regions } = data; + usePreventBackNavigation(); + return (
@@ -76,7 +79,7 @@ const RegionalLogin = () => { className="body-4 fw-bold stretched-link" onClick={(e) =>{ e.preventDefault(); - navigate(`/login?region=${region?.region}`)} + navigate(`/login?region=${region?.region}`, { replace: true })} } > {region?.cta?.title}