-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
22 changed files
with
399 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { GetUserInfoSchema, type GetUserInfo } from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getUserInfo = () => | ||
get<GetUserInfo>({ | ||
schema: GetUserInfoSchema, | ||
url: '/api/user/info', | ||
}); | ||
|
||
export const useGetUserInfo = () => { | ||
return useQuery({ | ||
queryKey: ['userInfo'], | ||
queryFn: getUserInfo, | ||
}); | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/frontend/src/apis/queries/auth/useGetUserStock.ts
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,19 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { | ||
GetUserStockResponseSchema, | ||
type GetUserStockResponse, | ||
} from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getUserStock = () => | ||
get<GetUserStockResponse>({ | ||
schema: GetUserStockResponseSchema, | ||
url: '/api/stock/user', | ||
}); | ||
|
||
export const useGetUserStock = () => { | ||
return useQuery({ | ||
queryKey: ['userStock'], | ||
queryFn: getUserStock, | ||
}); | ||
}; |
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 { useMutation } from '@tanstack/react-query'; | ||
import { PostLogout, PostLogoutSchema } from './schema'; | ||
import { post } from '@/apis/utils/post'; | ||
|
||
const postLogout = () => | ||
post<PostLogout>({ | ||
schema: PostLogoutSchema, | ||
url: '/api/auth/logout', | ||
}); | ||
|
||
export const usePostLogout = () => { | ||
return useMutation({ | ||
mutationKey: ['logout'], | ||
mutationFn: postLogout, | ||
}); | ||
}; |
22 changes: 22 additions & 0 deletions
22
packages/frontend/src/apis/queries/auth/usePostUserNickname.ts
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,22 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { PostUserNickname, PostUserNicknameSchema } from './schema'; | ||
import { post } from '@/apis/utils/post'; | ||
|
||
const postUserNickname = ({ nickname }: { nickname: string }) => | ||
post<PostUserNickname>({ | ||
params: { nickname }, | ||
schema: PostUserNicknameSchema, | ||
url: '/api/user/info', | ||
}); | ||
|
||
export const usePostUserNickname = ({ nickname }: { nickname: string }) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationKey: ['userNickname'], | ||
mutationFn: () => postUserNickname({ nickname }), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: ['userInfo'] }); | ||
}, | ||
}); | ||
}; |
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
17 changes: 17 additions & 0 deletions
17
packages/frontend/src/apis/queries/stocks/useGetStockIndex.ts
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 { useQuery } from '@tanstack/react-query'; | ||
import { z } from 'zod'; | ||
import { StockIndexSchema, type StockIndexResponse } from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getStockIndex = () => | ||
get<StockIndexResponse[]>({ | ||
schema: z.array(StockIndexSchema), | ||
url: `/api/stock/index`, | ||
}); | ||
|
||
export const useGetStockIndex = () => { | ||
return useQuery({ | ||
queryKey: ['stockIndex'], | ||
queryFn: getStockIndex, | ||
}); | ||
}; |
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,70 @@ | ||
import { useState } from 'react'; | ||
import { useGetUserInfo } from '@/apis/queries/auth/useGetUserInfo'; | ||
import { usePostLogout } from '@/apis/queries/auth/usePostLogout'; | ||
import { usePostUserNickname } from '@/apis/queries/auth/usePostUserNickname'; | ||
import { Button } from '@/components/ui/button'; | ||
import { Input } from '@/components/ui/input'; | ||
|
||
export const UserInfo = () => { | ||
const [isEdit, setIsEdit] = useState(false); | ||
const [newNickname, setNewNickname] = useState(''); | ||
|
||
const { data } = useGetUserInfo(); | ||
const { email, nickname } = data || {}; | ||
|
||
const { mutate: editNickname } = usePostUserNickname({ | ||
nickname: newNickname, | ||
}); | ||
const { mutate: logout } = usePostLogout(); | ||
|
||
return ( | ||
<div className="flex flex-col gap-5"> | ||
<section className="flex justify-between"> | ||
<div className="display-medium14 text-gray flex gap-3"> | ||
<h2 className="display-bold20 text-black">내정보</h2> | ||
{isEdit ? ( | ||
<> | ||
<button | ||
onClick={() => { | ||
editNickname(); | ||
setIsEdit(false); | ||
}} | ||
> | ||
완료 | ||
</button> | ||
<button onClick={() => setIsEdit(false)}>취소</button> | ||
</> | ||
) : ( | ||
<button onClick={() => setIsEdit(true)}>수정</button> | ||
)} | ||
</div> | ||
<Button | ||
onClick={() => { | ||
logout(); | ||
location.reload(); | ||
}} | ||
> | ||
로그아웃 | ||
</Button> | ||
</section> | ||
<section className="flex flex-col gap-3 [&>div]:flex [&>div]:gap-4"> | ||
<div> | ||
<span className="text-gray">이메일</span> | ||
<span className="text-dark-gray">{email}</span> | ||
</div> | ||
<div> | ||
<span className="text-gray">닉네임</span> | ||
{isEdit ? ( | ||
<Input | ||
defaultValue={nickname} | ||
autoFocus | ||
onChange={(e) => setNewNickname(e.target.value)} | ||
/> | ||
) : ( | ||
<span className="text-dark-gray">{nickname}</span> | ||
)} | ||
</div> | ||
</section> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.