Skip to content

Commit

Permalink
fix: errors
Browse files Browse the repository at this point in the history
  • Loading branch information
web-mi committed Feb 20, 2024
1 parent 7174ab6 commit 64cae5a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<SelectOption>(null);
Expand Down Expand Up @@ -100,7 +95,7 @@ export const ConsultingTypeAgencySelection = ({
}))
)
.then(setTopicOptions);
}, [possibleTopicIds]);
}, [possibleTopicIds, preselectedAgency, preselectedTopic]);

useEffect(() => {
const consultingTypeOptions = possibleConsultingTypes.map(
Expand Down Expand Up @@ -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',
Expand Down
16 changes: 10 additions & 6 deletions src/components/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -139,7 +138,6 @@ export const Login = () => {
}, [featureToolsEnabled, gcid]);

const [agency, setAgency] = useState<AgencyDataInterface>(null);
const [topic, setTopic] = useState<TopicsDataInterface>(null);
const [validity, setValidity] = useState(VALIDITY_INITIAL);
const [registerOverlayActive, setRegisterOverlayActive] = useState(false);
const [pwResetOverlayActive, setPwResetOverlayActive] = useState(false);
Expand Down Expand Up @@ -314,7 +312,12 @@ export const Login = () => {
setAgency(possibleAgencies[0]);
setValidity(VALIDITY_VALID);
}
}, [possibleAgencies, possibleConsultingTypes, topicsAreRequired]);
}, [
possibleAgencies,
possibleConsultingTypes,
possibleTopicIds.length,
topicsAreRequired
]);

useEffect(() => {
deleteCookieByName('tenantId');
Expand Down Expand Up @@ -364,15 +367,16 @@ export const Login = () => {
}
}),
[
reloadUserData,
locale,
initLocale,
consultant,
possibleAgencies,
possibleConsultingTypes.length,
reloadUserData,
handleRegistration,
topicsAreRequired,
possibleTopicIds,
gcid,
topicsAreRequired
handleRegistration
]
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/mainTopicSelection/MainTopicSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
3 changes: 0 additions & 3 deletions src/components/registration/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -70,7 +68,6 @@ export const Registration = ({
console.error(
'No `consultingType`, `consultant` or `agency` found in URL.'
);
window.location.href = settings.urls.landingpage;
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const useAgenciesForRegistration = ({
const {
consultant,
agency: preselectedAgency,
topic: preselectedTopic,
consultingType: preselectedConsultingType,
slugFallback
} = useContext(UrlParamsContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -53,7 +52,7 @@ export const useConsultantRegistrationData = () => {
)
)
],
[agencies]
[agencies, consultant, preselectedAgency, preselectedTopic]
);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/loadConsultingTypeForAgency.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { apiGetConsultingType } from '../api';
import { AgencyDataInterface } from '../globalState/interfaces';
import { AgencyDataInterface } from '../globalState';

export const loadConsultingTypeForAgency = async (
agency: AgencyDataInterface
Expand Down

0 comments on commit 64cae5a

Please sign in to comment.