'use client'; import './style.scss'; import { useState, useEffect } from 'react'; import { LoginLogType, WalletLogCategory } from '@/constants/common'; import { fetchApi, getDateTime } from '@/lib/utils/client'; import type { ChargeLogsResponse } from '@/types/response/account/chargeLogs'; import Loading from '@/app/component/Loading'; import Pagination from '@/app/component/Pagination'; import NavTabs from '../navTabs'; const STATUS_MAP: Record = { Paid: { label: '완료', cls: 'status--paid' }, Pending: { label: '대기', cls: 'status--pending' }, WaitingDeposit: { label: '입금대기', cls: 'status--pending' }, Failed: { label: '실패', cls: 'status--failed' }, Cancelled: { label: '취소', cls: 'status--cancelled' } }; const METHOD_MAP: Record = { Card: '신용카드', VirtualAccount: '가상계좌', Mobile: '휴대폰', Transfer: '계좌이체', NaverPay: '네이버페이', KakaoPay: '카카오페이', Payco: '페이코', Integrated: '통합결제' }; const TX_TYPE_MAP: Record = { Charge: '충전', RewardEarned: '보상 적립', Spend: '사용', Refund: '환불', Lock: '잠금', Unlock: '잠금 해제', Adjusted: '운영자 조정', OrderPay: '상점 결제', OrderRefund: '주문 환불', OrderChannelReward: '상점 채널 보상', OrderRefundChannelReward: '상점 보상 차감' }; const BALANCE_TYPE_MAP: Record = { PgCharged: 'PG 충전', Deposit: '예치금', Reward: '보상', Airdrop: '에어드랍', Locked: '잠금', Adjusted: '운영자 조정', StoreRevenue: '상점 수익' }; // 적립류 (+), 사용류 (-) 분류 — UI 표시용 부호 const EARN_TX_TYPES = new Set(['Charge', 'RewardEarned', 'Unlock', 'OrderChannelReward', 'OrderRefund', 'Refund']); export default function ChargeLogs() { const [error, setError] = useState(''); const [loading, setLoading] = useState(true); const [page, setPage] = useState(1); const [type, setType] = useState(LoginLogType.Today); const [category, setCategory] = useState(WalletLogCategory.Charge); const [data, setData] = useState({ total: 0, list: [] }); useEffect(() => { if (error) { alert(error); setError(''); } }, [error]); useEffect(() => { setLoading(true); fetchApi(`/api/mypage/charge-logs?type=${type}&category=${category}&page=${page}&perPage=20`).then((res) => { setData(res.data!); }).catch(err => { setError(err.message); }).finally(() => { setLoading(false); }); }, [type, category, page]); useEffect(() => { setPage(1); }, [type, category]); const tabItems = [ { label: "오늘", value: LoginLogType.Today }, { label: "1주일", value: LoginLogType.Week }, { label: "1개월", value: LoginLogType.Month }, { label: "3개월", value: LoginLogType.QuarterYear }, { label: "6개월", value: LoginLogType.HalfYear } ]; const categoryItems = [ { label: '전체', value: WalletLogCategory.All }, { label: '충전', value: WalletLogCategory.Charge }, { label: '적립', value: WalletLogCategory.Earn }, { label: '사용', value: WalletLogCategory.Spend }, { label: '환불', value: WalletLogCategory.Refund } ]; const getStatus = (status: string|null) => status ? (STATUS_MAP[status] ?? { label: status, cls: '' }) : { label: '', cls: '' }; const getMethod = (method: string|null) => method ? (METHOD_MAP[method] ?? method) : ''; const getTxType = (txType: string|null) => txType ? (TX_TYPE_MAP[txType] ?? txType) : ''; const getBalanceType = (bt: string|null) => bt ? (BALANCE_TYPE_MAP[bt] ?? bt) : ''; const isEarn = (txType: string|null) => txType !== null && EARN_TX_TYPES.has(txType); const isCharge = category === WalletLogCategory.Charge; return ( <>
{loading && }

(P) 충전 내역

합계: {data.total}
{tabItems.map((item, i) => ( ))}
{isCharge ? (
  • 일시
  • 주문번호
  • 결제 수단
  • 결제 금액
  • 캐시
  • 상태
) : (
  • 일시
  • 구분
  • 사유
  • 잔액 유형
  • 금액
  • 잔액 후
)}
{data.list.length > 0 ? ( data.list.map((row) => { if (isCharge || row.category === 'charge') { const st = getStatus(row.status); return (
{/* PC */}
  1. {getDateTime(row.paidAt ?? row.createdAt)}
  2. {row.orderID}
  3. {getMethod(row.paymentMethod)}
  4. {row.amount.toLocaleString()}원
  5. +{(row.pointAmount ?? 0).toLocaleString()}P
  6. {st.label}
{/* Mobile */}
); } // all/earn/spend/refund 행 const earn = isEarn(row.txType); const sign = earn ? '+' : '-'; const amountCls = earn ? 'amount-plus' : 'amount-minus'; return (
{/* PC */}
  1. {getDateTime(row.createdAt)}
  2. {getTxType(row.txType)}
  3. {row.reason}
  4. {getBalanceType(row.balanceType)}
  5. {sign}{row.amount.toLocaleString()}P
  6. {(row.balanceAfter ?? 0).toLocaleString()}P
{/* Mobile */}
); }) ) : (

기록이 없습니다.

)}
{data.list.length > 0 && ( )}
); }