Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor/#74] 배송비 계산 로직 재수정 및 콘솔 삭제 #75

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .yarn/install-state.gz
Binary file not shown.
7 changes: 2 additions & 5 deletions src/components/Cart/OrderBtn/OrderBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ interface OrderBtnProps {
}

const OrderBtn = ({ totalItems, totalPrice }: OrderBtnProps) => {
const shippingFee = totalPrice < 15000 && totalPrice > 0 ? 3000 : 0;
const finalPrice = totalPrice + shippingFee;

return (
<S.StyledBtn disabled={finalPrice === 0}>
{`${finalPrice.toLocaleString()}원 (${totalItems}) 주문하기`}
<S.StyledBtn disabled={totalItems === 0}>
{`${totalPrice.toLocaleString()}원 (${totalItems}) 주문하기`}
</S.StyledBtn>
);
};
Expand Down
8 changes: 6 additions & 2 deletions src/components/Cart/PriceInfo/PriceInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import * as S from './PriceInfo.styled';
interface PriceInfoProps {
productPrice: number;
discountPrice: number;
shippingFee: number;
}

const PriceInfo = ({ productPrice, discountPrice }: PriceInfoProps) => {
const shippingFee = productPrice - discountPrice < 15000 ? 3000 : 0;
const PriceInfo = ({
productPrice,
discountPrice,
shippingFee,
}: PriceInfoProps) => {
const totalPrice = productPrice - discountPrice + shippingFee;

return (
Expand Down
19 changes: 9 additions & 10 deletions src/pages/Cart/Cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ const Cart = () => {

const shippingFee =
selectedTotalDiscountedPrice === 0
? 3000
: selectedTotalDiscountedPrice < 15000
? 3000
: 0;

console.log(shippingFee);
? 0
: selectedTotalDiscountedPrice >= 15000
? 0
: 3000;

return (
<>
Expand Down Expand Up @@ -124,9 +122,9 @@ const Cart = () => {
<S.PriceBox>
{selectedTotalDiscountedPrice.toLocaleString()}원 ({selectedQty}
)
{shippingFee > 0
? `+ 배송비 ${shippingFee.toLocaleString()}원`
: '+ 배송비 무료'}
{selectedTotalDiscountedPrice > 15000
? '+ 배송비 무료'
: `+ 배송비 ${shippingFee.toLocaleString()}원`}
</S.PriceBox>
</S.ItemBox>
<S.DeliveryBox>
Expand All @@ -136,10 +134,11 @@ const Cart = () => {
discountPrice={
selectedTotalPrice - selectedTotalDiscountedPrice
}
shippingFee={shippingFee}
/>
<OrderBtn
totalItems={selectedQty}
totalPrice={selectedTotalDiscountedPrice}
totalPrice={selectedTotalDiscountedPrice + shippingFee}
/>
</S.DeliveryBox>
</S.CartContainer>
Expand Down