import moment from 'moment'; import { useEffect, useState } from 'react'; import { IMAGE_ROOT } from '@/shared/constants/common'; import { HomeMonthParams, HomeMonthResponse, HomeOverviewParams, HomeOverviewResponse, Sales, Settlement, TopPaymentMethodInfo, TopSalesDayInfo, TopSalesTimeInfo } from '../model/types'; import { useHomeOverviewMutation } from '../api/use-home-overview-mutation'; import { useHomeMonthwMutation } from '../api/use-home-month-mutation'; import { NumericFormat } from 'react-number-format'; import { useNavigate } from '@/shared/lib/hooks'; import { PATHS } from '@/shared/constants/paths'; import { useStore } from '@/shared/model/store'; import { useTranslation } from 'react-i18next'; export const BoxContainer2 = () => { const { navigate } = useNavigate(); const { t, i18n } = useTranslation(); const userMid = useStore.getState().UserStore.mid; const [mid, setMid] = useState(userMid); const [searchMonth, setSearchMonth] = useState(moment().format('YYYYMM')); const [searchDate, setSearchDate] = useState(moment().format('YYYYMMDD')); const [sales, setSales] = useState(); const [settlement, setSettlement] = useState(); const [salesIncrease, setSalesIncrease] = useState(); const [settlementIncrease, setSettlementIncrease] = useState(); const [averageTransactionAmount, setAverageTransactionAmount] = useState(); const [dailyAverageSales, setDailyAverageSales] = useState(); const [dailyAverageCount, setDailyAverageCount] = useState(); const [topSalesDayInfo, setTopSalesDayInfo] = useState(); const [topSalesTimeInfo, setTopSalesTimeInfo] = useState(); const [topPaymentMethodInfo, setTopPaymentMethodInfo] = useState(); const { mutateAsync: homeMonth } = useHomeMonthwMutation(); const { mutateAsync: homeOverview } = useHomeOverviewMutation(); const callMonth = () => { let params: HomeMonthParams = { searchDate: searchMonth, mid: mid, }; homeMonth(params).then((rs: HomeMonthResponse) => { setSales(rs.sales); setSettlement(rs.settlement); let currentMonthAmount = rs.sales.currentMonthAmount; let previousMonthAmount = rs.sales.previousMonthAmount; if(currentMonthAmount && previousMonthAmount){ let increase = (currentMonthAmount - previousMonthAmount) / previousMonthAmount * 100; increase = Math.round(increase * 100) / 100; setSalesIncrease(increase); } let currentMonthSettlementAmount = rs.settlement.currentMonthSettlementAmount; let previousMonthSettlementAmount = rs.settlement.previousMonthSettlementAmount; if(currentMonthSettlementAmount && previousMonthSettlementAmount){ let increase = (currentMonthSettlementAmount - previousMonthSettlementAmount) / previousMonthSettlementAmount * 100; increase = Math.round(increase * 100) / 100; setSettlementIncrease(increase); } }); }; const callOverview = () => { let params: HomeOverviewParams = { searchDate: searchDate, mid: mid, }; homeOverview(params).then((rs: HomeOverviewResponse) => { setAverageTransactionAmount(rs.averageTransactionAmount); setDailyAverageSales(rs.dailyAverageSales); setDailyAverageCount(rs.dailyAverageCount); setTopSalesDayInfo(rs.topSalesDayInfo); setTopSalesTimeInfo(rs.topSalesTimeInfo); setTopPaymentMethodInfo(rs.topPaymentMethodInfo); }); }; useEffect(() => { callMonth(); callOverview(); }, []); const onClickToNavigate = () => { navigate(PATHS.settlement.list); }; const translateDayOfWeek = (koreanDay: string): string => { if (i18n.language !== 'en') return koreanDay; const dayMap: { [key: string]: string } = { '월요일': 'Monday', '화요일': 'Tuesday', '수요일': 'Wednesday', '목요일': 'Thursday', '금요일': 'Friday', '토요일': 'Saturday', '일요일': 'Sunday' }; return dayMap[koreanDay] || koreanDay; }; return ( <>

{t('home.salesSettlementStatus')}

({t('home.comparedToPreviousMonth')})

{t('home.totalSales')}

{t('home.money', { value: new Intl.NumberFormat('en-US').format(sales?.currentMonthAmount || 0) })} = 0)? 'plus': 'minus'}` }> = 0)? '↑ ': '↓ '}` } suffix='%' > {t('home.goToSales')}

{t('home.totalSettlement')}

{t('home.money', { value: new Intl.NumberFormat('en-US').format(settlement?.currentMonthSettlementAmount || 0) })} = 0)? 'plus': 'minus'}` }> = 0)? '↑ ': '↓ '}` } suffix='%' > {t('home.goToSales')}

{t('home.transactionInsights')}

({t('home.basedOnLastWeek')})

{t('home.averageTransactionAmount')}

{t('home.money', { value: new Intl.NumberFormat('en-US').format(averageTransactionAmount || 0) })}

{t('home.dailyAverageSalesAndCount')}

{t('home.money', { value: new Intl.NumberFormat('en-US').format(dailyAverageSales || 0) })} ()

{t('home.topSalesDays')}

    { topSalesDayInfo?.daySalesRatios.map((value, index) => (
  • { (index + 1) } { translateDayOfWeek(value.dayOfWeek) } { value.ratio + '%' }
  • )) }

{t('home.topSalesHours')}

    { topSalesTimeInfo?.timeSalesRatios.map((value, index) => (
  • { (index + 1) } { value.hour } { value.ratio + '%' }
  • )) }

{t('home.topPaymentMethods')}

    { topPaymentMethodInfo?.paymentMethodRatios.map((value, index) => (
  • { (index + 1) } { value.paymentMethod } { value.ratio + '%' }
  • )) }
); };