Skip to content

5509 remove flash on intermediate verify step when sign in with sso #5526

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
99429b7
Remove modal layout on /verify
martmull May 21, 2024
7f0c6d9
Update page layout
martmull May 21, 2024
ace8814
Remove useless navigate
martmull May 21, 2024
d9f8895
Remove useNavigateAfterSignUp
martmull May 21, 2024
c135077
Merge branch 'main' into 5509-remove-flash-on-intermediate-verify-ste…
martmull May 22, 2024
466ad47
Merge branch 'main' into 5509-remove-flash-on-intermediate-verify-ste…
martmull May 22, 2024
5733004
Remove navigate from PasswordReset.tsx
martmull May 22, 2024
9ed2615
Remove navigate from Invite.tsx
martmull May 22, 2024
33c2d54
Remove navigate from signOutAndRedirect
martmull May 22, 2024
59e9773
Add back navigate from passwordReset and Invite
martmull May 22, 2024
51d539a
Remove workspaceInviteHashVerificationState
martmull May 22, 2024
39ad86a
Remove passwordResetTokenVerificationState
martmull May 22, 2024
8f7a73e
Simplify DefaultLayout
martmull May 22, 2024
afca6a4
Update PageChangeEffect
martmull May 22, 2024
e560468
TO BE VALIDATED: cleaning code + remove DefaultHomePage component
martmull May 22, 2024
71d2638
Clean code
martmull May 22, 2024
d9ae886
Use onboarding status in default layout
martmull May 22, 2024
b72a440
Split show auth modal and add test
martmull May 23, 2024
851265a
Split pageChangeEffect and add test
martmull May 23, 2024
f72e1fd
Correct typo
martmull May 23, 2024
c9effc2
Merge branch 'main' into 5509-remove-flash-on-intermediate-verify-ste…
martmull May 23, 2024
8385a7c
Fix refresh token expired blank screen
martmull May 24, 2024
aa093a9
Fix tests
martmull May 24, 2024
33ca4ef
Add test for defaultHomePagePath
martmull May 24, 2024
7281db1
Fix multiple info messages
martmull May 24, 2024
de73721
Simplify code
martmull May 24, 2024
f8765ea
Update isDefaultLayoutAuthModalVisibleState type
martmull May 24, 2024
6078480
Remove navigate from useSignInUp
martmull May 24, 2024
f14bdc2
Fix invitation
martmull May 24, 2024
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
6 changes: 1 addition & 5 deletions packages/twenty-front/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { Invite } from '~/pages/auth/Invite';
import { PasswordReset } from '~/pages/auth/PasswordReset';
import { PaymentSuccess } from '~/pages/auth/PaymentSuccess';
import { SignInUp } from '~/pages/auth/SignInUp';
import { DefaultHomePage } from '~/pages/DefaultHomePage';
import { ImpersonateEffect } from '~/pages/impersonate/ImpersonateEffect';
import { NotFound } from '~/pages/not-found/NotFound';
import { RecordIndexPage } from '~/pages/object-record/RecordIndexPage';
Expand Down Expand Up @@ -139,10 +138,7 @@ const createRouter = (isBillingEnabled?: boolean) =>
path={AppPath.PlanRequiredSuccess}
element={<PaymentSuccess />}
/>
<Route
path={indexAppPath.getIndexAppPath()}
element={<DefaultHomePage />}
/>
<Route path={indexAppPath.getIndexAppPath()} element={<></>} />
<Route path={AppPath.TasksPage} element={<Tasks />} />
<Route path={AppPath.Impersonate} element={<ImpersonateEffect />} />
<Route path={AppPath.RecordIndexPage} element={<RecordIndexPage />} />
Expand Down
89 changes: 8 additions & 81 deletions packages/twenty-front/src/effect-components/PageChangeEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,41 @@ 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';
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 =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding tests

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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { renderHook } from '@testing-library/react';
import { RecoilRoot, useSetRecoilState } from 'recoil';

import { currentUserState } from '@/auth/states/currentUserState';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { getObjectMetadataItemsMock } from '@/object-metadata/utils/getObjectMetadataItemsMock';
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
import { AppPath } from '@/types/AppPath';
import { useDefaultHomePagePath } from '~/hooks/useDefaultHomePagePath';
import { mockedUsersData } from '~/testing/mock-data/users';

const objectMetadataItem = getObjectMetadataItemsMock()[0];
jest.mock('@/object-metadata/hooks/useObjectMetadataItem');
jest.mocked(useObjectMetadataItem).mockReturnValue({
objectMetadataItem,
});

jest.mock('@/prefetch/hooks/usePrefetchedData');
const setupMockPrefetchedData = (viewId?: string) => {
jest.mocked(usePrefetchedData).mockReturnValue({
isDataPrefetched: true,
records: viewId
? [
{
id: viewId,
__typename: 'object',
objectMetadataId: objectMetadataItem.id,
},
]
: [],
});
};

const renderHooks = (withCurrentUser: boolean) => {
const { result } = renderHook(
() => {
const setCurrentUser = useSetRecoilState(currentUserState);
if (withCurrentUser) {
setCurrentUser(mockedUsersData[0]);
}
return useDefaultHomePagePath();
},
{
wrapper: RecoilRoot,
},
);
return { result };
};
describe('useDefaultHomePagePath', () => {
it('should return proper path when no currentUser', () => {
setupMockPrefetchedData();
const { result } = renderHooks(false);
expect(result.current.defaultHomePagePath).toEqual(AppPath.SignInUp);
});
it('should return proper path when no currentUser and existing view', () => {
setupMockPrefetchedData('viewId');
const { result } = renderHooks(false);
expect(result.current.defaultHomePagePath).toEqual(AppPath.SignInUp);
});
it('should return proper path when currentUser is defined', () => {
setupMockPrefetchedData();
const { result } = renderHooks(true);
expect(result.current.defaultHomePagePath).toEqual('/objects/companies');
});
it('should return proper path when currentUser is defined and view exists', () => {
setupMockPrefetchedData('viewId');
const { result } = renderHooks(true);
expect(result.current.defaultHomePagePath).toEqual(
'/objects/companies?view=viewId',
);
});
});
Loading
Loading