[구매 옵션 관련수정]

- select option 추가로 인한 옵션 오 선택 때문에 처리.
This commit is contained in:
junghoon86.park
2025-10-27 14:11:26 +09:00
parent 21f834c886
commit 5c06faa043

View File

@@ -443,29 +443,62 @@ const BuyOption = ({
nowMenu,
]);
// 첫번째 옵션 선택 핸들러 (SingleOption과 동일)
const handleFirstOptionSelect = (selected) => {
const optionValIdx = selected.selected - 1;
console.log('[BuyOption] First option selected:', optionValIdx);
const selectedIndex = selected.selected;
console.log('[BuyOption] First option selected:', selectedIndex);
setSelectedBtnOptIdx(optionValIdx);
// "Select Option"이 선택된 경우 (index 0)
if (selectedIndex === 0) {
// 초기 상태로 리셋
setSelectedBtnOptIdx(0);
setSelectedOptionItemIndex(0);
setSelectedOptions(undefined);
setIsOptionValue(false);
setIsOptionSelect(false);
return;
}
// selectedBtnOptIdx는 UI 인덱스 그대로 저장 (드롭다운 표시용)
setSelectedBtnOptIdx(selectedIndex);
// 실제 데이터 접근 시에는 selectedIndex - 1 사용
const dataIndex = selectedIndex - 1;
setSelectedOptionItemIndex(0);
setSelectedOptions(productOptionInfos[optionValIdx]?.prdtOptDtl[0]);
setSelectedOptions(productOptionInfos[dataIndex]?.prdtOptDtl[0]);
setIsOptionValue(false);
setIsOptionSelect(true);
};
// 두번째 옵션 선택 핸들러 (SingleOption과 동일)
const handleSecondOptionSelect = (selected) => {
const index = selected.selected - 1;
console.log('[BuyOption] Second option selected:', index);
setSelectedOptionItemIndex(index);
const selectedIndex = selected.selected;
console.log('[BuyOption] Second option selected:', selectedIndex);
// "Select Option"이 선택된 경우 (index 0)
if (selectedIndex === 0) {
// 초기 상태로 리셋
setSelectedOptionItemIndex(0);
setSelectedOptions(undefined);
setIsOptionValue(false);
return;
}
// selectedOptionItemIndex는 UI 인덱스 그대로 저장
setSelectedOptionItemIndex(selectedIndex);
// 실제 데이터 접근 시에는 -1 적용
const firstOptionDataIndex = selectedBtnOptIdx - 1; // 첫 번째 옵션의 실제 데이터 인덱스
const secondOptionDataIndex = selectedIndex - 1; // 두 번째 옵션의 실제 데이터 인덱스
setSelectedOptions(
productOptionInfos[selectedBtnOptIdx]?.prdtOptDtl[index]
productOptionInfos[firstOptionDataIndex]?.prdtOptDtl[
secondOptionDataIndex
]
);
dispatch(
getProductOptionId(
productOptionInfos[selectedBtnOptIdx]?.prdtOptDtl[index]?.prodOptCdCval
productOptionInfos[firstOptionDataIndex]?.prdtOptDtl[
secondOptionDataIndex
]?.prodOptCdCval
)
);
setIsOptionValue(true);
@@ -615,9 +648,11 @@ const BuyOption = ({
</div>
<div className={styles.buy_option__option_control}>
<CustomDropDown
options={['Select Option'].concat(
productOptionInfos.map((option) => option.optNm)
)}
options={[
'Select Option',
...(productOptionInfos?.map((option) => option.optNm) ||
[]),
]}
selectedIndex={selectedBtnOptIdx}
onSelect={handleFirstOptionSelect}
spotlightId="buy-option-first-dropdown"
@@ -644,7 +679,7 @@ const BuyOption = ({
options={[
'Select Option',
...(productOptionInfos[
selectedBtnOptIdx
selectedBtnOptIdx - 1 // 데이터 인덱스 사용
]?.prdtOptDtl.map((detail) => detail.prodOptCval) ||
[]),
]}