Files
twenty/packages/twenty-front/src/hooks/useDefaultHomePagePath.tsx
T
martmull 9080981990 5509 remove flash on intermediate verify step when sign in with sso (#5526)
- remove flash on /verify
- remove flash on signInUp
- remove useless redirections and hooks
- Remove DefaultHomePage component
- Move redirections to /objects/companies in PageChangeEffect
- add useShowAuthModal hooks and tests
- add usePageChangeEffectNaviteLocation hooks and tests
- fix refresh token expired produces blank screen
2024-05-25 10:36:59 +02:00

32 lines
1.1 KiB
TypeScript

import { useRecoilValue } from 'recoil';
import { currentUserState } from '@/auth/states/currentUserState';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { AppPath } from '@/types/AppPath';
import { isDefined } from '~/utils/isDefined';
export const useDefaultHomePagePath = () => {
const currentUser = useRecoilValue(currentUserState);
const { objectMetadataItem: companyObjectMetadataItem } =
useObjectMetadataItem({
objectNameSingular: CoreObjectNameSingular.Company,
});
const { records } = usePrefetchedData(PrefetchKey.AllViews);
if (!isDefined(currentUser)) {
return { defaultHomePagePath: AppPath.SignInUp };
}
const companyViewId = records.find(
(view: any) => view?.objectMetadataId === companyObjectMetadataItem.id,
)?.id;
return {
defaultHomePagePath:
'/objects/companies' + (companyViewId ? `?view=${companyViewId}` : ''),
};
};