-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 예약 메일 API 연동 #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: 예약 메일 API 연동 #111
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
79db29c
fix: 사용자 이름 setName 오류 해결
hyeeuncho e2aeab0
fix: user put요청 필드 수정
hyeeuncho 380a306
feat: 예약 메일 발송 api 연동
hyeeuncho f51ef18
feat: 예약 메일 조회 api 연동
hyeeuncho 8db9498
feat: 예약 메일 수정 api 연동
hyeeuncho 329c80a
feat: 예약 메일 삭제 api 연동
hyeeuncho 1cdc7b9
refact: React Query의 queryClient사용하여 부분 데이터 업데이트
hyeeuncho 3680e0c
feat: 티켓별 이메일 보내기 구현
hyeeuncho a47de35
refact: 예약 메일 시간 포맷 변경
hyeeuncho b8cf849
refact: 구매자 메일 조회 로직 변경
hyeeuncho 4116f3f
refact: api 타입 명시
hyeeuncho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
| import { axiosClient } from '../../../shared/types/api/http-client'; | ||
| import { EmailRequest, ReadEmailResponse } from '../model/emailInformation'; | ||
|
|
||
| export const readEmail = async (eventId: number, status: 'PENDING' | 'SENT'): Promise<ReadEmailResponse[]> => { | ||
| const response = await axiosClient.get<{ result: ReadEmailResponse[] }>( | ||
| `/reservation-emails`, | ||
| { | ||
| params: { | ||
| eventId, | ||
| status, | ||
| }, | ||
| } | ||
| ); | ||
| return response.data.result; | ||
| } | ||
|
|
||
| export const sendEmail = async (data: EmailRequest) => { | ||
| const response = await axiosClient.post('/reservation-emails', data); | ||
| return response.data.result; | ||
| }; | ||
|
|
||
| export const editEmail = async (reservationEmailId: number, data: EmailRequest) => { | ||
| const response = await axiosClient.put(`/reservation-emails/${reservationEmailId}`, data); | ||
| return response.data.result; | ||
| }; | ||
|
|
||
| export const deleteEmail = async (reservationEmailId: number) => { | ||
| const response = await axiosClient.delete(`/reservation-emails/${reservationEmailId}`); | ||
| return response.data.result; | ||
| } |
This file contains hidden or 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,60 @@ | ||
| import { useMutation, useQuery } from '@tanstack/react-query'; | ||
| import { sendEmail, editEmail, readEmail, deleteEmail } from '../api/mail'; | ||
| import { EmailRequest, EmailResponse, ReadEmailResponse } from '../model/emailInformation'; | ||
| import { useNavigate, useParams } from 'react-router-dom'; | ||
| import { useEmailStore } from '../model/EmailStore'; | ||
|
|
||
| export const useReadEmail = (eventId: number, status: 'PENDING' | 'SENT') => { | ||
| return useQuery<ReadEmailResponse[]>({ | ||
| queryKey: ['emails', eventId, status], | ||
| queryFn: () => readEmail(eventId, status), | ||
| enabled: !!eventId && !!status, | ||
| }); | ||
| } | ||
|
|
||
| export const useSendEmail = () => { | ||
| const { id } = useParams(); | ||
| const navigate = useNavigate(); | ||
| const { reset } = useEmailStore(); | ||
| return useMutation<EmailResponse, Error, EmailRequest>({ | ||
| mutationFn: sendEmail, | ||
| onSuccess: () => { | ||
| reset(); | ||
| alert("예약 메일이 성공적으로 발송되었습니다!"); | ||
| navigate(`/dashboard/${id}/mailBox`); | ||
| }, | ||
| onError: () => { | ||
| alert("메일 전송에 실패했습니다. 다시 시도해 주세요."); | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export const useEditEmail = () => { | ||
| const { id } = useParams(); | ||
| const navigate = useNavigate(); | ||
| const { reset } = useEmailStore(); | ||
| return useMutation<EmailResponse, Error, { reservationEmailId: number; data: EmailRequest }>({ | ||
| mutationFn: ({ reservationEmailId, data }) => editEmail(reservationEmailId, data), | ||
| onSuccess: () => { | ||
| reset(); | ||
| alert("예약 메일이 성공적으로 수정되었습니다!"); | ||
| navigate(`/dashboard/${id}/mailBox`); | ||
| }, | ||
| onError: () => { | ||
| alert("메일 수정에 실패했습니다. 다시 시도해 주세요."); | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export const useDeleteEmail = () => { | ||
| return useMutation<EmailResponse, Error, number>({ | ||
| mutationFn: (reservationEmailId) => deleteEmail(reservationEmailId), | ||
| onSuccess: () => { | ||
| alert("메일이 삭제되었습니다."); | ||
| window.location.reload(); | ||
| }, | ||
| onError: () => { | ||
| alert("메일 삭제에 실패했습니다. 다시 시도해 주세요."); | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or 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,41 @@ | ||
| import { create } from 'zustand'; | ||
|
|
||
| interface EmailState { | ||
| reservationEmailId: number; | ||
| title: string; | ||
| content: string; | ||
| recipients: string[]; | ||
| reservationDate: string; // 'YYYY-MM-DD' | ||
| reservationTime: string; // 'HH:mm' | ||
| setReservationEmailId: (reservationEmailId: number) => void; | ||
| setTitle: (title: string) => void; | ||
| setContent: (content: string) => void; | ||
| setRecipients: (recipients: string[]) => void; | ||
| setReservationDate: (date: string) => void; | ||
| setReservationTime: (time: string) => void; | ||
| reset: () => void; | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const useEmailStore = create<EmailState>((set) => ({ | ||
| reservationEmailId: 0, | ||
| title: '', | ||
| content: '', | ||
| recipients: [], | ||
| reservationDate: '', | ||
| reservationTime: '', // 추후 2개 통합 예정 | ||
| setReservationEmailId: (reservationEmailId) => set({reservationEmailId}), | ||
| setTitle: (title) => set({ title }), | ||
| setContent: (content) => set({ content }), | ||
| setRecipients: (recipients) => set({ recipients }), | ||
| setReservationDate: (date) => set({ reservationDate: date }), | ||
| setReservationTime: (time) => set({ reservationTime: time }), | ||
| reset: () => | ||
| set({ | ||
| reservationEmailId: 0, | ||
| title: '', | ||
| content: '', | ||
| recipients: [], | ||
| reservationDate: '', | ||
| reservationTime: '', | ||
| }), | ||
| })); | ||
This file contains hidden or 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,22 @@ | ||
| export interface EmailRequest { | ||
| eventId: number; | ||
| title: string; | ||
| content: string; | ||
| recipients: string[]; | ||
| reservationDate: string; | ||
| reservationTime: string; | ||
| } | ||
| export interface EmailResponse { | ||
| isSuccess: boolean; | ||
| code: string; | ||
| message: string; | ||
| result: string; | ||
| } | ||
| export interface ReadEmailResponse { | ||
| id: number; | ||
| title: string; | ||
| content: string; | ||
| recipients: string[]; | ||
| reservationDate: string; | ||
| reservationTime: string; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.