Skip to content

Commit 1cdc7b9

Browse files
committed
refact: React Query의 queryClient사용하여 부분 데이터 업데이트
1 parent 329c80a commit 1cdc7b9

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

src/features/dashboard/hook/useEmailHook.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQuery } from '@tanstack/react-query';
1+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
22
import { sendEmail, editEmail, readEmail, deleteEmail } from '../api/mail';
33
import { EmailRequest, EmailResponse, ReadEmailResponse } from '../model/emailInformation';
44
import { useNavigate, useParams } from 'react-router-dom';
@@ -47,11 +47,12 @@ export const useEditEmail = () => {
4747
};
4848

4949
export const useDeleteEmail = () => {
50+
const queryClient = useQueryClient();
5051
return useMutation<EmailResponse, Error, number>({
5152
mutationFn: (reservationEmailId) => deleteEmail(reservationEmailId),
5253
onSuccess: () => {
5354
alert("메일이 삭제되었습니다.");
54-
window.location.reload();
55+
queryClient.invalidateQueries({ queryKey: ['emails'] });
5556
},
5657
onError: () => {
5758
alert("메일 삭제에 실패했습니다. 다시 시도해 주세요.");

src/pages/dashboard/ui/ParticipantsMangementPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const ParticipantsManagementPage = () => {
5353
setEmailModalOpen(false);
5454
setTicketModalOpen(true);
5555
}}
56-
allParticipantEmails={participants.map((p: { email: any; }) => p.email)}
56+
allParticipantEmails={participants.map((p: { email: string; }) => p.email)}
5757
/>
5858
)}
5959
{ticketModalOpen && (

src/pages/dashboard/ui/mail/EmailEditPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const EmailEditPage = () => {
4444
<EmailInput
4545
type="이메일 내용 수정"
4646
openSelectTicket={() => setTicketModalOpen(true)}
47-
allParticipantEmails={participants.map((p: { email: any; }) => p.email)}
47+
allParticipantEmails={participants.map((p: { email: string; }) => p.email)}
4848
isEdited= {true}
4949
/>
5050
{/*시간 선택 컴포넌트*/}

src/pages/dashboard/ui/mail/EmailPage.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ const EmailPage = () => {
2626
} = useEmailStore();
2727

2828
const handleSend = () => {
29+
if (!title.trim()) {
30+
alert('제목을 입력해주세요.');
31+
return;
32+
}
33+
if (!content.trim()) {
34+
alert('내용을 입력해주세요.');
35+
return;
36+
}
37+
if (recipients.length === 0) {
38+
alert('수신자를 한 명 이상 선택해주세요.');
39+
return;
40+
}
41+
if (!reservationDate || !reservationTime) {
42+
alert('예약 날짜와 시간을 선택해주세요.');
43+
return;
44+
}
2945
const eventId = id ? parseInt(id) : 0;
3046
const emailData = {
3147
eventId,

src/widgets/dashboard/ui/EmailModal.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ const EmailModal = ({ onClose, openSelectTicket, allParticipantEmails }: EmailMo
2525
} = useEmailStore();
2626

2727
const handleSend = () => {
28+
if (!title.trim()) {
29+
alert('제목을 입력해주세요.');
30+
return;
31+
}
32+
if (!content.trim()) {
33+
alert('내용을 입력해주세요.');
34+
return;
35+
}
36+
if (recipients.length === 0) {
37+
alert('수신자를 한 명 이상 선택해주세요.');
38+
return;
39+
}
40+
if (!reservationDate || !reservationTime) {
41+
alert('예약 날짜와 시간을 선택해주세요.');
42+
return;
43+
}
2844
const eventId = id ? parseInt(id) : 0;
2945
const emailData = {
3046
eventId,

0 commit comments

Comments
 (0)