-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π κ΄λ¦¬μ νλ‘ν λΆλ¬μ€κΈ° #89
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AxiosError } from 'axios'; | ||
import { cookies } from 'next/headers'; | ||
import { NextResponse } from 'next/server'; | ||
import { apiClient } from '@/shared/libs/apiClient'; | ||
|
||
export async function GET() { | ||
const cookieStore = cookies(); | ||
const accessToken = cookieStore.get('accessToken')?.value; | ||
|
||
try { | ||
const response = await apiClient.get('/admin/my', { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
return NextResponse.json(response.data, { status: response.status }); | ||
} catch (error) { | ||
const axiosError = error as AxiosError<{ message: string }>; | ||
const status = axiosError.response?.status || 500; | ||
const message = | ||
axiosError.response?.data?.message || 'admin data get failed'; | ||
return NextResponse.json({ error: message }, { status }); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React, { useState } from 'react'; | ||
import { Logout } from '@/shared/assets/icons'; | ||
import { AdminData } from '@/shared/types/admin/type'; | ||
import { useDeleteUserAccount } from '../../model/useDeleteUserAccount'; | ||
import { useLogout } from '../../model/useLogout'; | ||
|
||
|
@@ -10,7 +11,7 @@ const ProfileInfo = ({ label, value }: { label: string; value: string }) => ( | |
</div> | ||
); | ||
|
||
const AdminProfile = () => { | ||
const AdminProfile = ({ data }: { data: AdminData }) => { | ||
const { mutate: logout } = useLogout(); | ||
const { mutate: deleteAccount } = useDeleteUserAccount(); | ||
const [isToggleLogout, setIsToggleLogout] = useState(false); | ||
|
@@ -23,9 +24,9 @@ const AdminProfile = () => { | |
<div className="relative flex w-full justify-between"> | ||
<div className="flex items-center gap-[124px] mobile:flex-col mobile:gap-[30px]"> | ||
<div className="space-y-[32px]"> | ||
<ProfileInfo label="μ΄λ¦" value="κΉμ§μ" /> | ||
<ProfileInfo label="μμ΄λ" value="jin1234" /> | ||
<ProfileInfo label="μ΄λ©μΌ" value="[email protected]" /> | ||
<ProfileInfo label="μ΄λ¦" value={data.name} /> | ||
<ProfileInfo label="μμ΄λ" value={data.nickname} /> | ||
<ProfileInfo label="μ΄λ©μΌ" value={data.email} /> | ||
</div> | ||
</div> | ||
<div> | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||
import axios from 'axios'; | ||||||||||||||||||||||||||||
import { ExpoItem, SignUpItem } from '@/shared/types/admin/type'; | ||||||||||||||||||||||||||||
import { AdminData, ExpoItem, SignUpItem } from '@/shared/types/admin/type'; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export const getExpoList = async (): Promise<ExpoItem[]> => { | ||||||||||||||||||||||||||||
const response = await axios.get('/api/expo'); | ||||||||||||||||||||||||||||
|
@@ -10,3 +10,8 @@ export const getRequestSignUp = async (): Promise<SignUpItem[]> => { | |||||||||||||||||||||||||||
const response = await axios.get('/api/admin'); | ||||||||||||||||||||||||||||
return response.data; | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export const getAdminData = async (): Promise<AdminData> => { | ||||||||||||||||||||||||||||
const response = await axios.get('/api/admin/my'); | ||||||||||||||||||||||||||||
return response.data; | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion μλ¬ μ²λ¦¬ λ‘μ§ μΆκ° νμ API νΈμΆ μ€ν¨ μμ μλ¬ μ²λ¦¬κ° λλ½λμ΄ μμ΅λλ€. try-catch λΈλ‘μ μΆκ°νμ¬ μλ¬λ₯Ό μ μ ν μ²λ¦¬ν΄ μ£ΌμΈμ. λ€μκ³Ό κ°μ΄ μμ νλ κ²μ μ μν©λλ€: export const getAdminData = async (): Promise<AdminData> => {
- const response = await axios.get('/api/admin/my');
- return response.data;
+ try {
+ const response = await axios.get('/api/admin/my');
+ return response.data;
+ } catch (error) {
+ console.error('κ΄λ¦¬μ λ°μ΄ν° μ‘°ν μ€ν¨:', error);
+ throw error;
+ }
}; π Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,10 @@ | ||||||
import { useQuery } from '@tanstack/react-query'; | ||||||
import { ExpoItem, SignUpItem } from '@/shared/types/admin/type'; | ||||||
import { getExpoList, getRequestSignUp } from '../api/getAdminData'; | ||||||
import { AdminData, ExpoItem, SignUpItem } from '@/shared/types/admin/type'; | ||||||
import { | ||||||
getAdminData, | ||||||
getExpoList, | ||||||
getRequestSignUp, | ||||||
} from '../api/getAdminData'; | ||||||
|
||||||
export const useAdminData = () => { | ||||||
const expoListData = useQuery<ExpoItem[], Error>({ | ||||||
|
@@ -13,7 +17,15 @@ export const useAdminData = () => { | |||||
queryFn: getRequestSignUp, | ||||||
}); | ||||||
|
||||||
const isLoading = expoListData.isLoading || requestSignUpData.isLoading; | ||||||
const requestAdminData = useQuery<AdminData, Error>({ | ||||||
queryKey: ['requestAdnubData'], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 쿼리 ν€μ μ€νλ₯Ό μμ ν΄ μ£ΌμΈμ 'requestAdnubData'μ μ€νκ° μμ΅λλ€. λ€μκ³Ό κ°μ΄ μμ νλ κ²μ μ μν©λλ€: - queryKey: ['requestAdnubData'],
+ queryKey: ['requestAdminData'], π Committable suggestion
Suggested change
|
||||||
queryFn: getAdminData, | ||||||
}); | ||||||
|
||||||
const isLoading = | ||||||
expoListData.isLoading || | ||||||
requestSignUpData.isLoading || | ||||||
requestAdminData.isLoading; | ||||||
|
||||||
return { expoListData, requestSignUpData, isLoading }; | ||||||
return { expoListData, requestSignUpData, requestAdminData, isLoading }; | ||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν ν° μ ν¨μ± κ²μ¬ μΆκ° νμ
accessTokenμ΄ μλ κ²½μ°μ λν μ²λ¦¬κ° λλ½λμ΄ μμ΅λλ€.
λ€μκ³Ό κ°μ΄ μμ νλ κ²μ μ μν©λλ€:
π Committable suggestion