From 64cae5af401d0f3a1026756665002bda23c36242 Mon Sep 17 00:00:00 2001 From: Marc Itzenthaler Date: Tue, 20 Feb 2024 10:42:11 +0100 Subject: [PATCH] fix: errors --- .../ConsultingTypeAgencySelection.tsx | 30 +++++++++---------- src/components/login/Login.tsx | 16 ++++++---- .../mainTopicSelection/MainTopicSelection.tsx | 2 +- src/components/registration/Registration.tsx | 3 -- .../hooks/useAgenciesForRegistration.ts | 1 - .../hooks/useConsultantRegistrationData.ts | 7 ++--- src/utils/loadConsultingTypeForAgency.ts | 2 +- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/components/consultingTypeSelection/ConsultingTypeAgencySelection.tsx b/src/components/consultingTypeSelection/ConsultingTypeAgencySelection.tsx index b1228eb3b..8e71c35c3 100644 --- a/src/components/consultingTypeSelection/ConsultingTypeAgencySelection.tsx +++ b/src/components/consultingTypeSelection/ConsultingTypeAgencySelection.tsx @@ -17,7 +17,6 @@ import { import { Text } from '../text/Text'; import { AgencyLanguages } from '../agencySelection/AgencyLanguages'; import { useTranslation } from 'react-i18next'; -import { useAppConfig } from '../../hooks/useAppConfig'; import { useConsultantRegistrationData } from '../../containers/registration/hooks/useConsultantRegistrationData'; import { apiGetTopicsData } from '../../api/apiGetTopicsData'; import { useTenant } from '../../globalState'; @@ -37,13 +36,9 @@ export const ConsultingTypeAgencySelection = ({ onKeyDown }: ConsultingTypeAgencySelectionProps) => { const { t: translate } = useTranslation(['common', 'consultingTypes']); - const settings = useAppConfig(); const tenantData = useTenant(); - const { - agency: preselectedAgency, - consultant, - topic: preselectedTopic - } = useContext(UrlParamsContext); + const { agency: preselectedAgency, topic: preselectedTopic } = + useContext(UrlParamsContext); const [selectedConsultingTypeOption, setSelectedConsultingTypeOption] = useState(null); @@ -100,7 +95,7 @@ export const ConsultingTypeAgencySelection = ({ })) ) .then(setTopicOptions); - }, [possibleTopicIds]); + }, [possibleTopicIds, preselectedAgency, preselectedTopic]); useEffect(() => { const consultingTypeOptions = possibleConsultingTypes.map( @@ -155,14 +150,17 @@ export const ConsultingTypeAgencySelection = ({ onValidityChange(agency ? VALIDITY_VALID : VALIDITY_INVALID); }, [agency]); // eslint-disable-line react-hooks/exhaustive-deps - const handleChange = useCallback((agency) => { - onChange({ - ...agency, - ...(topicsAreRequired - ? { topicIds: [parseInt(selectedTopicOption?.value)] } - : {}) - }); - }, []); + const handleChange = useCallback( + (agency) => { + onChange({ + ...agency, + ...(topicsAreRequired + ? { topicIds: [parseInt(selectedTopicOption?.value)] } + : {}) + }); + }, + [onChange, selectedTopicOption?.value, topicsAreRequired] + ); const consultingTypeSelect: SelectDropdownItem = { id: 'consultingTypeSelection', diff --git a/src/components/login/Login.tsx b/src/components/login/Login.tsx index a5b842058..9e641dea9 100644 --- a/src/components/login/Login.tsx +++ b/src/components/login/Login.tsx @@ -64,7 +64,6 @@ import { budibaseLogout } from '../budibase/budibaseLogout'; import { GlobalComponentContext } from '../../globalState/provider/GlobalComponentContext'; import { useConsultantRegistrationData } from '../../containers/registration/hooks/useConsultantRegistrationData'; import { UrlParamsContext } from '../../globalState/provider/UrlParamsProvider'; -import { TopicsDataInterface } from '../../globalState/interfaces/TopicsDataInterface'; const regexAccountDeletedError = /account disabled/i; @@ -139,7 +138,6 @@ export const Login = () => { }, [featureToolsEnabled, gcid]); const [agency, setAgency] = useState(null); - const [topic, setTopic] = useState(null); const [validity, setValidity] = useState(VALIDITY_INITIAL); const [registerOverlayActive, setRegisterOverlayActive] = useState(false); const [pwResetOverlayActive, setPwResetOverlayActive] = useState(false); @@ -314,7 +312,12 @@ export const Login = () => { setAgency(possibleAgencies[0]); setValidity(VALIDITY_VALID); } - }, [possibleAgencies, possibleConsultingTypes, topicsAreRequired]); + }, [ + possibleAgencies, + possibleConsultingTypes, + possibleTopicIds.length, + topicsAreRequired + ]); useEffect(() => { deleteCookieByName('tenantId'); @@ -364,15 +367,16 @@ export const Login = () => { } }), [ + reloadUserData, locale, initLocale, consultant, possibleAgencies, possibleConsultingTypes.length, - reloadUserData, - handleRegistration, + topicsAreRequired, + possibleTopicIds, gcid, - topicsAreRequired + handleRegistration ] ); diff --git a/src/components/mainTopicSelection/MainTopicSelection.tsx b/src/components/mainTopicSelection/MainTopicSelection.tsx index 24942ddaf..376c5d103 100644 --- a/src/components/mainTopicSelection/MainTopicSelection.tsx +++ b/src/components/mainTopicSelection/MainTopicSelection.tsx @@ -52,7 +52,7 @@ export const MainTopicSelection = ({ ) // Filter topics by preselected agency .filter((t) => !agency || agency.topicIds?.includes(t.id)), - [loadedTopics, agency, consultant] + [loadedTopics, topic, consultant, agency] ); useEffect(() => { diff --git a/src/components/registration/Registration.tsx b/src/components/registration/Registration.tsx index dde51e45c..35bf44644 100644 --- a/src/components/registration/Registration.tsx +++ b/src/components/registration/Registration.tsx @@ -13,7 +13,6 @@ import useIsFirstVisit from '../../utils/useIsFirstVisit'; import { useTranslation } from 'react-i18next'; import { GlobalComponentContext } from '../../globalState/provider/GlobalComponentContext'; import { UrlParamsContext } from '../../globalState/provider/UrlParamsProvider'; -import { useAppConfig } from '../../hooks/useAppConfig'; interface RegistrationProps { handleUnmatchConsultingType: Function; @@ -35,7 +34,6 @@ export const Registration = ({ const agencyId = getUrlParameter('aid'); const consultantId = getUrlParameter('cid'); const postcodeParameter = getUrlParameter('postcode'); - const settings = useAppConfig(); const { setInformal } = useContext(InformalContext); const { Stage } = useContext(GlobalComponentContext); @@ -70,7 +68,6 @@ export const Registration = ({ console.error( 'No `consultingType`, `consultant` or `agency` found in URL.' ); - window.location.href = settings.urls.landingpage; return; } diff --git a/src/containers/registration/hooks/useAgenciesForRegistration.ts b/src/containers/registration/hooks/useAgenciesForRegistration.ts index 7859a5768..2246e151c 100644 --- a/src/containers/registration/hooks/useAgenciesForRegistration.ts +++ b/src/containers/registration/hooks/useAgenciesForRegistration.ts @@ -31,7 +31,6 @@ export const useAgenciesForRegistration = ({ const { consultant, agency: preselectedAgency, - topic: preselectedTopic, consultingType: preselectedConsultingType, slugFallback } = useContext(UrlParamsContext); diff --git a/src/containers/registration/hooks/useConsultantRegistrationData.ts b/src/containers/registration/hooks/useConsultantRegistrationData.ts index c8cb288be..baf5f125d 100644 --- a/src/containers/registration/hooks/useConsultantRegistrationData.ts +++ b/src/containers/registration/hooks/useConsultantRegistrationData.ts @@ -3,9 +3,8 @@ import unionBy from 'lodash/unionBy'; import { ConsultingTypeInterface, - AgencyDataInterface, - TopicsDataInterface -} from '../../../globalState/interfaces'; + AgencyDataInterface +} from '../../../globalState'; import { useAppConfig } from '../../../hooks/useAppConfig'; import { UrlParamsContext } from '../../../globalState/provider/UrlParamsProvider'; @@ -53,7 +52,7 @@ export const useConsultantRegistrationData = () => { ) ) ], - [agencies] + [agencies, consultant, preselectedAgency, preselectedTopic] ); useEffect(() => { diff --git a/src/utils/loadConsultingTypeForAgency.ts b/src/utils/loadConsultingTypeForAgency.ts index 8d605db53..817561640 100644 --- a/src/utils/loadConsultingTypeForAgency.ts +++ b/src/utils/loadConsultingTypeForAgency.ts @@ -1,5 +1,5 @@ import { apiGetConsultingType } from '../api'; -import { AgencyDataInterface } from '../globalState/interfaces'; +import { AgencyDataInterface } from '../globalState'; export const loadConsultingTypeForAgency = async ( agency: AgencyDataInterface