Skip to content

Commit

Permalink
[fix] add cart (Custom & License)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongwoo-CU committed Nov 28, 2023
1 parent ba7aaf7 commit f43e97c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
65 changes: 45 additions & 20 deletions src/axios/cart/Cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,69 @@ import { ACCESS_TOKEN, GUEST_COOKIE } from '../../constants/token';
import { CONTENT_TYPE } from '../../constants/header';
import { BACK, CART } from '../../constants/path';
import {
ADD_CART,
ADD_CART_GUEST,
ADD_CART_CUSTOM,
ADD_CART_CUSTOM_GUEST,
ADD_CART_LICENSE,
CART_LIST,
DELETE_CART,
DELETE_CART_GUEST,
EDIT_CART,
EDIT_CART_GUEST,
PRODUCT_OPTION,
} from '../../constants/api';
import Swal from "sweetalert2";

export default function post(dto, file, isCustom) {
const formData = new FormData();
if (isCustom) formData.append('file', file);
formData.append('dto', new Blob([JSON.stringify(dto)], { type: CONTENT_TYPE.ApplicationJson }));
if (sessionStorage.getItem(ACCESS_TOKEN)) {
axios
.post(ADD_CART(), formData, {
headers: {
Authorization: sessionStorage.getItem(ACCESS_TOKEN),
"Content-Type": CONTENT_TYPE.MultipartFormData,
},
})
.then(() => {
alert('장바구니에 담겼습니다!');
window.location.replace(BACK);
});

function alertSuccess() {
Swal.fire({
title: '장바구니에 담겼습니다',
icon: 'success',
});
}

if (sessionStorage.getItem(ACCESS_TOKEN)) {
if (isCustom) {
formData.append('file', file);
axios
.post(ADD_CART_CUSTOM(), formData, {
headers: {
Authorization: sessionStorage.getItem(ACCESS_TOKEN),
"Content-Type": CONTENT_TYPE.MultipartFormData,
},
})
.then(() => {
alertSuccess();
});
}
if (!isCustom) {
axios
.post(ADD_CART_LICENSE(), formData, {
headers: {
Authorization: sessionStorage.getItem(ACCESS_TOKEN),
"Content-Type": CONTENT_TYPE.MultipartFormData,
},
})
.then(() => {
alertSuccess();
});
}
} else {
axios
.post(ADD_CART_GUEST, formData, {
.post(ADD_CART_CUSTOM_GUEST(), formData, {
headers: {
Authorization: cookie.load(GUEST_COOKIE),
'Content-Type': CONTENT_TYPE.MultipartFormData,
},
})
.then(() => {
alert('비회원 장바구니에 담겼습니다!');
window.location.replace(BACK);
});
.then(() => {
Swal.fire({
title: '비회원 장바구니에 담겼습니다',
icon: 'success',
});
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/component/order/OrderOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function OrderOptions({ productId, productInfo, price, setPrice }
data = {
productId: productInfo?.id,
optionDetailIds: options,
licenseOptionDetailId: img.id,
licenseOptionId: img.id,
quantity: parseInt(quantity),
};
}
Expand Down Expand Up @@ -104,7 +104,7 @@ export default function OrderOptions({ productId, productInfo, price, setPrice }
switch (mode) {
case ORDER_MODE.CART:
if (!pass) break;
post(data, imageFile);
post(data, imageFile, productInfo.custom);
break;
case ORDER_MODE.BUY:
if (!pass) break;
Expand Down
6 changes: 4 additions & 2 deletions src/constants/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export const DELETE_REVIEW = (reviewId) => `/product/reviews/${reviewId}`;
export const LICENSE_LIST = () => `/product/licenseImage`;

// cart api
export const ADD_CART = () => '/product/carts/custom-products';
export const ADD_CART_GUEST = () => '/product/guest/carts/custom-products';
export const ADD_CART_CUSTOM = () => '/product/carts/custom-products';
export const ADD_CART_LICENSE = () => '/product/carts/license-products';
export const ADD_CART_CUSTOM_GUEST = () => '/product/guest/carts/custom-products';
export const ADD_CART_LICENSE_GUEST = () => '/product/guest/carts/license-products';
export const CART_LIST = () => '/product/carts';
export const PRODUCT_OPTION = () => '/product/carts/productOptionInfo';
export const DELETE_CART = (id) => `/product/carts/custom-products/${id}`;
Expand Down
2 changes: 1 addition & 1 deletion src/screen/cart/CartList.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function CartList({ setEmptyMode }) {
}, [cartData]);

function pay() {
if (checkedList == '') {
if (checkedList === '') {
alert('체크된 장바구니 항목이 없습니다');
} else {
navigate(PAYMENT, {
Expand Down

0 comments on commit f43e97c

Please sign in to comment.