forked from picktoss/pick-toss-next
-
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: update user name (picktoss#289)
* feat: 사용자 profile api 요청 함수 및 훅 구현 * feat: change user name
- Loading branch information
1 parent
0eaf7e7
commit 79616e0
Showing
9 changed files
with
290 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,9 +4,10 @@ import { cn } from '@/shared/lib/utils' | |
import CategoryDrawer from '@/features/user/components/category-drawer' | ||
import SetNameDialog from '@/features/user/components/set-name-dialog' | ||
import Link from 'next/link' | ||
import { fetchUserInfo } from '@/requests/user' | ||
|
||
const AccountPage = () => { | ||
const email = '[email protected]' | ||
const AccountPage = async () => { | ||
const user = await fetchUserInfo() | ||
|
||
return ( | ||
<main className="h-[calc(100dvh-54px-88px)] w-full overflow-y-auto px-[16px]"> | ||
|
@@ -25,9 +26,9 @@ const AccountPage = () => { | |
</div> | ||
|
||
<div className="flex flex-col gap-[32px]"> | ||
<SetNameDialog userName={'픽토스'} /> | ||
<SetNameDialog userName={user.name} /> | ||
|
||
<CategoryDrawer interestedCategory={'IT·프로그래밍'} /> | ||
<CategoryDrawer interestedCategory={user.interestField?.[0] ?? '관심 분야 없음'} /> | ||
|
||
<Link href={'verify-email'} className="flex w-full items-center justify-between"> | ||
<div className="flex flex-col items-start gap-[4px]"> | ||
|
@@ -38,9 +39,9 @@ const AccountPage = () => { | |
{/* 이메일 등록 여부에 따라 다르게 보여야함 */} | ||
<Text | ||
typography="subtitle2-medium" | ||
className={cn('text-text-caption', email && 'text-text-primary')} | ||
className={cn('text-text-caption', user.email && 'text-text-primary')} | ||
> | ||
{email ? email : '이메일 주소를 등록해주세요'} | ||
{user.email ? user.email : '이메일 주소를 등록해주세요'} | ||
</Text> | ||
</div> | ||
<Icon name="chevron-right" className="size-[16px] text-icon-tertiary" /> | ||
|
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,9 +1,11 @@ | ||
import * as directory from './directory' | ||
import * as document from './document' | ||
import * as quiz from './quiz' | ||
import * as user from './user' | ||
|
||
export const REQUEST = { | ||
directory, | ||
document, | ||
quiz, | ||
user, | ||
} |
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,55 @@ | ||
'use client' | ||
|
||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' | ||
import { | ||
fetchUserInfo, | ||
updateTodayQuizCount, | ||
updateQuizNotification, | ||
updateUserName, | ||
updateCollectionFields, | ||
} from '.' | ||
|
||
export const useUserInfo = () => { | ||
return useQuery({ | ||
queryKey: ['userInfo'], | ||
queryFn: async () => fetchUserInfo(), | ||
}) | ||
} | ||
|
||
export const useUpdateTodayQuizCount = () => { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation({ | ||
mutationFn: async (payload: User.Request.UpdateTodayQuizCount) => updateTodayQuizCount(payload), | ||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['userInfo'] }), | ||
}) | ||
} | ||
|
||
export const useUpdateQuizNotification = () => { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation({ | ||
mutationFn: async (payload: User.Request.UpdateQuizNotification) => | ||
updateQuizNotification(payload), | ||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['userInfo'] }), | ||
}) | ||
} | ||
|
||
export const useUpdateUserName = () => { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation({ | ||
mutationFn: async (payload: User.Request.UpdateName) => updateUserName(payload), | ||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['userInfo'] }), | ||
}) | ||
} | ||
|
||
export const useUpdateCollectionFields = () => { | ||
const queryClient = useQueryClient() | ||
|
||
return useMutation({ | ||
mutationFn: async (payload: User.Request.UpdateCollectionFields) => | ||
updateCollectionFields(payload), | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
'use server' | ||
|
||
import { auth } from '@/app/api/auth/[...nextauth]/auth' | ||
import { API_ENDPOINTS } from '@/shared/configs/endpoint' | ||
import { http } from '@/shared/lib/axios/http' | ||
|
||
export const fetchUserInfo = async () => { | ||
const session = await auth() | ||
|
||
try { | ||
const { data } = await http.get<User.Info>(API_ENDPOINTS.USER.GET.INFO, { | ||
headers: { | ||
Authorization: `Bearer ${session?.user.accessToken}`, | ||
}, | ||
}) | ||
return data | ||
} catch (error: unknown) { | ||
throw error | ||
} | ||
} | ||
|
||
export const updateTodayQuizCount = async (payload: User.Request.UpdateTodayQuizCount) => { | ||
const session = await auth() | ||
|
||
try { | ||
await http.patch(API_ENDPOINTS.USER.PATCH.UPDATE_QUIZ_COUNT, payload, { | ||
headers: { | ||
Authorization: `Bearer ${session?.user.accessToken}`, | ||
}, | ||
}) | ||
} catch (error: unknown) { | ||
throw error | ||
} | ||
} | ||
|
||
export const updateQuizNotification = async (payload: User.Request.UpdateQuizNotification) => { | ||
const session = await auth() | ||
|
||
try { | ||
await http.patch(API_ENDPOINTS.USER.PATCH.UPDATE_NOTIFICATION, payload, { | ||
headers: { | ||
Authorization: `Bearer ${session?.user.accessToken}`, | ||
}, | ||
}) | ||
} catch (error: unknown) { | ||
throw error | ||
} | ||
} | ||
|
||
export const updateUserName = async (payload: User.Request.UpdateName) => { | ||
const session = await auth() | ||
|
||
try { | ||
await http.patch(API_ENDPOINTS.USER.PATCH.UPDATE_NAME, payload, { | ||
headers: { | ||
Authorization: `Bearer ${session?.user.accessToken}`, | ||
}, | ||
}) | ||
} catch (error: unknown) { | ||
throw error | ||
} | ||
} | ||
|
||
export const updateCollectionFields = async (payload: User.Request.UpdateCollectionFields) => { | ||
const session = await auth() | ||
|
||
try { | ||
await http.patch(API_ENDPOINTS.USER.PATCH.UPDATE_COLLECTION_FIELDS, payload, { | ||
headers: { | ||
Authorization: `Bearer ${session?.user.accessToken}`, | ||
}, | ||
}) | ||
} catch (error: unknown) { | ||
throw error | ||
} | ||
} |
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
Oops, something went wrong.