@ -1,8 +1,9 @@
|
|||||||
import { useMemo, useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
import { InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
import { InMemoryCache, NormalizedCacheObject } from '@apollo/client';
|
||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { previousUrlState } from '@/auth/states/previousUrlState';
|
||||||
import { tokenPairState } from '@/auth/states/tokenPairState';
|
import { tokenPairState } from '@/auth/states/tokenPairState';
|
||||||
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
|
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
|
||||||
import { AppPath } from '@/types/AppPath';
|
import { AppPath } from '@/types/AppPath';
|
||||||
@ -21,6 +22,8 @@ export const useApolloFactory = (options: Partial<Options<any>> = {}) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const isMatchingLocation = useIsMatchingLocation();
|
const isMatchingLocation = useIsMatchingLocation();
|
||||||
const [tokenPair, setTokenPair] = useRecoilState(tokenPairState);
|
const [tokenPair, setTokenPair] = useRecoilState(tokenPairState);
|
||||||
|
const [, setPreviousUrl] = useRecoilState(previousUrlState);
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const apolloClient = useMemo(() => {
|
const apolloClient = useMemo(() => {
|
||||||
apolloRef.current = new ApolloFactory({
|
apolloRef.current = new ApolloFactory({
|
||||||
@ -45,6 +48,7 @@ export const useApolloFactory = (options: Partial<Options<any>> = {}) => {
|
|||||||
!isMatchingLocation(AppPath.Invite) &&
|
!isMatchingLocation(AppPath.Invite) &&
|
||||||
!isMatchingLocation(AppPath.ResetPassword)
|
!isMatchingLocation(AppPath.ResetPassword)
|
||||||
) {
|
) {
|
||||||
|
setPreviousUrl(`${location.pathname}${location.search}`);
|
||||||
navigate(AppPath.SignInUp);
|
navigate(AppPath.SignInUp);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -56,7 +60,7 @@ export const useApolloFactory = (options: Partial<Options<any>> = {}) => {
|
|||||||
|
|
||||||
return apolloRef.current.getClient();
|
return apolloRef.current.getClient();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [setTokenPair, isDebugMode]);
|
}, [setTokenPair, isDebugMode, setPreviousUrl]);
|
||||||
|
|
||||||
useUpdateEffect(() => {
|
useUpdateEffect(() => {
|
||||||
if (isDefined(apolloRef.current)) {
|
if (isDefined(apolloRef.current)) {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { CurrentWorkspace } from '@/auth/states/currentWorkspaceState.ts';
|
import { CurrentWorkspace } from '@/auth/states/currentWorkspaceState.ts';
|
||||||
|
import { previousUrlState } from '@/auth/states/previousUrlState';
|
||||||
import { billingState } from '@/client-config/states/billingState.ts';
|
import { billingState } from '@/client-config/states/billingState.ts';
|
||||||
import { AppPath } from '@/types/AppPath.ts';
|
import { AppPath } from '@/types/AppPath.ts';
|
||||||
import { WorkspaceMember } from '~/generated/graphql.tsx';
|
import { WorkspaceMember } from '~/generated/graphql.tsx';
|
||||||
@ -10,6 +11,7 @@ import { WorkspaceMember } from '~/generated/graphql.tsx';
|
|||||||
export const useNavigateAfterSignInUp = () => {
|
export const useNavigateAfterSignInUp = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const billing = useRecoilValue(billingState);
|
const billing = useRecoilValue(billingState);
|
||||||
|
const previousUrl = useRecoilValue(previousUrlState);
|
||||||
const navigateAfterSignInUp = useCallback(
|
const navigateAfterSignInUp = useCallback(
|
||||||
(
|
(
|
||||||
currentWorkspace: CurrentWorkspace,
|
currentWorkspace: CurrentWorkspace,
|
||||||
@ -35,10 +37,10 @@ export const useNavigateAfterSignInUp = () => {
|
|||||||
navigate(AppPath.CreateProfile);
|
navigate(AppPath.CreateProfile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (previousUrl !== '') navigate(previousUrl);
|
||||||
navigate(AppPath.Index);
|
else navigate(AppPath.Index);
|
||||||
},
|
},
|
||||||
[billing, navigate],
|
[billing, previousUrl, navigate],
|
||||||
);
|
);
|
||||||
return { navigateAfterSignInUp };
|
return { navigateAfterSignInUp };
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
import { createState } from '@/ui/utilities/state/utils/createState';
|
||||||
|
|
||||||
|
export const previousUrlState = createState<string>({
|
||||||
|
key: 'previousUrlState',
|
||||||
|
defaultValue: '',
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user