From a6ef3e2866440586a02810241f09caaf8a6341d0 Mon Sep 17 00:00:00 2001 From: seung365 Date: Thu, 8 Aug 2024 02:06:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20getmailuniv=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/hooks/Mail/useGetMailUniv.tsx | 36 ++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/api/hooks/Mail/useGetMailUniv.tsx b/src/api/hooks/Mail/useGetMailUniv.tsx index 889c733..17cc5d8 100644 --- a/src/api/hooks/Mail/useGetMailUniv.tsx +++ b/src/api/hooks/Mail/useGetMailUniv.tsx @@ -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(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 }; +};