@@ -5,48 +5,41 @@ import { IconCheckbox } from 'twenty-ui';
5
5
6
6
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer' ;
7
7
import { useEventTracker } from '@/analytics/hooks/useEventTracker' ;
8
- import { useOnboardingStatus } from '@/auth/hooks/useOnboardingStatus' ;
9
- import { OnboardingStatus } from '@/auth/utils/getOnboardingStatus' ;
10
8
import { useRequestFreshCaptchaToken } from '@/captcha/hooks/useRequestFreshCaptchaToken' ;
11
9
import { isCaptchaScriptLoadedState } from '@/captcha/states/isCaptchaScriptLoadedState' ;
12
- import { isSignUpDisabledState } from '@/client-config/states/isSignUpDisabledState' ;
13
10
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu' ;
14
11
import { CommandType } from '@/command-menu/types/Command' ;
15
12
import { TableHotkeyScope } from '@/object-record/record-table/types/TableHotkeyScope' ;
16
13
import { AppBasePath } from '@/types/AppBasePath' ;
17
14
import { AppPath } from '@/types/AppPath' ;
18
15
import { PageHotkeyScope } from '@/types/PageHotkeyScope' ;
19
16
import { SettingsPath } from '@/types/SettingsPath' ;
20
- import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar' ;
21
17
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope' ;
22
- import { useGetWorkspaceFromInviteHashLazyQuery } from '~/generated/graphql' ;
23
18
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation' ;
19
+ import { usePageChangeEffectNavigateLocation } from '~/hooks/usePageChangeEffectNavigateLocation' ;
24
20
import { isDefined } from '~/utils/isDefined' ;
25
21
26
22
// TODO: break down into smaller functions and / or hooks
23
+ // - moved usePageChangeEffectNavigateLocation into dedicated hook
27
24
export const PageChangeEffect = ( ) => {
28
25
const navigate = useNavigate ( ) ;
29
26
const isMatchingLocation = useIsMatchingLocation ( ) ;
30
- const { enqueueSnackBar } = useSnackBar ( ) ;
31
27
32
28
const [ previousLocation , setPreviousLocation ] = useState ( '' ) ;
33
29
34
- const onboardingStatus = useOnboardingStatus ( ) ;
35
-
36
30
const setHotkeyScope = useSetHotkeyScope ( ) ;
37
31
38
32
const location = useLocation ( ) ;
39
33
34
+ const pageChangeEffectNavigateLocation =
35
+ usePageChangeEffectNavigateLocation ( ) ;
36
+
40
37
const eventTracker = useEventTracker ( ) ;
41
38
42
- const [ workspaceFromInviteHashQuery ] =
43
- useGetWorkspaceFromInviteHashLazyQuery ( ) ;
44
39
const { addToCommandMenu, setToInitialCommandMenu } = useCommandMenu ( ) ;
45
40
46
41
const openCreateActivity = useOpenCreateActivityDrawer ( ) ;
47
42
48
- const isSignUpDisabled = useRecoilValue ( isSignUpDisabledState ) ;
49
-
50
43
useEffect ( ( ) => {
51
44
if ( ! previousLocation || previousLocation !== location . pathname ) {
52
45
setPreviousLocation ( location . pathname ) ;
@@ -56,76 +49,10 @@ export const PageChangeEffect = () => {
56
49
} , [ location , previousLocation ] ) ;
57
50
58
51
useEffect ( ( ) => {
59
- const isMatchingOngoingUserCreationRoute =
60
- isMatchingLocation ( AppPath . SignInUp ) ||
61
- isMatchingLocation ( AppPath . Invite ) ||
62
- isMatchingLocation ( AppPath . Verify ) ;
63
-
64
- const isMatchingOnboardingRoute =
65
- isMatchingOngoingUserCreationRoute ||
66
- isMatchingLocation ( AppPath . CreateWorkspace ) ||
67
- isMatchingLocation ( AppPath . CreateProfile ) ||
68
- isMatchingLocation ( AppPath . PlanRequired ) ||
69
- isMatchingLocation ( AppPath . PlanRequiredSuccess ) ;
70
-
71
- if (
72
- onboardingStatus === OnboardingStatus . OngoingUserCreation &&
73
- ! isMatchingOngoingUserCreationRoute &&
74
- ! isMatchingLocation ( AppPath . ResetPassword )
75
- ) {
76
- navigate ( AppPath . SignInUp ) ;
77
- } else if (
78
- isDefined ( onboardingStatus ) &&
79
- onboardingStatus === OnboardingStatus . Incomplete &&
80
- ! isMatchingLocation ( AppPath . PlanRequired )
81
- ) {
82
- navigate ( AppPath . PlanRequired ) ;
83
- } else if (
84
- isDefined ( onboardingStatus ) &&
85
- [ OnboardingStatus . Unpaid , OnboardingStatus . Canceled ] . includes (
86
- onboardingStatus ,
87
- ) &&
88
- ! (
89
- isMatchingLocation ( AppPath . SettingsCatchAll ) ||
90
- isMatchingLocation ( AppPath . PlanRequired )
91
- )
92
- ) {
93
- navigate (
94
- `${ AppPath . SettingsCatchAll . replace ( '/*' , '' ) } /${ SettingsPath . Billing } ` ,
95
- ) ;
96
- } else if (
97
- onboardingStatus === OnboardingStatus . OngoingWorkspaceActivation &&
98
- ! isMatchingLocation ( AppPath . CreateWorkspace ) &&
99
- ! isMatchingLocation ( AppPath . PlanRequiredSuccess )
100
- ) {
101
- navigate ( AppPath . CreateWorkspace ) ;
102
- } else if (
103
- onboardingStatus === OnboardingStatus . OngoingProfileCreation &&
104
- ! isMatchingLocation ( AppPath . CreateProfile )
105
- ) {
106
- navigate ( AppPath . CreateProfile ) ;
107
- } else if (
108
- onboardingStatus === OnboardingStatus . Completed &&
109
- isMatchingOnboardingRoute &&
110
- ! isMatchingLocation ( AppPath . Invite )
111
- ) {
112
- navigate ( AppPath . Index ) ;
113
- } else if (
114
- onboardingStatus === OnboardingStatus . CompletedWithoutSubscription &&
115
- isMatchingOnboardingRoute &&
116
- ! isMatchingLocation ( AppPath . PlanRequired )
117
- ) {
118
- navigate ( AppPath . Index ) ;
52
+ if ( isDefined ( pageChangeEffectNavigateLocation ) ) {
53
+ navigate ( pageChangeEffectNavigateLocation ) ;
119
54
}
120
- } , [
121
- enqueueSnackBar ,
122
- isMatchingLocation ,
123
- isSignUpDisabled ,
124
- location . pathname ,
125
- navigate ,
126
- onboardingStatus ,
127
- workspaceFromInviteHashQuery ,
128
- ] ) ;
55
+ } , [ navigate , pageChangeEffectNavigateLocation ] ) ;
129
56
130
57
useEffect ( ( ) => {
131
58
switch ( true ) {
0 commit comments