mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
Previously this was disabled (perhaps unintentionally due to the duplicate settings in the .eslintrc.js). Enable the lint rule and fix the violations. May fix JS build issues on case-sensitive filesystems.
93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
import React, { Component } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { connect } from 'react-redux';
|
|
import { size } from 'lodash';
|
|
|
|
import AppConfigForm from 'components/forms/admin/AppConfigForm';
|
|
import configInterface from 'interfaces/config';
|
|
import deepDifference from 'utilities/deep_difference';
|
|
import { renderFlash } from 'redux/nodes/notifications/actions';
|
|
import WarningBanner from 'components/WarningBanner';
|
|
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 { appConfig, dispatch } = this.props;
|
|
const diff = deepDifference(formData, appConfig);
|
|
|
|
dispatch(updateConfig(diff))
|
|
.then(() => {
|
|
dispatch(renderFlash('success', 'Settings updated!'));
|
|
|
|
return false;
|
|
})
|
|
.catch((errors) => {
|
|
if (errors.base) {
|
|
dispatch(renderFlash('error', errors.base));
|
|
}
|
|
|
|
return 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;
|
|
}
|
|
|
|
const formData = { ...appConfig, enable_smtp: smtpConfigured };
|
|
|
|
return (
|
|
<div className={`${baseClass} body-wrap`}>
|
|
<h1>App Settings</h1>
|
|
<WarningBanner
|
|
message="Email is not currently configured in Fleet. Many features rely on email to work."
|
|
onDismiss={onDismissSmtpWarning}
|
|
shouldShowWarning={shouldShowWarning}
|
|
/>
|
|
<AppConfigForm
|
|
formData={formData}
|
|
handleSubmit={onFormSubmit}
|
|
serverErrors={error}
|
|
smtpConfigured={smtpConfigured}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = ({ app }) => {
|
|
const { config: appConfig, error } = app;
|
|
|
|
return { appConfig, error };
|
|
};
|
|
|
|
export default connect(mapStateToProps)(AppSettingsPage);
|