Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SELC-4581] feat: Guarantee correct page routing #708

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/pages/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useStore } from 'react-redux';
import { Route, Switch, matchPath, useHistory } from 'react-router';
import { useLocation } from 'react-router-dom';
import { resolvePathVariables } from '@pagopa/selfcare-common-frontend/utils/routes-utils';
import { useLoading } from '@pagopa/selfcare-common-frontend';
import withProductRolesMap from '../../decorators/withProductsRolesMap';
import withSelectedParty from '../../decorators/withSelectedParty';
import withSelectedProduct from '../../decorators/withSelectedPartyProduct';
Expand All @@ -22,6 +23,7 @@ import { ENV } from '../../utils/env';
import DashboardDelegationsPage from '../dashboardDelegations/DashboardDelegationsPage';
import AddDelegationPage from '../dashboardDelegationsAdd/AddDelegationPage';
import DashboardTechnologyPartnerPage from '../dashboardTechnologyPartnerPage/DashboardTechnologyPartnerPage';
import { LOADING_TASK_DASHBOARD_OVERVIEW } from '../../utils/constants';
import DashboardSideMenu from './components/dashboardSideMenu/DashboardSideMenu';

export type DashboardPageProps = {
Expand Down Expand Up @@ -89,6 +91,7 @@ const Dashboard = () => {
const parties = useAppSelector(partiesSelectors.selectPartiesList);
const party = useAppSelector(partiesSelectors.selectPartySelected);
const products = useAppSelector(partiesSelectors.selectPartySelectedProducts);
const setLoading = useLoading(LOADING_TASK_DASHBOARD_OVERVIEW);
const store = useStore();
const theme = useTheme();
const { i18n } = useTranslation();
Expand Down Expand Up @@ -140,12 +143,22 @@ const Dashboard = () => {
});

useEffect(() => {
if (party) {
const redirectPath = party.delegation
? DASHBOARD_ROUTES.TECHPARTNER.path
: DASHBOARD_ROUTES.OVERVIEW.path;
history.push(resolvePathVariables(redirectPath, { partyId: party?.partyId ?? '' }));
const notOverview =
window.location.pathname.endsWith('users') ||
window.location.pathname.endsWith('groups') ||
window.location.pathname.endsWith('admin');

setLoading(true);

if (party?.partyId && !notOverview) {
const route = party?.delegation
? resolvePathVariables(DASHBOARD_ROUTES.TECHPARTNER.path, { partyId: party?.partyId ?? '' })
: resolvePathVariables(DASHBOARD_ROUTES.OVERVIEW.path, { partyId: party?.partyId ?? '' });

history.push(route);
}

setLoading(false);
}, [party?.partyId]);

return party && products ? (
Expand Down
1 change: 1 addition & 0 deletions src/services/__mocks__/partyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ export const mockedParties: Array<Party> = [
productOnBoardingStatus: ProductOnBoardingStatusEnum.ACTIVE,
},
],
delegation: true,
},
// Test AS insurance company
{
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export const LOADING_TASK_TOKEN_EXCHANGE_INVOICE = 'TOKEN_EXCHANGE_INVOICE';
export const LOADING_TASK_FETCH_PRODUCT_ROLES = 'FETCH_PRODUCT_ROLES';
export const LOADING_TASK_SAVE_PARTY_GEOTAXONOMIES = 'SAVE_PARTY_GEOTAXONOMIES';
export const LOADING_TASK_DELEGATION_FORM = 'DELEGATION_FORM';
export const LOADING_TASK_DASHBOARD_OVERVIEW = 'DASHBOARD_OVERVIEW';
Loading