mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
* consistent error handling * Display server errors in InviteUserForm * Handle errors in Form component * Refactors query form * creates KolideAce component * Renders QueryForm from query page and manage hosts page * Moves ace editor and select targets dropdown to query form * Render base errors in Form HOC * LoginPage and ForgotPasswordPage server errors * Ensure unique key for user blocks * Adds base error to login form and forgot password form * Adds base error to query form * Adds base error to Pack Form * Adds errors to confirm invite form * Adds clearErrors action * clear errors when confirm invite page unmounts * Handle errors in the App Setting page * Handle server errors in the User Settings Page * Handle server errors in the User Management Page
81 lines
2 KiB
JavaScript
81 lines
2 KiB
JavaScript
import React, { Component, PropTypes } from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { size } from 'lodash';
|
|
|
|
import AppConfigForm from 'components/forms/admin/AppConfigForm';
|
|
import configInterface from 'interfaces/config';
|
|
import { renderFlash } from 'redux/nodes/notifications/actions';
|
|
import SmtpWarning from 'pages/Admin/AppSettingsPage/SmtpWarning';
|
|
import { updateConfig } from 'redux/nodes/app/actions';
|
|
|
|
export const baseClass = 'app-settings';
|
|
|
|
class AppSettingsPage extends Component {
|
|
static propTypes = {
|
|
appConfig: configInterface,
|
|
dispatch: PropTypes.func.isRequired,
|
|
error: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|
|
};
|
|
|
|
constructor (props) {
|
|
super(props);
|
|
|
|
this.state = { showSmtpWarning: true };
|
|
}
|
|
|
|
onDismissSmtpWarning = () => {
|
|
this.setState({ showSmtpWarning: false });
|
|
|
|
return false;
|
|
}
|
|
|
|
onFormSubmit = (formData) => {
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(updateConfig(formData))
|
|
.then(() => {
|
|
dispatch(renderFlash('success', 'Settings updated!'));
|
|
|
|
return false;
|
|
})
|
|
.catch(() => false);
|
|
|
|
return false;
|
|
}
|
|
|
|
render () {
|
|
const { appConfig, error } = this.props;
|
|
const { onDismissSmtpWarning, onFormSubmit } = this;
|
|
const { showSmtpWarning } = this.state;
|
|
const { configured: smtpConfigured } = appConfig;
|
|
const shouldShowWarning = !smtpConfigured && showSmtpWarning;
|
|
|
|
if (!size(appConfig)) {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
<div className={`${baseClass} body-wrap`}>
|
|
<h1>App Settings</h1>
|
|
<SmtpWarning
|
|
onDismiss={onDismissSmtpWarning}
|
|
shouldShowWarning={shouldShowWarning}
|
|
/>
|
|
<AppConfigForm
|
|
formData={appConfig}
|
|
serverErrors={error}
|
|
handleSubmit={onFormSubmit}
|
|
smtpConfigured={smtpConfigured}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = ({ app }) => {
|
|
const { config: appConfig, error } = app;
|
|
|
|
return { appConfig, error };
|
|
};
|
|
|
|
export default connect(mapStateToProps)(AppSettingsPage);
|