-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from YAPP-Github/feature/FE-059
- Loading branch information
Showing
16 changed files
with
90 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { default as useProfile } from './useProfile'; | ||
|
||
export { default as useLogin } from './useLogin'; | ||
|
||
export { default as useLogout } from './useLogout'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { useMutation } from '@/hooks'; | ||
import { userKeys } from '@/api/user/queryKeys'; | ||
import { userAPI } from '@/api/user/api'; | ||
|
||
const useLogout = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation(userAPI.postLogout, { | ||
onSuccess: () => { | ||
void queryClient.invalidateQueries(userKeys.profile()); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useLogout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useCallback } from 'react'; | ||
import { useRouter, usePathname, useSearchParams } from 'next/navigation'; | ||
|
||
const HOME_PATH = '/'; | ||
const LOGIN_PATH = '/login'; | ||
const REDIRECT_QUERY = 'redirectPath'; | ||
|
||
const useLoginRedirect = () => { | ||
const router = useRouter(); | ||
const searchParams = useSearchParams(); | ||
const currentPathname = usePathname(); | ||
|
||
const loginPath = `${LOGIN_PATH}?${REDIRECT_QUERY}=${currentPathname}`; | ||
|
||
const redirectToLogin = useCallback(() => { | ||
router.push(`${LOGIN_PATH}?${REDIRECT_QUERY}=${currentPathname}`); | ||
}, [router, currentPathname]); | ||
|
||
const redirectBack = useCallback(() => { | ||
if (searchParams.has(REDIRECT_QUERY)) { | ||
router.replace(searchParams.get(REDIRECT_QUERY) as string); | ||
} else { | ||
router.replace(HOME_PATH); | ||
} | ||
}, [router, searchParams]); | ||
|
||
return { loginPath, redirectToLogin, redirectBack }; | ||
}; | ||
|
||
export default useLoginRedirect; |
12 changes: 4 additions & 8 deletions
12
...mponents/Header/HydratedHeaderActions.tsx → src/providers/ProfileProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import { ReactNode } from 'react'; | ||
import { dehydrate, Hydrate } from '@tanstack/react-query'; | ||
import getQueryClient from '@/utils/getQueryClients'; | ||
import { api, queryKeys } from '@/api'; | ||
import HeaderActions from './HeaderActions'; | ||
|
||
const HydratedHeaderActions = async () => { | ||
const ProfileProvider = async ({ children }: { children: ReactNode }) => { | ||
const queryClient = getQueryClient(); | ||
await queryClient.prefetchQuery(queryKeys.user.profile(), () => api.user.getProfile()); | ||
const dehydratedState = dehydrate(queryClient); | ||
|
||
return ( | ||
<Hydrate state={dehydratedState}> | ||
<HeaderActions /> | ||
</Hydrate> | ||
); | ||
return <Hydrate state={dehydratedState}>{children}</Hydrate>; | ||
}; | ||
|
||
export default HydratedHeaderActions; | ||
export default ProfileProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as QueryProvider } from './QueryProvider'; | ||
|
||
export { OverlayProvider } from './OverlayProvider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as ProfileProvider } from './ProfileProvider'; |