import React, { useState, Fragment, useRef } from 'react'; import { useRecoilValue } from 'recoil'; import { useTranslation } from 'react-i18next'; import 'react-datepicker/dist/react-datepicker.css'; import { authList } from '../../store/authList'; import { authType, commonStatus, ViewTitleCountType, caliumStatus } from '../../assets/data'; import { Title, FormWrapper, TableStyle, TableWrapper, PopupMessage } from '../../styles/Components'; import { StatusWapper, ChargeBtn, StatusLabel, } from '../../styles/ModuleComponents'; import {Button, ExcelDownButton, Pagination, ViewTableInfo} from '../../components/common'; import { convertKTC, truncateText } from '../../utils'; import { CaliumRequestRegistModal } from '../../components/UserManage'; import { CaliumCharge, LogHistory } from '../../apis'; import { useModal, withAuth } from '../../hooks/hook'; import { CommonSearchBar, useCommonSearch } from '../../components/ServiceManage'; import { INITIAL_PAGE_LIMIT } from '../../assets/data/adminConstants'; import { useAlert } from '../../context/AlertProvider'; import { useLoading } from '../../context/LoadingProvider'; import { alertTypes } from '../../assets/data/types'; import useCommonSearchOld from '../../hooks/useCommonSearchOld'; import LogDetailModal from '../../components/common/modal/LogDetailModal'; import { historyTables } from '../../assets/data/data'; const CaliumRequest = () => { const token = sessionStorage.getItem('token'); const userInfo = useRecoilValue(authList); const { t } = useTranslation(); const { showModal, showToast } = useAlert(); const {withLoading} = useLoading(); const tableRef = useRef(null); const [selectCharge, setSelectCharge] = useState({}); const [historyData, setHistoryData] = useState({}); const { modalState, handleModalView, handleModalClose } = useModal({ register: 'hidden', history: 'hidden' }); const { config, searchParams, data: dataList, handleSearch, handleReset, handlePageChange, handlePageSizeChange, handleOrderByChange, updateSearchParams, configLoaded } = useCommonSearchOld("caliumRequestSearch"); const handleSubmit = async (type, param = null) => { switch (type) { case "history": const params = {}; params.db_type = "MYSQL" params.sql_id = param.id; params.table_name = historyTables.caliumRequest await LogHistory(token, params).then(data => { setHistoryData(data); handleModalView('history'); }); break; case "detail": showModal(param, { type: alertTypes.info }); break; case "chargedConfirm": setSelectCharge({id: param.id, count: param.count}); showModal('CALIUM_CHARGE_CONFIRM', { type: alertTypes.confirm, onConfirm: () => handleSubmit('charged') }); break; case "charged": await withLoading( async () => { return await CaliumCharge(token, selectCharge); }).then(data => { if(data.result === "SUCCESS") { showToast('CHARGE_COMPLTED', {type: alertTypes.success}); }else if(data.result === "ERROR_CALIUM_FINISH") { showToast('CHARGE_FINISH_FAIL', {type: alertTypes.error}); }else{ showToast('CHARGE_FAIL', {type: alertTypes.error}); } }).catch(error => { showToast('API_FAIL', {type: alertTypes.error}); }).finally(() =>{ setSelectCharge({}); handleSearch(updateSearchParams); }); break; } } return ( <> 칼리움 사용 수량 요청 { if (executeSearch) { handleSearch(newParams); } else { updateSearchParams(newParams); } }} onReset={handleReset} /> {userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === authType.eventUpdate) && (