import moment from 'moment'; import { IMAGE_ROOT } from "@/shared/constants/common"; import { useState, useEffect } from "react"; import { LinkPaymentHistoryFilter } from "./filter/link-payment-history-filter"; import { useNavigate } from '@/shared/lib/hooks/use-navigate'; import { PATHS } from "@/shared/constants/paths"; import { LinkPaymentHistoryList } from "./link-payment-history-list"; import { SortTypeBox } from '@/entities/common/ui/sort-type-box'; import { DefaultRequestPagination, SortTypeKeys } from '@/entities/common/model/types'; import { AdditionalServiceCategory, ProcessResult } from "../../model/types"; import { useExtensionLinkPayHistoryListMutation } from '../../api/link-payment/use-extension-link-pay-history-list-mutation'; import { DEFAULT_PAGE_PARAM } from '@/entities/common/model/constant'; import { useExtensionLinkPayHistoryDownloadExcelMutation } from '../../api/link-payment/use-extension-link-pay-history-download-excel-mutation'; import { useStore } from '@/shared/model/store'; import { ExtensionLinkPayHistoryListParams, LinkPaymentHistoryListItem, LinkPaymentPaymentMethod, LinkPaymentPaymentStatus, LinkPaymentSearchCl, LinkPaymentSendMethod, LinkPaymentSendStatus } from '../../model/link-pay/types'; import { EmailBottomSheet } from '@/entities/common/ui/email-bottom-sheet'; const paymentResultBtnGroup = [ { name: '전체', value: LinkPaymentPaymentStatus.ALL }, { name: '미완료/활성화', value: LinkPaymentPaymentStatus.ACTIVATE }, { name: '입금요청', value: LinkPaymentPaymentStatus.DEPOSIT_REQUEST }, { name: '결제완료', value: LinkPaymentPaymentStatus.PAYMENT_COMPLETE }, { name: '결제실패', value: LinkPaymentPaymentStatus.PAYMENT_FAIL }, { name: '결제중단/비활성화', value: LinkPaymentPaymentStatus.INACTIVE }, ]; export const LinkPaymentHistoryWrap = () => { const { navigate } = useNavigate(); const userMid = useStore.getState().UserStore.mid; const [filterOn, setFilterOn] = useState(false); const [sortType, setSortType] = useState(SortTypeKeys.LATEST); const [listItems, setListItems] = useState>([]); const [pageParam, setPageParam] = useState(DEFAULT_PAGE_PARAM); const [mid, setMid] = useState(userMid); const [searchCl, setSearchCl] = useState(LinkPaymentSearchCl.PHONE); const [searchValue, setSearchValue] = useState(''); const [paymentMethod, setPaymentMethod] = useState(LinkPaymentPaymentMethod.CARD); const [fromDate, setFromDate] = useState(moment().format('YYYYMMDD')); const [toDate, setToDate] = useState(moment().format('YYYYMMDD')); const [paymentStatus, setPaymentStatus] = useState(LinkPaymentPaymentStatus.ALL); const [sendStatus, setSendStatus] = useState(LinkPaymentSendStatus.ALL); const [sendMethod, setSendMethod] = useState(LinkPaymentSendMethod.ALL); const [emailBottomSheetOn, setEmailBottomSheetOn] = useState(false); const { mutateAsync: linkPayHistoryList } = useExtensionLinkPayHistoryListMutation(); const { mutateAsync: downloadExcel } = useExtensionLinkPayHistoryDownloadExcelMutation(); const onClickToNavigate = () => { navigate(PATHS.additionalService.linkPayment.request) }; const callList = (option?: { sortType?: SortTypeKeys, status?: LinkPaymentPaymentStatus }) => { let listParams: ExtensionLinkPayHistoryListParams = { mid: mid, searchCl: searchCl, searchValue: searchValue, fromDate: fromDate, toDate: toDate, paymentStatus: option?.status ?? paymentStatus, sendStatus: sendStatus, sendMethod: sendMethod, page: pageParam }; if (listParams.page) { listParams.page.sortType = option?.sortType || sortType; setPageParam(listParams.page); } linkPayHistoryList(listParams).then((rs) => { setListItems(rs.content); }); }; const onClickToOpenEmailBottomSheet = () => { setEmailBottomSheetOn(true); }; const onSendRequest = (selectedEmail?: string) => { if (selectedEmail) { downloadExcel({ mid: mid, email: selectedEmail, searchCl: searchCl, searchValue: searchValue, paymentMethod: paymentMethod, fromDate: fromDate, toDate: toDate, paymentStatus: paymentStatus, sendStatus: sendStatus, sendMethod: sendMethod, }).then((rs) => { console.log('Excel Download Status: ' + rs.status); }); } setEmailBottomSheetOn(false); }; const onClickPaymentStatus = (val: LinkPaymentPaymentStatus) => { setPaymentStatus(val); } const onClickToSort = (sort: SortTypeKeys) => { setSortType(sort); callList({ sortType: sort }); }; const onClickToOpenFilter = () => { setFilterOn(!filterOn); }; useEffect(() => { callList(); }, [ mid, searchCl, searchValue, paymentMethod, fromDate, toDate, paymentStatus, sendStatus, sendMethod ]); return ( <>
{ paymentResultBtnGroup.map((value, index) => ( onClickPaymentStatus(value.value)} >{value.name} )) }
); }