diff --git a/src/api/hooks/Mail/useGetMailBusiness.tsx b/src/api/hooks/Mail/useGetMailBusiness.tsx index 38f2a41..abf32af 100644 --- a/src/api/hooks/Mail/useGetMailBusiness.tsx +++ b/src/api/hooks/Mail/useGetMailBusiness.tsx @@ -6,18 +6,20 @@ 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 createApiClient = () => { + const token = sessionStorage.getItem('accessToken'); + return axios.create({ + baseURL: BASE_URL, + headers: { + Authorization: `Bearer ${token}`, + Job: 'business', + }, + }); +}; const getMailBusiness = async (page: number, size: number) => { try { + const apiClient = createApiClient(); const response = await apiClient.get(getMailPath(page, size)); return response.data; } catch (error) { diff --git a/src/api/hooks/Mail/useGetMailUniv.tsx b/src/api/hooks/Mail/useGetMailUniv.tsx index 79e5e7d..939296d 100644 --- a/src/api/hooks/Mail/useGetMailUniv.tsx +++ b/src/api/hooks/Mail/useGetMailUniv.tsx @@ -6,18 +6,20 @@ 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: `univ`, - }, -}); +const createApiClient = () => { + const token = sessionStorage.getItem('accessToken'); + return axios.create({ + baseURL: BASE_URL, + headers: { + Authorization: `Bearer ${token}`, + Job: 'univ', + }, + }); +}; const getMailUniv = async (page: number, size: number) => { try { + const apiClient = createApiClient(); const response = await apiClient.get(getMailPath(page, size)); return response.data; } catch (error) { diff --git a/src/api/hooks/Mail/usePostMail.tsx b/src/api/hooks/Mail/usePostMail.tsx index ac86a5d..c76d829 100644 --- a/src/api/hooks/Mail/usePostMail.tsx +++ b/src/api/hooks/Mail/usePostMail.tsx @@ -4,17 +4,21 @@ import { BASE_URL } from '../..'; import { useMutation } from '@tanstack/react-query'; export const postMailPath = () => `${BASE_URL}/save-email`; -const token = sessionStorage.getItem('accessToken'); -const apiClient = axios.create({ - baseURL: BASE_URL, - headers: { - Authorization: `Bearer ${token}`, - }, -}); +const createApiClient = () => { + const token = sessionStorage.getItem('accessToken'); + + return axios.create({ + baseURL: BASE_URL, + headers: { + Authorization: `Bearer ${token}`, + }, + }); +}; const postMail = async (mailInput: MailPostData) => { try { + const apiClient = createApiClient(); const response = await apiClient.post(postMailPath(), mailInput); return response.data; } catch (error) { diff --git a/src/components/Layout/Header/HeaderWithout.tsx b/src/components/Layout/Header/HeaderWithout.tsx index 12643ee..38d9c67 100644 --- a/src/components/Layout/Header/HeaderWithout.tsx +++ b/src/components/Layout/Header/HeaderWithout.tsx @@ -1,5 +1,5 @@ import styled from '@emotion/styled'; -import { Link } from 'react-router-dom'; +import { Link, useNavigate } from 'react-router-dom'; import { Button } from '@chakra-ui/react'; import { breakpoints } from '@/styles/variants'; import { useMail } from '@/Provider/MailContext'; @@ -13,6 +13,7 @@ export const Header = () => { throw new Error('MailContext not found'); } const { handleMail } = mailContext; + const navigate = useNavigate(); const handleMailInput = () => { handleMail({ @@ -23,6 +24,7 @@ export const Header = () => { subject: '', receiver: '', }); + navigate(RouterPath.mail); }; const { authInfo } = useAuth(); @@ -46,9 +48,7 @@ export const Header = () => {
- - AI 메일 생성하기 - + AI 메일 생성하기