(() => { const { pageHelper, EventManager, utils, constants, actions } = ShopbySkin; const BRIDGE_WITHDRAW_URL = 'https://bridge2.on-deal.nate.com/auth/withdraw'; const WITHDRAW_ERROR_MESSAGES = { NO_SFN: '로그인하셔야 본 서비스를 이용하실 수 있습니다.', UNKNOWN_ERROR: '인증 해제 처리 중 문제가 발생했습니다.', }; const requestBridgeWithdraw = async () => { const response = await fetch(BRIDGE_WITHDRAW_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${utils.memberAuth.get()}`, }, credentials: 'include', }); if (!response.ok) { const errorData = await response.json().catch(() => ({})); throw errorData; } }; const withdrawalHelper = pageHelper.withdrawalHelper(); const containerEl = document.querySelector('[shopby-helper-key="withdrawal"]'); withdrawalHelper.initialize({ helperKey: 'withdrawal', platform: 'PC', profileNonMasking: true, }); const socialWithdrawalMessageMap = { APPLE: 'Apple 로그인 회원은 쇼핑몰 인증 해제 후
iOS 설정에서 Apple 로그인 연결도 함께 해제해 주세요.', NAVER: '네이버 로그인 회원은 쇼핑몰 인증 해제 후
네이버 설정에서 네이버 로그인 연결도 함께 해제해 주세요.', KAKAO: '카카오 로그인 회원은 쇼핑몰 인증 해제 후
카카오 설정에서 카카오 로그인 연결도 함께 해제해 주세요.', GOOGLE: 'Google 로그인 회원은 쇼핑몰 인증 해제 후
Google 설정에서 Google 로그인 연결도 함께 해제해 주세요.', FACEBOOK: 'Facebook 로그인 회원은 쇼핑몰 인증 해제 후
Facebook 설정에서 Facebook 로그인 연결도 함께 해제해 주세요.', }; const fetchConfirmMessage = (helper) => { const { couponCnt, hasOrder, accumulationAmount: accumulation } = helper.getState().helperState; const accumulationAmount = Number(accumulation ?? 0).toLocaleString(); if (hasOrder) { return !!couponCnt || !!accumulationAmount ? `진행중인 주문 건이 있습니다.
네이트 회원 인증을 해제하시겠습니까?
사용가능한 쿠폰 ${couponCnt}장 / 적립금 ${accumulationAmount}원` : '진행중인 주문 건이 있습니다.
네이트 회원 인증을 해제하시겠습니까?'; } return `네이트 회원 인증을 해제하시겠습니까?
사용가능한 쿠폰 ${couponCnt}장 / 적립금 ${accumulationAmount}원`; }; const handleWithdrawal = (helper) => { const { withdrawalProfileForm } = helper.getState(); if (!withdrawalProfileForm.termAgreed) { EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'CAUTION', message: '인증 해제 동의를 체크해주세요.', }); return; } const confirmMessages = ['인증 해제가 완료되었습니다.']; const socialWithdrawalMessage = socialWithdrawalMessageMap[withdrawalProfileForm.openIdProvider] || ''; if (socialWithdrawalMessage) confirmMessages.push(socialWithdrawalMessage); EventManager.fire('MODAL_CONFIRM_OPEN', { noticeType: 'WARNING', message: `${fetchConfirmMessage(helper)}`, onConfirm: async () => { try { await requestBridgeWithdraw(); EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'SUCCESS', message: confirmMessages.join('
'), onClose: async () => { await actions.postSignOut(); utils.moveTo({ url: constants.PAGE.MAIN, replace: true }); }, }); } catch (error) { const errorCode = error?.code || 'UNKNOWN_ERROR'; const message = WITHDRAW_ERROR_MESSAGES[errorCode] || WITHDRAW_ERROR_MESSAGES['UNKNOWN_ERROR']; const isNoSfn = errorCode === 'NO_SFN'; EventManager.fire('MODAL_ALERT_OPEN', { noticeType: 'CAUTION', message: `${message}`, ...(isNoSfn && { onClose: () => { utils.moveTo({ url: `${constants.PAGE.SIGN_IN}?from=${encodeURIComponent(location.href)}`, replace: true, }); }, }), }); } }, }); }; const clickEventListener = ({ target }) => { const action = target.getAttribute('shopby-action'); if (action === 'CLICK_WITHDRAWAL') { handleWithdrawal(withdrawalHelper); } }; containerEl.addEventListener('click', clickEventListener); })();