import { ChangeEvent, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { PATHS } from '@/shared/constants/paths'; import { IMAGE_ROOT } from '@/shared/constants/common'; import { useNavigate } from '@/shared/lib/hooks/use-navigate'; import { CalendarType, HeaderType } from '@/entities/common/model/types'; import { useBillingChargeMutation } from '@/entities/transaction/api/use-billing-charge-mutation'; import { useSetOnBack, useSetHeaderTitle, useSetHeaderType, useSetFooterMode } from '@/widgets/sub-layout/use-sub-layout'; import { NumericFormat, PatternFormat } from 'react-number-format'; import { showAlert } from '@/widgets/show-alert'; import moment from 'moment'; import NiceCalendar from '@/shared/ui/calendar/nice-calendar'; import { notiBar, snackBar } from '@/shared/lib'; import { BillingChargeParams, BillingChargeResponse } from '@/entities/transaction/model/types'; import { useKeyboardAware } from '@/shared/lib/hooks/use-keyboard-aware'; export const BillingChargePage = () => { const { navigate } = useNavigate(); const { t } = useTranslation(); const [billKey, setBillKey] = useState(''); const [productName, setProductName] = useState(''); const [productAmount, setProductAmount] = useState(0); const [orderNumber, setOrderNumber] = useState(''); const [buyerName, setBuyerName] = useState(''); const [paymentRequestDate, setPaymentRequestDate] = useState(moment().format('YYYY.MM.DD')); const [installmentMonth, setInstallmentMonth] = useState('00'); const [calendarOpen, setCalendarOpen] = useState(false); const { handleInputFocus, keyboardAwarePadding } = useKeyboardAware(); useSetHeaderTitle(t('billing.charge')); useSetHeaderType(HeaderType.RightClose); useSetOnBack(() => { navigate(PATHS.transaction.billing.list); }); useSetFooterMode(false); const { mutateAsync: billingCharge } = useBillingChargeMutation(); const setNewDate = (date: string) => { setPaymentRequestDate(moment(date).format('YYYY.MM.DD')); setCalendarOpen(false); }; const onClickToOpenCalendar = () => { setCalendarOpen(true); }; const onClickToBillingCharge = () => { if (!billKey) { showAlert('빌키는 필수 입력 항목입니다.'); return; } else if (!productName) { showAlert('상품명은 필수 입력 항목입니다.'); } else if (!productAmount) { showAlert('상품금액은 필수 입력 항목입니다.'); } else if (productAmount <= 0) { showAlert('상품금액은 0보다 커야 합니다.'); } else if (!orderNumber) { showAlert('주문번호는 필수 입력 항목입니다.'); } else if (!buyerName) { showAlert('구매자명은 필수 입력 항목입니다.'); } let params: BillingChargeParams = { billKey: billKey, productName: productName, productAmount: productAmount, orderNumber: orderNumber, buyerName: buyerName, paymentRequestDate: moment(paymentRequestDate).format('YYYYMMDD'), installmentMonth: installmentMonth }; billingCharge(params).then((rs: BillingChargeResponse) => { snackBar('결제 신청을 성공하였습니다.', function () { navigate(PATHS.transaction.billing.list); }, 3000); }).catch((e: any) => { if (e.response?.data?.error?.message) { snackBar(e.response?.data?.error?.message); return; } }); }; const onChangeBillKey = (value: string) => { const pattern = /^[A-Za-z0-9]+$/; if (pattern.test(value) || value === '') { setBillKey(value); } }; const makeInstallmentMonthSelect = () => { let rs = []; rs.push( ); rs.push( ); for (let i = 2; i <= 24; i++) { let val = (i < 10) ? '0' + i : '' + i; rs.push( ); }; return rs; }; return ( <>
결제 정보 입력
빌키 *
) => onChangeBillKey(e.target.value)} onFocus={handleInputFocus} />
상품명 *
) => setProductName(e.target.value)} onFocus={handleInputFocus} />
상품금액 *
) => setProductAmount(parseInt(e.target.value))} onFocus={handleInputFocus} >
주문번호 *
) => setOrderNumber(e.target.value)} onFocus={handleInputFocus} />
구매자명 *
) => setBuyerName(e.target.value)} onFocus={handleInputFocus} />
결제 요청일자
할부 개월
); };