toast 메시지 추가

alert 글로벌화
loading 글로벌화
This commit is contained in:
2025-04-25 15:33:21 +09:00
parent d2ac5b338e
commit 826459f304
50 changed files with 3211 additions and 2385 deletions

View File

@@ -38,13 +38,17 @@ import BattleEventSearchBar, {
useBattleEventSearch,
} from '../../components/ServiceManage/searchBar/BattleEventSearchBar';
import { getDateOnly, getTimeOnly, secondToMinutes } from '../../utils/date';
import { battleEventStatusType } from '../../assets/data/types';
import { alertTypes, battleEventStatusType } from '../../assets/data/types';
import { useAlert } from '../../context/AlertProvider';
import { useLoading } from '../../context/LoadingProvider';
const BattleEvent = () => {
const token = sessionStorage.getItem('token');
const userInfo = useRecoilValue(authList);
const { t } = useTranslation();
const tableRef = useRef(null);
const { showToast, showModal } = useAlert();
const {withLoading} = useLoading();
const [detailData, setDetailData] = useState({});
@@ -53,13 +57,8 @@ const BattleEvent = () => {
handleModalView,
handleModalClose
} = useModal({
stopConfirm: 'hidden',
stopComplete: 'hidden',
detail: 'hidden',
deleteConfirm: 'hidden',
deleteComplete: 'hidden'
});
const [alertMsg, setAlertMsg] = useState('');
const [modalType, setModalType] = useState('regist');
const {
@@ -141,50 +140,61 @@ const BattleEvent = () => {
return timeDiff < 3;
});
if(date_check){
setAlertMsg(t('LAND_AUCTION_DELETE_DATE_WARNING'));
showToast('LAND_AUCTION_DELETE_DATE_WARNING', {type: alertTypes.warning});
return;
}
if(selectedRows[0].status === landAuctionStatusType.auction_start || selectedRows[0].status === landAuctionStatusType.stl_end){
setAlertMsg(t('LAND_AUCTION_DELETE_STATUS_WARNING'));
showToast('LAND_AUCTION_DELETE_STATUS_WARNING', {type: alertTypes.warning});
return;
}
handleModalView('deleteConfirm');
showModal('BATTLE_EVENT_SELECT_DELETE', {
type: alertTypes.confirm,
onConfirm: () => handleModalSubmit('deleteConfirm')
});
break;
case "stop":
const select_item = selectedRows[0];
if(select_item.status === battleEventStatusType.running){
setAlertMsg(t('BATTLE_EVENT_STATUS_RUNNING_WARNING'));
showToast('BATTLE_EVENT_STATUS_RUNNING_WARNING', {type: alertTypes.warning});
return;
}
const isStopTimeCheck = isStopMinutes(select_item.event_start_dt);
if(isStopTimeCheck){
setAlertMsg(t('BATTLE_EVENT_STOP_5MINUTES_DATE_WARNING'));
showToast('BATTLE_EVENT_STOP_5MINUTES_DATE_WARNING', {type: alertTypes.warning});
return;
}
if(isRunningTime(select_item.event_start_dt, select_item.event_operation_time)){
setAlertMsg(t('BATTLE_EVENT_STATUS_RUNNING_WARNING'));
showToast('BATTLE_EVENT_STATUS_RUNNING_WARNING', {type: alertTypes.warning});
return;
}
handleModalView('stopConfirm');
showModal('BATTLE_EVENT_SELECT_STOP', {
type: alertTypes.confirm,
onConfirm: () => handleModalSubmit('stopConfirm')
});
break;
case "stopConfirm":
const stop_item = selectedRows[0];
await BattleEventStop(token, stop_item.id, stop_item).then(data => {
handleModalClose('stopConfirm');
await withLoading(async () => {
return await BattleEventStop(token, stop_item.id, stop_item);
}).then(data => {
if(data.result === "SUCCESS") {
handleModalView('stopComplete');
showToast('STOP_COMPLETE', {type: alertTypes.success});
handleSearch(updateSearchParams);
}else if(data.result === "ERROR_BATTLE_EVENT_STATUS_START_IMPOSSIBLE"){
setAlertMsg(t('BATTLE_EVENT_STATUS_RUNNING_WARNING'));
showToast('BATTLE_EVENT_STATUS_RUNNING_WARNING', {type: alertTypes.error});
}else{
setAlertMsg(t('STOP_FAIL'));
showToast('STOP_FAIL', {type: alertTypes.error});
}
}).catch(reason => {
setAlertMsg(t('API_FAIL'));
showToast('API_FAIL', {type: alertTypes.error});
});
break;
case "deleteConfirm":
let list = [];
let isChecked = false;
@@ -198,35 +208,24 @@ const BattleEvent = () => {
});
if(isChecked) {
setAlertMsg(t('LAND_AUCTION_WARNING_DELETE'))
handleModalClose('deleteConfirm');
showToast('LAND_AUCTION_WARNING_DELETE', {type: alertTypes.warning});
return;
}
await BattleEventDelete(token, list).then(data => {
handleModalClose('deleteConfirm');
if(data.result === "SUCCESS") {
handleModalView('deleteComplete');
showToast('DEL_COMPLETE', {type: alertTypes.success});
handleSearch(updateSearchParams);
}else if(data.result === "ERROR_AUCTION_STATUS_IMPOSSIBLE"){
setAlertMsg(t('LAND_AUCTION_ERROR_DELETE_STATUS'));
showToast('LAND_AUCTION_ERROR_DELETE_STATUS', {type: alertTypes.error});
}else{
setAlertMsg(t('DELETE_FAIL'));
showToast('DELETE_FAIL', {type: alertTypes.error});
}
}).catch(reason => {
setAlertMsg(t('API_FAIL'));
showToast('API_FAIL', {type: alertTypes.error});
});
break;
case "deleteComplete":
handleModalClose('deleteComplete');
window.location.reload();
break;
case "stopComplete":
handleModalClose('stopComplete');
window.location.reload();
break;
case "warning":
setAlertMsg('')
break;
}
}
@@ -332,45 +331,19 @@ const BattleEvent = () => {
<Pagination postsPerPage={searchParams.pageSize} totalPosts={dataList?.total_all} setCurrentPage={handlePageChange} currentPage={searchParams.currentPage} pageLimit={INITIAL_PAGE_LIMIT} />
{/*상세*/}
<BattleEventModal modalType={modalType} detailView={modalState.detailModal} handleDetailView={() => handleModalClose('detail')} content={detailData} setDetailData={setDetailData} configData={battleConfigData} rewardData={battleRewardData} />
<BattleEventModal
modalType={modalType}
detailView={modalState.detailModal}
handleDetailView={() =>{
handleModalClose('detail');
handleSearch(updateSearchParams);
}}
content={detailData}
setDetailData={setDetailData}
configData={battleConfigData}
rewardData={battleRewardData}
/>
{/*중단 확인*/}
<DynamicModal
modalType={modalTypes.confirmOkCancel}
view={modalState.stopConfirmModal}
handleCancel={() => handleModalClose('stopConfirm')}
handleSubmit={() => handleModalSubmit('stopConfirm')}
modalText={t('BATTLE_EVENT_SELECT_STOP')}
/>
{/*중단 완료*/}
<DynamicModal
modalType={modalTypes.completed}
view={modalState.stopCompleteModal}
handleSubmit={() => handleModalSubmit('stopComplete')}
modalText={t('STOP_COMPLETE')}
/>
{/*삭제 확인*/}
<DynamicModal
modalType={modalTypes.confirmOkCancel}
view={modalState.deleteConfirmModal}
handleCancel={() => handleModalClose('deleteConfirm')}
handleSubmit={() => handleModalSubmit('deleteConfirm')}
modalText={t('BATTLE_EVENT_SELECT_DELETE')}
/>
{/*삭제 완료*/}
<DynamicModal
modalType={modalTypes.completed}
view={modalState.deleteCompleteModal}
handleSubmit={() => handleModalSubmit('deleteComplete')}
modalText={t('DEL_COMPLETE')}
/>
{/* 경고 모달 */}
<DynamicModal
modalType={modalTypes.completed}
view={alertMsg ? 'view' : 'hidden'}
modalText={alertMsg}
handleSubmit={() => handleModalSubmit('warning')}
/>
</>
)
};