(() => { const { EventManager, modules, pageHelper } = ShopbySkin; const myProductInquiryListHelper = pageHelper.myProductInquiryListHelper(); myProductInquiryListHelper.initialize({ answered: null, searchType: "CONTENT", hasTotalCount: true, }); // fetchProfileProductInquiries 내부에 searchType이 'ALL'로 고정되어 있어 fetch 레벨에서 searchType으로 교정 const _origFetch = window.fetch; window.fetch = (url, options) => { if (!(typeof url === 'string' && url.includes('product-inquiries'))) return _origFetch(url, options); const params = new URLSearchParams(window.location.search); const searchType = params.get('searchType'); const urlObj = new URL(url, location.origin); urlObj.searchParams.set('searchType', searchType || 'CONTENT'); setParams(); return _origFetch(urlObj.toString(), options); }; const setParams = () => { const params = new URLSearchParams(window.location.search); const keyword = params.get('searchKeyword'); const type = params.get('searchType'); if (!keyword || !type) return; const searchFieldEl = document.querySelector('search-field[shopby-module-key="product-inquiry-list-search-field"]'); if (!searchFieldEl) return; const newState = { ...searchFieldEl.store?.getState(), keyword: keyword || '', type: type || '' }; searchFieldEl.store?.setState(newState); searchFieldEl.handleRender?.({ state: newState }); }; const moduleActionHandler = { REGISTER: () => { EventManager.fire("OPEN_LAYER_MODAL", { name: "product-inquiry-form", title: "상품문의 등록", modalAddClass: "product-inquiry-form-modal", isFull: false, data: { isSelectProduct: true, commonData: myProductInquiryListHelper.commonData, }, visibleCloseBtn: false, onClose: ({ reason }) => { if (reason === "DID_SUBMIT") { EventManager.fire("MODAL_ALERT_OPEN", { noticeType: "SUCCESS", message: "상품문의가 등록됐습니다.", onClose: () => { location.reload(location.pathname); }, }); } }, }); }, }; document.addEventListener('click', (e) => { const link = e.target.closest('a[href*="product-inquiry-detail"]'); if (!link) return; const currentParams = new URLSearchParams(window.location.search); const url = new URL(link.href, location.origin); ['pageNumber', 'searchKeyword', 'searchType'].forEach((key) => { const val = currentParams.get(key); if (val) url.searchParams.set(key, val); }); link.href = url.toString(); }); const registerBtnEl = document.querySelector("[shopby-product-register-btn]"); registerBtnEl?.addEventListener("click", ({ target }) => { const action = target.getAttribute("shopby-action"); moduleActionHandler[action]?.(); }); document.removeEventListener("click", registerBtnEl); })();