Skip to content

Commit

Permalink
Merge pull request #312 from CheckMate-sookmyung/fix/#311-dashboard-api
Browse files Browse the repository at this point in the history
#311 fix: dashboard 내 다수 API 수정
  • Loading branch information
misung-dev authored Sep 18, 2024
2 parents 6d8d16e + f160a06 commit 0680596
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 54 deletions.
8 changes: 4 additions & 4 deletions src/apis/attendance.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { axiosInstance } from '@/axios';

export const getAttendanceList = async (userId, eventId) => {
export const getAttendanceList = async (eventId) => {
const { data } = await axiosInstance.get(
`/api/v1/attendance/list/${userId}/${eventId}`,
`/api/v1/events/attendanceList/${eventId}`,
);

return data;
};

export const updateAttendanceList = async (userId, eventId, body) => {
export const updateAttendanceList = async (eventId, body) => {
const { data } = await axiosInstance.put(
`/api/v1/attendance/list/${userId}/${eventId}`,
`/api/v1/attendance/list/${eventId}`,
body,
);

Expand Down
4 changes: 2 additions & 2 deletions src/apis/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const deleteEvent = async (eventId) => {
return data;
};

export const postEventManager = async (eventId, body) => {
const { data } = await axiosInstance.post(
export const putEventManager = async (eventId, body) => {
const { data } = await axiosInstance.put(
`/api/v1/events/manger/${eventId}`,
body,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,9 @@ const AttendanceStudentIdPage = () => {
};

useEffect(() => {
console.log('USER_ID:', USER_ID);
console.log('EVENT_ID:', EVENT_ID);
const fetchEventDetails = async () => {
try {
const response = await axiosInstance.get(
`/api/v1/events/${USER_ID}/${EVENT_ID}`,
);
const response = await axiosInstance.get(`/api/v1/events/${EVENT_ID}`);
const eventData = response.data;
setEventTitle(eventData.eventTitle);
setEventTarget(eventData.eventTarget);
Expand Down
27 changes: 12 additions & 15 deletions src/pages/DashboardPage/DashboardEmailPage/DashboardEmailPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export default function DashboardEmailPage() {
try {
const response = await axiosInstance.get(
`/api/v1/events/mail/content/${eventId}`,
{
params: {
mailType: 'REMIND',
},
},
);
if (response.status === 200) {
setEmailContent(response.data.content);
Expand All @@ -33,14 +38,11 @@ export default function DashboardEmailPage() {
fetchEmailContent();
}, [eventId]);

const handleInputChange = (e) => {
const newValue = e.target.value;
setSurveyUrl(newValue);
if (newValue !== '') {
setIsModified(true);
} else {
setIsModified(false);
}
const handleTextareaChange = (e) => {
const newEmailContent = e.target.value;

setEmailContent(newEmailContent);
setIsModified(newEmailContent !== '');
};

// 저장하기 버튼
Expand All @@ -51,7 +53,7 @@ export default function DashboardEmailPage() {

try {
const response = await axiosInstance.put(
`/api/v1/events/mail/content/{mailId}`,
`/api/v1/events/mail/content/${eventId}`,
);

if (response.status === 200) {
Expand Down Expand Up @@ -80,11 +82,6 @@ export default function DashboardEmailPage() {
<Button
label={isSaving ? '저장 중...' : '저장하기'}
onClick={handleSaveButtonClick}
disabled={!isModified || isSaving}
style={{
backgroundColor: isModified ? '#007bff' : '#ccc',
cursor: isModified ? 'pointer' : 'not-allowed',
}}
/>
</S.ButtonContainer>
</S.TopContainer>
Expand All @@ -104,7 +101,7 @@ export default function DashboardEmailPage() {
<Textarea
placeholder="행사 안내 메일 내용을 작성해 주세요."
value={emailContent}
onChange={(e) => setEmailContent(e.target.value)}
onChange={handleTextareaChange}
height="300px"
/>
)}
Expand Down
50 changes: 26 additions & 24 deletions src/pages/DashboardPage/DashboardPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, Sidebar, TopNavigation } from '@/components';
import { eventIDState } from '@/recoil/atoms/state';
import { useRecoilValue } from 'recoil';
import { Link, useNavigate } from 'react-router-dom';
import { deleteEvent, getEventDetail, postEventManager } from '@/apis';
import { deleteEvent, getEventDetail, putEventManager } from '@/apis';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';

export default function DashboardPage() {
Expand Down Expand Up @@ -46,21 +46,19 @@ export default function DashboardPage() {
},
});

const {
mutate: postEventManagerMutate,
isPending: isPostEventManagerPending,
} = useMutation({
mutationKey: ['postEventManager', eventId],
mutationFn: (body) => postEventManager(eventId, body),
onSuccess: () => {
queryClient.invalidateQueries(['getEventDetail']);
setIsEditing(false);
alert('연락처가 성공적으로 등록되었습니다.');
},
onError: () => {
alert('연락처 등록에 실패했습니다. 다시 시도해 주세요.');
},
});
const { mutate: putEventManagerMutate, isPending: isPutEventManagerPending } =
useMutation({
mutationKey: ['putEventManager', eventId],
mutationFn: (body) => putEventManager(eventId, body),
onSuccess: () => {
queryClient.invalidateQueries(['getEventDetail']);
setIsEditing(false);
alert('연락처가 성공적으로 등록되었습니다.');
},
onError: () => {
alert('연락처 등록에 실패했습니다. 다시 시도해 주세요.');
},
});

const handleEventDeleteButtonClick = () => {
const isConfirmed = window.confirm('행사를 완전히 삭제하시겠습니까?');
Expand Down Expand Up @@ -92,7 +90,7 @@ export default function DashboardPage() {
setEmailError(!isEmailValid);

if (isEditing && isNameValid && isPhoneValid && isEmailValid) {
postEventManagerMutate({
putEventManagerMutate({
manager: {
managerName: contacts.name,
managerPhoneNumber: contacts.phone,
Expand Down Expand Up @@ -145,6 +143,7 @@ export default function DashboardPage() {
if (scheduleEndDateTime < now) {
completedSessionsCount += 1;
}

return {
date: schedule.eventDate,
startTime: schedule.eventStartTime,
Expand Down Expand Up @@ -258,11 +257,13 @@ export default function DashboardPage() {
</S.EventTarget>
</S.EventTypeWrapper>
<S.EventDateWrapper>
{parsedEvents.schedules.map((schedule, index) => (
<S.EventDate key={index}>
{`• ${schedule.date} (${schedule.startTime} - ${schedule.endTime})`}
</S.EventDate>
))}
{eventDetail.eventSchedules.map(
({ eventScheduleId, eventDate, startTime, endTime }) => (
<S.EventDate key={eventScheduleId}>
{`• ${eventDate} (${startTime} - ${endTime})`}
</S.EventDate>
),
)}
</S.EventDateWrapper>
</S.ContentInfoWrapper>
</S.ContentBox>
Expand All @@ -277,7 +278,7 @@ export default function DashboardPage() {
</S.ContactTextWrapper>
<S.AddContactButton
type="button"
disabled={isPostEventManagerPending}
disabled={isPutEventManagerPending}
onClick={handleAddContactButtonClick}
>
{isEditing
Expand Down Expand Up @@ -401,7 +402,8 @@ export default function DashboardPage() {
</S.ProgressDescription>
</S.ProgressText>
<S.ProgressNumber>
<em>{averageAttendance}</em> / {parsedEvents.totalParticipants}
<em>{eventDetail.averageAttendees}</em>
{` / ${eventDetail.totalAttendees}`}
</S.ProgressNumber>
</S.ProgressBox>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export default function DashboardSurveyPage() {

try {
const response = await axiosInstance.put(
`/api/v1/events/survey/${eventId}`,
{
surveyUrl: surveyUrl,
},
`/api/v1/events/survey/${eventId}?surveyUrl=${surveyUrl}`,
);

if (response.status === 200) {
Expand Down

0 comments on commit 0680596

Please sign in to comment.