Skip to content

Commit

Permalink
Merge pull request #222 from SCBJ-7/feature/#212-saledetail-api
Browse files Browse the repository at this point in the history
구매내역 판매내역 NoResult처리
  • Loading branch information
chaeminseok authored Jan 25, 2024
2 parents ae7a311 + 3e74650 commit 789381b
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 39 deletions.
23 changes: 11 additions & 12 deletions src/apis/fetchSaleDetail.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// import { END_POINTS } from "@constants/api";
// import { axiosInstance } from "./axiosInstance";
import axios from "axios";
import { END_POINTS } from "@constants/api";
import { axiosInstance } from "./axiosInstance";
import type { ResponseData } from "@type/responseType";
import type { ISaleData } from "@type/saleDetail";

// FIXME as below (백엔드 수정 후)
// export const fetchSaleDetail = async (id: string): Promise<ISaleData> => {
export const fetchSaleDetail = async (id: number): Promise<ISaleData> => {
const response = await axiosInstance.get<ResponseData<ISaleData>>(
END_POINTS.SALE_DETAIL(id),
);
return response.data.data;
};

// export const fetchSaleDetail = async () => {
// const { data } = await axios.get<ResponseData<ISaleData>>(
// END_POINTS.SALE_DETAIL(id),
// "/v1/sale-history/49",
// );
// return data.data;
// };

