-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 자신이 속한 팀 조회 api #240 * feat: useGetUser - #240 * feat: useFetchWithToken - #240 * feat: 내 팀조회 + 스터디 api - #240 * feat: 사이드바에 api 적용 - #240 * chore: 오타 수정 - #240
- Loading branch information
1 parent
aa6a655
commit 3ad4e50
Showing
7 changed files
with
115 additions
and
70 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
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,32 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
/* eslint-disable react-hooks/rules-of-hooks */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import useGetUser from '@/hooks/useGetUser'; | ||
|
||
export function useGetFetchWithToken(fetch: (token: string, ...props: any[]) => any, props: any[], originUser?: any) { | ||
const user = originUser !== undefined ? originUser : useGetUser(); | ||
const [result, setResult] = useState<any>(); | ||
const propsStr = Object.entries(props).toString(); | ||
|
||
useEffect(() => { | ||
if (user?.isLogin) { | ||
fetch(user?.token, props).then((res: any) => { | ||
if (res?.ok) { | ||
setResult(res.body); | ||
} else { | ||
setResult(null); | ||
} | ||
}); | ||
} | ||
}, [user, fetch, propsStr]); | ||
|
||
return result; | ||
} | ||
|
||
export function useMutateWithToken(fetch: (token: string, ...props: any[]) => any) { | ||
const user = useGetUser(); | ||
|
||
return (props: any[]) => fetch(user?.token || '', ...props); | ||
} |
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,17 @@ | ||
import { useAtomValue } from 'jotai'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { userAtom } from '@/atom'; | ||
|
||
const useGetUser = () => { | ||
const [isMounted, setIsMounted] = useState(false); | ||
const user = useAtomValue(userAtom); | ||
|
||
useEffect(() => { | ||
setIsMounted(true); | ||
}, []); | ||
|
||
return isMounted ? user : null; | ||
}; | ||
|
||
export default useGetUser; |
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