-
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.
Merge pull request #65 from Beside-Potenday/seungbeom
�메일 저장 버튼 추가
- Loading branch information
Showing
5 changed files
with
101 additions
and
5 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
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,36 @@ | ||
import { MailPostData } from '@/types'; | ||
import axios from 'axios'; | ||
import { BASE_URL } from '..'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
export const postMailPath = () => `${BASE_URL}/save-mail`; | ||
|
||
const apiClient = axios.create({ | ||
baseURL: BASE_URL, | ||
headers: { | ||
Authorization: `Bearer ${sessionStorage.getItem('accessToken')}`, | ||
}, | ||
}); | ||
|
||
const postMail = async (mailInput: MailPostData) => { | ||
try { | ||
const response = await apiClient.post<number>(postMailPath(), mailInput); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error posting mail:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const usePostMail = () => { | ||
const { mutate } = useMutation({ | ||
mutationFn: postMail, | ||
onSuccess: (result) => { | ||
console.log('Mail posted successfully:', result); | ||
}, | ||
onError: (error) => { | ||
console.error('Error posting mail:', error); | ||
}, | ||
}); | ||
return { mutate }; | ||
}; |
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