Skip to content

Commit

Permalink
fix: 공연 삭제 로직 수정
Browse files Browse the repository at this point in the history
alert의 okText를 누르면 검사하던 예매자 존재 여부를 헤더의 삭제 버튼 클릭시 검사하도록 변경
useEffect의 인자로 isBookerExist 추가하여 예매자 존재 여부 함수 내부에서 받아오지 못하던 오류 수정
  • Loading branch information
pepperdad committed Aug 13, 2024
1 parent 4edd187 commit 2aee951
Showing 1 changed file with 32 additions and 47 deletions.
79 changes: 32 additions & 47 deletions src/pages/modifyManage/ModifyManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
TextField,
TimePicker,
} from "@components/commons";

import MetaTag from "@components/commons/meta/MetaTag";
import { NAVIGATION_STATE } from "@constants/navigationState";
import { useHeader, useModal } from "@hooks";
import Content from "@pages/gig/components/content/Content";
Expand All @@ -34,12 +34,11 @@ import { GENRE_LIST } from "./constants/genreList";
import * as S from "./ModifyManage.styled";
import { BANK_TYPE, Cast, DataProps, Schedule, Staff } from "./typings/gigInfo";
import { isAllFieldsFilled } from "./utils/handleEvent";
import MetaTag from "@components/commons/meta/MetaTag";

const ModifyManage = () => {
const [ModifyManageStep, setModifyManageStep] = useState(1); // 등록 step 나누기
const [modifyManageStep, setModifyManageStep] = useState(1); // 등록 step 나누기
const { openConfirm, closeConfirm, openAlert, closeAlert } = useModal();
// gigInfo 초기화

const { performanceId } = useParams();
const navigate = useNavigate();

Expand Down Expand Up @@ -85,6 +84,7 @@ const ModifyManage = () => {
setPerformanceContact(data.performanceContact);
setTicketPrice(data.ticketPrice);
setTotalScheduleCount(data.totalScheduleCount);
setIsExist(data.isBookerExist);
setScheduleList(
data.scheduleList.map((item) => ({
scheduleId: item.scheduleId ?? -1,
Expand Down Expand Up @@ -123,7 +123,6 @@ const ModifyManage = () => {

const { mutateAsync: updatePerformance } = useUpdatePerformance();

//여기서 공연 수정하기 PUT 요청 보내야함
const handleComplete = async () => {
const filteredCastList = castList.filter(
(cast) => cast.castName || cast.castRole || cast.castPhoto
Expand Down Expand Up @@ -183,14 +182,6 @@ const ModifyManage = () => {
setIsChecked(e.target.checked);
};

useEffect(() => {
setIsExist(data?.isBookerExist);
}, [data?.isBookerExist]);

// useEffect(() => {
// setBankInfo(bankName);
// }, [bankName]);

// 티켓 가격이 무료일 때 가격을 0으로 설정하고 수정 불가능하게 함
useEffect(() => {
if (isFree) {
Expand All @@ -214,7 +205,7 @@ const ModifyManage = () => {
const { setHeader } = useHeader();

const handleLeftBtn = () => {
if (ModifyManageStep === 1) {
if (modifyManageStep === 1) {
openConfirm({
title: "수정을 취소할까요?",
subTitle: "페이지를 나갈 경우, 내용이 저장되지 않아요.",
Expand Down Expand Up @@ -244,63 +235,57 @@ const ModifyManage = () => {
setTicketPrice(numericValue);
};

const { mutate, mutateAsync } = usePerformanceDelete();
const { mutate, mutateAsync: deletePerformance } = usePerformanceDelete();

const handleDeletePerformance = async (_performanceId: number) => {
await deletePerformance(Number(performanceId));

const handleDeletePerformance = async (_performanceId: number, isExisttt: boolean) => {
//사용자가 한명 이상 있으면 안된다는 문구 띄움 - 동훈이가 수정 시 공연 정보 조회 API (GET)에 COUNT나 bookingList를 넘겨줄 듯
console.log("isExisttt", isExisttt);
openAlert({
title: "공연이 삭제되었습니다.",
okText: "확인했어요",
okCallback: () => navigate("/gig-manage"),
});
};

if (isExisttt) {
const handleRightBtn = () => {
if (isBookerExist) {
openAlert({
title: "공연 삭제가 불가해요.",
subTitle: "예매자가 1명 이상 있을 경우, 삭제할 수 없어요.",
okText: "확인했어요",
okCallback: closeAlert,
});
} else {
//공연 삭제하는 로직 - performanceId 하나로 DELETE 요청 보내고,
mutateAsync(Number(performanceId));
navigate("/gig-manage");
openConfirm({
title: "공연을 삭제하시겠어요?",
subTitle: "삭제할 경우, 작성했던 내용을 되돌릴 수 없어요.",
okText: "삭제할게요",
okCallback: () => handleDeletePerformance(Number(performanceId)),
noText: "아니요",
noCallback: () => closeConfirm(),
});
}
};

const handleRightBtn = () => {
openConfirm({
title: "공연을 삭제하시겠어요?",
subTitle: "삭제할 경우, 작성했던 내용을 되돌릴 수 없어요.",
okText: "삭제할게요",
okCallback: () => {
//공연 수정 DELETE API 요청 쏘는 로직 존재할 예정
handleDeletePerformance(Number(performanceId), isBookerExist as boolean); //예시로 박아둠
},
noText: "아니요",
noCallback: () => {
closeConfirm();
},
});
};

useEffect(() => {
const pageTitle =
ModifyManageStep === 1
? "공연 수정하기"
: ModifyManageStep === 2
? "공연 수정하기"
: "미리보기";
modifyManageStep === 1 ? "공연 수정하기" : modifyManageStep === 2 ? "미리보기" : "";

setHeader({
headerStyle: NAVIGATION_STATE.ICON_TITLE_SUB_TEXT,
title: pageTitle,
subText: "삭제",
leftOnClick: handleLeftBtn,
rightOnClick: handleRightBtn,
rightOnClick: () => handleRightBtn(),
});
}, [setHeader, ModifyManageStep]);
}, [modifyManageStep, isBookerExist]);

if (isLoading) {
return <Loading />;
}

if (data) {
if (ModifyManageStep === 1) {
if (modifyManageStep === 1) {
return (
<>
<MetaTag title="공연 수정" />
Expand Down Expand Up @@ -546,7 +531,7 @@ const ModifyManage = () => {
// );
// }

if (ModifyManageStep === 2) {
if (modifyManageStep === 2) {
return (
<>
<MetaTag title="공연 수정" />
Expand Down

0 comments on commit 2aee951

Please sign in to comment.