add confirm box
This commit is contained in:
parent
27d2209ea2
commit
b07e51ef7c
@ -3,7 +3,7 @@
|
||||
* @param {string} msg
|
||||
* @param {function} act
|
||||
*/
|
||||
export const add_dialog_msg =(msg, act) => ({
|
||||
export const add_dialog_msg = (msg, act) => ({
|
||||
type: 'dialog_addmsg',
|
||||
msg: msg,
|
||||
act: act || null
|
||||
@ -16,6 +16,16 @@ export const remove_dialog_msg = () => ({
|
||||
type: 'dialog_remove_first'
|
||||
});
|
||||
|
||||
export const add_confirm = (msg, act = null) => ({
|
||||
type: 'confirm_addmsg',
|
||||
msg,
|
||||
act
|
||||
})
|
||||
|
||||
export const remove_confirm = () => ({
|
||||
type: 'confirm_remove'
|
||||
})
|
||||
|
||||
/**
|
||||
* set i18next object
|
||||
* @param {object} i18n i18next object
|
||||
@ -52,12 +62,12 @@ export const getRequest = (data = {}) => {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
mode:'cors'
|
||||
mode: 'cors'
|
||||
};
|
||||
let token = sessionStorage.getItem('token');
|
||||
if(token) json.headers['x-auth-token'] = token;
|
||||
if (token) json.headers['x-auth-token'] = token;
|
||||
|
||||
json.body = JSON.stringify({data});
|
||||
json.body = JSON.stringify({ data });
|
||||
|
||||
return json;
|
||||
}
|
||||
@ -68,11 +78,11 @@ export const get_network_info = () => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1){
|
||||
if (json.status != 1) {
|
||||
return dispatch(add_dialog_msg(json.message));
|
||||
}
|
||||
let j = {};
|
||||
if('data' in json && 'record' in json.data && json.data.record.length > 0) j = json.data.record[0];
|
||||
if ('data' in json && 'record' in json.data && json.data.record.length > 0) j = json.data.record[0];
|
||||
return dispatch(network_info(j));
|
||||
});
|
||||
}
|
||||
@ -87,7 +97,7 @@ export const set_network_info = (dhcpMode, ip, netmask, gateway, dns) => dispatc
|
||||
let type = dhcpMode ? 'dhcp' : 'manual';
|
||||
let req = getRequest();
|
||||
let json = {
|
||||
data:{
|
||||
data: {
|
||||
type,
|
||||
ip,
|
||||
netmask,
|
||||
@ -100,7 +110,7 @@ export const set_network_info = (dhcpMode, ip, netmask, gateway, dns) => dispatc
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(get_network_info());
|
||||
});
|
||||
}
|
||||
@ -111,11 +121,11 @@ export const get_system_time = () => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1){
|
||||
if (json.status != 1) {
|
||||
return dispatch(add_dialog_msg(json.message));
|
||||
}
|
||||
let t = '';
|
||||
if('data' in json && 'record' in json.data && json.data.record.length > 0) t = json.data.record[0].time;
|
||||
if ('data' in json && 'record' in json.data && json.data.record.length > 0) t = json.data.record[0].time;
|
||||
return dispatch(system_time(t));
|
||||
});
|
||||
}
|
||||
@ -127,12 +137,12 @@ const system_time = (time) => ({
|
||||
|
||||
export const set_system_time = time => dispatch => {
|
||||
dispatch(toggle_loading(1));
|
||||
let req = getRequest({time});
|
||||
let req = getRequest({ time });
|
||||
return fetch('/api/system/updatetime', req)
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(get_system_time());
|
||||
});
|
||||
}
|
||||
@ -144,7 +154,7 @@ export const get_user_list = () => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(user_list(json.data.record));
|
||||
});
|
||||
}
|
||||
@ -161,7 +171,7 @@ const userApi = (url, data = {}) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(get_user_list());
|
||||
});
|
||||
}
|
||||
@ -184,7 +194,7 @@ export const get_dio_info = () => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(dioinfo(json.data.rt.do || [], json.data.rt.di || []));
|
||||
});
|
||||
}
|
||||
@ -193,7 +203,7 @@ export const get_dio_status = () => dispatch => {
|
||||
return fetch('/api/dio/getio', getRequest())
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(diostatus(json.data.rt.do, json.data.rt.di));
|
||||
});
|
||||
}
|
||||
@ -202,7 +212,7 @@ export const set_do_status = (data) => dispatch => {
|
||||
return fetch('/api/dio/dotrun', getRequest(data))
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
})
|
||||
}
|
||||
|
||||
@ -212,7 +222,7 @@ export const set_dio_info = (data) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(get_dio_info());
|
||||
})
|
||||
}
|
||||
@ -229,11 +239,11 @@ const dioinfo = (dod, did) => ({
|
||||
|
||||
export const get_log_list = (p = 1) => dispatch => {
|
||||
dispatch(toggle_loading(1));
|
||||
return fetch('/api/log/getlog', getRequest({p}))
|
||||
return fetch('/api/log/getlog', getRequest({ p }))
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(loglist(json.data.record, json.data.page));
|
||||
});
|
||||
}
|
||||
@ -251,9 +261,9 @@ export const scan_leone = (data) => (dispatch, getState) => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
let {i18n} = getState();
|
||||
if(json.data.record.length == 0) return dispatch(add_dialog_msg(i18n&&i18n.t? i18n.t('tip.scan_empty') : ''));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
let { i18n } = getState();
|
||||
if (json.data.record.length == 0) return dispatch(add_dialog_msg(i18n && i18n.t ? i18n.t('tip.scan_empty') : ''));
|
||||
return dispatch(show_scan_leone(json.data.record));
|
||||
})
|
||||
}
|
||||
@ -264,7 +274,7 @@ export const clear_scan_leone = (clrRemote = false) => dispatch => {
|
||||
return fetch('/api/leone/clearscanleone', getRequest())
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
return ;
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
@ -276,18 +286,18 @@ export const add_scan_leone = (data) => dispatch => {
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
dispatch(clear_scan());
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(get_leone_list());
|
||||
})
|
||||
}
|
||||
|
||||
export const get_leone_list = (showLoading = true) => dispatch => {
|
||||
if(showLoading) dispatch(toggle_loading(1));
|
||||
if (showLoading) dispatch(toggle_loading(1));
|
||||
return fetch('/api/leone/getleonelist', getRequest())
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(leone_list(json.data.record, json.data.rt.status));
|
||||
});
|
||||
}
|
||||
@ -310,7 +320,7 @@ const leone_api = (url, data) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(get_leone_list());
|
||||
});
|
||||
}
|
||||
@ -340,8 +350,8 @@ export const io_cmd = (data, cb = null) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if(cb && typeof cb == 'function') return cb();
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (cb && typeof cb == 'function') return cb();
|
||||
});
|
||||
}
|
||||
|
||||
@ -351,7 +361,7 @@ export const get_iogroup_list = () => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(iogroup_list(json.data.record, json.data.rt.do, json.data.rt.leone));
|
||||
});
|
||||
}
|
||||
@ -369,7 +379,7 @@ const group_api = (url, data) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(get_iogroup_list());
|
||||
});
|
||||
}
|
||||
@ -390,7 +400,7 @@ export const get_select_list = (data) => dispatch => {
|
||||
return fetch('/api/system/getselectlist', getRequest(data))
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(select_list(json.data.record || []));
|
||||
})
|
||||
}
|
||||
@ -409,7 +419,7 @@ const schedule_api = (url, data) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(get_schedule_list());
|
||||
})
|
||||
}
|
||||
@ -428,7 +438,7 @@ export const get_schedule_list = () => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
return dispatch(schedule_list(json.data.record || [], json.data.rt.do || [], json.data.rt.leone || [], json.data.rt.iogroup || []));
|
||||
})
|
||||
}
|
||||
@ -452,7 +462,7 @@ export const clear_userlist = () => ({
|
||||
export const clear_dio = () => ({
|
||||
type: 'clear_dio'
|
||||
});
|
||||
export const clear_leone =() => ({
|
||||
export const clear_leone = () => ({
|
||||
type: 'clear_leone'
|
||||
});
|
||||
export const clear_log = () => ({
|
||||
@ -471,7 +481,7 @@ export const get_modbus_list = () => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1 ) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(modbus_list(json.data.record || []));
|
||||
});
|
||||
}
|
||||
@ -491,7 +501,7 @@ const modbus_api = (url, data) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(get_modbus_list());
|
||||
})
|
||||
}
|
||||
@ -514,7 +524,7 @@ export const get_mb_data = data => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(mb_data(data.id, json.data.rt.iolist || [], json.data.rt.aioset || []));
|
||||
})
|
||||
}
|
||||
@ -530,7 +540,7 @@ export const get_mb_iostatus = data => dispatch => {
|
||||
return fetch('/api/modbus/getiostatus', getRequest(data))
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(mb_iostatus(data.id, data.type, json.data.record || []));
|
||||
})
|
||||
}
|
||||
@ -548,8 +558,8 @@ const mb_iolist_api = (url, data) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(get_mb_data({id: data.devuid}));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(get_mb_data({ id: data.devuid }));
|
||||
});
|
||||
}
|
||||
|
||||
@ -559,8 +569,8 @@ const mb_aio_api = (url, data) => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(get_mb_data({id: data.devuid}));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(get_mb_data({ id: data.devuid }));
|
||||
});
|
||||
}
|
||||
|
||||
@ -590,7 +600,7 @@ export const get_mb_log = data => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(mb_log(json.data.record || []));
|
||||
});
|
||||
}
|
||||
@ -606,7 +616,7 @@ export const get_link_list = () => dispatch => {
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
dispatch(toggle_loading(0));
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(link_list(json.data.record || []))
|
||||
})
|
||||
}
|
||||
@ -623,7 +633,7 @@ const link_api = (url, data) => dispatch => {
|
||||
return fetch(url, getRequest(data))
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
dispatch(get_link_list());
|
||||
})
|
||||
}
|
||||
@ -642,9 +652,9 @@ export const get_dashboard = () => dispatch => {
|
||||
return fetch('/api/system/dashboard', getRequest())
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||
let rt = json.data.rt;
|
||||
dispatch(dashboard(rt.ip[0]? rt.ip[0].ip : '', rt.version[0]? rt.version[0].version : '', rt.di, rt.leone))
|
||||
dispatch(dashboard(rt.ip[0] ? rt.ip[0].ip : '', rt.version[0] ? rt.version[0].version : '', rt.di, rt.leone))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -75,13 +75,15 @@ class Location extends React.Component {
|
||||
|
||||
delLocation = (id) => {
|
||||
if(!id) return ;
|
||||
let {showDialog} = this.props;
|
||||
let {showDialog, callConfirm} = this.props;
|
||||
callConfirm('確定要刪除這筆定位點資料?', ()=>{
|
||||
fetch('/api/wristband/dellocation', getRequest({id}))
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if(json.status != 1) return showDialog(json.message);
|
||||
this.getList();
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -44,13 +44,16 @@ class WristbandInfo extends React.Component {
|
||||
|
||||
delWristband = (id) => {
|
||||
if(!id) return ;
|
||||
let {showDialog, callConfirm} = this.props;
|
||||
|
||||
callConfirm('確定要刪除這筆手環資料?', ()=>{
|
||||
fetch('/api/wristband/delwristband', getRequest({id}))
|
||||
.then(response=>response.json())
|
||||
.then(json=>{
|
||||
if(json.status!=1) return showDialog(json.message);
|
||||
this.getList();
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
openModal = (type, data = {}) => {
|
||||
|
15
src/components/ConfirmBox.js
Normal file
15
src/components/ConfirmBox.js
Normal file
@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import {Modal, Button} from 'semantic-ui-react';
|
||||
|
||||
const ConfirmBox = ({obj, getNext}) => (
|
||||
<Modal open={obj && obj.msg != '' ? true : false} onClose={() => getNext()} style={{zIndex: "2001"}}>
|
||||
<Modal.Content>{obj && obj.msg ? obj.msg : ''}</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={() => getNext(true, obj.act)} content="Submit" />
|
||||
<Button onClick={() => getNext()} content="Cancel" />
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
);
|
||||
|
||||
|
||||
export default ConfirmBox;
|
@ -1,5 +1,5 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { add_dialog_msg, toggle_loading } from '../../../actions';
|
||||
import { add_dialog_msg, toggle_loading, add_confirm } from '../../../actions';
|
||||
import LocationPage from '../../../components/AdminPage/Wristband/Location';
|
||||
|
||||
|
||||
@ -13,6 +13,9 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
},
|
||||
toggleLoading: (flag = false) => {
|
||||
dispatch(toggle_loading(flag));
|
||||
},
|
||||
callConfirm: (msg, act = null) => {
|
||||
dispatch(add_confirm(msg, act))
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { add_dialog_msg, toggle_loading } from '../../../actions';
|
||||
import { add_dialog_msg, toggle_loading, add_confirm } from '../../../actions';
|
||||
import WristbandInfo from '../../../components/AdminPage/Wristband/WristbandInfo';
|
||||
|
||||
|
||||
@ -13,6 +13,9 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
},
|
||||
toggleLoading: (flag = false) => {
|
||||
dispatch(toggle_loading(flag));
|
||||
},
|
||||
callConfirm: (msg, act = null) => {
|
||||
dispatch(add_confirm(msg, act))
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {connect} from 'react-redux';
|
||||
import {add_dialog_msg, toggle_loading} from '../../../actions';
|
||||
import { connect } from 'react-redux';
|
||||
import { add_dialog_msg, toggle_loading, add_confirm } from '../../../actions';
|
||||
import WristbandPage from '../../../components/AdminPage/Wristband';
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ import Datetime from 'react-datetime';
|
||||
import MainMenu from '../../containers/MenuControl';
|
||||
import Loading from '../../containers/LoadingControl';
|
||||
import Dialog from '../DialogControl';
|
||||
import ConfirmBox from '../ConfirmControl';
|
||||
import Dashboard from '../../containers/DashBoard';
|
||||
import {toggle_dashboard} from '../../actions'
|
||||
|
||||
@ -27,6 +28,7 @@ class AdmPage extends React.Component {
|
||||
<div style={{height: '100%'}}>
|
||||
<Loading />
|
||||
<Dialog />
|
||||
<ConfirmBox />
|
||||
<MainMenu i18n={i18n} >
|
||||
<Dashboard />
|
||||
{children}
|
||||
|
19
src/containers/ConfirmControl.js
Normal file
19
src/containers/ConfirmControl.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { connect } from 'react-redux';
|
||||
import ConfirmBox from '../components/ConfirmBox';
|
||||
import { remove_confirm } from '../actions'
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
obj: state.confirmbox[0] || null
|
||||
});
|
||||
|
||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
getNext: (doit = false, act = null) => {
|
||||
//get next dialog message
|
||||
if (doit) {
|
||||
if (typeof act == 'function') act();
|
||||
}
|
||||
dispatch(remove_confirm());
|
||||
}
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ConfirmBox);
|
15
src/reducers/confirmbox.js
Normal file
15
src/reducers/confirmbox.js
Normal file
@ -0,0 +1,15 @@
|
||||
const confirmbox = (state = [], action) => {
|
||||
switch (action.type) {
|
||||
case 'confirm_addmsg':
|
||||
return [...state, {
|
||||
msg: action.msg,
|
||||
act: action.act || null
|
||||
}];
|
||||
case 'confirm_remove':
|
||||
return state.slice(1);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export default confirmbox;
|
@ -1,16 +1,18 @@
|
||||
import {combineReducers} from 'redux';
|
||||
import { combineReducers } from 'redux';
|
||||
import dialog from './dialog';
|
||||
import i18n from './i18n';
|
||||
import ui from './ui';
|
||||
import sysinfo from './sysinfo';
|
||||
import lists from './lists';
|
||||
import confirmbox from './confirmbox';
|
||||
|
||||
const reducers = combineReducers({
|
||||
dialog,
|
||||
i18n,
|
||||
ui,
|
||||
sysinfo,
|
||||
lists
|
||||
lists,
|
||||
confirmbox
|
||||
});
|
||||
|
||||
export default reducers;
|
Loading…
Reference in New Issue
Block a user