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
This commit is contained in:
@ -5,11 +5,8 @@ import { IconCheckbox } from 'twenty-ui';
|
||||
|
||||
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
|
||||
import { useEventTracker } from '@/analytics/hooks/useEventTracker';
|
||||
import { useOnboardingStatus } from '@/auth/hooks/useOnboardingStatus';
|
||||
import { OnboardingStatus } from '@/auth/utils/getOnboardingStatus';
|
||||
import { useRequestFreshCaptchaToken } from '@/captcha/hooks/useRequestFreshCaptchaToken';
|
||||
import { isCaptchaScriptLoadedState } from '@/captcha/states/isCaptchaScriptLoadedState';
|
||||
import { isSignUpDisabledState } from '@/client-config/states/isSignUpDisabledState';
|
||||
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
|
||||
import { CommandType } from '@/command-menu/types/Command';
|
||||
import { TableHotkeyScope } from '@/object-record/record-table/types/TableHotkeyScope';
|
||||
@ -17,36 +14,32 @@ import { AppBasePath } from '@/types/AppBasePath';
|
||||
import { AppPath } from '@/types/AppPath';
|
||||
import { PageHotkeyScope } from '@/types/PageHotkeyScope';
|
||||
import { SettingsPath } from '@/types/SettingsPath';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||
import { useGetWorkspaceFromInviteHashLazyQuery } from '~/generated/graphql';
|
||||
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';
|
||||
import { usePageChangeEffectNavigateLocation } from '~/hooks/usePageChangeEffectNavigateLocation';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
// TODO: break down into smaller functions and / or hooks
|
||||
// - moved usePageChangeEffectNavigateLocation into dedicated hook
|
||||
export const PageChangeEffect = () => {
|
||||
const navigate = useNavigate();
|
||||
const isMatchingLocation = useIsMatchingLocation();
|
||||
const { enqueueSnackBar } = useSnackBar();
|
||||
|
||||
const [previousLocation, setPreviousLocation] = useState('');
|
||||
|
||||
const onboardingStatus = useOnboardingStatus();
|
||||
|
||||
const setHotkeyScope = useSetHotkeyScope();
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
const pageChangeEffectNavigateLocation =
|
||||
usePageChangeEffectNavigateLocation();
|
||||
|
||||
const eventTracker = useEventTracker();
|
||||
|
||||
const [workspaceFromInviteHashQuery] =
|
||||
useGetWorkspaceFromInviteHashLazyQuery();
|
||||
const { addToCommandMenu, setToInitialCommandMenu } = useCommandMenu();
|
||||
|
||||
const openCreateActivity = useOpenCreateActivityDrawer();
|
||||
|
||||
const isSignUpDisabled = useRecoilValue(isSignUpDisabledState);
|
||||
|
||||
useEffect(() => {
|
||||
if (!previousLocation || previousLocation !== location.pathname) {
|
||||
setPreviousLocation(location.pathname);
|
||||
@ -56,76 +49,10 @@ export const PageChangeEffect = () => {
|
||||
}, [location, previousLocation]);
|
||||
|
||||
useEffect(() => {
|
||||
const isMatchingOngoingUserCreationRoute =
|
||||
isMatchingLocation(AppPath.SignInUp) ||
|
||||
isMatchingLocation(AppPath.Invite) ||
|
||||
isMatchingLocation(AppPath.Verify);
|
||||
|
||||
const isMatchingOnboardingRoute =
|
||||
isMatchingOngoingUserCreationRoute ||
|
||||
isMatchingLocation(AppPath.CreateWorkspace) ||
|
||||
isMatchingLocation(AppPath.CreateProfile) ||
|
||||
isMatchingLocation(AppPath.PlanRequired) ||
|
||||
isMatchingLocation(AppPath.PlanRequiredSuccess);
|
||||
|
||||
if (
|
||||
onboardingStatus === OnboardingStatus.OngoingUserCreation &&
|
||||
!isMatchingOngoingUserCreationRoute &&
|
||||
!isMatchingLocation(AppPath.ResetPassword)
|
||||
) {
|
||||
navigate(AppPath.SignInUp);
|
||||
} else if (
|
||||
isDefined(onboardingStatus) &&
|
||||
onboardingStatus === OnboardingStatus.Incomplete &&
|
||||
!isMatchingLocation(AppPath.PlanRequired)
|
||||
) {
|
||||
navigate(AppPath.PlanRequired);
|
||||
} else if (
|
||||
isDefined(onboardingStatus) &&
|
||||
[OnboardingStatus.Unpaid, OnboardingStatus.Canceled].includes(
|
||||
onboardingStatus,
|
||||
) &&
|
||||
!(
|
||||
isMatchingLocation(AppPath.SettingsCatchAll) ||
|
||||
isMatchingLocation(AppPath.PlanRequired)
|
||||
)
|
||||
) {
|
||||
navigate(
|
||||
`${AppPath.SettingsCatchAll.replace('/*', '')}/${SettingsPath.Billing}`,
|
||||
);
|
||||
} else if (
|
||||
onboardingStatus === OnboardingStatus.OngoingWorkspaceActivation &&
|
||||
!isMatchingLocation(AppPath.CreateWorkspace) &&
|
||||
!isMatchingLocation(AppPath.PlanRequiredSuccess)
|
||||
) {
|
||||
navigate(AppPath.CreateWorkspace);
|
||||
} else if (
|
||||
onboardingStatus === OnboardingStatus.OngoingProfileCreation &&
|
||||
!isMatchingLocation(AppPath.CreateProfile)
|
||||
) {
|
||||
navigate(AppPath.CreateProfile);
|
||||
} else if (
|
||||
onboardingStatus === OnboardingStatus.Completed &&
|
||||
isMatchingOnboardingRoute &&
|
||||
!isMatchingLocation(AppPath.Invite)
|
||||
) {
|
||||
navigate(AppPath.Index);
|
||||
} else if (
|
||||
onboardingStatus === OnboardingStatus.CompletedWithoutSubscription &&
|
||||
isMatchingOnboardingRoute &&
|
||||
!isMatchingLocation(AppPath.PlanRequired)
|
||||
) {
|
||||
navigate(AppPath.Index);
|
||||
if (isDefined(pageChangeEffectNavigateLocation)) {
|
||||
navigate(pageChangeEffectNavigateLocation);
|
||||
}
|
||||
}, [
|
||||
enqueueSnackBar,
|
||||
isMatchingLocation,
|
||||
isSignUpDisabled,
|
||||
location.pathname,
|
||||
navigate,
|
||||
onboardingStatus,
|
||||
workspaceFromInviteHashQuery,
|
||||
]);
|
||||
}, [navigate, pageChangeEffectNavigateLocation]);
|
||||
|
||||
useEffect(() => {
|
||||
switch (true) {
|
||||
|
||||
Reference in New Issue
Block a user