import moment from 'moment'; import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useStore } from '@/shared/model/store'; import { IMAGE_ROOT } from '@/shared/constants/common'; import { PATHS } from '@/shared/constants/paths'; import { useNavigate } from '@/shared/lib/hooks/use-navigate'; import { BillingList } from '@/entities/transaction/ui/billing-list'; import { TransactionCategory, BillingRequestStatus, BillingProcessResult, BillingPaymentMethod, BillingSearchType, ListItemProps, BillingListParams, BillingListResponse, DetailData } from '@/entities/transaction/model/types'; import { useBillingListMutation } from '@/entities/transaction/api/use-billing-list-mutation'; import { useDownloadExcelMutation } from '@/entities/transaction/api/use-download-excel-mutation'; import { DEFAULT_PAGE_PARAM } from '@/entities/common/model/constant'; import { BillingFilter } from '@/entities/transaction/ui/filter/billing-filter'; import { SortTypeBox } from '@/entities/common/ui/sort-type-box'; import { getBillingRequestStatusBtnGroup } from '@/entities/transaction/model/contant'; import { SortTypeKeys, HeaderType, DefaultRequestPagination } from '@/entities/common/model/types'; import { useSetOnBack, useSetHeaderTitle, useSetHeaderType, useSetFooterMode } from '@/widgets/sub-layout/use-sub-layout'; import { EmailBottomSheet } from '@/entities/common/ui/email-bottom-sheet'; import useIntersectionObserver from '@/widgets/intersection-observer'; import { BillingDetail } from '@/entities/transaction/ui/detail/billing-detail'; import { showAlert } from '@/widgets/show-alert'; import { checkGrant } from '@/shared/lib/check-grant'; /* 빌링 34 */ const menuId = 34; export const BillingListPage = () => { const { navigate } = useNavigate(); const { t } = useTranslation(); const userMid = useStore.getState().UserStore.mid; const [onActionIntersect, setOnActionIntersect] = useState(false); const [sortType, setSortType] = useState(SortTypeKeys.LATEST); const [listItems, setListItems] = useState>([]); const [filterOn, setFilterOn] = useState(false); const [pageParam, setPageParam] = useState(DEFAULT_PAGE_PARAM); const [mid, setMid] = useState(userMid); const [searchType, setSearchType] = useState(BillingSearchType.ALL); const [searchKeyword, setSearchKeyword] = useState(''); const [startDate, setStartDate] = useState(moment().subtract(1, 'month').format('YYYYMMDD')); //const [startDate, setStartDate] = useState(moment().format('YYYYMMDD')); const [endDate, setEndDate] = useState(moment().format('YYYYMMDD')); const [requestStatus, setRequestStatus] = useState(BillingRequestStatus.ALL); const [processResult, setProcessResult] = useState(BillingProcessResult.ALL); const [paymentMethod, setPaymentMethod] = useState(BillingPaymentMethod.ALL); const [minAmount, setMinAmount] = useState(); const [maxAmount, setMaxAmount] = useState(); const [downloadBottomSheetOn, setDownloadBottomSheetOn] = useState(false); const [detailOn, setDetailOn] = useState(false); const [detailTid, setDetailTid] = useState(''); useSetHeaderTitle(t('billing.title')); useSetHeaderType(HeaderType.LeftArrow); useSetOnBack(() => { navigate(PATHS.home); }); useSetFooterMode(false); const { mutateAsync: billingList } = useBillingListMutation(); const { mutateAsync: downloadExcel } = useDownloadExcelMutation(); const onIntersect: IntersectionObserverCallback = (entries: Array) => { entries.forEach((entry: IntersectionObserverEntry) => { if(entry.isIntersecting){ if(onActionIntersect && !!pageParam.cursor){ setOnActionIntersect(false); callList('page'); } } }); }; const { setTarget } = useIntersectionObserver({ threshold: 1, onIntersect }); const callList = (type?: string) => { setOnActionIntersect(false); let listParams: BillingListParams = { mid: mid, searchType: searchType, searchKeyword: searchKeyword, startDate: startDate, endDate: endDate, requestStatus: requestStatus, processResult: processResult, paymentMethod: paymentMethod, minAmount: minAmount, maxAmount: maxAmount, page: { ...pageParam, ...{ sortType: sortType } } }; if(type !== 'page' && listParams.page){ listParams.page.cursor = null; } billingList(listParams).then((rs: BillingListResponse) => { if(type === 'page'){ setListItems([ ...listItems, ...rs.content ]); } else{ setListItems(rs.content); } if(rs.hasNext && rs.nextCursor !== pageParam.cursor && rs.content.length === DEFAULT_PAGE_PARAM.size ){ setPageParam({ ...pageParam, ...{ cursor: rs.nextCursor } }); } else{ setPageParam({ ...pageParam, ...{ cursor: null } }); } setOnActionIntersect( !!rs.hasNext && rs.nextCursor !== pageParam.cursor && rs.content.length === DEFAULT_PAGE_PARAM.size ); }); } const onClickToOpenFilter = () => { setFilterOn(!filterOn); }; const onClickToOpenDownloadBottomSheet = () => { if(checkGrant(menuId, 'D')){ setDownloadBottomSheetOn(true); } else{ showAlert(t('common.nopermission')); } }; const onClickToSort = (sort: SortTypeKeys) => { setSortType(sort); }; const onClickToRequestStatus = (val: BillingRequestStatus) => { setRequestStatus(val); }; const onClickToNavigate = () => { if(checkGrant(menuId, 'X')){ navigate(PATHS.transaction.billing.charge); } else{ showAlert(t('common.nopermission')); } }; const onRequestDownload = (userEmail?: string) => { }; const setDetailData = (detailData: DetailData) => { setDetailOn(detailData.detailOn); setDetailTid(detailData.tid); }; useEffect(() => { callList(); }, [ mid, searchType, searchKeyword, startDate, endDate, sortType, requestStatus, processResult, paymentMethod, minAmount, maxAmount ]); return ( <>
{ getBillingRequestStatusBtnGroup(t).map((value: any, index: number) => ( onClickToRequestStatus(value.value) } >{ value.name } )) }
{ !!downloadBottomSheetOn && } ); };