add not found redirection logic if object in url param not exists (#10339)
closes #10150
This commit is contained in:
@ -1,9 +1,13 @@
|
||||
import { useIsLogged } from '@/auth/hooks/useIsLogged';
|
||||
import { useDefaultHomePagePath } from '@/navigation/hooks/useDefaultHomePagePath';
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { useOnboardingStatus } from '@/onboarding/hooks/useOnboardingStatus';
|
||||
import { AppPath } from '@/types/AppPath';
|
||||
import { SettingsPath } from '@/types/SettingsPath';
|
||||
import { useIsWorkspaceActivationStatusSuspended } from '@/workspace/hooks/useIsWorkspaceActivationStatusSuspended';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import { OnboardingStatus } from '~/generated/graphql';
|
||||
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';
|
||||
|
||||
@ -33,6 +37,12 @@ export const usePageChangeEffectNavigateLocation = () => {
|
||||
isMatchingLocation(AppPath.PlanRequired) ||
|
||||
isMatchingLocation(AppPath.PlanRequiredSuccess);
|
||||
|
||||
const objectNamePlural = useParams().objectNamePlural ?? '';
|
||||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
||||
const objectMetadataItem = objectMetadataItems.find(
|
||||
(objectMetadataItem) => objectMetadataItem.namePlural === objectNamePlural,
|
||||
);
|
||||
|
||||
if (isMatchingOpenRoute) {
|
||||
return;
|
||||
}
|
||||
@ -96,5 +106,12 @@ export const usePageChangeEffectNavigateLocation = () => {
|
||||
return defaultHomePagePath;
|
||||
}
|
||||
|
||||
if (
|
||||
isMatchingLocation(AppPath.RecordIndexPage) &&
|
||||
!isDefined(objectMetadataItem)
|
||||
) {
|
||||
return AppPath.NotFound;
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user