Added test logon
This commit is contained in:
@@ -2,15 +2,18 @@ import React from 'react';
|
||||
import Box from '../../components/UI/Box/Box';
|
||||
import Button from '../../components/UI/Button/Button';
|
||||
import DropDown from '../../components/UI/DropDown/DropDown';
|
||||
import IPCContainer from '../IPCContainer/IPCContainer';
|
||||
import PropTypes from 'prop-types';
|
||||
import Text from '../../components/UI/Text/Text';
|
||||
import { Component } from 'react';
|
||||
import { addEditHostAction } from '../../redux/actions/host_actions';
|
||||
import { connect } from 'react-redux';
|
||||
import { createDismissDisplay } from '../../utils.jsx';
|
||||
import { notifyError } from '../../redux/actions/error_actions';
|
||||
import { notifyApplicationBusy } from '../../redux/actions/common_actions';
|
||||
import { notifyError, notifyInfo } from '../../redux/actions/error_actions';
|
||||
|
||||
class AddEditHost extends Component {
|
||||
const Constants = require('../../constants');
|
||||
|
||||
class AddEditHost extends IPCContainer {
|
||||
state = {
|
||||
AgentString: '',
|
||||
ApiPassword: '',
|
||||
@@ -25,13 +28,19 @@ class AddEditHost extends Component {
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.setRequestHandler(Constants.IPC_Skynet_Test_Logon_Reply, this.onSkynetTestLogonReply);
|
||||
|
||||
if (this.props.HostData) {
|
||||
this.setState({ ...this.state, ...this.props.HostData });
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
super.componentWillUnmount();
|
||||
}
|
||||
|
||||
handleSave = () => {
|
||||
if (this.state.HostNameOrIp.trim().length == 0) {
|
||||
if (this.state.HostNameOrIp.trim().length === 0) {
|
||||
this.props.notifyError('Host / IP cannot be empty');
|
||||
return;
|
||||
}
|
||||
@@ -51,7 +60,7 @@ class AddEditHost extends Component {
|
||||
(i) =>
|
||||
(i.HostNameOrIp || '').trim() === this.state.HostNameOrIp &&
|
||||
i.Protocol === this.state.Protocol &&
|
||||
i.ApiPort == this.state.ApiPort
|
||||
i.ApiPort == this.state.ApiPort,
|
||||
)
|
||||
) {
|
||||
this.props.notifyError(`Portal already exists`);
|
||||
@@ -61,7 +70,33 @@ class AddEditHost extends Component {
|
||||
this.props.completeAddEditHost(this.state);
|
||||
};
|
||||
|
||||
handleTestLogon = () => {
|
||||
try {
|
||||
this.props.notifyApplicationBusy(true);
|
||||
this.sendRequest(Constants.IPC_Skynet_Test_Logon, {
|
||||
Version: this.props.InstalledVersion,
|
||||
AuthURL: this.state.AuthURL,
|
||||
AuthUser: this.state.AuthUser,
|
||||
AuthPassword: this.state.AuthPassword,
|
||||
});
|
||||
} catch (e) {
|
||||
this.props.notifyApplicationBusy(false);
|
||||
this.props.notifyError(e);
|
||||
}
|
||||
};
|
||||
|
||||
onSkynetTestLogonReply = (_, arg) => {
|
||||
this.props.notifyApplicationBusy(false);
|
||||
if (arg.data.Success) {
|
||||
this.props.notifyInfo('Logon was successful!');
|
||||
} else {
|
||||
this.props.notifyError(arg.data.Error);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const allowTestLogon = this.state.AuthURL && this.state.AuthUser;
|
||||
|
||||
return (
|
||||
<Box dxDark dxStyle={{ width: '430px', height: 'auto', padding: '5px' }}>
|
||||
{createDismissDisplay(this.props.Close)}
|
||||
@@ -154,7 +189,21 @@ class AddEditHost extends Component {
|
||||
</div>
|
||||
<div style={{ height: 'var(--default_spacing)' }} />
|
||||
<div style={{ display: 'flex', flexDirection: 'row' }}>
|
||||
<Text text={'Authentication URL (premium)'} textAlign={'left'} type={'Heading2'} />
|
||||
<Text noOwner text={'Authentication URL (premium)'}
|
||||
textAlign={'left'} type={'Heading2'} style={{ marginRight: 'auto' }} />
|
||||
{allowTestLogon ? (
|
||||
<a
|
||||
href={'#'}
|
||||
onClick={
|
||||
(e) => {
|
||||
this.handleTestLogon();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
>
|
||||
<u>test logon</u>
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
||||
<input
|
||||
@@ -191,13 +240,13 @@ class AddEditHost extends Component {
|
||||
<p>
|
||||
<b>
|
||||
{'Portal URL: ' +
|
||||
this.state.Protocol +
|
||||
'://' +
|
||||
this.state.HostNameOrIp +
|
||||
((this.state.Protocol === 'http' && this.state.ApiPort != 80) ||
|
||||
(this.state.Protocol === 'https' && this.state.ApiPort != 443)
|
||||
? ':' + this.state.ApiPort.toString()
|
||||
: '')}
|
||||
this.state.Protocol +
|
||||
'://' +
|
||||
this.state.HostNameOrIp +
|
||||
((this.state.Protocol === 'http' && this.state.ApiPort != 80) ||
|
||||
(this.state.Protocol === 'https' && this.state.ApiPort != 443)
|
||||
? ':' + this.state.ApiPort.toString()
|
||||
: '')}
|
||||
</b>
|
||||
</p>
|
||||
<div style={{ height: 'var(--default_spacing)' }} />
|
||||
@@ -212,6 +261,7 @@ const mapStateToProps = (state) => {
|
||||
return {
|
||||
HostData: state.host.HostData,
|
||||
HostList: state.host.HostList,
|
||||
InstalledVersion: state.relver.InstalledVersion,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -219,16 +269,21 @@ const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
Close: () => dispatch(addEditHostAction.complete(false)),
|
||||
completeAddEditHost: (host_data) => dispatch(addEditHostAction.complete(true, { host_data })),
|
||||
notifyApplicationBusy: (busy) => dispatch(notifyApplicationBusy(busy, true)),
|
||||
notifyError: (msg) => dispatch(notifyError(msg)),
|
||||
notifyInfo: (msg) => dispatch(notifyInfo(msg)),
|
||||
};
|
||||
};
|
||||
|
||||
AddEditHost.propTypes = {
|
||||
Close: PropTypes.func.isRequired,
|
||||
completeAddEditHost: PropTypes.func.isRequired,
|
||||
HostData: PropTypes.object,
|
||||
HostList: PropTypes.array.isRequired,
|
||||
InstalledVersion: PropTypes.string.isRequired,
|
||||
completeAddEditHost: PropTypes.func.isRequired,
|
||||
notifyApplicationBusy: PropTypes.func.isRequired,
|
||||
notifyError: PropTypes.func.isRequired,
|
||||
notifyInfo: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(AddEditHost);
|
||||
|
||||
Reference in New Issue
Block a user