export const fetchSaleDetail = async () => {
const { data } = await axios.get<ResponseData<ISaleData>>(
"/v1/sale-history/49",
);
return data.data;
};
4 changes: 2 additions & 2 deletions src/apis/fetchSaleList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { axiosInstance } from "./axiosInstance";
export const fetchSaleList = async () => {
try {
const { data } = await axiosInstance.get("/v1/members/sale-history");
console.log(data);
console.log("data", data);
return data;
} catch (err) {
alert("⚠️예기치 못한 에러가 발생하였습니다.");
throw new Error("⚠️예기치 못한 에러가 발생하였습니다.");
}
};
2 changes: 1 addition & 1 deletion src/components/layout/header/HeaderTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Header = () => {
title = "마이페이지";
undo = true;
break;
case PATH.PURCAHSE_DEATAIL:
case PATH.PURCHASE_DEATAIL:
alarmIC = false;
settingIC = false;
title = "구매내역상세";
Expand Down
2 changes: 1 addition & 1 deletion src/constants/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const END_POINTS = {
PURCHASE_HISTORY: "/v1/members/purchased-history",
PURCHASE_DETAIL: (purchaseId: string) =>
`/v1/members/purchased-history/${purchaseId}`,
SALE_DETAIL: (saleId: string) => `/v1/sale-history/${saleId}`,
SALE_DETAIL: (saleId: number) => `/v1/members/sale-history/${saleId}`,
EMAIL: "/v1/members/email",
YANOLJA: "/v1/members/yanolja",
ACCOUNT: "/v1/members/account",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const PATH = {
CREATE_TRIP: "/trip-new",
SALE_LIST: "/my-page/sale-list",
PURCHASE_LIST: "/my-page/purchase-list",
PURCAHSE_DEATAIL: "/my-page/purchase-detail",
PURCHASE_DEATAIL: "/my-page/purchase-detail",
SALE_DETAIL: "/my-page/sale-detail",
DETAIL_ROOM: (productId: string | number) => `/room/${productId}`,
WRITE_TRANSFER: "/transfer/new",
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/api/query/useSaleDetailQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { fetchSaleDetail } from "@apis/fetchSaleDetail";
import { useSuspenseQuery } from "@tanstack/react-query";
import type { ISaleData } from "@type/saleDetail";

export const useSaleDetailQuery = (saleId: string) => {
export const useSaleDetailQuery = (saleId: number) => {
const saleDetail = useSuspenseQuery<ISaleData>({
queryKey: ["sale", saleId],
// FIXME: 백엔드 수정 후 saleId를 넣어서 api 요청하도록 변경 필요
// queryFn: async () => await fetchSaleDetail(saleId),
queryFn: async () => await fetchSaleDetail(),
queryFn: async () => await fetchSaleDetail(saleId),
});

return saleDetail;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/myPage/MyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MyPage = () => {
const { getProfileData } = useProfileApi();
const [userProfile, setUserProfile] = useState<ProfileData>();
const isConnected = userProfile?.linkedToYanolja;

localStorage.setItem("isConnected", JSON.stringify(isConnected));
const fetchUserProfile = async () => {
try {
const res = await getProfileData(END_POINTS.USER_INFO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const PaymentSuccessButton = ({ productId }: { productId: string }) => {
type="button"
variant="outline"
aria-label="상세내역 확인"
onClick={() => navigate(PATH.PURCAHSE_DEATAIL)}
onClick={() => navigate(PATH.PURCHASE_DEATAIL)}
>
상세내역 확인
</S.Button>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/saleDetailPage/SaleDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const SaleDetail = () => {
// FIXME as below (백엔드 수정 후)
// const { data } = useSaleDetailQuery(saleId);

// 아래 부분 대신 위로 수정
// 아래 부분 대신 위로 수정\
const [data, setData] = useState<ISaleData>();
const fetch = async () => {
const res = await fetchSaleDetail();
const res = await fetchSaleDetail(Number(saleId));
setData(res);
};
useEffect(() => {
Expand Down
1 change: 0 additions & 1 deletion src/pages/searchPage/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const Search = () => {
const handleScroll = () => {
if (scrollContainerRef.current) {
const currentPosition = scrollContainerRef.current.scrollTop;
console.log(currentPosition);
setScrollPosition(currentPosition);
}
};
Expand Down
9 changes: 9 additions & 0 deletions src/pages/transferPurchasePage/TransferPurchase.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ export const NoResult = styled.div`
align-items: center;
${({ theme }) => theme.typo.title4}
`;

export const NoResultAll = styled.div`
display: flex;
margin-top: 1rem;
justify-content: center;
align-items: center;
${({ theme }) => theme.typo.body4}
color: ${({ theme }) => theme.color.greyScale2};
`;
29 changes: 25 additions & 4 deletions src/pages/transferPurchasePage/TransferPurchase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const TransferPurchase = () => {
return true;
}
});
console.log(filteredPurchaseItems);
console.log(sortedPurchaseItems);
if (isLoading) {
return <Loading />;
}
Expand All @@ -77,11 +77,32 @@ const TransferPurchase = () => {
/>
))
) : status === "done" ? (
<S.NoResult>구매 내역이 없습니다</S.NoResult>
<>
<S.NoResult>구매내역이 없습니다</S.NoResult>
{!sortedPurchaseItems.length && (
<S.NoResultAll>
지금 상품을 구매하고 호캉스 떠나보세요!
</S.NoResultAll>
)}
</>
) : status === "yet" ? (
<S.NoResult>이용예정 내역이 없습니다</S.NoResult>
<>
<S.NoResult>이용예정 내역이 없습니다</S.NoResult>
{!sortedPurchaseItems.length && (
<S.NoResultAll>
지금 상품을 구매하고 호캉스 떠나보세요!
</S.NoResultAll>
)}
</>
) : (
<S.NoResult>이용완료 내역이 없습니다</S.NoResult>
<>
<S.NoResult>이용완료 내역이 없습니다</S.NoResult>
{!sortedPurchaseItems.length && (
<S.NoResultAll>
지금 상품을 구매하고 호캉스 떠나보세요!
</S.NoResultAll>
)}
</>
)}
</S.PurchaseList>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useNavigate } from "react-router-dom";
const PuchaseItem = (props: IPurchaseItemWithRemainDate) => {
const navigate = useNavigate();
const handleClick = () => {
navigate(`${PATH.PURCAHSE_DEATAIL}?id=${props.id}`);
navigate(`${PATH.PURCHASE_DEATAIL}?id=${props.id}`);
};
return (
<S.PurchaseItemContainer onClick={handleClick}>
Expand Down
1 change: 1 addition & 0 deletions src/pages/transferSalePage/TransferSale.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export const NoSaleItems = styled.div`
}
span {
${({ theme }) => theme.typo.body4}
color: ${({ theme }) => theme.color.greyScale2};
}
`;
10 changes: 6 additions & 4 deletions src/pages/transferSalePage/TransferSale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const TransferSale = () => {
const [saleItems, setSaleItems] = useState<ISaleItemWithRemainDate[]>([]);
const [searchParams] = useSearchParams();
const status = searchParams.get("status");

const isConnected = localStorage.getItem("isConnected");
const fetchData = async () => {
try {
const { data } = await fetchSaleList();
Expand All @@ -53,7 +53,6 @@ const TransferSale = () => {
console.error(error);
}
};

const NoItemText = () => {
if (status === "for-sale") return <h2>판매중인 내역이 없습니다</h2>;
if (status === "sale-completed") return <h2>판매완료 내역이 없습니다</h2>;
Expand All @@ -68,14 +67,17 @@ const TransferSale = () => {
fetchData();
// eslint-disable-next-line
}, [status]);

if (saleItems.length === 0)
return (
<>
<SaleNav />
<S.NoSaleItems>
<NoItemText />
{!status && <span>계정을 연동하고 판매글을 작성해보세요!</span>}
{isConnected === "true" ? (
""
) : (
<span>계정을 연동하고 판매글을 작성해보세요!</span>
)}
</S.NoSaleItems>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const TransferWritingSuccess = () => {

const navigate = useNavigate();
const doneHandler = () => {
navigate(PATH.PURCHASE_LIST);
navigate(PATH.MY_PAGE);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ const AccountBottomSheet = ({ content, onSetContent }: BottomSheetProps) => {
try {
localStorage.removeItem("newAccount");
localStorage.removeItem("newBank");
navigate(PATH.PURCHASE_LIST);
navigate(PATH.MY_PAGE);
} catch {
navigate(PATH.PURCHASE_LIST);
navigate(PATH.MY_PAGE);
}
},
});
Expand Down Expand Up @@ -108,7 +108,7 @@ const AccountBottomSheet = ({ content, onSetContent }: BottomSheetProps) => {
<button onClick={clickHandler}>기본 계좌로 등록하기</button>
<button
className="cancel"
onClick={() => navigate(PATH.PURCHASE_LIST)}
onClick={() => navigate(PATH.MY_PAGE)}
>
변경하지 않기
</button>
Expand Down Expand Up @@ -155,7 +155,7 @@ const AccountBottomSheet = ({ content, onSetContent }: BottomSheetProps) => {
</button>
<button
className="cancel"
onClick={() => navigate(PATH.PURCHASE_LIST)}
onClick={() => navigate(PATH.MY_PAGE)}
>
나중에 입력하기
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const router = createBrowserRouter([
element: <PasswordReset />,
},
{
path: PATH.PURCAHSE_DEATAIL,
path: PATH.PURCHASE_DEATAIL,
element: (
<LocalErrorBoundary>
<Suspense fallback={<Loading />}>
Expand Down

0 comments on commit 789381b

Please sign in to comment.