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

[feature/extractCouponCart] 장바구니 쿠폰 적용 알고리즘 변경 #133

Merged
merged 6 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions apis/defaultApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CONTENT_TYPE = 'application/json';

axios.defaults.headers.common['Content-Type'] = CONTENT_TYPE;
axios.defaults.headers.post['Content-Type'] = CONTENT_TYPE;
axios.defaults.headers.patch['Content-Type'] = CONTENT_TYPE;

export const GET = async (url, params, headers) => {
let apiUrl = API_BASE_URL + url;
Expand Down
75 changes: 44 additions & 31 deletions components/cart/CartContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,62 @@ import CartContentFooter from '@components/cart/CartContentFooter';
import CartContentHeader from '@components/cart/CartContentHeader';

export default function CartContent({
headers,
cartBySellerDtoList,
checkBoxStates,
cartCheckBoxChange,
cartInfoChange,
}) {
const CommerceCartContentContainer = styled.div``;

const CartStoreSection = styled.div`
background-color: ${ThemeWhite};
border-radius: 6px;
margin-bottom: 20px;

@media (max-width: 1024px) {
padding: 10px 10px;
function ShowCartStore({ item }) {
let contentTotalPrice = 0;
const cartItemDtoList = item.cartItemDtoList;
if (cartItemDtoList && cartItemDtoList.length > 0) {
cartItemDtoList.forEach((item) => {
contentTotalPrice =
(contentTotalPrice + item.product.productPrice) * item.count;
});
}
@media (min-width: 1024px) {
padding: 10px 20px;
margin: 30px 0;
}
`;

return (
<CartStoreSection className="cart-store-section">
<CartContentHeader storeName={item.storeName} />
<CartContentDetail
storeName={item.storeName}
cartItemDtoList={item.cartItemDtoList}
checkBoxStates={checkBoxStates}
cartCheckBoxChange={cartCheckBoxChange}
cartInfoChange={cartInfoChange}
/>
<CartContentFooter
contentTotalPrice={contentTotalPrice}
storeName={item.storeName}
sellerId={item.sellerId}
/>
</CartStoreSection>
);
}

return (
<CommerceCartContentContainer className="commerce-cart-content-container">
{cartBySellerDtoList &&
cartBySellerDtoList.map((item) => (
<CartStoreSection className="cart-store-section" key={item.sellerId}>
<CartContentHeader storeName={item.storeName} />
<CartContentDetail
headers={headers}
storeName={item.storeName}
cartItemDtoList={item.cartItemDtoList}
checkBoxStates={checkBoxStates}
cartCheckBoxChange={cartCheckBoxChange}
cartInfoChange={cartInfoChange}
/>
<CartContentFooter
couponDto={item.couponDto}
storeName={item.storeName}
cartItemDtoList={item.cartItemDtoList}
/>
</CartStoreSection>
<ShowCartStore item={item} key={item.sellerId} />
))}
</CommerceCartContentContainer>
);
}

const CommerceCartContentContainer = styled.div``;

const CartStoreSection = styled.div`
background-color: ${ThemeWhite};
border-radius: 6px;
margin-bottom: 20px;

@media (max-width: 1024px) {
padding: 10px 10px;
}
@media (min-width: 1024px) {
padding: 10px 20px;
margin: 30px 0;
}
`;
12 changes: 11 additions & 1 deletion components/cart/CartContentDetail.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { useContext } from 'react';
import { useRouter } from 'next/router';
import styled from '@emotion/styled';
import { DELETE } from '@apis/defaultApi';
import { ThemeGray1 } from '@utils/constants/themeColor';
import CartProduct from '@components/cart/CartProduct';
import { LoginHeaderContext } from '@pages/user/cart/index';

export default function CartContentDetail({
headers,
cartItemDtoList,
checkBoxStates,
cartCheckBoxChange,
cartInfoChange,
}) {
const router = useRouter();
const headers = useContext(LoginHeaderContext);

const ProductCheckSection = styled.div`
position: relative;
Expand Down Expand Up @@ -51,9 +53,17 @@ export default function CartContentDetail({

const CartDetailSection = styled.div`
padding-top: 5px;
padding-bottom: 10px;

border-top: 1px solid white;
border-bottom: 1px solid white;
display: flex;

@media (max-width: 1024px) {
}
@media (min-width: 1024px) {
height: 100px;
}
`;

const deleteCartItem = ({ input }) => {
Expand Down
33 changes: 22 additions & 11 deletions components/cart/CartContentFooter.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import { useState } from 'react';
import { useState, useContext, useEffect } from 'react';
import styled from '@emotion/styled';
import { SmallLineBlue } from '@components/input/Button';
import CartCouponModal from '@components/cart/CartCouponModal';
import { LoginHeaderContext } from '@pages/user/cart/index';
import { GET_DATA } from '@apis/defaultApi';

export default function CartContentFooter({
cartItemDtoList,
contentTotalPrice,
storeName,
couponDto,
sellerId,
}) {
const headers = useContext(LoginHeaderContext);
const [modalState, setModalState] = useState(false);
let contentTotalPrice = 0;
if (cartItemDtoList && cartItemDtoList.length > 0) {
cartItemDtoList.forEach((item) => {
contentTotalPrice =
(contentTotalPrice + item.product.productPrice) * item.count;
const [couponArray, setCouponArray] = useState([]);

useEffect(() => {
GET_DATA(
`/coupon`,
{ sellerId, totalFee: contentTotalPrice },
headers,
).then((res) => {
console.log(res);
if (res) {
setCouponArray(res);
}
});
}
}, []);

const showModal = () => {
setModalState(true);
Expand All @@ -32,9 +42,10 @@ export default function CartContentFooter({
{modalState && (
<CartCouponModal
setModalState={setModalState}
couponDto={couponDto}
contentTotalPrice={contentTotalPrice}
storeName={storeName}
sellerId={sellerId}
couponArray={couponArray}
contentTotalPrice={contentTotalPrice}
/>
)}
</ContentFooterSection>
Expand Down
Loading