mirror of
https://github.com/serghey-rodin/vesta.git
synced 2025-08-20 13:24:24 -07:00
Fixed Packages, Firewall and Server tabs.
This commit is contained in:
parent
b7cf917141
commit
7540c9881d
27 changed files with 151 additions and 79 deletions
|
@ -17,16 +17,17 @@ export const getBanList = () => {
|
||||||
return axios.get(BASE_URL + banListUri);
|
return axios.get(BASE_URL + banListUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const bulkAction = (action, firewalls) => {
|
export const bulkAction = (action, ips, banIps) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("action", action);
|
formData.append("action", action);
|
||||||
formData.append("token", getAuthToken());
|
formData.append("token", getAuthToken());
|
||||||
|
|
||||||
firewalls.forEach(firewall => {
|
ips.forEach(ip => {
|
||||||
formData.append("rule[]", firewall);
|
const banIp = banIps.find(banIp => banIp.NAME === ip);
|
||||||
|
formData.append("ipchain[]", `${ip}:${banIp['CHAIN']}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
return axios.post(BASE_URL + '/api/v1/bulk/firewall/', formData);
|
return axios.post(BASE_URL + '/api/v1/bulk/firewall/banlist/', formData);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleAction = uri => {
|
export const handleAction = uri => {
|
||||||
|
@ -54,11 +55,13 @@ export const getBanIps = data => {
|
||||||
export const addBanIp = (data) => {
|
export const addBanIp = (data) => {
|
||||||
let formDataObject = new FormData();
|
let formDataObject = new FormData();
|
||||||
|
|
||||||
|
formDataObject.append('token', getAuthToken());
|
||||||
|
|
||||||
for (let key in data) {
|
for (let key in data) {
|
||||||
formDataObject.append(key, data[key]);
|
formDataObject.append(key, data[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return axios.get(BASE_URL + addBanIpsUri, {
|
return axios.post(BASE_URL + addBanIpsUri, formDataObject, {
|
||||||
params: {
|
params: {
|
||||||
token: getAuthToken()
|
token: getAuthToken()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getAuthToken } from "src/utils/token";
|
import { getAuthToken } from "src/utils/token";
|
||||||
|
|
||||||
const deleteAutoUpdateUri = '/delete/cron/autoupdate/';
|
const deleteAutoUpdateUri = '/api/v1/delete/cron/autoupdate/';
|
||||||
const addAutoUpdateUri = '/add/cron/autoupdate/';
|
const addAutoUpdateUri = '/api/v1/add/cron/autoupdate/';
|
||||||
const webApiUri = '/api/v1/list/updates/index.php';
|
const webApiUri = '/api/v1/list/updates/index.php';
|
||||||
const BASE_URL = window.location.origin;
|
const BASE_URL = window.location.origin;
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ $errorColor: #BE5ABF;
|
||||||
label.label-wrapper {
|
label.label-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
|
|
||||||
span {
|
span {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
.content .edit-template.add-firewall {
|
.content .edit-template.add-firewall {
|
||||||
.toolbar .search-toolbar-name {
|
.toolbar .search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
label.label-wrapper[for=ip] span {
|
label.label-wrapper[for=ip] span {
|
||||||
|
|
|
@ -43,15 +43,18 @@ const AddBanIP = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(newUser).length !== 0 && newUser.constructor === Object) {
|
if (Object.keys(newUser).length !== 0 && newUser.constructor === Object) {
|
||||||
|
setState({ ...state, loading: true });
|
||||||
addBanIp(newUser)
|
addBanIp(newUser)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
const { error_msg, ok_msg } = result.data;
|
const { error_msg, ok_msg } = result.data;
|
||||||
|
|
||||||
if (error_msg) {
|
if (error_msg) {
|
||||||
setState({ ...state, errorMessage: error_msg, okMessage: '' });
|
setState({ ...state, errorMessage: error_msg, okMessage: '', loading: false });
|
||||||
} else if (ok_msg) {
|
} else if (ok_msg) {
|
||||||
setState({ ...state, errorMessage: '', okMessage: ok_msg });
|
setState({ ...state, errorMessage: '', okMessage: ok_msg, loading: false });
|
||||||
|
} else {
|
||||||
|
setState({ ...state, loading: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -81,6 +84,8 @@ const AddBanIP = () => {
|
||||||
<AddItemLayout>
|
<AddItemLayout>
|
||||||
{state.loading ? <Spinner /> :
|
{state.loading ? <Spinner /> :
|
||||||
<form onSubmit={event => submitFormHandler(event)} id="add-user">
|
<form onSubmit={event => submitFormHandler(event)} id="add-user">
|
||||||
|
<input type="hidden" name="ok" value="add" />
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label htmlFor="chain">{i18n.Banlist}</label>
|
<label htmlFor="chain">{i18n.Banlist}</label>
|
||||||
<select class="form-control" id="chain" name="v_chain">
|
<select class="form-control" id="chain" name="v_chain">
|
||||||
|
|
|
@ -6,14 +6,13 @@ import { useSelector } from 'react-redux';
|
||||||
|
|
||||||
const Ban = ({ data, ...props }) => {
|
const Ban = ({ data, ...props }) => {
|
||||||
const { i18n } = useSelector(state => state.session);
|
const { i18n } = useSelector(state => state.session);
|
||||||
const token = localStorage.getItem("token");
|
|
||||||
|
|
||||||
const checkItem = () => {
|
const checkItem = () => {
|
||||||
props.checkItem(data.NAME);
|
props.checkItem(data.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
props.handleModal(data.delete_conf, `/api/v1/delete/firewall/banlist/?ip=${data.NAME}&chain=${data.CHAIN}`);
|
props.handleModal(data.delete_confirmation, `/api/v1/delete/firewall/banlist/?ip=${data.NAME}&chain=${data.CHAIN}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -32,10 +31,10 @@ const Ban = ({ data, ...props }) => {
|
||||||
<div></div>
|
<div></div>
|
||||||
</Container>
|
</Container>
|
||||||
<Container className="c-2 w-30">
|
<Container className="c-2 w-30">
|
||||||
<div>{data.CHAIN}</div>
|
<div><b>{data.CHAIN}</b></div>
|
||||||
</Container>
|
</Container>
|
||||||
<Container className="c-2 w-30">
|
<Container className="c-2 w-30">
|
||||||
<div>{data.NAME}</div>
|
<div><b>{data.NAME}</b></div>
|
||||||
</Container>
|
</Container>
|
||||||
</div>
|
</div>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
|
@ -13,8 +13,6 @@ import QS from 'qs';
|
||||||
|
|
||||||
import './EditFirewall.scss';
|
import './EditFirewall.scss';
|
||||||
import { Helmet } from 'react-helmet';
|
import { Helmet } from 'react-helmet';
|
||||||
import { checkAuthHandler } from 'src/actions/Session/sessionActions';
|
|
||||||
import { refreshCounters } from 'src/actions/MenuCounters/menuCounterActions';
|
|
||||||
import HtmlParser from 'react-html-parser';
|
import HtmlParser from 'react-html-parser';
|
||||||
|
|
||||||
const EditFirewall = props => {
|
const EditFirewall = props => {
|
||||||
|
@ -37,6 +35,11 @@ const EditFirewall = props => {
|
||||||
dispatch(removeFocusedElement());
|
dispatch(removeFocusedElement());
|
||||||
|
|
||||||
if (rule) {
|
if (rule) {
|
||||||
|
fetchData(rule);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const fetchData = rule => {
|
||||||
setState({ ...state, loading: true });
|
setState({ ...state, loading: true });
|
||||||
|
|
||||||
getFirewallInfo(rule)
|
getFirewallInfo(rule)
|
||||||
|
@ -51,7 +54,6 @@ const EditFirewall = props => {
|
||||||
})
|
})
|
||||||
.catch(err => console.error(err));
|
.catch(err => console.error(err));
|
||||||
}
|
}
|
||||||
}, []);
|
|
||||||
|
|
||||||
const submitFormHandler = event => {
|
const submitFormHandler = event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -64,7 +66,7 @@ const EditFirewall = props => {
|
||||||
if (Object.keys(updatedDomain).length !== 0 && updatedDomain.constructor === Object) {
|
if (Object.keys(updatedDomain).length !== 0 && updatedDomain.constructor === Object) {
|
||||||
setState({ ...state, loading: true });
|
setState({ ...state, loading: true });
|
||||||
|
|
||||||
updateFirewall(updatedDomain, state.data.domain)
|
updateFirewall(updatedDomain, state.data.rule)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
const { error_msg: errorMessage, ok_msg: okMessage } = result.data;
|
const { error_msg: errorMessage, ok_msg: okMessage } = result.data;
|
||||||
|
@ -72,12 +74,11 @@ const EditFirewall = props => {
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
setState({ ...state, errorMessage, okMessage, loading: false });
|
setState({ ...state, errorMessage, okMessage, loading: false });
|
||||||
} else {
|
} else {
|
||||||
dispatch(refreshCounters()).then(() => {
|
|
||||||
setState({ ...state, okMessage, errorMessage: '', loading: false });
|
setState({ ...state, okMessage, errorMessage: '', loading: false });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.then(() => fetchData(state.data.rule))
|
||||||
.catch(err => console.error(err));
|
.catch(err => console.error(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,18 @@ import './Firewall.scss';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
|
|
||||||
const Firewall = ({ data, ...props }) => {
|
const Firewall = ({ data, ...props }) => {
|
||||||
const token = localStorage.getItem("token");
|
|
||||||
const { i18n } = useSelector(state => state.session);
|
const { i18n } = useSelector(state => state.session);
|
||||||
|
|
||||||
const toggleFav = (starred) => {
|
const toggleFav = (starred) => {
|
||||||
if (starred) {
|
if (starred) {
|
||||||
props.toggleFav(props.data.NAME, 'add');
|
props.toggleFav(data.NAME, 'add');
|
||||||
} else {
|
} else {
|
||||||
props.toggleFav(props.data.NAME, 'delete');
|
props.toggleFav(data.NAME, 'delete');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkItem = () => {
|
const checkItem = () => {
|
||||||
props.checkItem(props.data.NAME);
|
props.checkItem(data.NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSuspend = () => {
|
const handleSuspend = () => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
.logs-list {
|
.logs-list {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
padding: 6px 12.5%;
|
padding: 6px 13%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.statistic-item {
|
.statistic-item {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
.content .edit-template.add-mail-account {
|
.content .edit-template.add-mail-account {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
form {
|
form {
|
||||||
|
|
|
@ -21,7 +21,7 @@ $textColor: #555;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
padding: 3px 10% 1px;
|
padding: 3px 13% 1px;
|
||||||
border-top: 1px solid #e0e0e0;
|
border-top: 1px solid #e0e0e0;
|
||||||
border-bottom: 1px solid #e0e0e0;
|
border-bottom: 1px solid #e0e0e0;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
label.label-wrapper {
|
label.label-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
|
|
||||||
span {
|
span {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.content .edit-template.edit-bind9 {
|
.content .edit-template.edit-bind9 {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.content .edit-template.edit-bind9 {
|
.content .edit-template.edit-bind9 {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ $textColor: #555;
|
||||||
padding: 7px 15px;
|
padding: 7px 15px;
|
||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
|
|
|
@ -4,7 +4,7 @@ $secondaryLight: #f8b014;
|
||||||
.content .edit-template.edit-httpd {
|
.content .edit-template.edit-httpd {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: $secondary;
|
color: $secondary;
|
||||||
|
@ -17,7 +17,7 @@ $secondaryLight: #f8b014;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link {
|
.link {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
margin-left: 15px;
|
margin-left: 15px;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.content .edit-template.edit-mysql {
|
.content .edit-template.edit-mysql {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@ $secondaryLight: #f8b014;
|
||||||
.content .edit-template.edit-nginx {
|
.content .edit-template.edit-nginx {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
.link {
|
.link {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
margin-left: 15px;
|
margin-left: 15px;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
|
|
|
@ -5,13 +5,13 @@ $textColor: #555;
|
||||||
.content .edit-template.edit-php {
|
.content .edit-template.edit-php {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
color: $textColor;
|
color: $textColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-toolbar-name,
|
.search-toolbar-name,
|
||||||
.link {
|
.link {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.content .edit-template.edit-pgsql {
|
.content .edit-template.edit-pgsql {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.content .edit-template.edit-service {
|
.content .edit-template.edit-service {
|
||||||
.toolbar {
|
.toolbar {
|
||||||
.search-toolbar-name {
|
.search-toolbar-name {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ $textColor: #555;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:nth-child(2) {
|
&:nth-child(2) {
|
||||||
width: fit-content;
|
width: max-content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,11 +233,11 @@ const BanLists = props => {
|
||||||
const { selection } = state;
|
const { selection } = state;
|
||||||
|
|
||||||
if (selection.length && action) {
|
if (selection.length && action) {
|
||||||
bulkAction(action, selection)
|
bulkAction(action, selection, state.banIps)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
toggleAll(false);
|
toggleAll(false);
|
||||||
fetchData().then(() => refreshMenuCounters());
|
fetchData();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => console.error(err));
|
.catch(err => console.error(err));
|
||||||
|
@ -261,15 +261,11 @@ const BanLists = props => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return displayModal(res.data.error, '');
|
return displayModal(res.data.error, '');
|
||||||
}
|
}
|
||||||
fetchData().then(() => refreshMenuCounters())
|
fetchData();
|
||||||
})
|
})
|
||||||
.catch(err => { setLoading(false); console.error(err); });
|
.catch(err => { setLoading(false); console.error(err); });
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshMenuCounters = () => {
|
|
||||||
dispatch(refreshCounters()).then(() => setLoading(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
const modalCancelHandler = () => {
|
const modalCancelHandler = () => {
|
||||||
setModal({ ...modal, visible: !modal.visible, text: '', actionUrl: '' });
|
setModal({ ...modal, visible: !modal.visible, text: '', actionUrl: '' });
|
||||||
}
|
}
|
||||||
|
@ -289,18 +285,18 @@ const BanLists = props => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
<div className="banlist-wrapper">
|
|
||||||
{loading
|
{loading
|
||||||
? <Spinner />
|
? <Spinner />
|
||||||
: (<>
|
: (<>
|
||||||
|
<div className="banlist-wrapper">
|
||||||
{banIps()}
|
{banIps()}
|
||||||
<div className="buttons-wrapper">
|
<div className="buttons-wrapper">
|
||||||
<div className="total">{state.totalAmount}</div>
|
<div className="total">{state.totalAmount}</div>
|
||||||
<button type="button" className="back" onClick={() => history.push('/list/firewall/')}>{i18n.Back}</button>
|
<button type="button" className="back" onClick={() => history.push('/list/firewall/')}>{i18n.Back}</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</>)
|
</>)
|
||||||
}
|
}
|
||||||
</div>
|
|
||||||
<Modal
|
<Modal
|
||||||
onSave={modalConfirmHandler}
|
onSave={modalConfirmHandler}
|
||||||
onCancel={modalCancelHandler}
|
onCancel={modalCancelHandler}
|
||||||
|
|
|
@ -1,10 +1,21 @@
|
||||||
.banlist-wrapper {
|
.banlist-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
> div {
|
> div {
|
||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.list-item {
|
||||||
|
.l-col {
|
||||||
|
div.star {
|
||||||
|
.checkbox + div {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.buttons-wrapper {
|
.buttons-wrapper {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
@ -18,7 +18,7 @@ div.content {
|
||||||
color: $textColor;
|
color: $textColor;
|
||||||
|
|
||||||
.toolbar {
|
.toolbar {
|
||||||
padding: 6px 12.5%;
|
padding: 6px 13%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rrd-item {
|
.rrd-item {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
color: #686868;
|
color: #686868;
|
||||||
|
|
||||||
.toolbar {
|
.toolbar {
|
||||||
padding: 6px 12.5%;
|
padding: 6px 13%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.l-col {
|
.l-col {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { bulkAction, getUpdatesList, enableAutoUpdate, disableAutoUpdate } from
|
||||||
import * as MainNavigation from '../../actions/MainNavigation/mainNavigationActions';
|
import * as MainNavigation from '../../actions/MainNavigation/mainNavigationActions';
|
||||||
import SearchInput from '../../components/MainNav/Toolbar/SearchInput/SearchInput';
|
import SearchInput from '../../components/MainNav/Toolbar/SearchInput/SearchInput';
|
||||||
import LeftButton from '../../components/MainNav/Toolbar/LeftButton/LeftButton';
|
import LeftButton from '../../components/MainNav/Toolbar/LeftButton/LeftButton';
|
||||||
|
import Modal from 'src/components/ControlPanel/Modal/Modal';
|
||||||
import Checkbox from '../../components/MainNav/Toolbar/Checkbox/Checkbox';
|
import Checkbox from '../../components/MainNav/Toolbar/Checkbox/Checkbox';
|
||||||
import Select from '../../components/MainNav/Toolbar/Select/Select';
|
import Select from '../../components/MainNav/Toolbar/Select/Select';
|
||||||
import Toolbar from '../../components/MainNav/Toolbar/Toolbar';
|
import Toolbar from '../../components/MainNav/Toolbar/Toolbar';
|
||||||
|
@ -27,6 +28,11 @@ const Updates = props => {
|
||||||
loading: false,
|
loading: false,
|
||||||
toggledAll: false
|
toggledAll: false
|
||||||
});
|
});
|
||||||
|
const [modal, setModal] = useState({
|
||||||
|
text: '',
|
||||||
|
visible: false,
|
||||||
|
actionUrl: ''
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(addActiveElement('/list/updates/'));
|
dispatch(addActiveElement('/list/updates/'));
|
||||||
|
@ -126,7 +132,7 @@ const Updates = props => {
|
||||||
...state,
|
...state,
|
||||||
selection: [],
|
selection: [],
|
||||||
updates: reformatData(result.data.data),
|
updates: reformatData(result.data.data),
|
||||||
autoUpdate: result.data.totalAmount,
|
autoUpdate: result.data.autoUpdate,
|
||||||
loading: false
|
loading: false
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -202,10 +208,16 @@ const Updates = props => {
|
||||||
|
|
||||||
if (selection.length && action !== 'apply to selected') {
|
if (selection.length && action !== 'apply to selected') {
|
||||||
bulkAction(action, selection)
|
bulkAction(action, selection)
|
||||||
.then(result => {
|
.then(res => {
|
||||||
if (result.status === 200) {
|
|
||||||
fetchData();
|
|
||||||
toggleAll(false);
|
toggleAll(false);
|
||||||
|
if (res.status === 200) {
|
||||||
|
if (res.data.error) {
|
||||||
|
setState({ ...state, loading: false });
|
||||||
|
return displayModal(res.data.error, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
displayModal(res.data.message, '');
|
||||||
|
fetchData();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => console.error(err));
|
.catch(err => console.error(err));
|
||||||
|
@ -215,13 +227,54 @@ const Updates = props => {
|
||||||
const handleAutoUpdate = () => {
|
const handleAutoUpdate = () => {
|
||||||
if (state.autoUpdate === 'Enabled') {
|
if (state.autoUpdate === 'Enabled') {
|
||||||
disableAutoUpdate()
|
disableAutoUpdate()
|
||||||
.then(() => fetchData())
|
.then(res => {
|
||||||
.catch(err => console.error(err));
|
if (res.data.error) {
|
||||||
|
setState({ ...state, loading: false });
|
||||||
|
return displayModal(res.data.error, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
displayModal(res.data.message, '');
|
||||||
|
fetchData();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
setState({ ...state, loading: false });
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
enableAutoUpdate()
|
enableAutoUpdate()
|
||||||
.then(() => fetchData())
|
.then(res => {
|
||||||
.catch(err => console.error(err));
|
if (res.data.error) {
|
||||||
|
setState({ ...state, loading: false });
|
||||||
|
return displayModal(res.data.error, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
displayModal(res.data.message, '');
|
||||||
|
fetchData();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
setState({ ...state, loading: false });
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const displayModal = (text, url) => {
|
||||||
|
setState({ ...state, loading: true });
|
||||||
|
setModal({
|
||||||
|
...modal,
|
||||||
|
visible: true,
|
||||||
|
text: text,
|
||||||
|
actionUrl: url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const modalCancelHandler = () => {
|
||||||
|
setModal({
|
||||||
|
...modal,
|
||||||
|
visible: false,
|
||||||
|
text: '',
|
||||||
|
actionUrl: ''
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const printAutoUpdateButtonName = () => {
|
const printAutoUpdateButtonName = () => {
|
||||||
|
@ -249,6 +302,11 @@ const Updates = props => {
|
||||||
</div>
|
</div>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
{state.loading ? <Spinner /> : updates()}
|
{state.loading ? <Spinner /> : updates()}
|
||||||
|
<Modal
|
||||||
|
onSave={modalCancelHandler}
|
||||||
|
onCancel={modalCancelHandler}
|
||||||
|
show={modal.visible}
|
||||||
|
text={modal.text} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue