import { motion } from 'framer-motion'; import { DetailMotionDuration, DetailMotionStyle, DetailMotionVariants } from "@/entities/common/model/constant"; import { FullMenuClose } from '@/entities/common/ui/full-menu-close'; import { useTranslation } from 'react-i18next'; import { AllTransactionAllCancel } from './all-transaction-all-cancel'; import { AllTransactionPartCancel } from './all-transaction-part-cancel'; import { AllTransactionCancelInfoParams, AllTransactionCancelInfoResponse, AllTransactionCancelParams, CancelTabKeys, DebtPreventionCancelDisplayInfo, DebtPreventionCancelRequestInfo } from '../model/types'; import { useEffect, useState } from 'react'; import { useAllTransactioCancleMutation } from '../api/use-all-transaction-cancel-mutation'; import { useAllTransactioCancleInfoMutation } from '../api/use-all-transaction-cancel-info-mutation'; import { snackBar } from '@/shared/lib'; import { useStore } from '@/shared/model/store'; export interface AllTransactionCancelProps { cancelOn: boolean; setCancelOn: (cancelOn: boolean) => void; serviceCode: string; tid: string; }; export const AllTransactionCancel = ({ cancelOn, setCancelOn, serviceCode, tid }: AllTransactionCancelProps) => { const { t } = useTranslation(); const userInfo = useStore.getState().UserStore.userInfo; const userMid = useStore.getState().UserStore.mid; const [tabAction, setTabAction] = useState(CancelTabKeys.All); const [debtPreventionCancelDisplayInfo, setDebtPreventionCancelDisplayInfo] = useState(null); const [debtPreventionCancelRequestInfo, setDebtPreventionCancelRequestInfo] = useState(null); const [goodsVat, setGoodsVat] = useState(null); const [isCompoundTax, setIsCompoundTax] = useState(false); const [isConditionalVatAutoCalcMerchant, setIsConditionalVatAutoCalcMerchant] = useState(false); const [isNpg, setIsNpg] = useState(false); const [isVatAutoCalcMerchant, setIsVatAutoCalcMerchant] = useState(false); const [isVatDisplayed, setIsVatDisplayed] = useState(false); const [partCancelCl, setPartCancelCl] = useState(false); const [remainAmount, setRemainAmount] = useState(0); const [serviceAmount, setServiceAmount] = useState(null); const [supplyAmount, setSupplyAmount] = useState(null); const [taxFreeAmount, setTaxFreeAmount] = useState(null); const [vatAutoCalcSummary, setVatAutoCalcSummary] = useState(0); const [totalCancelAmount, setTotalCancelAmount] = useState(0); const [cancelPassword, setCancelPassword] = useState(''); const [cancelSupplyAmount, setCancelSupplyAmount] = useState(0); const [cancelGoodsVat, setCancelGoodsVat] = useState(0); const [cancelTaxFreeAmount, setCancelTaxFreeAmount] = useState(0); const [cancelServiceAmount, setCancelServiceAmount] = useState(0); const [requestSuccess, setRequestSuccess] = useState(true); const [bankCode, setBankCode] = useState(''); const [accountNo, setAccountNo] = useState(''); const [accountHolder, setAccountHolder] = useState(''); const [cancelPreventBondOn, setCancelPreventBondOn] = useState(false); const { mutateAsync: transactionCancel } = useAllTransactioCancleMutation(); const { mutateAsync: allTransactionCancelInfo } = useAllTransactioCancleInfoMutation(); const callCancelInfo = () => { let params: AllTransactionCancelInfoParams = { serviceCode: serviceCode, tid: tid, mid: userMid }; allTransactionCancelInfo(params).then((rs: AllTransactionCancelInfoResponse) => { if(rs.debtPreventionCancelDisplayInfo !== null){ setCancelPreventBondOn(true); } else{ setDebtPreventionCancelDisplayInfo(rs.debtPreventionCancelDisplayInfo); setDebtPreventionCancelRequestInfo(rs.debtPreventionCancelRequestInfo); setGoodsVat(rs.goodsVat); setIsCompoundTax(rs.isCompoundTax); setIsConditionalVatAutoCalcMerchant(rs.isConditionalVatAutoCalcMerchant); setIsNpg(rs.isNpg); setIsVatAutoCalcMerchant(rs.isVatAutoCalcMerchant); setIsVatDisplayed(rs.isVatDisplayed); setPartCancelCl(rs.partCancelCl); setRemainAmount(rs.remainAmount); setServiceAmount(rs.serviceAmount); setSupplyAmount(rs.supplyAmount); setTaxFreeAmount(rs.taxFreeAmount); setVatAutoCalcSummary(rs.vatAutoCalcSummary); if(!partCancelCl){ setTotalCancelAmount(rs.remainAmount); } else{ setTotalCancelAmount(0); } } // partCancelCl == true ==> 부분취소 버튼 활성화 // isCompoundTax == true ==> 부분취소의 복합과세 노출 // debtPreventionCancelDisplayInfo != null => 입금 후 취소 페이지 노출 // [취소신청]버튼 클릭시 // debtPreventionCancelDisplayInfo.isCancel == true => 취소api호출 // debtPreventionCancelRequestInfo 이 값 통쨰로 변조없이 그대로 api에 전달 // debtPreventionCancelDisplayInfo.isCancel == false => 얼럿만 띄우고 취소요청하면안됨 }).catch((e: any) => { if(e.response?.data?.error?.message){ snackBar(e.response?.data?.error?.message); return; } }); }; const callTransactionCancel = () => { if(debtPreventionCancelDisplayInfo?.isCancel === false){ snackBar(t('transaction.cancel.requestNotPossible')); } else{ let transactionCancelParams: AllTransactionCancelParams = { tid: tid, cancelAmount: totalCancelAmount || 0, cancelPassword: cancelPassword, bankCode: bankCode, accountNo: accountNo, accountHolder: accountHolder, supplyAmount: (!!partCancelCl)? cancelSupplyAmount: (supplyAmount || 0), goodsVatAmount: (!!partCancelCl)? cancelGoodsVat: (goodsVat || 0), taxFreeAmount: (!!partCancelCl)? cancelTaxFreeAmount: (taxFreeAmount || 0), serviceAmount: (!!partCancelCl)? cancelServiceAmount: (serviceAmount || 0), clientIp: userInfo.clientAddressIP, partCancelCl: partCancelCl, isNpg: isNpg, serviceCode: serviceCode }; transactionCancel(transactionCancelParams).then((rs: any) => { console.log(rs); if(rs.resultCode === "2024") { snackBar(t('transaction.cancel.passwordGroup.pleaseCheckPassword')); setRequestSuccess(false); } else { setRequestSuccess(true); } }).catch((e: any) => { setRequestSuccess(false); if(e.response?.data?.error?.message){ snackBar(e.response?.data?.error?.message); return; } }); } }; const onClickToClose = () => { setCancelOn(false); }; const onClickToChangeTab = (tab: CancelTabKeys) => { setTabAction(tab); }; useEffect(() => { callCancelInfo(); }, []); return ( <>
{ t('transaction.cancelTitle') }
{ !!partCancelCl && }
{ (tabAction === CancelTabKeys.All) && } { !!partCancelCl && (tabAction === CancelTabKeys.Part) && }
); };