-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 changed file
with
35 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,3 +1,37 @@ | ||
import { BASE_URL } from '@/api'; | ||
import axios from 'axios'; | ||
import { MailListResponse } from '@/types'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export const getMailPath = () => `${BASE_URL}/`; | ||
export const getMailPath = (page: number, size: number) => | ||
`${BASE_URL}/emails?page=${page}&size=${size}`; | ||
|
||
const token = sessionStorage.getItem('accessToken'); | ||
|
||
const apiClient = axios.create({ | ||
baseURL: BASE_URL, | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
job: `univ`, | ||
}, | ||
}); | ||
|
||
const getMailUniv = async (page: number, size: number) => { | ||
try { | ||
const response = await apiClient.get<MailListResponse>(getMailPath(page, size)); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error fetching mail:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const useGetMailUniv = (page: number, size: number) => { | ||
const { | ||
data: univData, | ||
isLoading: univLoading, | ||
isError: univError, | ||
} = useQuery({ queryKey: ['emails', page, size], queryFn: () => getMailUniv(page, size) }); | ||
|
||
return { univData, univLoading, univError }; | ||
}; |