Skip to content

Commit

Permalink
feat: getmailbusiness 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
seung365 committed Aug 7, 2024
1 parent a6ef3e2 commit 9a0ba6b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/api/hooks/Mail/useGetMailBusiness.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { BASE_URL } from '@/api';
import axios from 'axios';
import { MailListResponse } from '@/types';
import { useQuery } from '@tanstack/react-query';

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: `business`,
},
});

const getMailBusiness = 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 useGetMailBusiness = (page: number, size: number) => {
const {
data: businessData,
isLoading: businessLoading,
isError: businessError,
} = useQuery({ queryKey: ['emails', page, size], queryFn: () => getMailBusiness(page, size) });
return { businessData, businessLoading, businessError };
};

0 comments on commit 9a0ba6b

Please sign in to comment.