add notification message if user has no permission to edit config

This commit is contained in:
Maren Süwer
2018-08-16 13:28:46 +02:00
parent 08328bb95f
commit d9aa04e620
2 changed files with 35 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import ProxySettings from "./ProxySettings";
import GeneralSettings from "./GeneralSettings";
import BaseUrlSettings from "./BaseUrlSettings";
import AdminSettings from "./AdminSettings";
import Notification from "../../../components/Notification";
type Props = {
submitForm: Config => void,
@@ -17,7 +18,8 @@ type Props = {
};
type State = {
config: Config
config: Config,
showNotification: boolean
};
class ConfigForm extends React.Component<Props, State> {
@@ -48,15 +50,18 @@ class ConfigForm extends React.Component<Props, State> {
enabledXsrfProtection: true,
defaultNamespaceStrategy: "",
_links: {}
}
},
showNotification: false
};
}
componentDidMount() {
const { config } = this.props;
console.log(config);
const { config, configUpdatePermission } = this.props;
if (config) {
this.setState({ config: { ...config } });
this.setState({ ...this.state, config: { ...config } });
}
if (!configUpdatePermission) {
this.setState({ ...this.state, showNotification: true });
}
}
@@ -67,9 +72,23 @@ class ConfigForm extends React.Component<Props, State> {
render() {
const { loading, t, configUpdatePermission } = this.props;
let config = this.state.config;
const config = this.state.config;
let noPermissionNotification = null;
if (this.state.showNotification) {
noPermissionNotification = (
<Notification
type={"info"}
children={t("config-form.no-permission-notification")}
onClose={() => this.onClose()}
/>
);
}
return (
<form onSubmit={this.submit}>
{noPermissionNotification}
<GeneralSettings
realmDescription={config.realmDescription}
enableRepositoryArchive={config.enableRepositoryArchive}
@@ -132,6 +151,7 @@ class ConfigForm extends React.Component<Props, State> {
onChange = (isValid: boolean, changedValue: any, name: string) => {
if (isValid) {
this.setState({
...this.state,
config: {
...this.state.config,
[name]: changedValue
@@ -139,6 +159,13 @@ class ConfigForm extends React.Component<Props, State> {
});
}
};
onClose = () => {
this.setState({
...this.state,
showNotification: false
});
};
}
export default translate("config")(ConfigForm);