-
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.
- Loading branch information
Showing
6 changed files
with
34 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import axios from 'axios'; | ||
|
||
const PATH = '/api/v1/admin/users'; | ||
|
||
const BASE_URL = import.meta.env.VITE_API_URL; | ||
|
||
const deleteUserApi = async (userId: number | number[]) => { | ||
const accessToken = localStorage.getItem('accessToken'); | ||
const userIds = Array.isArray(userId) ? userId : [userId]; | ||
|
||
try { | ||
const queryParam = userIds.map((id) => `userId=${id}`).join('&'); | ||
const url = `${BASE_URL}${PATH}?${queryParam}`; | ||
const response = await axios.delete(url, { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
return response.data; | ||
} catch (error: any) { | ||
throw new Error(error.response?.data?.message || '유저 추방 실패'); | ||
} | ||
}; | ||
|
||
export default deleteUserApi; |
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,40 +1,16 @@ | ||
import { useEffect, useState } from 'react'; | ||
import axios from 'axios'; | ||
|
||
const BASE_URL = import.meta.env.VITE_API_URL; | ||
|
||
export const getAllUsers = async (orderBy = 'NAME_ASCENDING') => { | ||
const getAllUsers = async (orderBy = 'NAME_ASCENDING') => { | ||
const accessToken = localStorage.getItem('accessToken'); | ||
const refreshToken = localStorage.getItem('refreshToken'); | ||
|
||
return axios.get(`${BASE_URL}/api/v1/admin/users/all`, { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
Authorization_refresh: `Bearer ${refreshToken}`, | ||
}, | ||
params: { orderBy }, | ||
}); | ||
}; | ||
|
||
export const useGetAllUsers = () => { | ||
const [allUsers, setAllUsers] = useState<any[]>([]); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchUsers = async () => { | ||
try { | ||
const response = await getAllUsers(); | ||
setAllUsers(response.data.data); | ||
setError(null); | ||
} catch (err: any) { | ||
setError(err.response?.data?.message); | ||
} | ||
}; | ||
|
||
fetchUsers(); | ||
}, []); | ||
|
||
return { allUsers, error }; | ||
}; | ||
|
||
export default useGetAllUsers; | ||
export default getAllUsers; |
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