Skip to content

Commit

Permalink
[#15] orderReview와 ordeDetail 페이지에서 사용하는 모달 컴포넌트 통합을 위한 코드 수정
Browse files Browse the repository at this point in the history
orderReview와 ordeDetail 페이지에서 사용하는 모달 컴포넌트 통합을 위한 코드 수정
  • Loading branch information
Joonhyung-Choi committed Apr 30, 2023
1 parent 372de03 commit b515989
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 119 deletions.
35 changes: 23 additions & 12 deletions pages/orderDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@ import { DetailBottm } from "../src/components/orderDetailPage/Detailbottom";
import { useRouter } from "next/router";
import axios from "axios";
import { useEffect, useState } from "react";
import { ErrorModal } from "../src/components/orderDetailPage/ErrorModal";
import { ReviewModal } from "../src/components/modal/ReviewModal";

export default function OrderDetail() {
const router = useRouter();
const id = router.query.id;
const [detailDataState, setDetailDataState] = useState<any>();
const [errorModalState, setErrorModalState] = useState<{
const [modalState, setModalState] = useState<{
modalRole: string;
state: boolean;
text: string;
}>({ state: false, text: "" });
onClickConfirmButton: () => void;
}>({ modalRole: "", state: false, text: "", onClickConfirmButton: () => {} });

function getErrorModalState(modalState: { state: boolean; text: string }) {
setErrorModalState(modalState);
function getModalState(modalState: {
modalRole: string;
state: boolean;
text: string;
onClickConfirmButton: () => void;
}) {
setModalState(modalState);
}

const getDetailData = async () => {
Expand All @@ -44,18 +51,22 @@ export default function OrderDetail() {

return (
<Wrapper>
<ErrorModal
errorModalState={errorModalState}
getErrorModalState={getErrorModalState}
></ErrorModal>
<ReviewModal
modalState={modalState}
getModalState={getModalState}
></ReviewModal>
<DetailTop />
<DetailContnets detailData={detailDataState && detailDataState} />
<DetailContnets
detailData={detailDataState && detailDataState}
modalState={modalState}
getModalState={getModalState}
/>
<DetailBottm
id={detailDataState && detailDataState.id}
like={detailDataState && detailDataState.like}
progress={detailDataState && detailDataState.state}
errorModalState={errorModalState}
getErrorModalState={getErrorModalState}
modalState={modalState}
getModalState={getModalState}
/>
</Wrapper>
);
Expand Down
56 changes: 40 additions & 16 deletions src/components/orderDetailPage/DetailContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,52 @@ type contentsTypes = {
db: any;
starRating: any;
};

type propTypes = {
detailData: contentsTypes;
modalState: {
modalRole: string;
state: boolean;
text: string;
onClickConfirmButton: () => void;
};
getModalState: (modalState: {
modalRole: string;
state: boolean;
text: string;
onClickConfirmButton: () => void;
}) => void;
};

export const DetailContnets = ({
detailData,
}: {
detailData: contentsTypes;
}) => {
modalState,
getModalState,
}: propTypes) => {
const router = useRouter();

const onClickOrderCancelButton = async () => {
try {
const response = await axios.delete(
`http://localhost:8080/orders/${detailData.id}`,
{
headers: {
Authorization: `${localStorage.getItem("token")}`,
},
getModalState({
modalRole: "confirm",
state: true,
text: "정말로 발주를 취소하시겠습니까?",
onClickConfirmButton: async () => {
try {
const response = await axios.delete(
`http://localhost:8080/orders/${detailData.id}`,
{
headers: {
Authorization: `${localStorage.getItem("token")}`,
},
}
);
console.log(response);
} catch (err) {
console.log(err);
}
);
console.log(response);
} catch (err) {
console.log(err);
}
router.back();
router.back();
},
});
};

//이거는 발주 상태 변경 테스트용
Expand Down
25 changes: 20 additions & 5 deletions src/components/orderDetailPage/Detailbottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ type propTypes = {
id: number;
like: number;
progress: string;
errorModalState: { state: boolean; text: string };
getErrorModalState: (modalState: { state: boolean; text: string }) => void;
modalState: {
modalRole: string;
state: boolean;
text: string;
onClickConfirmButton: () => void;
};
getModalState: (modalState: {
modalRole: string;
state: boolean;
text: string;
onClickConfirmButton: () => void;
}) => void;
};

export const DetailBottm = ({
id,
like,
progress,
errorModalState,
getErrorModalState,
modalState,
getModalState,
}: propTypes) => {
//
const router = useRouter();
Expand All @@ -37,7 +47,12 @@ export const DetailBottm = ({
);
console.log(response);
} catch (err: any) {
getErrorModalState({ state: true, text: err.response.data.error });
getModalState({
modalRole: "likeMyOrder",
state: true,
text: err.response.data.error,
onClickConfirmButton: () => {},
});
console.log(err.response.data.error);
}
};
Expand Down
86 changes: 0 additions & 86 deletions src/components/orderDetailPage/ErrorModal.tsx

This file was deleted.

0 comments on commit b515989

Please sign in to comment.