226 lines
5.8 KiB
JavaScript
226 lines
5.8 KiB
JavaScript
import { URLS } from '../api/apiConfig';
|
|
import { TAxios } from '../api/TAxios';
|
|
import { types } from './actionTypes';
|
|
import {
|
|
changeAppStatus,
|
|
showError,
|
|
} from './commonActions';
|
|
|
|
// 회원 체크아웃 정보 조회 IF-LGSP-345
|
|
export const getMyInfoCheckoutInfo =
|
|
(props, callback) => (dispatch, getState) => {
|
|
const { mbrNo, dirPurcSelYn, cartList } = props;
|
|
|
|
dispatch(
|
|
// changeAppStatus({ showLoadingPanel: { show: true, type: "wait" } })
|
|
changeAppStatus({ isLoading: true })
|
|
);
|
|
|
|
const onSuccess = (response) => {
|
|
console.log("getMyInfoCheckoutInfo onSuccess: ", response.data);
|
|
|
|
// 🔍 API 응답 구조 분석
|
|
const checkoutData = response.data.data || response.data;
|
|
const defaultAddrSno = checkoutData?.shippingAddressList?.[0]?.dlvrAddrSno || checkoutData?.shippingAddressList?.[0]?.addrSno;
|
|
const defaultBilAddrSno = checkoutData?.billingAddressList?.[0]?.bilAddrSno || checkoutData?.billingAddressList?.[0]?.addrSno;
|
|
|
|
console.log('[checkoutActions] 🔍 Checkout data structure:', {
|
|
hasResponseDataData: !!response.data.data,
|
|
directData: !!response.data,
|
|
defaultAddrSno,
|
|
defaultBilAddrSno,
|
|
shippingAddressCount: checkoutData?.shippingAddressList?.length,
|
|
billingAddressCount: checkoutData?.billingAddressList?.length,
|
|
});
|
|
|
|
// 🔴 billingAddressList 상세 분석
|
|
console.log('[checkoutActions] 🔴 billingAddressList analysis:', {
|
|
billingAddressList: checkoutData?.billingAddressList,
|
|
firstBillingAddress: checkoutData?.billingAddressList?.[0],
|
|
firstBillingAddressKeys: Object.keys(checkoutData?.billingAddressList?.[0] || {}),
|
|
});
|
|
|
|
// 기본 주소 선택 (첫 번째 주소 사용)
|
|
const infoForCheckoutData = {
|
|
dlvrAddrSno: defaultAddrSno,
|
|
bilAddrSno: defaultBilAddrSno,
|
|
};
|
|
|
|
console.log('[checkoutActions] 📦 Dispatching GET_CHECKOUT_INFO with:', {
|
|
infoForCheckoutData,
|
|
checkoutData,
|
|
});
|
|
|
|
dispatch({
|
|
type: types.GET_CHECKOUT_INFO,
|
|
payload: {
|
|
...checkoutData,
|
|
...infoForCheckoutData, // 기본 주소 정보 추가
|
|
},
|
|
});
|
|
|
|
if (callback) callback(response.data);
|
|
};
|
|
|
|
const onFail = (error) => {
|
|
console.error("getMyInfoCheckoutInfo OnFail: ", error);
|
|
};
|
|
|
|
TAxios(
|
|
dispatch,
|
|
getState,
|
|
"post",
|
|
URLS.GET_CHECKOUT_INFO,
|
|
{},
|
|
{ mbrNo, dirPurcSelYn, cartList },
|
|
onSuccess,
|
|
onFail
|
|
);
|
|
};
|
|
|
|
// 회원 CheckOut 상품 주문 IF-LGSP-346
|
|
export const insertMyInfoCheckoutOrder =
|
|
(props, callback) => (dispatch, getState) => {
|
|
const {
|
|
mbrNo,
|
|
bilAddrSno,
|
|
dlvrAddrSno,
|
|
pinCd,
|
|
orderProductCoupontUse,
|
|
orderProductQtyInfo,
|
|
} = props;
|
|
|
|
const onSuccess = (response) => {
|
|
console.log("insertMyInfoCheckoutOrder onSuccess: ", response.data);
|
|
|
|
if (response.data.retCode === 0) {
|
|
dispatch({
|
|
type: types.INSERT_MY_INFO_CHECKOUT_ORDER,
|
|
payload: response.data.data,
|
|
});
|
|
|
|
if (callback) callback(response);
|
|
} else {
|
|
dispatch(
|
|
showError(
|
|
response.data.retCode,
|
|
response.data.retMsg,
|
|
true,
|
|
response.data.retDetailCode
|
|
)
|
|
);
|
|
}
|
|
|
|
dispatch(
|
|
changeAppStatus({
|
|
showLoadingPanel: { show: false, showMessage: false },
|
|
})
|
|
);
|
|
};
|
|
|
|
const onFail = (error) => {
|
|
console.error("insertMyInfoCheckoutOrder onFail: ", error);
|
|
dispatch(
|
|
changeAppStatus({
|
|
showLoadingPanel: { show: false, showMessage: false },
|
|
})
|
|
);
|
|
};
|
|
|
|
TAxios(
|
|
dispatch,
|
|
getState,
|
|
"post",
|
|
URLS.INSERT_MY_INFO_CHECKOUT_ORDER,
|
|
{},
|
|
{
|
|
mbrNo,
|
|
bilAddrSno,
|
|
dlvrAddrSno,
|
|
pinCd,
|
|
orderProductCoupontUse,
|
|
orderProductQtyInfo,
|
|
},
|
|
onSuccess,
|
|
onFail
|
|
);
|
|
};
|
|
|
|
export const getCheckoutTotalAmt =
|
|
(params, callback) => (dispatch, getState) => {
|
|
const {
|
|
mbrNo,
|
|
dirPurcSelYn,
|
|
bilAddrSno,
|
|
dlvrAddrSno,
|
|
isPageLoading,
|
|
orderProductCoupontUse,
|
|
} = params;
|
|
|
|
dispatch(changeAppStatus({ isLoading: false }));
|
|
|
|
dispatch(
|
|
changeAppStatus({ showLoadingPanel: { show: true, type: "wait" } })
|
|
);
|
|
|
|
const onSuccess = (response) => {
|
|
console.log("getCheckoutTotalAmt onSuccess: ", response.data);
|
|
|
|
if (response.data.retCode === 0) {
|
|
dispatch({
|
|
type: types.GET_CHECKOUT_TOTAL_AMT,
|
|
payload: response.data.data,
|
|
});
|
|
|
|
if (callback) callback(response.data);
|
|
} else {
|
|
dispatch(
|
|
showError(
|
|
response.data.retCode,
|
|
response.data.retMsg,
|
|
true,
|
|
response.data.retDetailCode
|
|
)
|
|
);
|
|
}
|
|
|
|
dispatch(changeAppStatus({ showLoadingPanel: { show: false } }));
|
|
};
|
|
|
|
const onFail = (error) => {
|
|
console.error("getCheckoutTotalAmt onFail: ", error);
|
|
|
|
dispatch(changeAppStatus({ showLoadingPanel: { show: false } }));
|
|
};
|
|
|
|
TAxios(
|
|
dispatch,
|
|
getState,
|
|
"post",
|
|
URLS.GET_CHECKOUT_TOTAL_AMT,
|
|
{},
|
|
{ mbrNo, dirPurcSelYn, bilAddrSno, dlvrAddrSno, isPageLoading, orderProductCoupontUse },
|
|
onSuccess,
|
|
onFail
|
|
);
|
|
};
|
|
|
|
export const updateSelectedShippingAddr = (dlvrAddrSno) => ({
|
|
type: types.UPDATE_SELECTED_SHIPPING_ADDR,
|
|
payload: dlvrAddrSno,
|
|
});
|
|
|
|
export const updateSelectedBillingAddr = (bilAddrSno) => ({
|
|
type: types.UPDATE_SELECTED_BILLING_ADDR,
|
|
payload: bilAddrSno,
|
|
});
|
|
|
|
export const updateSelectedCoupon = (productId, coupon) => ({
|
|
type: types.UPDATE_SELECTED_COUPON,
|
|
payload: { productId, coupon },
|
|
});
|
|
|
|
export const resetCheckoutData = () => ({
|
|
type: types.CHECKOUT_DATA_RESET,
|
|
});
|