(() => {
const { pageHelper, EventManager, utils } = ShopbySkin;
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 로그인 연결도 함께 해제해 주세요.',
};
EventManager.on('PROCESS_AUTHENTICATION', ({ status }) => {
if (status === 'success') {
const modifyMember = document.querySelector('.withdrawal-form');
modifyMember?.classList.remove('unauthentication');
}
const buttonEl = document.querySelector("[shopby-btn='authentication']");
if (!buttonEl) return;
if (status === 'pending') {
buttonEl.disabled = true;
}
if (status === 'finish') {
buttonEl.disabled = false;
}
});
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.reason) {
EventManager.fire('MODAL_ALERT_OPEN', {
noticeType: 'CAUTION',
message: '탈퇴 사유를 입력해주세요.',
});
return;
}
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 () => {
await helper.withdrawal({
reason: withdrawalProfileForm.reason,
onSuccess: () => {
EventManager.fire('MODAL_ALERT_OPEN', {
noticeType: 'SUCCESS',
message: confirmMessages.join('
'),
onClose: () => {
utils.signOut({
redirect: '/',
});
},
});
},
});
},
});
};
const CLICK_EVENT_HANDLER_MAP = {
OPEN_ID_CLICK: (target) => {
const provider = target.getAttribute('shopby-provider');
if (provider === 'app-card') {
EventManager.fire('OPEN_LAYER_MODAL', {
name: 'app-card-authenticate',
classModifier: 'app-card-authenticate',
isFull: false,
data: {
nextPath: location.href,
previousPath: location.href,
provider,
redirectUri: `${location.origin}/callback/auth-callback.html`,
},
});
return;
}
const passwordAuthenticationLayerModalHelper = pageHelper.passwordAuthenticationLayerModalHelper();
passwordAuthenticationLayerModalHelper.openIdSignIn({
nextPath: location.href,
previousPath: location.href,
provider,
redirectUri: `${location.origin}/callback/auth-callback.html`,
});
},
CANCEL_AUTHENTICATION: () => {
location.replace('/pages/my/my-page.html');
},
};
const clickEventListener = ({ target }) => {
const action = target.getAttribute('shopby-action');
if (action === 'CLICK_WITHDRAWAL') {
handleWithdrawal(withdrawalHelper);
}
};
containerEl.addEventListener('click', clickEventListener);
document.querySelector('check-my-authentication')?.addEventListener('click', ({ target }) => {
CLICK_EVENT_HANDLER_MAP[target.getAttribute('shopby-action')]?.(target);
});
})();